7 import "GuiApplication"
28 #if !defined(ECERE_VANILLA) && !defined(ECERE_NO3D)
32 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
41 // Had to define this here for native decorations support, because the menu bar is part of total decoration's size, but not part of the system decorations
42 define skinMenuHeight = 25;
43 define statusBarHeight = 18;
45 default extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
47 public enum DialogResult { cancel, yes, no, ok };
49 public class MouseButtons
52 bool left:1, right:1, middle:1;
55 public struct SizeAnchor
58 bool isClientW, isClientH;
63 #define SNAPDOWN(x, d) \
66 if(x < 0) x -= ((d) - Abs(x) % (d)); else x -= x % (d); \
69 #define SNAPUP(x, d) \
72 if(x > 0) x += ((d) - Abs(x) % (d)); else x += x % (d); \
75 /*static */define MAX_DIRTY_BACK = 10;
77 /////////////////////////////////////////////////////////////////////////////
78 ////////// EXTENT MANIPULATION //////////////////////////////////////////////
79 /////////////////////////////////////////////////////////////////////////////
81 #define ACCESS_ITEM(l, id) \
84 #define FASTLIST_LOOP(l, v) \
85 for(v = (BoxItem)l.first; v; v = (BoxItem)v.next)
87 #define FASTLIST_LOOPN(l, v, n) \
88 for(v = (BoxItem)l.first, n = (BoxItem)(v ? v.next : null); v; v = (BoxItem)next, n = (BoxItem)(v ? v.next : null))
91 #define ACCESS_ITEM(l, id) \
92 ((FastItem)(((id) == -1) ? null : (((byte *)((l).items)) + (id) * (l).itemSize)))
94 #define FASTLIST_LOOP(l, v) \
95 for(v = (void *)ACCESS_ITEM((l), (l).first); v; v = (void *)ACCESS_ITEM((l), v.next))
97 #define FASTLIST_LOOPN(l, v, n) \
98 for( v = (void *)ACCESS_ITEM((l), (l).first), \
99 n = v ? ((void *)ACCESS_ITEM((l), v.next)): null; \
100 v; v = n, n = n ? (void *)ACCESS_ITEM((l), n.next) : null)
103 private class FastItem : struct
108 private struct FastList
113 int count, size, itemSize;
120 first = last = free = -1;
128 // FASTLIST_LOOPN(this, item, next) { Delete(item); };
131 FastItem Add(uint itemSize)
134 if(free == -1 || !size)
141 newSize = (size + (size >> 1));
142 items = (FastItem)renew items byte[newSize * itemSize];
147 this.itemSize = itemSize;
148 items = (FastItem)new byte[newSize * itemSize];
151 for(c = size; c<newSize-1; c++)
153 ACCESS_ITEM(this, c).prev = -1;
154 ACCESS_ITEM(this, c).next = c+1;
156 ACCESS_ITEM(this, c).prev = -1;
157 ACCESS_ITEM(this, c).next = -1;
161 item = ACCESS_ITEM(this, free);
164 ACCESS_ITEM(this, item.prev).next = free;
174 void Delete(FastItem item)
177 ACCESS_ITEM(this, item.prev).next = item.next;
179 ACCESS_ITEM(this, item.next).prev = item.prev;
181 if(ACCESS_ITEM(this, first) == item)
183 if(ACCESS_ITEM(this, last) == item)
188 free = ((byte *)item - (byte *)items) / itemSize;
196 free = first = last = -1;
200 private class BoxItem : Item //FastItem
205 public /*private */struct Extent : OldList //FastList
214 //BoxItem extentBox = (BoxItem)Add(sizeof(class BoxItem));
215 Add(BoxItem { box = box });
218 void Copy(Extent source)
224 //FASTLIST_LOOP(source, extentBox)
225 for(extentBox = (BoxItem)source.first; extentBox; extentBox = (BoxItem)extentBox.next)
226 AddBox(extentBox.box);
229 void IntersectBox(Box box)
231 // Clip all boxes of extent against inside of the new box
232 BoxItem extentBox, next;
234 //FASTLIST_LOOPN(this, extentBox, next) // Macros still mess up the parser!
235 for(extentBox = (BoxItem)this.first; extentBox; extentBox = next)
237 next = (BoxItem)extentBox.next;
238 if(box.left > extentBox.box.left) extentBox.box.left = box.left;
239 if(box.top > extentBox.box.top) extentBox.box.top = box.top;
240 if(box.right < extentBox.box.right) extentBox.box.right = box.right;
241 if(box.bottom < extentBox.box.bottom) extentBox.box.bottom = box.bottom;
242 if(extentBox.box.right < extentBox.box.left || extentBox.box.bottom < extentBox.box.top)
247 void ExcludeBox(Box box, Extent temp)
254 for(extentBox = (BoxItem)temp.first; extentBox; extentBox = (BoxItem)extentBox.next)
256 if(extentBox.box.left < box.right && extentBox.box.right > box.left &&
257 extentBox.box.top < box.bottom && extentBox.box.bottom > box.top)
260 if(extentBox.box.top < box.top && extentBox.box.bottom >= box.top)
264 extentBox.box.left, extentBox.box.top,
265 extentBox.box.right, Min(extentBox.box.bottom, box.top -1)
271 if(extentBox.box.bottom > box.bottom && extentBox.box.top <= box.bottom)
275 extentBox.box.left, Max(extentBox.box.top,box.bottom +1),
276 extentBox.box.right, extentBox.box.bottom
282 if(extentBox.box.bottom >= box.top && extentBox.box.top <= box.bottom)
285 if(extentBox.box.left < box.left && extentBox.box.right >= box.left)
289 extentBox.box.left, Max(extentBox.box.top, box.top),
290 Min(extentBox.box.right, box.left-1), Min(extentBox.box.bottom, box.bottom)
296 if(extentBox.box.right > box.right && extentBox.box.left <= box.right)
300 Max(extentBox.box.left, box.right+1), Max(extentBox.box.top, box.top),
301 extentBox.box.right, Min(extentBox.box.bottom, box.bottom)
309 AddBox(extentBox.box);
315 void UnionBox(Box box, Extent temp)
317 BoxItem extentBox, next;
319 // First pass: check if this box is not already covered by one of the extent's box
320 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
322 if(extentBox.box.left <= box.left && extentBox.box.right >= box.right &&
323 extentBox.box.top <= box.top && extentBox.box.bottom >= box.bottom)
330 // Second pass: only keep boxes not completely covered in the new box
331 for(extentBox = (BoxItem)this.first; extentBox; extentBox = next)
333 next = (BoxItem)extentBox.next;
334 if(extentBox.box.left >= box.left && extentBox.box.right <= box.right &&
335 extentBox.box.top >= box.top && extentBox.box.bottom <= box.bottom)
339 // Add the exclusion to the extent
340 ExcludeBox(box, temp);
343 if(box.bottom >= box.top && box.right >= box.left)
345 // Optimization: if the resulting boxes touch, add them smarter
346 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
348 if(box.top == extentBox.box.top && box.bottom == extentBox.box.bottom)
350 if(Abs(box.right - extentBox.box.left) <= 1)
352 extentBox.box.left = box.left;
355 else if(Abs(box.left - extentBox.box.right) <= 1)
357 extentBox.box.right = box.right;
361 else if(box.left == extentBox.box.left && box.right == extentBox.box.right)
363 if(Abs(box.bottom - extentBox.box.top) <= 1)
365 extentBox.box.top = box.top;
368 else if(Abs(box.top - extentBox.box.bottom) <= 1)
370 extentBox.box.bottom = box.bottom;
382 void Union(Extent b, Extent temp)
386 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
387 UnionBox(extentBox.box, temp);
390 void Intersection(Extent b, Extent temp, Extent temp2, Extent temp3)
397 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
400 temp2.IntersectBox(extentBox.box);
407 void Exclusion(Extent b, Extent temp)
410 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
411 ExcludeBox(extentBox.box, temp);
414 void Offset(int x, int y)
417 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
419 extentBox.box.left += x;
420 extentBox.box.top += y;
421 extentBox.box.right += x;
422 extentBox.box.bottom += y;
427 private define MINIMIZED_WIDTH = 160;
428 private define CASCADE_SPACE = 16;
430 // namespace Windows;
432 private class ScrollFlags
434 bool snapX:1, snapY:1, dontHide:1;
437 public class BorderBits { public: bool contour:1, fixed:1, sizable:1, deep:1, bevel:1, thin:1; };
439 class WindowBits : BorderBits
441 BorderBits borderBits:6:0;
442 bool hidden:1, isActiveClient:1, hasHorzScroll:1, hasVertScroll:1, stayOnTop:1, modal:1, isDefault:1, inactive:1, isRemote:1, drawBehind:1;
443 bool interim:1, tabCycle:1, noCycle:1, dontScrollHorz:1, dontScrollVert:1, hasMaximize:1, hasMinimize:1, hasClose:1;
444 bool embedded:1, hasMenuBar:1, isDocument:1, showInTaskBar:1, hasStatusBar:1, nonClient:1, clickThrough:1;
447 public enum BorderStyle : BorderBits
450 contour = BorderBits { contour = true },
451 fixed = BorderBits { fixed = true } | contour,
452 sizable = BorderBits { sizable = true } | fixed,
453 thin = BorderBits { fixed = true, thin = true } | contour,
454 sizableThin = BorderBits { sizable = true } | thin,
455 deep = BorderBits { deep = true },
456 bevel = BorderBits { bevel = true },
457 sizableDeep = sizable|deep,
458 sizableBevel = sizable|bevel,
459 fixedDeep = fixed|deep,
460 fixedBevel = fixed|bevel,
461 deepContour = deep|contour
464 public enum CreationActivationOption
466 activate, flash, doNothing
469 public enum WindowState { normal, minimized, maximized };
471 private class ResPtr : struct
478 private class HotKeySlot : struct
480 HotKeySlot prev, next;
488 class_data char * icon;
490 class_default_property text;
491 // class_initialize GuiApplication::Initialize;
492 class_designer FormDesigner;
493 class_property char * icon
495 set { class_data(icon) = value; }
496 get { return class_data(icon); }
501 if(guiApp) guiApp.Initialize(true);
503 if(guiApp && guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
505 if(_vTbl == ((subclass(Window))_class).pureVTbl)
507 _vTbl = _class._vTbl;
509 else if(_vTbl != _class._vTbl)
512 for(m = 0; m < _class.vTblSize; m++)
514 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
515 _vTbl[m] = _class._vTbl[m];
520 //tempExtents[0] = { /*first = -1, last = -1, free = -1*/ };
521 //tempExtents[1] = { /*first = -1, last = -1, free = -1*/ };
522 //tempExtents[2] = { /*first = -1, last = -1, free = -1*/ };
523 //tempExtents[3] = { /*first = -1, last = -1, free = -1*/ };
527 // caption = CopyString(class.name);
529 children.offset = (byte*)&prev - (byte*)this;
530 childrenOrder.circ = true;
531 childrenCycle.circ = true;
533 maxSize = Size { MAXINT, MAXINT };
537 //style.isActiveClient = true;
540 modifyVirtArea = true;
541 manageDisplay = true;
543 // scrollFlags = ScrollFlags { snapX = true, snapY = true };
544 sbStep.x = sbStep.y = 8;
546 if(guiApp) // dynamic_cast<GuiApplication>(thisModule)
548 cursor = guiApp.GetCursor(arrow);
549 property::parent = guiApp.desktop;
561 stopwatching(parent, font);
562 if(parent.activeChild == this)
563 parent.activeChild = null;
564 if(parent.activeClient == this)
565 parent.activeClient = null;
570 // Prevent destructor from being called again...
576 /////////////////////////////////
579 OldLink slave = master.slaves.FindLink(this);
580 master.slaves.Delete(slave);
587 parent.childrenCycle.Remove(cycle);
589 parent.childrenOrder.Remove(order);
590 parent.children.Remove(this);
595 /////////////////////////////////
597 while(ptr = resources.first)
600 resources.Delete(ptr);
607 for(child = children.first; child; child = child.next)
609 // child.stopwatching(this, font);
611 eInstance_StopWatching(this, __ecereProp___ecereNameSpace__ecere__gui__Window_font, child);
612 // Don't want property here
613 *&child.parent = null;
616 while(slave = slaves.first)
618 // Don't want property here
619 *&((Window)slave.data).master = null;
620 slaves.Delete(slave);
623 // Because we do a decref in DestroyEx...
631 // Why was this commented?
632 //if(this != guiApp.desktop)
645 if(((subclass(Window))_class).pureVTbl)
647 if(_vTbl == _class._vTbl)
649 _vTbl = ((subclass(Window))_class).pureVTbl;
654 for(m = 0; m < _class.vTblSize; m++)
656 if(_vTbl[m] == _class._vTbl[m])
657 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
661 if(_vTbl == ((subclass(Window))_class).pureVTbl || _vTbl == _class._vTbl)
664 dirtyArea.Free(null);
665 renderArea.Free(null);
666 overRenderArea.Free(null);
667 clipExtent.Free(null);
668 scrollExtent.Free(null);
669 dirtyBack.Free(null);
673 tempExtents[0].Free(null);
674 tempExtents[1].Free(null);
675 tempExtents[2].Free(null);
676 tempExtents[3].Free(null);
681 //#if !defined(ECERE_VANILLA)
682 char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
684 if(this == activeDesigner)
688 char * name = property::name;
689 return name ? name : "";
694 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
695 bool OnGetDataFromString(char * string)
697 FormDesigner designer = (FormDesigner)activeDesigner.classDesigner;
700 if(!strcmp(string, "this") || !strcmp(string, designer.form.name))
701 this = designer.form;
702 else if(!strcmpi(string, "(Desktop)"))
703 this = activeDesigner;
705 return activeDesigner.FindObject(&this, string);
711 // --- Window updates system ---
713 // Setup a bitmap for Redrawing on client area of Window
714 Surface Redraw(Box box)
716 Surface surface = null;
718 Box clientArea = this.clientArea;
722 mox.left -= clientStart.x;
723 mox.top -= clientStart.y;
724 mox.right -= clientStart.x;
725 mox.bottom -= clientStart.y;
727 mox.Clip(clientArea);
728 // mox.ClipOffset(against, scrolledPos.x, scrolledPos.y);
730 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && mox.right >= mox.left && mox.bottom >= mox.top)
732 int x = absPosition.x + clientStart.x;
733 int y = absPosition.y + clientStart.y;
734 if(rootWindow.nativeDecorations)
736 x -= rootWindow.clientStart.x;
737 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
739 if(!guiApp.fullScreenMode || is3D)
741 x -= rootWindow.absPosition.x;
742 y -= rootWindow.absPosition.y;
746 x += rootWindow.parent.clientStart.x;
747 y += rootWindow.parent.clientStart.y;
749 mox.left += rootWindow.parent.clientStart.x;
750 mox.top += rootWindow.parent.clientStart.y;
751 mox.right += rootWindow.parent.clientStart.x;
752 mox.bottom += rootWindow.parent.clientStart.y;
757 surface = display.GetSurface(x, y, mox);
760 surface.width = clientSize.w;
761 surface.height = clientSize.h;
767 // Setup a bitmap for Redrawing on full Window
768 Surface RedrawFull(Box box)
770 Surface surface = null;
778 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && box.right >= box.left && box.bottom >= box.top)
780 int x = absPosition.x;
781 int y = absPosition.y;
782 if(rootWindow.nativeDecorations)
784 x -= rootWindow.clientStart.x;
785 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
787 if(!guiApp.fullScreenMode || is3D)
789 x -= rootWindow.absPosition.x;
790 y -= rootWindow.absPosition.y;
793 x += rootWindow.parent.clientStart.x;
794 y += rootWindow.parent.clientStart.y;
796 mox.left += rootWindow.parent.clientStart.x;
797 mox.top += rootWindow.parent.clientStart.y;
798 mox.right += rootWindow.parent.clientStart.x;
799 mox.bottom += rootWindow.parent.clientStart.y;
804 surface = display.GetSurface(x, y, mox);
807 surface.width = size.w;
808 surface.height = size.h;
814 void FigureCaption(char * caption)
818 strcpy(caption, this.caption);
819 if(style.isDocument || fileName)
821 if(caption[0]) strcat(caption, " - ");
823 strcat(caption, fileName);
827 sprintf(title, "Untitled %d", documentID);
828 strcat(caption, title);
831 strcat(caption, " *");
833 if(activeClient && menuBar &&
834 activeClient.state == maximized)
836 if(activeClient.caption)
838 if(caption[0]) strcat(caption, " - ");
839 strcat(caption, activeClient.caption);
841 if(activeClient.style.isDocument || activeClient.fileName)
843 if(caption[0]) strcat(caption, " - ");
844 strcat(caption, "[");
845 if(activeClient.fileName)
846 strcat(caption, activeClient.fileName);
850 sprintf(title, "Untitled %d", activeClient.documentID);
851 strcat(caption, title);
853 if(activeClient.modifiedDocument)
854 strcat(caption, " *");
855 strcat(caption, "]");
860 // Code for returning dirty from ScrollDisplay:
862 for(d = 0; d<scrollExtent.count; d++)
864 Box * box = &scrollExtent.boxes[d];
870 Min(box.right, box.left-scroll.x),box.bottom
872 dirtyArea.UnionBox(update);
878 Max(box.left, box.right-scroll.x), box.top,
879 box.right, box.bottom
881 dirtyArea.UnionBox(update);
889 box.right, Min(box.bottom, box.top-scroll.y),
891 dirtyArea.UnionBox(update);
897 box.left, Max(box.top, box.bottom-scroll.y),
898 box.right, box.bottom
900 dirtyArea.UnionBox(update);
905 void UpdateDecorations(void)
907 // TODO: *** TEMPORARY HACK ***
914 Update({ -clientStart.x, -clientStart.y, -clientStart.x + size.w-1, 0 });
916 Update({ -clientStart.x, clientSize.h, -clientStart.x + size.w-1, -clientStart.y + size.h-1 });
918 Update({ -clientStart.x,0, -1, clientSize.h-1 });
920 Update({ clientSize.w, 0, -clientStart.x + size.w-1, clientSize.h-1 });
923 // Returns w & h for Position
924 void ComputeAnchors(Anchor anchor, SizeAnchor sizeAnchor, int *ox, int *oy, int *ow, int *oh)
926 Window parent = this.parent ? this.parent : guiApp.desktop;
927 int vpw = parent ? parent.clientSize.w : 0;
928 int vph = parent ? parent.clientSize.h : 0;
929 int pw = parent ? parent.clientSize.w : 0;
930 int ph = parent ? parent.clientSize.h : 0;
931 int w = sizeAnchor.size.w, h = sizeAnchor.size.h;
932 int x = anchor.left.distance, y = anchor.top.distance;
934 MinMaxValue ew = 0, eh = 0;
936 float cascadeW, cascadeH;
938 int tilingW, tilingH, tilingSplit, tilingLastH;
939 int addX = 0, addY = 0;
941 if(parent && rootWindow == this && guiApp && guiApp.interfaceDriver)
943 Window masterWindow = this;
944 Box box { addX, addY, addX + vpw - 1, addY + vph - 1 };
947 if(master == guiApp.desktop)
948 masterWindow = guiApp.desktop.activeChild;
950 masterWindow = master.rootWindow;
951 if(!masterWindow) masterWindow = this;
953 guiApp.interfaceDriver.GetScreenArea(masterWindow, box);
954 if((anchor.left.type == offset && anchor.right.type == offset) || anchor.left.type == none)
957 pw = vpw = box.right - box.left + 1;
959 if((anchor.top.type == offset && anchor.bottom.type == offset) || anchor.top.type == none)
962 ph = vph = box.bottom - box.top + 1;
978 vpw = pw = parent.size.w;
979 vph = ph = parent.size.h;
981 else if(!style.fixed /*|| style.isDocument*/)
983 if(!style.dontScrollHorz && parent.scrollArea.w) vpw = parent.scrollArea.w;
984 if(!style.dontScrollVert && parent.scrollArea.h) vph = parent.scrollArea.h;
986 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
989 Desktop3D_FixSize(&pw, &ph);
990 Desktop3D_FixSize(&vpw, &vph);
993 if(pw < skinMinSize.w) pw = skinMinSize.w;
994 if(ph < skinMinSize.h) ph = skinMinSize.h;
995 if(vpw < skinMinSize.w) vpw = skinMinSize.w;
996 if(vph < skinMinSize.h) vph = skinMinSize.h;
998 // TODO: Must fix what we're snapping
1001 if(anchor.left.type)
1003 SNAPUP(x, textCellW);
1005 else if(anchor.right.type)
1007 SNAPDOWN(x, textCellW);
1012 SNAPUP(y, textCellH);
1014 else if(anchor.bottom.type)
1016 SNAPDOWN(y, textCellH);
1020 // This is required to get proper initial decoration size using native decorations on Windows
1021 if(nativeDecorations && guiApp && guiApp.interfaceDriver && !visible)
1022 guiApp.interfaceDriver.PositionRootWindow(this, x, y, Max(1, size.w), Max(1, size.h), true, true);
1023 GetDecorationsSize(&ew, &eh);
1025 if(anchor.left.type >= cascade && (state == normal /*|| state == Hidden*/))
1027 if(parent.sbv && !parent.sbv.style.hidden)
1028 pw += guiApp.currentSkin.VerticalSBW();
1029 if(parent.sbh && !parent.sbh.style.hidden)
1030 ph += guiApp.currentSkin.HorizontalSBH();
1032 if(anchor.left.type == cascade)
1034 w = (int)(pw * 0.80);
1035 h = (int)(ph * 0.80);
1037 else if(anchor.left.type >= vTiled)
1042 numTiling = parent.numPositions - parent.numIcons;
1043 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1044 if(anchor.left.type == vTiled)
1046 tilingH = (int)sqrt(numTiling);
1047 tilingW = numTiling / tilingH;
1051 tilingW = (int)sqrt(numTiling);
1052 tilingH = numTiling / tilingW;
1055 leftOver = numTiling - tilingH * tilingW;
1058 tilingSplit = (tilingW - leftOver) * tilingH;
1059 tilingLastH = tilingH+1;
1062 tilingSplit = numTiling;
1064 if(positionID >= tilingSplit)
1066 x = pw * (tilingSplit / tilingH + (positionID - tilingSplit) / tilingLastH)/tilingW;
1067 y = ph * ((positionID - tilingSplit) % tilingLastH) / tilingLastH;
1068 x2 = pw * (tilingSplit/tilingH + (positionID - tilingSplit) / tilingLastH + 1)/tilingW;
1069 y2 = ph * (((positionID - tilingSplit) % tilingLastH) + 1) / tilingLastH;
1073 x = pw * (positionID / tilingH) / tilingW;
1074 y = ph * (positionID % tilingH) / tilingH;
1075 x2 = pw * (positionID / tilingH + 1) / tilingW;
1076 y2 = ph * ((positionID % tilingH) + 1) / tilingH;
1080 SNAPDOWN(x, textCellW);
1081 SNAPDOWN(y, textCellH);
1082 SNAPDOWN(x2, textCellW);
1083 SNAPDOWN(y2, textCellH);
1091 if(sizeAnchor.isClientW) w += ew;
1092 if(sizeAnchor.isClientH) h += eh;
1094 if(anchor.left.type == offset)
1095 x = anchor.left.distance;
1096 else if(anchor.left.type == relative)
1097 x = (anchor.left.percent < 0) ? ((int)(vpw * anchor.left.percent - 0.5)) : (int)(vpw * anchor.left.percent + 0.5);
1098 else if(anchor.right.type == relative)
1099 // ex = (anchor.right.percent < 0) ? ((int)(vpw * anchor.right.percent + 0)) : ((int)(vpw * anchor.right.percent + 0));
1100 ex = (anchor.right.percent < 0) ? ((int)(vpw * (1.0-anchor.right.percent) + 0)) : ((int)(vpw * (1.0-anchor.right.percent) + 0));
1101 else if(anchor.right.type == offset)
1102 ex = vpw - anchor.right.distance;
1104 if(anchor.top.type == offset)
1105 y = anchor.top.distance;
1106 else if(anchor.top.type == relative)
1107 y = (anchor.top.percent < 0) ? ((int)(vph * anchor.top.percent - 0.5)) : ((int)(vph * anchor.top.percent + 0.5));
1108 else if(anchor.bottom.type == relative)
1109 //ey = (anchor.bottom.percent < 0) ? ((int)(vph * anchor.bottom.percent + 0)) : ((int)(vph * anchor.bottom.percent + 0));
1110 ey = (anchor.bottom.percent < 0) ? ((int)(vph * (1.0-anchor.bottom.percent) + 0)) : ((int)(vph * (1.0-anchor.bottom.percent) + 0));
1111 else if(anchor.bottom.type == offset)
1112 ey = vph - anchor.bottom.distance;
1114 if(anchor.left.type && anchor.right.type)
1116 switch(anchor.right.type)
1119 ex = pw * (1.0f-anchor.right.percent);
1120 w = Max((int)(ex + 0.5) - x, 0);
1123 ex = vpw - anchor.right.distance;
1124 w = Max((int)(ex + 0.5) - x, 0);
1128 if(anchor.top.type && anchor.bottom.type)
1130 switch(anchor.bottom.type)
1133 ey = ph * (1.0f-anchor.bottom.percent);
1134 h = Max((int)(ey + 0.5) - y, 0);
1137 ey = vph - anchor.bottom.distance;
1138 h = Max((int)(ey + 0.5) - y, 0);
1147 if(state == normal /*|| state == Hidden*/)
1149 bool addSbV = false, addSbH = false;
1151 if(sizeAnchor.isClientW || (anchor.left.type && anchor.right.type)) w = Max(w, 1); else w = Max(w, 0);
1152 if(sizeAnchor.isClientH || (anchor.top.type && anchor.bottom.type)) h = Max(h, 1); else h = Max(h, 0);
1154 w = Max(w, minSize.w);
1155 h = Max(h, minSize.h);
1156 w = Min(w, maxSize.w);
1157 h = Min(h, maxSize.h);
1159 if((sizeAnchor.isClientW || !w || (anchor.left.type && anchor.right.type)) && reqScrollArea.h > h /*&& w*/ && sbv)
1161 if(w) w -= guiApp.currentSkin.VerticalSBW();
1164 if((sizeAnchor.isClientH || !h || (anchor.top.type && anchor.bottom.type)) && reqScrollArea.w > w /*&& h*/ && sbh)
1166 if(h) h -= guiApp.currentSkin.HorizontalSBH();
1170 if(!OnResizing(&w, &h))
1176 if((addSbV)) // || reqScrollArea.h > h) && sbv)
1177 w += guiApp.currentSkin.VerticalSBW();
1178 if((addSbH)) // || reqScrollArea.w > w) && sbh)
1179 h += guiApp.currentSkin.HorizontalSBH();
1181 w = Max(w, skinMinSize.w);
1182 h = Max(h, skinMinSize.h);
1195 SNAPDOWN(w, textCellW);
1196 SNAPDOWN(h, textCellH);
1199 if(anchor.left.type == cascade && (state == normal /*|| state == Hidden*/))
1201 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1204 (pw - w) / CASCADE_SPACE,
1205 (ph - h) / CASCADE_SPACE);
1211 cascW = (pw - w) / (numCascade-1);
1212 cascH = (ph - h) / (numCascade-1);
1213 SNAPDOWN(cascW, textCellW);
1214 SNAPDOWN(cascH, textCellH);
1215 cascadeW = (float)cascW;
1216 cascadeH = (float)cascH;
1220 numCascade = Max(numCascade, 2);
1221 cascadeW = (float)(pw - w) / (numCascade-1);
1222 cascadeH = (float)(ph - h) / (numCascade-1);
1225 x = (int)((positionID % numCascade) * cascadeW);
1226 y = (int)((positionID % numCascade) * cascadeH);
1228 else if(anchor.left.type < vTiled)
1230 if(!anchor.left.type || anchor.horz.type == middleRelative)
1232 if(!anchor.right.type)
1234 if(anchor.horz.type == middleRelative)
1235 x = (int)(vpw * (0.5 + anchor.horz.percent) - w / 2);
1237 x = vpw / 2 + anchor.horz.distance - w / 2;
1243 // case A_EDGE: x = x - w; break;
1245 if(!anchor.top.type || anchor.vert.type == middleRelative)
1247 if(!anchor.bottom.type)
1249 if(anchor.vert.type == middleRelative)
1250 y = (int)(vph * (0.5 + anchor.vert.percent) - h / 2);
1252 y = vph / 2 + anchor.vert.distance - h / 2;
1258 // case A_EDGE: y = y - h; break;
1261 if((state == normal /*|| state == Hidden*/) && !OnMoving(&x, &y, w, h))
1269 SNAPDOWN(x, textCellW);
1270 SNAPDOWN(y, textCellH);
1282 if(anchored && style.fixed && style.isActiveClient)
1287 void UpdateCaret(bool forceUpdate, bool erase)
1289 static Window lastWindow = null;
1290 static int caretX, caretY, caretSize;
1292 if(guiApp && guiApp.caretOwner == this)
1294 int x = caretPos.x - scroll.x;
1295 int y = caretPos.y - scroll.y;
1297 if((erase || this.caretSize) &&
1298 x >= clientArea.left && x <= clientArea.right &&
1299 y >= clientArea.top && y <= clientArea.bottom)
1303 guiApp.interfaceDriver.SetCaret(
1304 x + absPosition.x + clientStart.x,
1305 y + absPosition.y + clientStart.y, this.caretSize);
1306 guiApp.caretEnabled = true;
1308 if(erase || lastWindow != this || caretX != x || caretY != y || caretSize != this.caretSize || forceUpdate)
1312 if(lastWindow != this)
1314 updateBox.left = x + 1;
1316 updateBox.right = x + 2;
1317 updateBox.bottom = y + this.caretSize - 1;
1321 updateBox.left = Min(x + 1, caretX + 1);
1322 updateBox.top = Min(y, caretY);
1323 updateBox.right = Max(x + 2, caretX + 2);
1324 updateBox.bottom = Max(y + this.caretSize - 1, caretY + caretSize - 1);
1327 guiApp.caretOwner.Update(updateBox);
1334 caretSize = this.caretSize;
1340 guiApp.interfaceDriver.SetCaret(0,0,0);
1341 guiApp.caretEnabled = false;
1347 void SetPosition(int x, int y, int w, int h, bool modifyArea, bool modifyThisArea, bool modifyClientArea)
1352 scrolledPos.x = position.x = x;
1353 scrolledPos.y = position.y = y;
1355 clientSize.w = size.w = w;
1356 clientSize.h = size.h = h;
1358 if(parent && !style.nonClient)
1360 //if(!style.fixed || style.isDocument)
1362 if(!style.dontScrollHorz) scrolledPos.x -= parent.scroll.x;
1363 if(!style.dontScrollVert) scrolledPos.y -= parent.scroll.y;
1367 clientStart.x = clientStart.y = 0;
1369 SetWindowArea(&clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1371 //if(!activeClient || activeClient.state != maximized)
1372 if(!noAutoScrollArea)
1374 // Check if scroll area must be modified
1375 if(guiApp && !guiApp.modeSwitching && (sbv || sbh))
1377 bool foundChild = false;
1379 int cw = clientSize.w;// + ((!sbv || sbv.range > 1) ? guiApp.currentSkin.VerticalSBW() : 0);
1380 int ch = clientSize.h;// + ((!sbh || sbh.rangw > 1) ? guiApp.currentSkin.HorizontalSBH() : 0);
1381 for(child = children.first; child; child = child.next)
1383 if(child.modifyVirtArea && !child.style.hidden && child.created && /*!child.anchored &&*/
1384 !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1386 if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == offset)
1387 w = Max(w, child.position.x + child.size.w);
1388 else if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == none)
1389 w = Max(w, Max(child.position.x, 0) + child.size.w);
1390 if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == offset)
1391 h = Max(h, child.position.y + child.size.h);
1392 else if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == none)
1393 h = Max(h, Max(child.position.y, 0) + child.size.h);
1398 if(foundChild && (w > cw || h > ch))
1400 //if((w > reqScrollArea.w) || (h > reqScrollArea.w))
1402 int stepX = sbStep.x, stepY = sbStep.y;
1403 // Needed to make snapped down position match the skin's check of client area
1404 // against realvirtual
1407 SNAPDOWN(stepX, textCellW);
1408 SNAPDOWN(stepY, textCellH);
1409 stepX = Max(stepX, textCellW);
1410 stepY = Max(stepY, textCellH);
1412 if(scrollFlags.snapX)
1414 if(scrollFlags.snapY)
1417 reqScrollArea.w = w;
1418 reqScrollArea.h = h;
1421 else if(reqScrollArea.w || reqScrollArea.h)
1423 reqScrollArea.w = 0;
1424 reqScrollArea.h = 0;
1425 SetScrollPosition(0,0);
1430 // Automatic MDI Client Scrolling Area Adjustment
1431 if(parent && !parent.noAutoScrollArea)
1433 if(modifyArea && modifyVirtArea /*&& !anchored*/ && (parent.sbv || parent.sbh) &&
1434 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient)
1436 Window parent = this.parent;
1437 int w = parent.reqScrollArea.w;
1438 int h = parent.reqScrollArea.h;
1440 if(stateAnchor.right.type == none && stateAnchor.left.type == offset)
1441 w = Max(w, position.x + size.w);
1442 else if(stateAnchor.right.type == none && stateAnchor.left.type == none)
1443 w = Max(w, Max(position.x, 0) + size.w);
1444 if(stateAnchor.bottom.type == none && stateAnchor.top.type == offset)
1445 h = Max(h, position.y + size.h);
1446 else if(stateAnchor.bottom.type == none && stateAnchor.top.type == none)
1447 h = Max(h, Max(position.y, 0) + size.h);
1449 if((w > parent.clientSize.w && w > parent.reqScrollArea.w) ||
1450 (h > parent.clientSize.h && h > parent.reqScrollArea.h))
1452 /*bool resize = false;
1453 int stepX = parent.sbStep.x, stepY = parent.sbStep.y;
1454 // Needed to make snapped down position match the skin's check of client area
1455 // against realvirtual
1458 SNAPDOWN(stepX, textCellW);
1459 SNAPDOWN(stepY, textCellH);
1460 stepX = Max(stepX, textCellW);
1461 stepY = Max(stepY, textCellH);
1463 if(parent.scrollFlags.snapX)
1465 if(parent.scrollFlags.snapY)
1467 if(parent.reqScrollArea.w != w || parent.reqScrollArea.h != h)
1469 parent.reqScrollArea.w = w;
1470 parent.reqScrollArea.h = h;*/
1472 // parent.UpdateScrollBars(true, true);
1473 parent.Position(parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1474 false, true, true, true, false, false);
1479 GetRidOfVirtualArea();
1483 UpdateScrollBars(modifyThisArea, false);
1484 else if(guiApp.currentSkin)
1487 &clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1489 if(sbv && (scrollFlags.dontHide || sbv.range > 1))
1490 clientSize.w -= guiApp.currentSkin.VerticalSBW();
1491 if(sbh && (scrollFlags.dontHide || sbh.range > 1))
1492 clientSize.h -= guiApp.currentSkin.HorizontalSBH();
1495 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1496 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1498 absPosition = scrolledPos;
1499 if(guiApp && guiApp.driver != null && guiApp.interfaceDriver)
1500 guiApp.interfaceDriver.OffsetWindow(this, &absPosition.x, &absPosition.y);
1502 if(this != guiApp.desktop && parent)
1504 absPosition.x += parent.absPosition.x;
1505 absPosition.y += parent.absPosition.y;
1506 if(!style.nonClient && this != guiApp.desktop)
1508 absPosition.x += parent.clientStart.x;
1509 absPosition.y += parent.clientStart.y;
1513 box = Box { 0, 0, size.w - 1, size.h - 1 };
1518 // Clip against parent's client area
1519 box.ClipOffset(against, scrolledPos.x, scrolledPos.y);
1521 // Compute client area in this window coordinate system
1522 clientArea.left = 0;
1524 clientArea.right = clientSize.w - 1;
1525 clientArea.bottom = clientSize.h - 1;
1527 // Clip against parent's client area
1529 clientArea.ClipOffset(against, scrolledPos.x + clientStart.x, scrolledPos.y + clientStart.y);
1533 //absPosition.x -= parent.clientStart.x;
1534 //absPosition.y -= parent.clientStart.y;
1537 // Adjust all children
1538 for(child = children.first; child; child = child.next)
1539 child.SetPosition(child.position.x, child.position.y, child.size.w, child.size.h, false, true, true);
1541 UpdateCaret(false, false);
1544 void GetRidOfVirtualArea(void)
1546 if(parent && !parent.destroyed && style.fixed &&
1547 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient &&
1548 parent.reqScrollArea.w && parent.reqScrollArea.h)
1550 if(!parent.noAutoScrollArea)
1554 for(child = children.first; child; child = child.next)
1556 if(child.modifyVirtArea && !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1558 if(child.position.x + child.size.w > parent.clientSize.w + ((!parent.sbv || parent.sbv.style.hidden) ? 0 : guiApp.currentSkin.VerticalSBW()) ||
1559 child.position.y + child.size.h > parent.clientSize.h + ((!parent.sbh || parent.sbh.style.hidden) ? 0 : guiApp.currentSkin.HorizontalSBH()))
1568 Window parent = this.parent;
1570 parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1571 false, true, true, true, false, false);
1573 parent.SetScrollArea(0,0,true);
1574 parent.SetScrollPosition(0,0);
1580 public void ExternalPosition(int x, int y, int w, int h)
1582 Position(x, y, w, h, false, true, true, true, false, false);
1585 // (w, h): Full window size
1586 bool Position(int x, int y, int w, int h, bool force, bool processAnchors, bool modifyArea, bool updateScrollBars, bool thisOnly, bool changeRootWindow)
1588 bool result = false;
1589 int oldCW = clientSize.w, oldCH = clientSize.h;
1590 bool clientResized, windowResized, windowMoved;
1592 bool realResized = size.w != w || size.h != h;
1594 // TOCHECK: This wasn't in ecere.dll
1595 //if(!parent) return true;
1596 if(destroyed) return false;
1598 windowMoved = position.x != x || position.y != y || force;
1600 // windowResized = realResized || force;
1601 windowResized = size.w != w || size.h != h || force;
1603 if(rootWindow != this && display && !display.flags.flipping && scrolledPos.x != MININT)
1609 scrolledPos.x - parent.clientStart.x + this.box.left, scrolledPos.y - parent.clientStart.y + this.box.top,
1610 scrolledPos.x - parent.clientStart.x + this.box.right,
1611 scrolledPos.y - parent.clientStart.y + this.box.bottom
1617 Box box { scrolledPos.x + this.box.left, scrolledPos.y + this.box.top, scrolledPos.x + this.box.right, scrolledPos.y + this.box.bottom};
1622 SetPosition(x, y, w, h, true, modifyArea, updateScrollBars);
1624 clientResized = oldCW != clientSize.w || oldCH != clientSize.h || force;
1626 if(display && rootWindow != this)
1629 if(guiApp && guiApp.windowMoving)
1631 if(guiApp.windowMoving.style.nonClient)
1632 guiApp.windowMoving.parent.SetMouseRangeToWindow();
1634 guiApp.windowMoving.parent.SetMouseRangeToClient();
1644 // Buttons bitmap resources crash if we do this while switching mode
1645 if(!guiApp || !guiApp.modeSwitching)
1648 // Process Anchored Children
1652 for(child = children.first; child; child = child.next)
1655 ((child.stateAnchor.left.type != offset ||
1656 child.stateAnchor.top.type != offset ||
1657 child.stateAnchor.right.type != none ||
1658 child.stateAnchor.bottom.type != none) ||
1659 child.state == maximized || child.state == minimized))
1661 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor,
1663 // child.Position(x, y, w, h, false, true, true, true, false);
1664 // This must be true cuz otherwise we're gonna miss everything since we SetPosition recursively already
1665 child.Position(x, y, w, h, true, true, true, true, false, true /*false*/);
1671 // Is this gonna cause other problems? Commented out for the FileDialog end bevel bug
1672 //if(updateScrollBars)
1674 OnResize(clientSize.w, clientSize.h);
1676 if((clientResized || windowMoved) && created)
1677 OnPosition(position.x, position.y, clientSize.w, clientSize.h);
1679 if(guiApp.interimWindow && guiApp.interimWindow.master.rootWindow == this)
1681 Window master = guiApp.interimWindow.master;
1682 master.OnPosition(master.position.x, master.position.y, master.clientSize.w, master.clientSize.h);
1685 if(rootWindow == this && !is3D)
1689 x -= guiApp.desktop.absPosition.x;
1690 y -= guiApp.desktop.absPosition.y;
1692 //guiApp.Log("Position %s\n", caption);
1693 if(windowResized || windowMoved)
1694 if(display && !display.flags.memBackBuffer && changeRootWindow)
1695 guiApp.interfaceDriver.PositionRootWindow(this, x, y, w, h, windowMoved, windowResized); //realResized);
1697 if(!guiApp.fullScreenMode && this != guiApp.desktop && (windowResized || windowMoved))
1698 for(child = parent.children.first; child && child != this; child = child.next)
1699 if(child.rootWindow)
1700 guiApp.interfaceDriver.UpdateRootWindow(child.rootWindow);
1704 if(windowMoved || windowResized)
1706 display.Lock(true /*false*/);
1709 display.Position(absPosition.x, absPosition.y);
1710 //display.Position(absPosition.x + clientStart.x, absPosition.y + clientStart.y);
1713 // result = realResized ? display.Resize(size.w, size.h) : true;
1714 if(nativeDecorations)
1716 int w = clientSize.w, h = clientSize.h;
1717 if(hasMenuBar) h += skinMenuHeight;
1718 if(hasStatusBar) h += statusBarHeight;
1719 if(sbv && sbv.visible) w += sbv.size.w;
1720 if(sbh && sbh.visible) h += sbh.size.h;
1721 result = manageDisplay ? display.Resize(w, h) : true;
1724 result = manageDisplay ? display.Resize(size.w, size.h) : true;
1728 else if(clientResized)
1730 // --- Major Slow Down / Fix OpenGL Resizing Main Window Lag
1733 if(!guiApp.fullScreenMode && !guiApp.modeSwitching && this == rootWindow)
1737 if(windowMoved || windowResized)
1742 if(guiApp.driver && changeRootWindow)
1744 if(windowResized || windowMoved)
1745 if(!display || display.flags.memBackBuffer)
1746 guiApp.interfaceDriver.PositionRootWindow(this,
1747 x, y, w, h, windowMoved, windowResized);
1748 guiApp.interfaceDriver.UpdateRootWindow(this);
1750 for(child = children.first; child; child = child.next)
1752 if(child.is3D && child.created)
1754 // Copy Display Content
1755 child.display.displaySystem = display.displaySystem;
1756 child.display.window = display.window;
1757 child.display.current = display.current;
1758 child.display.width = display.width;
1759 child.display.height = display.height;
1760 child.display.driverData = display.driverData;
1761 child.display.mutex = null;
1772 void UpdateScrollBars(bool flag, bool fullThing)
1775 bool resizeH = false, resizeV = false;
1776 bool scrolled = false;
1777 rvw = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.w;
1778 rvh = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.h;
1780 if(destroyed) return;
1781 if(guiApp.currentSkin)
1783 MinMaxValue cw = 0, ch = 0;
1784 bool sbvVisible, sbhVisible;
1786 int positionH, positionV;
1788 // First get client area with no respect to scroll bars
1793 &clientStart.x, &clientStart.y, &size.w, &size.h, &cw, &ch);
1795 if(scrollFlags.dontHide)
1798 cw -= guiApp.currentSkin.VerticalSBW();
1800 ch -= guiApp.currentSkin.HorizontalSBH();
1802 // Update the scrollbar visibility
1808 sbh.disabled = rangeH <= 1;
1809 if(sbh.style.hidden)
1819 sbv.disabled = rangeV <= 1;
1820 if(sbv.style.hidden)
1828 // Then start off with horizontal scrollbar range
1831 positionH = sbh.thumbPosition;
1836 ch -= guiApp.currentSkin.HorizontalSBH();
1839 // Do the same for vertical scrollbar
1842 positionV = sbv.thumbPosition;
1848 cw -= guiApp.currentSkin.VerticalSBW();
1849 // Maybe we need to set the range on the horizontal scrollbar again
1854 sbh.Action(setRange, positionH, 0);
1855 if(rangeH <= 1 && sbh.range > 1)
1857 ch -= guiApp.currentSkin.HorizontalSBH();
1861 sbv.Action(setRange, positionV, 0);
1868 // Update the scrollbar visibility
1869 if(!scrollFlags.dontHide)
1871 if(sbh && ((rangeH <= 1 && !sbh.style.hidden) || (rangeH > 1 && sbh.style.hidden)))
1875 if(sbv && ((rangeV <= 1 && !sbv.style.hidden) || (rangeV > 1 && sbv.style.hidden)))
1882 if(guiApp.currentSkin)
1889 sbhVisible = sbh.style.hidden ? true : false;
1891 sbvVisible = sbv.style.hidden ? true : false;
1893 // Do our resize here
1894 if(flag && (resizeH || resizeV) && fullThing)
1896 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, false);
1901 OnResize(clientSize.w, clientSize.h);
1907 sbh.visible = sbhVisible;
1909 sbv.visible = sbvVisible;
1911 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1912 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1915 sbh.pageStep = clientSize.w;
1917 sbv.pageStep = clientSize.h;
1919 // Notify doesn't handle setRange anymore... process it here
1922 int positionH = sbh.thumbPosition;
1923 if(scroll.x != positionH)
1925 OnHScroll(setRange, positionH, 0);
1929 SNAPDOWN(positionH, textCellW);
1930 scroll.x = positionH;
1936 int seen = clientSize.w, total = reqScrollArea.w;
1939 if(scrollFlags.snapX)
1940 SNAPDOWN(seen, sbStep.x);
1942 if(!total) total = seen;
1943 range = total - seen + 1;
1945 range = Max(range, 1);
1947 if(x >= range) x = range - 1;
1949 if(scrollFlags.snapX)
1950 SNAPUP(x, sbStep.x);
1954 OnHScroll(setRange, x, 0);
1959 SNAPDOWN(x, textCellW);
1965 int positionV = sbv.thumbPosition;
1966 if(scroll.y != positionV)
1968 OnVScroll(setRange, positionV, 0);
1972 SNAPDOWN(positionV, textCellH);
1973 scroll.y = positionV;
1979 int seen = clientSize.h, total = reqScrollArea.h;
1982 if(scrollFlags.snapY)
1983 SNAPDOWN(seen, sbStep.y);
1985 if(!total) total = seen;
1986 range = total - seen + 1;
1987 range = Max(range, 1);
1989 if(y >= range) y = range - 1;
1991 if(scrollFlags.snapY)
1992 SNAPUP(y, sbStep.y);
1996 OnVScroll(setRange, y, 0);
2001 SNAPDOWN(y, textCellH);
2007 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2010 for(child = children.first; child; child = child.next)
2012 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2015 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2016 child.Position(x, y, w, h, false, true, false, true, false, false);
2023 // Process Scrollbars
2025 if(sbh) // && !sbh.style.hidden
2027 sbh.Move(clientStart.x, clientStart.y + clientSize.h, clientSize.w,0);
2028 // Need to set the range again (should improve...) since the scrollbars didn't have
2029 // the right size when UpdateScrollArea set the range on it
2032 sbh.seen = clientSize.w;
2036 if(sbv) // && !sbv.state.hidden
2038 sbv.Move(clientStart.x + clientSize.w, clientStart.y, 0, clientSize.h);
2039 // Need to set the range again (should improve...) since the scrollbars didn't have
2040 // the right size when UpdateScrollArea set the range on it
2043 sbv.seen = clientSize.h;
2048 // TESTING THIS LOWER
2049 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2052 for(child = children.first; child; child = child.next)
2054 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2057 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2058 child.Position(x, y, w, h, false, true, false, true, false, false);
2064 bool MaximizeButtonClicked(Button button, int x, int y, Modifiers mods)
2066 SetState(maximized, false, mods);
2070 bool RestoreButtonClicked(Button button, int x, int y, Modifiers mods)
2072 SetState(normal, false, mods);
2076 bool MinimizeButtonClicked(Button button, int x, int y, Modifiers mods)
2078 SetState(minimized, false, mods);
2079 parent.CycleChildren(false, true, false, true);
2083 void ScrollBarNotification(ScrollBar control, ScrollBarAction action, int position, Key keyFlags)
2086 // Scroll bar notifications
2087 if(action != setRange)
2089 bool changed = false;
2093 if(scroll.x != position)
2095 OnHScroll(action, position, keyFlags);
2100 SNAPDOWN(position, textCellW);
2102 scroll.x = position;
2106 if(scroll.y != position)
2108 OnVScroll(action, position, keyFlags);
2113 SNAPDOWN(position, textCellH);
2115 scroll.y = position;
2119 bool childMove = false;
2120 for(child = children.first; child; child = child.next)
2122 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2125 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2126 child.Position(x, y, w, h, false, true, false, true, false, false);
2130 // Testing this patch out to solve MDI workspace redraw bugs
2131 // We were already supposed to be updating parent's affected area in Position() but it doesn't seem to be working
2132 // Scroll offsets to blame?
2136 UpdateCaret(false, false);
2140 // Testing this patch out to solve MDI workspace redraw bugs
2141 for(child = children.first; child; child = child.next)
2143 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2152 void CreateSystemChildren(void)
2154 Window parent = this;
2155 bool scrollBarChanged = false;
2156 bool hasClose = false, hasMaxMin = false;
2157 Point scroll = this.scroll;
2159 if(state == maximized && this.parent.menuBar)
2161 if(this.parent.activeClient == this)
2162 parent = this.parent.menuBar;
2169 if(style.hasClose) hasClose = true;
2170 if(style.hasMaximize || style.hasMinimize)
2177 if(sysButtons[2] && (!hasClose || sysButtons[2].parent != parent))
2179 sysButtons[2].Destroy(0);
2180 sysButtons[2] = null;
2182 if(sysButtons[1] && (!hasMaxMin || sysButtons[1].parent != parent))
2184 sysButtons[1].Destroy(0);
2185 sysButtons[1] = null;
2187 if(sysButtons[0] && (!hasMaxMin || sysButtons[0].parent != parent))
2189 sysButtons[0].Destroy(0);
2190 sysButtons[0] = null;
2193 if(hasClose && parent)
2200 parent, master = this,
2201 inactive = true, nonClient = true, visible = false;
2203 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
2209 if(this.parent == guiApp.desktop)
2210 sysButtons[2].hotKey = altF4;
2211 else if(style.isActiveClient)
2212 sysButtons[2].hotKey = ctrlF4;
2213 sysButtons[2].Create();
2216 sysButtons[2].symbol = 'X';
2217 sysButtons[2].disabled = !style.hasClose;
2220 if(hasMaxMin && parent)
2224 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2225 if(state == maximized)
2228 method = RestoreButtonClicked;
2234 method = MaximizeButtonClicked;
2242 parent, master = this,
2243 hotKey = altEnter, inactive = true, nonClient = true, visible = false
2245 sysButtons[1].Create();
2247 sysButtons[1].NotifyClicked = method;
2249 sysButtons[1].symbol = symbol;
2250 sysButtons[1].disabled = !style.hasMaximize;
2253 if(hasMaxMin && parent)
2257 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2258 if (state == minimized)
2261 method = RestoreButtonClicked;
2267 method = MinimizeButtonClicked;
2275 parent, master = this,
2276 hotKey = altM, inactive = true, nonClient = true, visible = false
2278 sysButtons[0].Create();
2280 sysButtons[0].NotifyClicked = method;
2282 sysButtons[0].symbol = symbol;
2283 sysButtons[0].disabled = !style.hasMinimize;
2286 // Create the scrollbars
2287 if(style.hasHorzScroll && !sbh)
2293 direction = horizontal,
2297 snap = scrollFlags.snapX,
2298 NotifyScrolling = ScrollBarNotification
2301 scrollBarChanged = true;
2303 else if(sbh && !style.hasHorzScroll)
2309 if(style.hasVertScroll && !sbv)
2315 direction = vertical,
2319 snap = scrollFlags.snapY,
2320 NotifyScrolling = ScrollBarNotification
2323 scrollBarChanged = true;
2325 else if(sbv && !style.hasVertScroll)
2330 if(scrollBarChanged)
2332 SetScrollLineStep(sbStep.x, sbStep.y);
2333 UpdateScrollBars(true, true);
2337 if(scrollBarChanged)
2339 if(sbh) sbh.thumbPosition = scroll.x;
2340 if(sbv) sbv.thumbPosition = scroll.y;
2344 void UpdateCaption(void)
2346 if(rootWindow == this)
2349 FigureCaption(caption);
2350 guiApp.interfaceDriver.SetRootWindowCaption(this, caption);
2352 UpdateDecorations();
2355 if(parent.rootWindow == parent && parent.activeClient == this) // Added this last check
2358 parent.FigureCaption(caption);
2359 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
2361 parent.UpdateDecorations();
2365 void UpdateActiveDocument(Window previous)
2367 Window activeClient = this.activeClient;
2368 Window activeChild = this.activeChild;
2375 activeClient.CreateSystemChildren();
2377 previous.CreateSystemChildren();
2388 if(activeClient && activeClient.menu && activeClient.state != minimized)
2392 //activeClient.menu.Clean(activeClient);
2393 menu.Merge(activeClient.menu, true, activeClient);
2397 if(activeChild && activeChild != activeClient && activeChild.menu && activeChild.state != minimized)
2400 menu.Merge(activeChild.menu, true, activeChild);
2403 // Build window list
2406 Menu windowMenu = menu.FindMenu("Window");
2411 for(id = 0, cycle = activeClient.cycle; cycle && id<10;)
2414 Window document = cycle.data;
2415 if(!document.style.nonClient && document.style.isActiveClient && document.visible)
2417 char name[2048], caption[2048];
2418 document.FigureCaption(caption);
2419 sprintf(name, "%d %s", id+1, caption);
2420 windowMenu.AddDynamic(MenuItem
2422 copyText = true, text = name, hotKey = Key { k1 + id }, id = id++,
2423 NotifySelect = MenuWindowSelectWindow
2427 if(activeClient.cycle == cycle) break;
2432 if((!previous && activeClient) || !activeClient)
2438 item = menu.FindItem(MenuWindowCloseAll, 0);
2439 if(item) item.disabled = false;
2440 item = menu.FindItem(MenuWindowNext, 0);
2441 if(item) item.disabled = false;
2442 item = menu.FindItem(MenuWindowPrevious, 0);
2443 if(item) item.disabled = false;
2444 item = menu.FindItem(MenuWindowCascade, 0);
2445 if(item) item.disabled = false;
2446 item = menu.FindItem(MenuWindowTileHorz, 0);
2447 if(item) item.disabled = false;
2448 item = menu.FindItem(MenuWindowTileVert, 0);
2449 if(item) item.disabled = false;
2450 item = menu.FindItem(MenuWindowArrangeIcons, 0);
2451 if(item) item.disabled = false;
2452 item = menu.FindItem(MenuWindowWindows, 0);
2453 if(item) item.disabled = false;
2456 item = menu.FindItem(MenuFileClose, 0);
2457 if(item) item.disabled = !activeClient || !activeClient.style.hasClose;
2458 item = menu.FindItem(MenuFileSaveAll, 0);
2459 if(item) item.disabled = numDocuments < 1;
2461 // This is called again for a child window change, with same active client
2462 OnActivateClient(activeClient, previous);
2465 void _ShowDecorations(Box box, bool post)
2467 if(rootWindow == this && nativeDecorations) return;
2468 if(visible && this != guiApp.desktop)
2470 Surface surface = RedrawFull(box);
2474 FigureCaption(caption);
2477 ShowDecorations(captionFont.font,
2480 active, //parent.activeClient == this
2481 guiApp.windowMoving == this);
2483 PreShowDecorations(captionFont.font,
2486 active, //parent.activeClient == this
2487 guiApp.windowMoving == this);
2494 void UpdateExtent(Box refresh)
2496 Surface surface = null;
2498 if(!manageDisplay) { OnRedraw(null);return; }
2499 _ShowDecorations(refresh, false);
2501 surface = Redraw(refresh);
2502 // Opaque background: just fill before EW_REDRAW (clear?)
2505 surface.SetBackground(background);
2506 surface.SetForeground(foreground);
2507 surface.DrawingChar(' ');
2508 if(this == rootWindow)
2510 if(style.drawBehind || background.a)
2511 surface.Clear(colorBuffer);
2513 else if(background.a)
2517 background.color = { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2518 surface.SetForeground((background.color.r > 128 || background.color.g > 128) ? black : white);
2521 if(display.flags.alpha && background.a < 255 && background)
2523 surface.Area(0,0,clientSize.w, clientSize.h);
2524 /*if(style.clearDepthBuffer)
2525 surface.Clear(depthBuffer);*/
2527 else if(/*style.clearDepthBuffer || */background.a)
2529 // surface.Clear((style.clearDepthBuffer ? depthBuffer : 0) | (background.a ? colorBuffer : 0));
2530 surface.Clear(colorBuffer);
2535 surface.TextFont(usedFont.font);
2536 surface.TextOpacity(false);
2540 // Draw the caret ...
2541 if(!disabled && this == guiApp.caretOwner && guiApp.caretEnabled /*&& !guiApp.interimWindow*/ && !guiApp.currentSkin.textMode)
2543 // surface.SetBackground(0xFFFFFF - background.color);
2544 surface.SetBackground(~background.color);
2546 caretPos.x - scroll.x + 1, caretPos.y - scroll.y,
2547 caretPos.x - scroll.x + 2, caretPos.y - scroll.y + caretSize - 1);
2553 void DrawOverChildren(Box refresh)
2555 Surface surface = Redraw(refresh);
2559 surface.DrawingChar(' ');
2560 surface.SetBackground(background);
2561 surface.SetForeground(foreground);
2563 surface.TextFont(usedFont.font);
2564 surface.TextOpacity(false);
2566 OnDrawOverChildren(surface);
2571 _ShowDecorations(refresh, true);
2574 void ComputeClipExtents(void)
2577 Extent clipExtent { /*first = -1, last = -1, free = -1*/ };
2579 clipExtent.Copy(this.clipExtent);
2581 for(child = children.last; child; child = child.prev)
2583 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2585 bool opaque = child.IsOpaque(); // TODO: acess background directly
2586 int dx = child.absPosition.x - absPosition.x, dy = child.absPosition.y - absPosition.y;
2588 child.clipExtent.Copy(clipExtent);
2589 child.clipExtent.Offset(-dx, -dy);
2590 child.clipExtent.IntersectBox(child.box);
2592 child.ComputeClipExtents();
2594 if(opaque && !child.style.nonClient)
2596 // Adjust the box for the parent:
2597 Box box { child.box.left + dx, child.box.top + dy, child.box.right + dx, child.box.bottom + dy };
2598 clipExtent.ExcludeBox(box, rootWindow.tempExtents[0]);
2603 // ??? Only do this for overlapped window or if parent has with clip children flag
2605 // Do this if window has clip children flag on (default false?)
2606 // this.clipExtent = clipExtent;
2608 clipExtent.Free(null);
2611 void ComputeRenderAreaNonOpaque(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2613 bool opaque = IsOpaque();
2615 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2616 if(rootWindow.nativeDecorations)
2618 offsetX -= rootWindow.clientStart.x;
2619 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2623 for(child = children.last; child; child = child.prev)
2625 ColorAlpha background = *(ColorAlpha *)&child.background;
2626 bool opaque = child.IsOpaque();
2627 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2631 // Adjust renderArea to the root window level
2632 Extent * renderArea = &rootWindow.tempExtents[1];
2634 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2635 if(child.rootWindow.nativeDecorations)
2637 offsetX -= child.rootWindow.clientStart.x;
2638 offsetY -= child.rootWindow.clientStart.y - (child.rootWindow.hasMenuBar ? skinMenuHeight : 0);
2642 Extent childRenderArea;
2644 if(backBufferUpdate != null)
2646 childRenderArea.Copy(backBufferUpdate);
2647 childRenderArea.Offset(-offsetX, -offsetY);
2650 childRenderArea.Copy(child.dirtyArea);
2652 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2653 renderArea.Copy(dirtyExtent);
2654 renderArea.Offset(-offsetX, -offsetY);
2655 childRenderArea.Union(renderArea);
2658 // Intersect with the clip extent
2659 childRenderArea.Intersection(child.clipExtent);
2662 renderArea->Copy(child.dirtyArea /*childRenderArea*/);
2663 renderArea->Offset(offsetX, offsetY);
2664 dirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2665 // overDirtyExtent.Union(renderArea);
2666 renderArea->Empty();
2667 // childRenderArea.Free();
2669 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2674 for(child = children.last; child; child = child.prev)
2676 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2678 child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2683 void ComputeRenderArea(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2685 bool opaque = IsOpaque();
2686 Extent * dirtyExtentWindow = &rootWindow.tempExtents[1];
2688 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2689 if(rootWindow.nativeDecorations)
2691 offsetX -= rootWindow.clientStart.x;
2692 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2696 for(child = children.last; child; child = child.prev)
2698 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2700 ColorAlpha background = *(ColorAlpha *)&child.background;
2701 bool opaque = child.IsOpaque();
2702 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2706 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2707 // Adjust renderArea to the root window level
2709 renderArea.Copy(child.dirtyArea);
2710 renderArea.Offset(offsetX, offsetY);
2711 dirtyExtent.Union(renderArea);
2712 overDirtyExtent.Union(renderArea);
2718 for(child = children.last; child; child = child.prev)
2720 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2722 child.ComputeRenderArea(dirtyExtent, overDirtyExtent, backBufferUpdate);
2726 if(backBufferUpdate != null)
2728 renderArea.Copy(backBufferUpdate);
2729 renderArea.Offset(-offsetX, -offsetY);
2731 overRenderArea.Copy(backBufferUpdate);
2732 overRenderArea.Offset(-offsetX, -offsetY);
2738 renderArea.Copy(dirtyArea);
2740 overRenderArea.Copy(dirtyArea);
2743 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2744 dirtyExtentWindow->Copy(dirtyExtent);
2745 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2746 renderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2747 dirtyExtentWindow->Empty();
2749 // Intersect with the clip extent
2750 renderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2753 if(renderArea.count > 10)
2756 printf("\nToo many extents (%d):\n", renderArea.count);
2758 //extent.UnionBox({ 112, 6, 304, 7 }, rootWindow.tempExtents[0]);
2759 //extent.UnionBox({ 112, 8, 304, 17 }, rootWindow.tempExtents[0]);
2764 for(c = 0; c<10; c++)
2767 FASTLIST_LOOP(renderArea, extentBox)
2769 extent.UnionBox(extentBox.box, rootWindow.tempExtents[0]);
2771 renderArea.Copy(extent);
2773 FASTLIST_LOOP(renderArea, extentBox)
2776 printf("(%d, %d) - (%d, %d)\n",
2777 extentBox.box.left, extentBox.box.top,
2778 extentBox.box.right, extentBox.box.bottom);
2782 printf("\nNow %d\n", renderArea.count);
2788 // WHY WAS THIS COMMENTED ??
2790 // Add extent forced by DrawOverChildren to the dirty area, adjusting dirty extent to the window
2791 dirtyExtentWindow->Copy(overDirtyExtent);
2792 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2793 overRenderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2794 dirtyExtentWindow->Empty();
2796 // Intersect with the clip extent
2797 overRenderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2803 if(scrollExtent.count)
2805 // Subtract render extent from scrolling extent
2806 scrollExtent.Exclusion(renderArea, rootWindow.tempExtents[0]);
2808 if(backBufferUpdate == null)
2810 Extent * dirty = &rootWindow.tempExtents[3];
2813 // Intersect scrolling extent with clip extent
2814 scrollExtent.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2816 // offset this scroll to be at the root window level
2817 scrollExtent.Offset(offsetX, offsetY);
2818 // Add area that was scrolled to the dirty extents of the back buffer
2819 rootWindow.dirtyBack.Union(scrollExtent, rootWindow.tempExtents[0]);
2823 // Will need scrolledArea.x & scrolledArea.y to support multiple scrolls
2824 for(scrollBox = (BoxItem)scrollExtent.first; scrollBox; scrollBox = (BoxItem)scrollBox.next)
2825 display.Scroll(scrollBox.box, scrolledArea.x, scrolledArea.y, dirty);
2830 scrollExtent.Empty();
2832 // Add the exposed extent to the window render area
2833 dirty->Offset(-offsetX, -offsetY);
2834 renderArea.Union(dirty, rootWindow.tempExtents[0]);
2839 // Subtract the window's box from the transparency forced extent
2840 dirtyExtent.ExcludeBox({box.left + offsetX, box.top + offsetY, box.right + offsetX, box.bottom + offsetY }, rootWindow.tempExtents[0]);
2846 renderArea.Copy(this.renderArea);
2847 renderArea.Offset(offsetX, offsetY);
2848 dirtyExtent.Union(renderArea);
2854 Extent renderArea { };
2856 renderArea.Copy(overRenderArea);
2857 renderArea.Offset(offsetX, offsetY);
2858 overDirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2863 if(backBufferUpdate != null)
2865 // Remove render area from dirty area
2866 dirtyArea.Exclusion(renderArea, rootWindow.tempExtents[0]);
2868 dirtyArea.Exclusion(overRenderArea, rootWindow.tempExtents[0]);
2875 // Remove the window render area from the dirty extents of the back buffer
2876 rootWindow.dirtyBack.Exclusion(renderArea);
2880 void Render(Extent updateExtent)
2884 Window rootWindow = this.rootWindow;
2885 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2886 if(rootWindow.nativeDecorations)
2888 offsetX -= rootWindow.clientStart.x;
2889 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2892 if(rootWindow.fullRender)
2901 background = Color { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2902 foreground = (background.color.r > 128 || background.color.g > 128) ? black : white;
2907 /*if(renderArea.count)
2908 printf("\n\nRendering %s (%x):\n------------------------------------------\n", _class.name, this);*/
2911 for(extentBox = (BoxItem)renderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
2913 Box box = extentBox.box;
2916 /*printf("(%d, %d) - (%d, %d)\n",
2917 extentBox.box.left, extentBox.box.top,
2918 extentBox.box.right, extentBox.box.bottom);*/
2923 box.left += offsetX;
2925 box.right += offsetX;
2926 box.bottom += offsetY;
2928 if(updateExtent != null)
2929 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
2933 for(child = children.first; child; child = child.next)
2934 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && !child.nonClient)
2935 child.Render(updateExtent);
2937 if(rootWindow.fullRender)
2938 DrawOverChildren(box);
2941 // TO DO: There's an issue about draw over children...
2942 // TO DO: Don't wanna go through this if method isn't used
2943 for(extentBox = (BoxItem)overRenderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
2944 //FASTLIST_LOOP(/*renderArea */overRenderArea, extentBox)
2946 Box box = extentBox.box;
2948 DrawOverChildren(box);
2950 box.left += offsetX;
2952 box.right += offsetX;
2953 box.bottom += offsetY;
2955 if(updateExtent != null)
2956 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
2959 for(child = children.first; child; child = child.next)
2960 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && child.nonClient)
2961 child.Render(updateExtent);
2964 overRenderArea.Empty();
2967 public void UpdateDisplay(void)
2969 if(!manageDisplay) { OnRedraw(null);return; }
2970 if(rootWindow && this != rootWindow)
2971 rootWindow.UpdateDisplay();
2974 Extent dirtyExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be forced due to transparency
2975 Extent overExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that forced for DrawOverChildren
2978 dirtyExtent.Clear();
2981 clipExtent.AddBox(box);
2983 display.StartUpdate();
2985 if(!rootWindow.fullRender)
2987 ComputeClipExtents();
2988 ComputeRenderAreaNonOpaque(dirtyExtent, overExtent, null);
2989 ComputeRenderArea(dirtyExtent, overExtent, null);
2992 clipExtent.Free(null);
2994 dirtyExtent.Free(null);
2995 overExtent.Free(null);
2997 if(display.flags.flipping)
3000 display.Update(null);
3004 Extent updateExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be updated
3005 updateExtent.Clear();
3007 Render(updateExtent);
3009 updateExtent.UnionBox(this.box, tempExtents[0]);
3012 //printf("\n\nUpdate:\n------------------------------------------\n");
3015 //FASTLIST_LOOP(updateExtent, extentBox)
3016 for(extentBox = (BoxItem)updateExtent.first; extentBox; extentBox = (BoxItem)extentBox.next)
3019 /*printf("Updating (%d, %d) - (%d, %d)\n",
3020 extentBox.box.left, extentBox.box.top,
3021 extentBox.box.right, extentBox.box.bottom);*/
3024 display.Update(extentBox.box);
3027 updateExtent.Free(null);
3030 display.EndUpdate();
3038 void UpdateBackDisplay(Box box)
3044 Extent intersection { /*first = -1, last = -1, free = -1*/ };
3046 //printf("UpdateBackDisplay going through!\n");
3047 display.StartUpdate();
3051 intersection.Copy(dirtyBack);
3052 intersection.IntersectBox(box);
3054 dirtyExtent.Clear();
3057 clipExtent.AddBox(box);
3059 if(!rootWindow.fullRender)
3061 ComputeClipExtents();
3062 ComputeRenderArea(dirtyExtent, overExtent, intersection);
3065 clipExtent.Free(null);
3067 intersection.Free(null);
3068 dirtyExtent.Free(null);
3069 overExtent.Free(null);
3074 if(display.flags.flipping)
3075 display.Update(null);
3078 rootWindow.display.Update(box);
3081 display.EndUpdate();
3085 dirtyBack.ExcludeBox(box, rootWindow.tempExtents[0]);
3086 if(dirtyBack.count > MAX_DIRTY_BACK)
3088 BoxItem extentBox, next;
3089 BoxItem first = (BoxItem)ACCESS_ITEM(dirtyBack, dirtyBack.first);
3090 for(extentBox = (BoxItem)dirtyBack.first; extentBox; extentBox = next)
3092 next = (BoxItem)extentBox.next;
3093 if(extentBox != first)
3095 if(extentBox.box.left < first.box.left)
3096 first.box.left = extentBox.box.left;
3097 if(extentBox.box.top < first.box.top)
3098 first.box.top = extentBox.box.top;
3099 if(extentBox.box.right > first.box.right)
3100 first.box.right = extentBox.box.right;
3101 if(extentBox.box.bottom > first.box.bottom)
3102 first.box.bottom = extentBox.box.bottom;
3103 dirtyBack.Delete(extentBox);
3112 // --- Window positioning ---
3113 // --- Window identification ---
3115 // Returns window at position "Position"
3116 Window GetAtPosition(int x, int y, bool clickThru, bool acceptDisabled, Window last)
3118 Window child, result = null;
3120 box.left += absPosition.x;
3121 box.right += absPosition.x;
3122 box.top += absPosition.y;
3123 box.bottom += absPosition.y;
3125 if(!destroyed && visible && (acceptDisabled || !disabled))
3127 int lx = x - absPosition.x;
3128 int ly = y - absPosition.y;
3129 if(IsInside(lx, ly))
3130 // if(box.IsPointInside(Point{x, y}))
3132 if(!clickThru || !style.clickThrough) result = (this == last) ? null : this;
3133 // If the window is disabled, stop looking in children (for acceptDisabled mode)
3136 for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
3138 if(child != statusBar && child.rootWindow == rootWindow)
3140 Window childResult = child.GetAtPosition(x, y, clickThru, acceptDisabled, last);
3147 for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
3149 if(child != statusBar && child.rootWindow == rootWindow)
3151 Window childResult = child.GetAtPosition(x, y, false, acceptDisabled, last);
3163 Window FindModal(void)
3165 Window modalWindow = this, check;
3166 Window check2 = null;
3167 for(check = this; check.master; check = check.master)
3169 if(check.master.modalSlave && check.master.modalSlave.created && check != check.master.modalSlave)
3171 modalWindow = check.master.modalSlave;
3172 check = modalWindow;
3174 // TESTING THIS FOR DROPBOX...
3175 if(!rootWindow || !rootWindow.style.interim)
3177 for(check2 = check; check2.activeChild; check2 = check2.activeChild)
3179 if(check2.modalSlave && check2.modalSlave.created)
3181 modalWindow = check2.modalSlave;
3189 if(modalWindow == this)
3191 for(check = this; check.activeChild; check = check.activeChild)
3193 if(check.modalSlave)
3195 modalWindow = check.modalSlave;
3201 for(; modalWindow.modalSlave && modalWindow.modalSlave.created; modalWindow = modalWindow.modalSlave);
3202 return (modalWindow == this || this == guiApp.interimWindow || IsDescendantOf(modalWindow)) ? null : modalWindow;
3205 void StopMoving(void)
3207 if(this == guiApp.windowMoving)
3209 guiApp.windowMoving = null;
3210 UpdateDecorations();
3211 SetMouseRange(null);
3214 if(rootWindow.active)
3215 guiApp.interfaceDriver.StopMoving(rootWindow);
3218 guiApp.resizeX = guiApp.resizeY = guiApp.resizeEndX = guiApp.resizeEndY = false;
3219 guiApp.windowIsResizing = false;
3223 void SelectMouseCursor(void)
3228 Window cursorWindow = null;
3229 bool rx, ry, rex, rey;
3231 guiApp.desktop.GetMousePosition(&x, &y);
3232 mouseWindow = rootWindow ? rootWindow.GetAtPosition(x,y, true, false, null) : null;
3234 if((guiApp.windowMoving && !guiApp.windowIsResizing) || guiApp.windowScrolling)
3235 guiApp.SetCurrentCursor(guiApp.systemCursors[moving]);
3236 else if(mouseWindow)
3238 modalWindow = mouseWindow.FindModal();
3239 x -= mouseWindow.absPosition.x;
3240 y -= mouseWindow.absPosition.y;
3241 if(guiApp.windowIsResizing)
3243 rex = guiApp.resizeEndX;
3244 rey = guiApp.resizeEndY;
3245 rx = guiApp.resizeX;
3246 ry = guiApp.resizeY;
3247 if((rex && rey) || (rx && ry))
3248 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
3249 else if((rex && ry) || (rx && rey))
3250 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
3251 else if((ry || rey) && (!rx && !rex))
3252 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
3253 else if((rx || rex) && (!ry && !rey))
3254 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
3256 else if(!modalWindow && !guiApp.windowCaptured &&
3257 mouseWindow.IsMouseResizing(x, y, mouseWindow.size.w, mouseWindow.size.h,
3258 &rx, &ry, &rex, &rey))
3260 if((rex && rey) || (rx && ry))
3261 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
3262 else if((rex && ry) || (rx && rey))
3263 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
3264 else if((ry || rey) && (!rx && !rex))
3265 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
3266 else if((rx || rex) && (!ry && !rey))
3267 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
3269 else if(!guiApp.windowCaptured && !modalWindow && !guiApp.interimWindow)
3271 if(!mouseWindow.clientArea.IsPointInside({x - mouseWindow.clientStart.x, y - mouseWindow.clientStart.y}))
3272 cursorWindow = mouseWindow.parent;
3274 cursorWindow = mouseWindow;
3276 else if(!guiApp.interimWindow)
3277 cursorWindow = guiApp.windowCaptured;
3280 for(; !cursorWindow.cursor && !cursorWindow.style.nonClient; cursorWindow = cursorWindow.parent);
3281 guiApp.SetCurrentCursor(cursorWindow.cursor ? cursorWindow.cursor : guiApp.systemCursors[arrow]);
3283 else if(modalWindow)
3285 guiApp.SetCurrentCursor(guiApp.systemCursors[arrow]);
3287 else if(guiApp.interimWindow)
3289 if(guiApp.interimWindow.cursor)
3290 guiApp.SetCurrentCursor(guiApp.interimWindow.cursor);
3292 guiApp.SetCurrentCursor(mouseWindow.cursor ? mouseWindow.cursor : guiApp.systemCursors[arrow]);
3297 // --- State based input ---
3298 bool AcquireInputEx(bool state)
3303 guiApp.interfaceDriver.GetMousePosition(&guiApp.acquiredMouseX, &guiApp.acquiredMouseY);
3304 guiApp.interfaceDriver.SetMousePosition(clientSize.w/2 + absPosition.x, clientSize.h/2 + absPosition.y);
3306 result = guiApp.interfaceDriver.AcquireInput(rootWindow, state);
3308 guiApp.acquiredWindow = state ? this : null;
3311 SetMouseRangeToClient();
3312 guiApp.interfaceDriver.SetMouseCursor((SystemCursor)-1);
3317 SelectMouseCursor();
3319 if(!state) guiApp.interfaceDriver.SetMousePosition(guiApp.acquiredMouseX, guiApp.acquiredMouseY);
3323 // --- Window activation ---
3324 bool PropagateActive(bool active, Window previous, bool * goOnWithActivation, bool direct)
3327 if(!parent || !parent.style.inactive)
3329 Window parent = this.parent;
3332 if(rootWindow == this)
3333 Log(active ? "active\n" : "inactive\n");
3336 // Testing this here...
3337 if(!parent || parent == guiApp.desktop || parent.active)
3339 this.active = active;
3342 // TESTING THIS HERE
3343 UpdateDecorations();
3344 if(result = OnActivate(active, previous, goOnWithActivation, direct) && *goOnWithActivation && master)
3345 result = NotifyActivate(master, this, active, previous);
3348 this.active = !active;
3353 if(!parent || parent == guiApp.desktop || parent.active)
3355 this.active = active;
3357 AcquireInputEx(active);
3362 if(guiApp.caretOwner)
3366 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 1,
3367 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + 1,
3368 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 2,
3369 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + guiApp.caretOwner.caretSize - 1
3371 guiApp.caretOwner.Update(extent);
3374 if(visible || !guiApp.caretOwner)
3375 guiApp.caretOwner = this;
3376 UpdateCaret(false, false);
3382 this.active = false;
3384 AcquireInputEx(active);
3386 if(!active && guiApp.caretOwner == this)
3388 UpdateCaret(false, true);
3389 guiApp.caretOwner = null;
3390 guiApp.interfaceDriver.SetCaret(0,0,0);
3391 guiApp.caretEnabled = false;
3396 if(!active && parent && parent.activeChild && parent.activeChild != this)
3397 if(!parent.activeChild.PropagateActive(false, previous, goOnWithActivation, true) || !*goOnWithActivation)
3403 if(!active && menuBar)
3406 menuBar.OnActivate(false, null, &goOn, true);
3407 menuBar.NotifyActivate(menuBar.master, menuBar, false, null);
3411 if(!activeChild.PropagateActive(active, previous, goOnWithActivation, false) || !*goOnWithActivation)
3420 void ConsequentialMouseMove(bool kbMoving)
3424 if(kbMoving || !guiApp.windowMoving)
3428 if(rootWindow == guiApp.desktop || rootWindow.parent == guiApp.desktop)
3430 guiApp.interfaceDriver.GetMousePosition(&x, &y);
3432 if(guiApp.windowMoving || rootWindow.GetAtPosition(x, y, true, false, null))
3433 rootWindow.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove, x, y, &mods, true, false);
3439 bool IsDescendantOf(Window ancestor)
3442 for(window = this; window && window != ancestor; window = window.parent);
3443 return window == ancestor;
3446 bool IsSlaveOf(Window master)
3449 for(window = this; window && window != master; window = window.master);
3450 return window == master;
3453 bool ActivateEx(bool active, bool activateParent, bool moveInactive, bool activateRoot, Window external, Window externalSwap)
3457 if(this && !destroyed /*&& state != Hidden*/)
3459 Window swap = externalSwap;
3467 if(activateParent &&
3468 (parent.activeChild != this ||
3469 (guiApp.interimWindow && !IsDescendantOf(guiApp.interimWindow))) &&
3470 active && _isModal &&
3471 parent != master && master)
3472 master.ActivateEx(true, true, false, activateRoot, external, externalSwap);
3478 bool real = parent.activeChild != this;
3480 // TEST THIS: New activateParent check here!!! CAUSED MENUS NOT GOING AWAY
3481 if(/*activateParent && */guiApp.interimWindow &&
3482 !IsDescendantOf(guiApp.interimWindow) &&
3483 !IsSlaveOf(guiApp.interimWindow))
3485 Window interimWindow = guiApp.interimWindow;
3486 while(interimWindow && interimWindow != this)
3488 Window master = interimWindow.master;
3490 guiApp.interimWindow = null;
3491 if(guiApp.caretOwner)
3492 guiApp.caretOwner.UpdateCaret(false, false);
3494 incref interimWindow;
3495 if(!interimWindow.PropagateActive(false, this, &goOn, true))
3500 delete interimWindow;
3501 interimWindow = (master && master.style.interim) ? master : null;
3506 guiApp.interimWindow = this;
3507 /*guiApp.interfaceDriver.SetCaret(0,0,0);
3508 guiApp.caretEnabled = false;*/
3509 UpdateCaret(false, true);
3514 bool acquireInput = false;
3516 parent.activeChild &&
3517 parent.activeChild.state == maximized &&
3518 parent != guiApp.desktop;
3520 if(!style.inactive) // (!style.isRemote || parent.active || parent.style.hidden))
3525 swap = parent.activeChild;
3526 if(swap && swap.destroyed) swap = null;
3527 if(swap && swap != this)
3530 if(!swap.PropagateActive(false, this, &goOn, true))
3531 swap = parent.activeChild;
3542 if(!parent || parent.activeChild != this || style.interim)
3545 result = PropagateActive(true, swap, &goOn, true);
3546 if(!result && !goOn)
3551 acquireInput = true;
3555 if(style.hasMaximize && parent != guiApp.desktop)
3558 SetState(maximized, false, 0);
3559 else if(state != maximized)
3562 for(child = parent.children.first; child; child = child.next)
3564 if(this != child && child.state == maximized)
3565 child.SetState(normal, false, 0);
3572 if(!style.inactive && !style.interim /*&& (!style.isRemote || parent.active || parent.style.hidden)*/)
3574 Window previous = parent.activeClient;
3575 parent.activeChild = this;
3576 if(!style.nonClient /*&& style.isActiveClient*/)
3578 if(style.isActiveClient && !style.hidden)
3579 parent.activeClient = this;
3580 parent.UpdateActiveDocument(previous);
3585 //if(!style.isRemote)
3587 if(rootWindow != this)
3589 if(activateParent && parent && !parent.active /*parent != parent.parent.activeChild*/)
3590 parent.ActivateEx(true, true, moveInactive, activateRoot, external, externalSwap);
3592 else if(!guiApp.fullScreenMode)
3594 Window modalRoot = FindModal();
3595 if(!modalRoot) modalRoot = this;
3596 if(!modalRoot.isForegroundWindow)
3598 modalRoot.isForegroundWindow = true;
3599 // To check : Why is parent null?
3600 if(activateRoot && modalRoot.parent && !modalRoot.parent.display && external != modalRoot)
3602 guiApp.interfaceDriver.ActivateRootWindow(modalRoot);
3604 modalRoot.isForegroundWindow = false;
3609 if(result && real && (!style.inactive || moveInactive) && parent)
3611 Window last = parent.children.last;
3613 if(!style.stayOnTop)
3614 for(; last && last.style.stayOnTop; last = last.prev);
3616 parent.children.Move(this, last);
3618 // Definitely don't want that: why not?
3622 parent.childrenOrder.Move(order, parent.childrenOrder.last);
3628 if(!parent || style.interim || (parent.activeChild == this && !style.inactive))
3635 parent.activeChild = null;
3636 if(!style.nonClient /*&& style.isActiveClient*/)
3638 Window previous = parent.activeClient;
3639 if(style.isActiveClient)
3640 parent.activeClient = null;
3641 parent.UpdateActiveDocument(previous);
3645 if(this == guiApp.interimWindow)
3647 guiApp.interimWindow = null;
3648 if(guiApp.caretOwner)
3649 guiApp.caretOwner.UpdateCaret(false, false);
3651 if(!PropagateActive(false, externalSwap, &goOn, true) || !goOn)
3658 if(!active || !swap)
3659 UpdateDecorations();
3661 swap.UpdateDecorations();
3663 if(active && rootWindow != this)
3664 ConsequentialMouseMove(false);
3671 // --- Input Messages ---
3672 void ::UpdateMouseMove(int mouseX, int mouseY, bool consequential)
3674 static bool reEntrancy = false;
3675 if(reEntrancy) return;
3679 guiApp.cursorUpdate = true;
3680 if(guiApp.windowScrolling && !consequential)
3682 guiApp.windowScrolling.SetScrollPosition(
3683 (guiApp.windowScrolling.sbh) ?
3684 (guiApp.windowScrollingBefore.x - mouseX + guiApp.windowScrollingStart.x) : 0,
3685 (guiApp.windowScrolling.sbv) ?
3686 (guiApp.windowScrollingBefore.y - mouseY + guiApp.windowScrollingStart.y) : 0);
3688 if(guiApp.windowMoving)
3690 if(mouseX != guiApp.movingLast.x || mouseY != guiApp.movingLast.y)
3692 Window window = guiApp.windowMoving;
3694 int w = window.size.w;
3695 int h = window.size.h;
3700 rx = mouseX - guiApp.windowMovingStart.x;
3701 ry = mouseY - guiApp.windowMovingStart.y;
3704 window.GetDecorationsSize(&ew, &eh);
3706 if(guiApp.windowIsResizing)
3708 x = window.scrolledPos.x;
3709 y = window.scrolledPos.y;
3713 aw = Max(guiApp.windowResizingBefore.w - rx,window.skinMinSize.w);
3714 rx = guiApp.windowResizingBefore.w - aw;
3715 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3716 w = guiApp.windowResizingBefore.w - rx;
3720 ah = Max(guiApp.windowResizingBefore.h - ry,window.skinMinSize.h);
3721 ry = guiApp.windowResizingBefore.h - ah;
3722 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3723 ry = Max(ry, -guiApp.windowMovingBefore.y);
3724 h = guiApp.windowResizingBefore.h - ry;
3726 if(guiApp.resizeEndX)
3728 w = guiApp.windowResizingBefore.w + rx;
3731 if(guiApp.resizeEndY) h = guiApp.windowResizingBefore.h + ry;
3739 w = Max(w, window.minSize.w);
3740 h = Max(h, window.minSize.h);
3741 w = Min(w, window.maxSize.w);
3742 h = Min(h, window.maxSize.h);
3744 if(!window.OnResizing(&w, &h))
3746 w = window.clientSize.w;
3747 h = window.clientSize.h;
3750 w = Max(w, window.skinMinSize.w);
3751 h = Max(h, window.skinMinSize.h);
3758 SNAPDOWN(w, textCellW);
3759 SNAPDOWN(h, textCellH);
3764 aw = Max(w,window.skinMinSize.w);
3765 rx = guiApp.windowResizingBefore.w - aw;
3766 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3767 w = guiApp.windowResizingBefore.w - rx;
3771 ah = Max(h,window.skinMinSize.h);
3772 ry = guiApp.windowResizingBefore.h - ah;
3773 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3774 ry = Max(ry, -guiApp.windowMovingBefore.y);
3775 h = guiApp.windowResizingBefore.h - ry;
3780 if(!guiApp.windowIsResizing || guiApp.resizeX)
3781 x = guiApp.windowMovingBefore.x + rx;
3782 if(!guiApp.windowIsResizing || guiApp.resizeY)
3783 y = guiApp.windowMovingBefore.y + ry;
3785 if(!guiApp.windowIsResizing)
3788 if(window.parent == guiApp.desktop && guiApp.virtualScreen.w)
3790 x = Min(x, (guiApp.virtualScreen.w + guiApp.virtualScreenPos.x) -1);
3791 y = Min(y, (guiApp.virtualScreen.h + guiApp.virtualScreenPos.y) -1);
3792 x = Max(x,-(w-1) + guiApp.virtualScreenPos.x);
3793 y = Max(y,-(h-1) + guiApp.virtualScreenPos.y);
3797 x = Min(x, (window.parent.reqScrollArea.w ? window.parent.reqScrollArea.w : window.parent.clientSize.w) -1);
3798 y = Min(y, (window.parent.reqScrollArea.h ? window.parent.reqScrollArea.h : window.parent.clientSize.h) -1);
3804 if(!guiApp.windowIsResizing || (guiApp.resizeX || guiApp.resizeY))
3806 if(!window.OnMoving(&x, &y, w, h))
3808 x = window.scrolledPos.x;
3809 y = window.scrolledPos.y;
3815 SNAPDOWN(x, textCellW);
3816 SNAPDOWN(y, textCellH);
3819 if(!window.style.nonClient)
3821 if(!window.style.fixed /*|| window.style.isDocument*/)
3823 if(!window.style.dontScrollHorz)
3824 x += window.parent.scroll.x;
3825 if(!window.style.dontScrollVert)
3826 y += window.parent.scroll.y;
3830 // Break the anchors for moveable/resizable windows
3831 // Will probably cause problem with IDE windows... Will probably need a way to specify if anchors should break
3832 if(window.style.fixed)
3834 if(window.state == normal)
3836 window.normalAnchor = Anchor { left = x, top = y };
3837 window.normalSizeAnchor = SizeAnchor { { w, h } };
3838 window.anchored = false;
3842 window.stateAnchor = Anchor { left = x, top = y };
3843 window.stateSizeAnchor = SizeAnchor { { w, h } };
3845 window.Position(x, y, w, h, false, true, guiApp.windowIsResizing, guiApp.windowIsResizing, false, true);
3846 // TOCHECK: Investigate why the following only redraws the scrollbars
3847 //window.Position(x, y, w, h, false, true, true, true, false, true);
3849 guiApp.movingLast.x = mouseX;
3850 guiApp.movingLast.y = mouseY;
3856 public bool MouseMessage(uint method, int x, int y, Modifiers * mods, bool consequential, bool activate)
3859 bool wasMoving = guiApp.windowMoving ? true : false;
3860 bool wasScrolling = guiApp.windowScrolling ? true : false;
3862 while(result && w != this)
3864 Window msgWindow = GetAtPosition(x,y, false, true, w);
3865 Window trueWindow = GetAtPosition(x,y, false, false, w);
3866 bool windowDragged = false;
3871 window = (w && !w.disabled) ? w : null;
3873 if(trueWindow) incref trueWindow;
3875 if(consequential) mods->isSideEffect = true;
3877 UpdateMouseMove(x, y, consequential);
3879 if(guiApp.windowCaptured && (guiApp.windowCaptured.rootWindow == this))
3881 if(!guiApp.windowCaptured.isEnabled)
3882 guiApp.windowCaptured.ReleaseCapture();
3884 window = guiApp.windowCaptured;
3887 if(trueWindow && activate &&
3888 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
3889 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
3890 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
3891 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
3893 if(mods->alt && !mods->ctrl && !mods->shift)
3895 Window moved = trueWindow;
3896 for(moved = trueWindow; moved; moved = moved.parent)
3897 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
3902 windowDragged = true;
3904 // Cancel the ALT menu toggling...
3905 window.rootWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
3910 if(window && activate &&
3911 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
3912 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
3913 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
3914 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
3916 Window modalWindow = window.FindModal();
3918 /*if(mods->alt && !mods->shift && !mods->ctrl)
3920 Window moved = window;
3921 for(moved = window; moved; moved = moved.parent)
3922 if(method == OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
3927 windowDragged = true;
3929 // Cancel the ALT menu toggling...
3930 window.rootWindow.KeyMessage(OnKeyDown, 0, 0);
3936 Window activateWindow = modalWindow ? modalWindow : window;
3937 if(activateWindow && !activateWindow.isRemote)
3939 bool doActivation = true;
3940 //bool needToDoActivation = false;
3941 Window check = activateWindow;
3943 for(check = activateWindow; check && check != guiApp.desktop; check = check.parent)
3945 if(!check.style.inactive)
3947 //needToDoActivation = true;
3949 doActivation = false;
3954 if(!needToDoActivation)
3955 doActivation = false;
3958 if((doActivation && (activateWindow.parent != guiApp.desktop || guiApp.fullScreen)) ||
3959 (guiApp.interimWindow && !window.IsDescendantOf(guiApp.interimWindow)))
3961 // Let the OnLeftButtonDown do the activating instead
3962 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
3970 incref activateWindow;
3971 if(!activateWindow.ActivateEx(true, true, false, true, null, null))
3973 delete activateWindow;
3977 if(activateWindow._refCount == 1)
3979 delete activateWindow;
3983 delete activateWindow;
3985 mods->isActivate = true;
3989 if(!modalWindow && window && !window.destroyed)
3991 if(!guiApp.windowCaptured || windowDragged)
3993 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown)
3995 bool moving = ((window.state != maximized &&
3996 window.IsMouseMoving(
3997 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
3998 || (guiApp.windowMoving && !guiApp.windowIsResizing);
4000 if(!moving && window.IsMouseResizing(
4001 x - window.absPosition.x,
4002 y - window.absPosition.y,
4003 window.size.w, window.size.h,
4004 &guiApp.resizeX, &guiApp.resizeY, &guiApp.resizeEndX, &guiApp.resizeEndY))
4006 guiApp.windowIsResizing = true;
4007 guiApp.windowResizingBefore.w = window.size.w;
4008 guiApp.windowResizingBefore.h = window.size.h;
4010 if(guiApp.windowIsResizing || windowDragged || moving)
4013 guiApp.windowMoving = window;
4014 guiApp.windowMovingStart.x = guiApp.movingLast.x = x;
4015 guiApp.windowMovingStart.y = guiApp.movingLast.y = y;
4016 guiApp.windowMovingBefore.x = window.position.x;//s;
4017 guiApp.windowMovingBefore.y = window.position.y;//s;
4018 if(guiApp.windowMoving == guiApp.windowMoving.rootWindow)
4019 guiApp.interfaceDriver.StartMoving(guiApp.windowMoving.rootWindow, 0,0,false);
4022 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown)
4024 if(window.style.fixed &&
4026 window.IsMouseMoving(
4027 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4029 window.ShowSysMenu(x, y);
4033 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown)
4035 if(window.sbv || window.sbh)
4038 guiApp.windowScrolling = window;
4039 guiApp.windowScrollingStart.x = x;
4040 guiApp.windowScrollingStart.y = y;
4041 guiApp.windowScrollingBefore.x = window.scroll.x;
4042 guiApp.windowScrollingBefore.y = window.scroll.y;
4045 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4047 if(window.style.hasMaximize &&
4048 window.IsMouseMoving(
4049 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h))
4052 (window.state == maximized) ? normal : maximized, false, *mods);
4060 if(guiApp.windowMoving)
4062 if(guiApp.windowMoving.parent)
4064 if(guiApp.windowMoving.style.nonClient)
4065 guiApp.windowMoving.parent.SetMouseRangeToWindow();
4067 guiApp.windowMoving.parent.SetMouseRangeToClient();
4071 window.UpdateDecorations();
4074 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp)
4076 // Log("\n*** LEFT BUTTON UP ***\n");
4077 if(guiApp.windowMoving)
4078 guiApp.windowMoving.StopMoving();
4080 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp)
4082 if(guiApp.windowScrolling)
4084 Window windowScrolling = guiApp.windowScrolling;
4085 guiApp.windowScrolling = null;
4086 windowScrolling.ReleaseCapture();
4090 if(!result || (window && window.destroyed)) window = null;
4092 if(window && window.FindModal())
4095 if(trueWindow && trueWindow.FindModal())
4103 msgWindow = GetAtPosition(x,y, true, false);
4105 msgWindow.SelectMouseCursor();
4108 if(guiApp.windowCaptured || trueWindow)
4110 Window prevWindow = guiApp.prevWindow;
4111 if(guiApp.prevWindow && trueWindow != guiApp.prevWindow)
4113 guiApp.prevWindow.mouseInside = false;
4114 guiApp.prevWindow = null;
4116 // Eventually fix this not to include captured?
4117 if(!prevWindow.OnMouseLeave(*mods))
4120 if(result && trueWindow && !trueWindow.destroyed/* && trueWindow == window*/)
4122 Box box = trueWindow.box;
4123 box.left += trueWindow.absPosition.x;
4124 box.right += trueWindow.absPosition.x;
4125 box.top += trueWindow.absPosition.y;
4126 box.bottom += trueWindow.absPosition.y;
4128 if(box.IsPointInside({x, y}) && trueWindow != /*guiApp.*/prevWindow /*!trueWindow.mouseInside*/)
4130 int overX = x - (trueWindow.absPosition.x + trueWindow.clientStart.x);
4131 int overY = y - (trueWindow.absPosition.y + trueWindow.clientStart.y);
4133 overX = Max(Min(overX, 32767),-32768);
4134 overY = Max(Min(overY, 32767),-32768);
4136 trueWindow.mouseInside = true;
4137 if(!trueWindow.OnMouseOver(overX, overY, *mods))
4141 if(trueWindow && trueWindow._refCount > 1 && !trueWindow.destroyed)
4142 guiApp.prevWindow = trueWindow;
4144 guiApp.prevWindow = null;
4146 SelectMouseCursor();
4148 if(window && !guiApp.windowMoving && !wasMoving && !wasScrolling)
4150 int clientX = x - (window.absPosition.x + window.clientStart.x);
4151 int clientY = y - (window.absPosition.y + window.clientStart.y);
4153 bool (* MouseMethod)(Window instance, int x, int y, Modifiers mods);
4155 clientX = Max(Min(clientX, 32767),-32768);
4156 clientY = Max(Min(clientY, 32767),-32768);
4158 MouseMethod = (void *)window._vTbl[method];
4160 if(MouseMethod /*&& !consequential*/ && !window.disabled)
4163 if(!MouseMethod(window, clientX, clientY, *mods))
4170 if(result && w && w.clickThrough && w.parent)
4175 if(!result || !w || !w.clickThrough)
4182 // --- Mouse cursor management ---
4184 bool KeyMessage(uint method, Key key, unichar character)
4189 if(guiApp.interimWindow)
4190 this = guiApp.interimWindow;
4193 if((SmartKey)key != alt && (SmartKey)key != Key::control && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && parent && this != parent.menuBar)
4197 if(!style.inactive || rootWindow != this)
4199 bool (*KeyMethod)(Window window, Key key, unichar ch) = (void *)_vTbl[method];
4200 Window modalWindow = FindModal();
4201 Window interimMaster = master ? master.rootWindow : null;
4205 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4206 status = OnSysKeyDown(key, character);
4207 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4208 status = OnSysKeyHit(key, character);
4209 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4210 status = OnSysKeyUp(key, character);
4217 // Process Key Message for Internal UI Keyboard actions
4218 if(status && !destroyed && menuBar && state != minimized)
4221 if((SmartKey)key != alt)
4222 menuBar.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4225 SmartKey sk = (SmartKey) key;
4226 if((character && !key.alt && !key.ctrl) || sk == left || sk == right || sk == up || sk == down || sk == home || sk == end || sk == escape || sk == alt)
4228 status = menuBar.KeyMessage(method, key, character);
4233 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4234 menuBar.OnKeyHit(escape, 0);
4236 if(!menuBar.focus && guiApp.caretOwner)
4237 guiApp.caretOwner.UpdateCaret(true, false);
4240 if(!destroyed && status)
4242 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4246 case left: case up: case right: case down:
4247 if(guiApp.windowMoving == this)
4250 int w = guiApp.windowMoving.size.w;
4251 int h = guiApp.windowMoving.size.h;
4252 int x = guiApp.windowMoving.scrolledPos.x;
4253 int y = guiApp.windowMoving.scrolledPos.y;
4257 if(key == down || key == up)
4258 step = Max(step, textCellH);
4260 step = Max(step, textCellW);
4263 if(guiApp.windowIsResizing)
4267 case left: w-=step; break;
4268 case right: w+=step; break;
4269 case up: h-=step; break;
4270 case down: h+=step; break;
4277 case left: x-=step; break;
4278 case right: x+=step; break;
4279 case up: y-=step; break;
4280 case down: y+=step; break;
4284 if(guiApp.resizeX) x += w - guiApp.windowMoving.size.w;
4285 if(guiApp.resizeY) y += h - guiApp.windowMoving.size.h;
4287 if(!guiApp.windowIsResizing || guiApp.resizeX)
4288 x = (x - guiApp.windowMovingBefore.x) + guiApp.windowMovingStart.x;
4290 x = (w - guiApp.windowResizingBefore.w) + guiApp.windowMovingStart.x;
4292 if(!guiApp.windowIsResizing || guiApp.resizeY)
4293 y = (y - guiApp.windowMovingBefore.y) + guiApp.windowMovingStart.y;
4295 y = (h - guiApp.windowResizingBefore.h) + guiApp.windowMovingStart.y;
4297 guiApp.interfaceDriver.SetMousePosition(x, y);
4298 ConsequentialMouseMove(true);
4306 if(guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4308 guiApp.windowMoving.StopMoving();
4309 ConsequentialMouseMove(false);
4317 ShowSysMenu(absPosition.x, absPosition.y);
4325 if(!destroyed && status && state != minimized)
4327 // Process all the way down the children
4328 if(activeChild && !activeChild.disabled)
4330 status = activeChild.KeyMessage(method, key, character);
4332 if(status && activeClient && activeChild != activeClient && !activeClient.disabled && (key.alt || key.ctrl) &&
4333 key.code != left && key.code != right && key.code != up && key.code != down)
4335 status = activeClient.KeyMessage(method, key, character);
4339 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4341 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && !defaultControl.disabled && state != minimized)
4342 // && defaultControl != activeChild)
4344 delete previousActive;
4345 previousActive = activeChild;
4346 if(previousActive) incref previousActive;
4348 ConsequentialMouseMove(false);
4349 if((defaultControl.active ||
4350 defaultControl.ActivateEx(true, true, false, true, null, null)) && !defaultControl.disabled)
4351 defaultControl.KeyMessage(method, defaultKey, character);
4357 if(!destroyed && status && (!modalWindow || this == guiApp.desktop))
4359 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4366 ShowSysMenu(absPosition.x, absPosition.y);
4373 if(this != guiApp.desktop)
4375 if(!guiApp.windowMoving && !guiApp.windowCaptured)
4377 if(state != maximized && (key.shift ? style.sizeable : style.fixed))
4379 MenuMoveOrSize(key.shift, true);
4383 else if(guiApp.windowMoving)
4385 guiApp.windowMoving.StopMoving();
4386 ConsequentialMouseMove(false);
4394 if(!destroyed && status && state != minimized)
4396 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4400 case tab: case shiftTab:
4402 Window cycleParent = this;
4403 if(this == guiApp.interimWindow && !master.style.interim && !cycleParent.style.tabCycle)
4404 cycleParent = master.parent;
4406 if(!guiApp.windowCaptured && cycleParent.style.tabCycle)
4408 if(cycleParent.CycleChildren(!key.shift, false, false, true))
4410 Window child = cycleParent.activeChild;
4412 // Scroll the window to include the active control
4414 if(cycleParent.sbh && !child.style.dontScrollHorz)
4416 if(child.scrolledPos.x < 0)
4417 cycleParent.sbh.Action(Position,
4418 cycleParent.scroll.x + child.scrolledPos.x, 0);
4419 else if(child.scrolledPos.x + child.size.w > cycleParent.clientSize.w)
4420 cycleParent.sbh.Action(Position,
4421 cycleParent.scroll.x + child.scrolledPos.x + child.size.w - cycleParent.clientSize.w, 0);
4423 if(cycleParent.sbv && !child.style.dontScrollVert)
4425 if(child.scrolledPos.y < 0)
4426 cycleParent.sbv.Action(Position,
4427 cycleParent.scroll.y + child.scrolledPos.y, 0);
4428 else if(child.scrolledPos.y + child.size.w > window.clientSize.h)
4429 cycleParent.sbv.Action(Position,
4430 cycleParent.scroll.y + child.scrolledPos.y+child.size.h - cycleParent.clientSize.h, 0);
4433 cycleParent.ConsequentialMouseMove(false);
4439 case f6: case shiftF6:
4440 if(!guiApp.windowMoving /*!guiApp.windowCaptured*/)
4442 // NOT NEEDED... guiApp.windowMoving.ReleaseCapture();
4443 if(parent == guiApp.desktop)
4444 if(guiApp.desktop.CycleChildren(key.shift, true, false, true))
4449 if(style.tabCycle ||
4450 CycleChildren(key.shift, true, false, true))
4458 // mIRC Style Window Shortcuts
4459 case alt1: case alt2: case alt3: case alt4: case alt5:
4460 case alt6: case alt7: case alt8: case alt9: case alt0:
4465 for(document = children.first; document; document = document.next)
4467 if(document.style.isDocument && document.documentID - 1 == key.code - k1)
4469 if(document == activeChild)
4471 if(document.state == minimized)
4472 document.SetState(normal, false, key);
4475 document.SetState(minimized, false, key);
4476 CycleChildren(false, true, false);
4481 if(activeChild.state == maximized && document.style.hasMaximize)
4482 document.SetState(maximized, false, key);
4483 else if(document.state == minimized)
4484 document.SetState(normal, false, key);
4485 document.Activate();
4500 if(!destroyed && status)
4502 if(state == minimized)
4507 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4509 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && previousActive)
4511 if(defaultControl.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, key, character))
4512 previousActive.ActivateEx(true, false, false, true, null, null);
4513 delete previousActive;
4519 if(!destroyed && status)
4521 status = ProcessHotKeys(method, key, character);
4523 if(!destroyed && status && !modalWindow && state != minimized)
4526 status = KeyMethod(this, key, character);
4527 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4528 status = OnKeyHit(key, character);
4529 if(!destroyed && status && (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit))
4531 bool result = false;
4534 case ctrlUp: case ctrlDown:
4535 if(sbv && !guiApp.windowScrolling)
4536 result = sbv.Action((key == ctrlUp) ? up : down, 0, key);
4538 case wheelUp: case wheelDown:
4539 if(sbv && !guiApp.windowScrolling)
4541 result = sbv.Action((key == wheelUp) ? wheelUp : wheelDown, 0, key);
4542 // Do we want to do a consequential move regardless of result in this case?
4543 ConsequentialMouseMove(false);
4546 case ctrlPageUp: case ctrlPageDown:
4547 if(sbh && !guiApp.windowScrolling)
4548 result = sbh.Action((key == ctrlPageUp) ? up : down, 0, key);
4553 ConsequentialMouseMove(false);
4558 if(status && !destroyed && menuBar && state != minimized)
4559 status = menuBar.KeyMessage(method, key, character);
4561 if(style.interim && /*destroyed && */status && interimMaster)
4563 // Testing this... for Ctrl-O to open dialog when autocompletion listbox is popped...
4564 status = interimMaster.KeyMessage(method, key, character);
4571 bool ProcessHotKeys(uint method, Key key, unichar character)
4576 for(hotKey = hotKeys.first; hotKey; hotKey = hotKey.next)
4577 if((hotKey.key == key || (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp && hotKey.key.code == key.code)) &&
4578 !hotKey.window.disabled && (hotKey.window.style.nonClient || state != minimized))
4580 Window hotKeyWindow = hotKey.window;
4581 Window parent = hotKeyWindow.parent;
4582 Window prevActiveWindow = activeChild;
4584 // Don't process non-visible buttons, but make an exception for the Alt-F4 with Native Decorations turned on
4585 if(hotKeyWindow.style.hidden && (!hotKeyWindow.style.nonClient || !parent || !parent.nativeDecorations || (hotKeyWindow != parent.sysButtons[2] && hotKeyWindow != parent.sysButtons[1] )))
4588 if(prevActiveWindow) incref prevActiveWindow;
4589 incref hotKeyWindow;
4590 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && !hotKeyWindow.style.nonClient)
4591 if(!hotKeyWindow.ActivateEx(true, true, false, true, null, null))
4594 delete hotKeyWindow;
4595 delete prevActiveWindow;
4599 if(hotKeyWindow.style.nonClient && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4600 method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
4601 if(!hotKeyWindow.KeyMessage(method, Key::hotKey, character))
4603 // ********* WORKING ON THIS ***********
4604 if(prevActiveWindow && !guiApp.interimWindow)
4605 prevActiveWindow.ActivateEx(true, false, false, false, null, null);
4608 else if(hotKeyWindow.style.inactive)
4609 status = hotKeyWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, Key::hotKey, character);
4611 delete prevActiveWindow;
4612 delete hotKeyWindow;
4613 // For Key Ups, don't set status to false... (e.g.: Releasing Enter vs AltEnter hot key)
4614 if(method != __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4618 if(status && tabCycle)
4621 for(child = children.first; child; child = child.next)
4623 if(child.tabCycle && !child.ProcessHotKeys(method, key, character))
4634 // --- Windows and graphics initialization / termination ---
4635 bool SetupRoot(void)
4639 // Setup relationship with outside world (bb root || !bb)
4640 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || this == guiApp.desktop ||
4641 (_displayDriver && dispDriver != parent.dispDriver))
4645 tempExtents = new0 Extent[4];
4650 /*if(guiApp.fullScreenMode)
4651 rootWindow = guiApp.desktop;
4653 //rootWindow = parent.created ? parent.rootWindow : null;
4654 rootWindow = parent.rootWindow;
4657 against = &parent.box;
4659 against = &parent.clientArea;
4662 for(child = children.first; child; child = child.next)
4665 return (rootWindow && (rootWindow == this || rootWindow.created)) ? true : false;
4668 bool Setup(bool positionChildren)
4670 bool result = false;
4673 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || (guiApp.fullScreenMode && (this == guiApp.desktop || (_displayDriver && dispDriver != parent.dispDriver))))
4675 subclass(DisplayDriver) dDriver = (dispDriver && !formDesigner) ? dispDriver : GetDisplayDriver(guiApp.defaultDisplayDriver);
4676 DisplaySystem displaySystem = dDriver ? dDriver.displaySystem : null;
4678 windowHandle = dDriver.printer ? null : guiApp.interfaceDriver.CreateRootWindow(this);
4680 // This was here, is it really needed?
4681 //guiApp.interfaceDriver.ActivateRootWindow(this);
4685 displaySystem = DisplaySystem {};
4686 if(!displaySystem.Create(dDriver.name, guiApp.fullScreenMode ? windowHandle : windowHandle /*null*/, guiApp.fullScreenMode))
4688 delete displaySystem;
4693 display = Display { alphaBlend = alphaBlend, useSharedMemory = useSharedMemory, windowDriverData = windowData };
4694 if(display.Create(displaySystem, windowHandle))
4701 guiApp.interfaceDriver.SetIcon(this, icon);
4703 else if(this != guiApp.desktop)
4705 display = rootWindow ? rootWindow.display : null;
4711 if(guiApp.acquiredWindow && rootWindow == guiApp.acquiredWindow.rootWindow)
4712 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, true);
4714 for(child = children.first; child; child = child.next)
4716 if(child.created && !child.Setup(false))
4722 bool SetupDisplay(void)
4724 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
4725 if(is3D) return Window3D_SetupDisplay(this); else
4732 class_data void ** pureVTbl;
4734 bool LoadGraphics(bool creation, bool resetAnchors)
4736 bool result = false;
4737 bool success = false;
4739 WindowState stateBackup = state;
4742 if(!rootWindow.created)
4746 if(((subclass(Window))_class).pureVTbl)
4748 if(_vTbl == _class._vTbl)
4750 _vTbl = ((subclass(Window))_class).pureVTbl;
4755 for(m = 0; m < _class.vTblSize; m++)
4757 if(_vTbl[m] == _class._vTbl[m])
4758 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
4762 if(guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
4764 if(_vTbl == ((subclass(Window))_class).pureVTbl)
4766 _vTbl = _class._vTbl;
4771 for(m = 0; m < _class.vTblSize; m++)
4773 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
4774 _vTbl[m] = _class._vTbl[m];
4779 if(guiApp.fullScreenMode || this != guiApp.desktop)
4781 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
4787 display.Lock(false);
4788 if(rootWindow == this)
4790 // Set Color Palette
4791 display.SetPalette(palette, true);
4795 if(guiApp.fullScreenMode && this == guiApp.desktop)
4800 for(c=0; c<SystemCursor::enumSize; c++)
4801 if(!guiApp.systemCursors[c].bitmap)
4803 guiApp.systemCursors[c].bitmapName = guiApp.currentSkin.CursorsBitmaps(c,
4804 &guiApp.systemCursors[c].hotSpotX,&guiApp.systemCursors[c].hotSpotY, &guiApp.systemCursors[c].paletteShades);
4805 if(guiApp.systemCursors[c].bitmapName)
4807 guiApp.systemCursors[c].bitmap = eBitmap_LoadT(guiApp.systemCursors[c].bitmapName, null,
4808 guiApp.systemCursors[c].paletteShades ? null : guiApp.desktop.display.displaySystem);
4809 if(guiApp.systemCursors[c].bitmap)
4810 guiApp.systemCursors[c].bitmap.paletteShades = guiApp.systemCursors[c].paletteShades;
4815 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
4817 cursor.bitmap = eBitmap_LoadT(cursor.bitmapName, null,
4818 cursor.paletteShades ? null : guiApp.desktop.display.displaySystem);
4820 cursor.bitmap.paletteShades = cursor.paletteShades;
4824 guiApp.cursorUpdate = true;
4827 ConsequentialMouseMove(false);
4833 // Load Window Graphic Resources
4836 if(usedFont == setFont || usedFont == window.systemFont)
4837 RemoveResource(usedFont);
4840 RemoveResource(setFont); // TESTING setFont instead of usedFont);
4843 RemoveResource(systemFont);
4846 RemoveResource(captionFont);
4848 for(ptr = resources.first; ptr; ptr = ptr.next)
4850 ptr.loaded = display.displaySystem.LoadResource(ptr.resource);
4853 AddResource(setFont);
4855 AddResource(systemFont);
4857 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
4864 //if(master && master.font)
4865 if(parent && parent.font)
4869 faceName = parent.font.faceName,
4870 size = parent.font.size,
4871 bold = parent.font.bold,
4872 italic = parent.font.italic,
4873 underline = parent.font.underline
4875 //font = parent.font;
4876 watch(parent) { font { } };
4879 font = guiApp.currentSkin.SystemFont();
4886 captionFont = guiApp.currentSkin.CaptionFont();
4887 AddResource(captionFont);
4889 if(OnLoadGraphics())
4895 //SetScrollLineStep(sbStep.x, sbStep.y);
4897 if(this != guiApp.desktop)
4901 normalAnchor = anchor;
4902 normalSizeAnchor = sizeAnchor;
4905 // Break the anchors for moveable/resizable windows
4907 if(style.fixed && style.isDocument)
4909 ComputeAnchors(ax, ay, aw, ah, &x, &y, &w, &h);
4921 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
4922 stateSizeAnchor = SizeAnchor {};
4927 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
4932 left = (iconID % maxIcons) * MINIMIZED_WIDTH,
4933 bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24)
4936 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
4940 stateAnchor = normalAnchor;
4941 stateSizeAnchor = normalSizeAnchor;
4944 position = Point { };
4945 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
4956 if(Position(x, y, w, h, true, false, true, true, true, true))
4958 if((this != guiApp.desktop || guiApp.fullScreenMode) && rootWindow == this)
4961 guiApp.interfaceDriver.SetRootWindowState(this, normal, true);
4978 success = result = true;
4981 if(!creation && result)
4983 // Load menu bar first because sys buttons are on it...
4986 if(!menuBar.LoadGraphics(false, resetAnchors))
4992 for(child = children.first; child; child = child.next)
4994 if(child.created && child != menuBar && !child.LoadGraphics(false, resetAnchors))
5001 CreateSystemChildren();
5005 if(this == guiApp.desktop && !guiApp.fullScreenMode)
5008 guiApp.interfaceDriver.ActivateRootWindow(activeChild);
5013 //guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, caption);
5014 guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, class.name);
5017 // Do this here to avoid problems on Windows
5018 if(stateBackup == maximized)
5019 property::state = maximized;
5023 void UnloadGraphics(bool destroyWindows)
5027 // Free children's graphics
5028 for(child = children.first; child; child = child.next)
5029 child.UnloadGraphics(destroyWindows);
5032 display.Lock(false);
5035 if(guiApp.fullScreenMode && this == guiApp.desktop)
5040 for(c=0; c<SystemCursor::enumSize; c++)
5041 if(guiApp.systemCursors[c].bitmap)
5042 delete guiApp.systemCursors[c].bitmap;
5044 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5045 delete cursor.bitmap;
5047 guiApp.cursorBackground.Free();
5050 if(display && display.displaySystem)
5054 for(ptr = resources.first; ptr; ptr = ptr.next)
5058 display.displaySystem.UnloadResource(ptr.resource, ptr.loaded);
5063 // Free window graphics
5066 // Free skin graphics
5067 if(rootWindow == this)
5069 DisplaySystem displaySystem = display.displaySystem;
5072 display.driverData = null;
5073 display.displaySystem = null;
5077 if(displaySystem && !displaySystem.numDisplays && !is3D)
5078 delete displaySystem;
5087 if(guiApp.acquiredWindow && this == guiApp.acquiredWindow.rootWindow)
5088 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, false);
5090 if(this == guiApp.desktop || parent == guiApp.desktop)
5092 if((guiApp.fullScreenMode || this != guiApp.desktop) && rootWindow == this && windowHandle && destroyWindows)
5093 guiApp.interfaceDriver.DestroyRootWindow(this);
5097 // --- Window Hiding ---
5099 void SetVisibility(bool state)
5101 bool visible = (style.hidden || !created) ? false : state;
5102 if(visible != this.visible)
5106 this.visible = visible;
5107 for(child = children.first; child; child = child.next)
5108 child.SetVisibility(visible);
5110 ConsequentialMouseMove(false);
5114 // --- Windows and graphics initialization / termination ---
5116 bool DisplayModeChanged(void)
5118 bool result = false;
5119 if(!guiApp.fullScreenMode && !guiApp.modeSwitching/* && guiApp.desktop.active*/)
5121 guiApp.modeSwitching = true;
5122 UnloadGraphics(false);
5124 if(LoadGraphics(false, false))
5126 guiApp.modeSwitching = false;
5131 // --- Window updates system ---
5133 void UpdateDirty(Box updateBox)
5135 if(!manageDisplay) { OnRedraw(null);return; }
5138 if(display && (!guiApp.fullScreenMode || guiApp.desktop.active) && !guiApp.modeSwitching)
5141 if(display.flags.flipping)
5144 rootWindow.UpdateDisplay();
5147 UpdateBackDisplay(updateBox);
5149 if(guiApp.fullScreenMode)
5151 guiApp.cursorUpdate = true;
5152 guiApp.PreserveAndDrawCursor();
5154 if(guiApp.fullScreenMode)
5155 guiApp.RestoreCursorBackground();
5161 // This function is strictly called as a result of system window activation
5162 bool ExternalActivate(bool active, bool activateRoot, Window window, Window swap)
5165 Window interimMaster = null;
5166 Window interimWindow = guiApp.interimWindow;
5167 if(interimWindow && interimWindow.master)
5168 interimMaster = interimWindow.master.rootWindow;
5170 if(active && state == minimized) // && (!window.nativeDecorations || window.rootWindow != window)
5171 // SetState(normal, false, 0);
5172 SetState(lastState, false, 0);
5174 if(interimMaster && swap == interimMaster && interimMaster.IsSlaveOf(window))
5178 /* WTH is this doing here?
5179 while(swap && swap.activeChild)
5181 swap = swap.activeChild;
5184 // TESTING THIS BEFORE...
5185 if(interimWindow && this == interimMaster)
5189 // Window interimSwap = this;
5190 Window menuBar = this.menuBar;
5191 if(menuBar && interimWindow.master == menuBar)
5194 while(interimSwap && interimSwap.activeChild)
5195 interimSwap = interimSwap.activeChild;
5197 result = interimWindow.ActivateEx(false, false, false, activateRoot, null,
5198 (menuBar && interimWindow.master == menuBar) ? menuBar : interimSwap);
5200 result = /*interimWindow.*/ActivateEx(false, false, false, activateRoot, null, menuBar);
5201 //result = ActivateEx(true, true, false, activateRoot, window, null);
5206 // Testing & FindModal() here: broke reactivating when a modal dialog is up (didn't root activate dialog)
5207 result = ActivateEx(active, active, false, activateRoot /*&& FindModal()*/, window, swap);
5209 if(interimWindow == this && interimMaster && !active)
5211 while(interimMaster && interimMaster.interim && interimMaster.master)
5213 // printf("Going up one master %s\n", interimMaster._class.name);
5214 interimMaster = interimMaster.master.rootWindow;
5216 // printf("Unactivating interim master %s (%x)\n", interimMaster._class.name, interimMaster);
5217 interimMaster.ActivateEx(active, active, false, activateRoot, window, swap);
5223 bool DestroyEx(int returnCode)
5226 Timer timer, nextTimer;
5228 OldLink prevOrder = null;
5229 Window client = null;
5231 if(parent) stopwatching(parent, font);
5233 // if(window.modalSlave) return false;
5234 if(destroyed || !created)
5241 OldLink slave = master.slaves.FindLink(this);
5242 master.slaves.Delete(slave);
5245 // TOFIX IMMEDIATELY: COMMENTED THIS OUT... causes problem second time creating file dialog
5251 this.returnCode = (DialogResult)returnCode;
5253 AcquireInput(false);
5258 master.hotKeys.Delete(hotKey);
5262 if(guiApp.prevWindow == this)
5264 guiApp.prevWindow = null;
5267 if(guiApp.caretOwner == this)
5269 guiApp.interfaceDriver.SetCaret(0,0,0);
5270 UpdateCaret(false, true);
5271 guiApp.caretEnabled = false;
5276 parent.childrenCycle.Remove(cycle);
5280 OldLink tmpPrev = order.prev;
5281 if(tmpPrev && !(((Window)tmpPrev.data).style.hidden) && !(((Window)tmpPrev.data).destroyed) && (((Window)tmpPrev.data).created))
5282 prevOrder = tmpPrev;
5285 client = tmpPrev ? tmpPrev.data : null;
5286 if(client == this) { client = null; break; }
5287 if(client && (client.style.hidden || client.destroyed || !client.created))
5288 tmpPrev = client.order.prev;
5292 prevOrder = tmpPrev;
5297 // If this window can be an active client, make sure the next window we activate can also be one
5298 if(!style.nonClient && style.isActiveClient)
5300 tmpPrev = prevOrder;
5303 client = tmpPrev ? tmpPrev.data : null;
5304 if(client == this) { client = null; break; }
5305 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
5306 tmpPrev = client.order.prev;
5310 prevOrder = tmpPrev;
5314 if(client && client.style.hidden) client = null;
5316 // parent.childrenOrder.Remove(order);
5319 if(parent && style.isActiveClient && visible)
5321 if(state == minimized) parent.numIcons--;
5322 parent.numPositions--;
5325 // TESTING THIS HERE!
5329 // If no display, don't bother deactivating stuff (causes unneeded problems when trying
5330 // to create a window inside a rootwindow that's being destroyed)
5331 // DISABLED THIS BECAUSE OF CREATING WINDOW IN DESKTOP IN WINDOWED MODE
5333 if(master && !master.destroyed /*&&
5334 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5336 if(master.defaultControl == this)
5337 master.defaultControl = null;
5339 if(parent && !parent.destroyed /*&&
5340 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5342 if((parent.activeChild == this /*|| parent.activeClient == this */|| guiApp.interimWindow == this))
5344 if(order && prevOrder && prevOrder.data != this && active)
5346 //((Window)prevOrder.data).ActivateEx(true, false, false, false /*true*/, null);
5348 ((Window)prevOrder.data).ActivateEx(true, false, false, (rootWindow == this) ? true : false, null, null);
5349 if(parent.activeClient == this)
5351 parent.activeClient = null;
5352 parent.UpdateActiveDocument(null);
5357 if(guiApp.interimWindow == this)
5360 PropagateActive(false, null, &goOn, true);
5364 //if(window.parent.activeChild == window)
5365 parent.activeChild = null;
5366 if(!style.nonClient /*&& style.isActiveClient*/)
5368 Window previous = parent.activeClient;
5369 if(style.isActiveClient)
5370 parent.activeClient = null;
5371 parent.UpdateActiveDocument(previous);
5376 else if(parent.activeClient == this)
5378 parent.activeClient = client;
5379 parent.UpdateActiveDocument(this);
5383 if(guiApp.interimWindow == this)
5385 guiApp.interimWindow = null;
5386 if(guiApp.caretOwner)
5388 Window desktop = guiApp.desktop;
5389 if(desktop.activeChild && desktop.activeChild.menuBar && !desktop.activeChild.menuBar.focus)
5390 guiApp.caretOwner.UpdateCaret(false, false);
5395 if(_isModal && master && master.modalSlave == this)
5396 master.modalSlave = null;
5400 if(!guiApp.caretOwner && parent.caretSize)
5402 guiApp.caretOwner = parent;
5403 parent.UpdateCaret(false, false);
5404 parent.Update(null);
5407 // Why was this commented out?
5408 GetRidOfVirtualArea();
5414 dirtyArea.Free(null);
5415 dirtyBack.Free(null);
5416 scrollExtent.Free(null);
5418 /* ATTEMPTING TO MOVE THAT ABOVE
5427 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5428 for(;(child = window.children.first);)
5430 for(; child && (child.destroyed || !child.created); child = child.next);
5439 UnloadGraphics(true);
5442 delete previousActive;
5445 // statusBar = null;
5448 if(master && !master.destroyed)
5450 //master.NotifyDestroyed(this, this.returnCode);
5451 NotifyDestroyed(master, this, this.returnCode);
5454 for(timer = guiApp.windowTimers.first; timer; timer = nextTimer)
5456 nextTimer = timer.next;
5457 if(timer.window == this)
5459 // WHY WERE WE SETTING THIS TO NULL? NO MORE WINDOW WHEN RECREATING...
5460 // timer.window = null;
5466 if(this == guiApp.windowMoving)
5469 if(guiApp.windowCaptured == this)
5471 //guiApp.windowCaptured = null;
5473 if(rootWindow != this && rootWindow)
5474 rootWindow.ConsequentialMouseMove(false);
5482 //for(child = children.first; next = child ? child.next : null, child; child = next)
5483 for(;(child = children.first); )
5485 for(; child && (child.destroyed || !child.created); child = child.next);
5495 /* // MOVED THIS UP...
5498 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5499 for(;(child = window.children.first); )
5501 for(; child && (child.destroyed || !child.created); child = child.next);
5510 while((slave = slaves.first))
5512 for(; slave && (((Window)slave.data).destroyed || !((Window)slave.data).created); slave = slave.next);
5514 ((Window)slave.data).DestroyEx(0);
5519 if(guiApp.caretOwner == this)
5520 guiApp.caretOwner = null;
5522 sysButtons[0] = null;
5523 sysButtons[1] = null;
5524 sysButtons[2] = null;
5527 if(rootWindow != this)
5529 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
5532 box.left -= parent.clientStart.x;
5533 box.top -= parent.clientStart.y;
5534 box.right -= parent.clientStart.x;
5535 box.bottom -= parent.clientStart.y;
5537 if(parent) parent.Update(box);
5542 OldLink slave = master.slaves.FindVoid(this);
5543 master.slaves.Delete(slave);
5549 parent.children.Remove(this);
5554 //autoCreate = false;
5557 // SHOULD THIS BE HERE? FIXED CRASH WITH GOTO DIALOG
5558 if(((subclass(Window))_class).pureVTbl)
5560 if(_vTbl == _class._vTbl)
5562 _vTbl = ((subclass(Window))_class).pureVTbl;
5567 for(m = 0; m < _class.vTblSize; m++)
5569 if(_vTbl[m] == _class._vTbl[m])
5570 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5579 void SetStateEx(WindowState newState, bool activate)
5582 WindowState prevState = state;
5586 if(prevState != newState)
5587 lastState = prevState;
5589 if(rootWindow != this || !nativeDecorations)
5591 if(style.isActiveClient && !style.hidden && prevState == minimized)
5594 // This block used to be at the end of the function... moved it for flicker problem in X
5595 // ------------------------------------------------------
5599 stateAnchor = normalAnchor;
5600 stateSizeAnchor = normalSizeAnchor;
5603 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5604 stateSizeAnchor = SizeAnchor {};
5608 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5611 byte * idBuffer = new0 byte[size];
5613 for(child = parent.children.first; child; child = child.next)
5615 if(child != this && child.state == minimized)
5617 if(child.iconID > size - 2)
5619 idBuffer = renew0 idBuffer byte[size*2];
5620 memset(idBuffer + size, 0, size);
5623 idBuffer[child.iconID] = (byte)bool::true;
5626 for(c = 0; c<size; c++)
5631 if(style.isActiveClient && !style.hidden)
5634 stateAnchor = Anchor { left = (iconID % maxIcons) * MINIMIZED_WIDTH, bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24) };
5635 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
5639 // TOCHECK: Why was this here?
5640 //position.x = (tx > 0) ? tx & 0xFFFFF : tx;
5641 //position.y = (ty > 0) ? ty & 0xFFFFF : ty;
5642 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5644 Position(x, y, w, h, true, true, true, true, false, true);
5646 if(!style.inactive && !style.interim && this == parent.activeClient)
5647 parent.UpdateActiveDocument(null);
5650 CreateSystemChildren();
5651 // ------------------------------------------------------
5654 int GetPositionID(Window forChild)
5658 byte * idBuffer = new0 byte[size];
5661 for(child = children.first; child; child = child.next)
5663 if(child.style.isActiveClient && !child.style.hidden && child != forChild)
5665 if(child.positionID > size - 2)
5667 idBuffer = renew0 idBuffer byte[size*2];
5668 memset(idBuffer + size, 0, size);
5671 idBuffer[child.positionID] = (byte)bool::true;
5674 for(c = 0; c<size; c++)
5681 // --- Window related graphics ---
5683 void SetPalette(ColorAlpha * newPalette, bool colorMatch)
5685 palette = newPalette;
5686 if(rootWindow.display)
5687 rootWindow.display.SetPalette(palette, colorMatch);
5690 public bool AcquireInput(bool acquired)
5693 if(acquiredInput != acquired)
5695 if(active || (!visible && creationActivation == activate))
5696 result = AcquireInputEx(acquired);
5701 acquiredInput = acquired ? result : !result;
5706 void ListChildren(ListBox listBox)
5710 for(child = children.first; child; child = child.next)
5712 if(child.cycle && !child.style.nonClient && child.style.isActiveClient && child.visible)
5714 DataRow row = listBox.AddRow();
5715 row.tag = (int)child;
5716 child.FigureCaption(caption);
5717 row.SetData(null, caption);
5722 void UpdateVisual(Box extent)
5724 if(guiApp.driver != null)
5726 if(guiApp.fullScreenMode && guiApp.desktop.display)
5728 guiApp.desktop.mutex.Wait();
5729 guiApp.desktop.display.Lock(true);
5732 if(guiApp.desktop.active)
5734 if(guiApp.desktop.dirty || guiApp.cursorUpdate)
5736 if(guiApp.desktop.display.flags.flipping)
5737 guiApp.desktop.Update(null);
5738 guiApp.desktop.UpdateDisplay();
5739 guiApp.cursorUpdate = true;
5741 if(guiApp.cursorUpdate || guiApp.desktop.dirty)
5743 guiApp.PreserveAndDrawCursor();
5744 // guiApp.desktop.display.ShowScreen();
5745 guiApp.cursorUpdate = false;
5746 guiApp.desktop.dirty = false;
5747 guiApp.RestoreCursorBackground();
5751 guiApp.desktop.display.Unlock();
5752 guiApp.desktop.mutex.Release();
5756 Window rootWindow = this.rootWindow;
5757 rootWindow.mutex.Wait();
5762 guiApp.SignalEvent();
5765 guiApp.waitMutex.Wait();
5766 guiApp.interfaceDriver.Lock(rootWindow);
5767 if(!rootWindow.style.hidden && rootWindow.dirty)
5769 if(rootWindow.display)
5771 rootWindow.UpdateDisplay();
5772 //rootWindow.display.ShowScreen(null);
5774 rootWindow.dirty = false;
5776 guiApp.interfaceDriver.Unlock(rootWindow);
5777 guiApp.waitMutex.Release();
5780 rootWindow.mutex.Release();
5785 void UnlockDisplay(void)
5787 guiApp.interfaceDriver.Unlock(rootWindow);
5790 void LockDisplay(void)
5792 guiApp.interfaceDriver.Lock(rootWindow);
5795 Surface GetSurface(Box box)
5797 return Redraw((box == null) ? this.box : box);
5800 void SetMousePosition(int x, int y)
5802 guiApp.interfaceDriver.SetMousePosition(x + absPosition.x + clientStart.x, y + absPosition.y + clientStart.y);
5806 void IntegrationActivate(bool active)
5808 if(!guiApp.modeSwitching && !guiApp.fullScreenMode)
5810 isForegroundWindow = true;
5811 ActivateEx(active, active, false, false, null, null);
5812 isForegroundWindow = false;
5817 Window QueryCapture(void)
5819 return guiApp.windowCaptured;
5822 int GetDocumentID(void)
5826 byte * idBuffer = new0 byte[size];
5829 for(child = children.first; child; child = child.next)
5831 if(child.style.isDocument)
5833 if(child.documentID-1 > size - 2)
5835 idBuffer = renew0 idBuffer byte[size*2];
5836 memset(idBuffer + size, 0, size);
5839 idBuffer[child.documentID-1] = 1;
5842 for(c = 0; c<size; c++)
5850 void SetInitSize(Size size)
5853 sizeAnchor.size = size;
5854 normalSizeAnchor = sizeAnchor;
5856 // Break the anchors for moveable/resizable windows
5857 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
5859 stateAnchor = normalAnchor;
5860 stateSizeAnchor = normalSizeAnchor;
5862 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5863 Position(x,y, w, h, true, true, true, true, false, true);
5867 void MenuMoveOrSize(bool resize, bool setCursorPosition)
5869 if(this != guiApp.desktop && state != maximized && (resize ? (state != minimized && style.sizable) : (style.fixed || moveable)))
5871 guiApp.windowIsResizing = resize;
5872 guiApp.windowMoving = this;
5873 guiApp.windowMovingStart = guiApp.movingLast = absPosition;
5874 if(guiApp.windowIsResizing)
5876 guiApp.windowMovingStart.x += size.w - 1;
5877 guiApp.windowMovingStart.y += size.h - 1;
5879 guiApp.windowMovingBefore = scrolledPos;
5880 guiApp.windowResizingBefore = size;
5881 guiApp.windowMoving.UpdateDecorations();
5882 if(guiApp.windowIsResizing)
5883 guiApp.resizeEndX = guiApp.resizeEndY = true;
5885 if(setCursorPosition)
5886 guiApp.interfaceDriver.SetMousePosition(guiApp.windowMovingStart.x, guiApp.windowMovingStart.y);
5890 guiApp.interfaceDriver.GetMousePosition(&x, &y);
5891 guiApp.windowMovingStart.x += x - absPosition.x;
5892 guiApp.windowMovingStart.y += y - absPosition.y;
5895 if(guiApp.windowMoving)
5897 if(guiApp.windowMoving.style.nonClient)
5898 guiApp.windowMoving.parent.SetMouseRangeToWindow();
5900 guiApp.windowMoving.parent.SetMouseRangeToClient();
5905 if(this == rootWindow)
5906 guiApp.interfaceDriver.StartMoving(rootWindow, guiApp.windowMovingStart.x, guiApp.windowMovingStart.y, true);
5914 bool result = false;
5918 else if(guiApp && guiApp.driver != null)
5920 void * systemParent = null;
5921 OldLink slaveHolder;
5923 bool visible = !style.hidden;
5927 systemParent = parent;
5928 parent = guiApp.desktop;
5930 last = parent ? parent.children.last : null;
5932 if((parent && parent != guiApp.desktop && !parent.created) ||
5933 (master && master != guiApp.desktop && !master.created))
5937 property::parent = guiApp.desktop;
5938 if(!master) master = parent;
5940 if(_isModal && master.modalSlave)
5941 property::master = master.modalSlave;
5945 parent.children.Remove(this);
5948 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
5949 if(slaveHolder.data == this)
5951 master.slaves.Delete(slaveHolder);
5956 if(parent == guiApp.desktop && !mutex)
5959 if(style.isDocument)
5962 parent.numDocuments--;
5963 documentID = parent.GetDocumentID();
5966 if(!style.stayOnTop)
5967 for(; last && last.style.stayOnTop; last = last.prev);
5969 parent.children.Insert((last == this) ? null : last, this);
5970 //parent.children.Add(this);
5973 dispDriver = parent.dispDriver;
5976 master.modalSlave = this;
5978 box = Box { MAXINT, MAXINT, MININT, MININT }; //-MAXINT, -MAXINT };
5983 master.slaves.Add(slaveHolder = OldLink { data = this });
5988 master.hotKeys.Add(hotKey = HotKeySlot { key = setHotKey, window = this });
5990 if(style.isDefault && !master.defaultControl)
5991 master.defaultControl = this;
5993 stateAnchor = normalAnchor = anchor;
5994 stateSizeAnchor = normalSizeAnchor = sizeAnchor;
5996 // TOCHECK: Why is this here?
5997 //position.x = (ax > 0) ? ax & 0xFFFFF : ax;
5998 //position.y = (ay > 0) ? ay & 0xFFFFF : ay;
6000 this.visible = false;
6001 style.hidden = true;
6004 // autoCreate = true;
6012 if(parent == guiApp.desktop)
6013 Log("LoadGraphics %s\n", caption);
6015 if(LoadGraphics(true, false))
6023 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
6030 if(style.hasMenuBar /*&& menu*/)
6036 menu = menu, isMenuBar = true, anchor = Anchor { top = 23, left = 1, right = 1 },
6037 interim = false, inactive = true, nonClient = true, size.h = 24
6045 // Create the system buttons
6046 CreateSystemChildren();
6048 UpdateActiveDocument(null);
6050 if(style.isDocument)
6054 MenuItem item = menu.FindItem(MenuFileSave, 0);
6055 if(item) item.disabled = !modifiedDocument && fileName;
6060 if(parent == guiApp.desktop)
6061 Log("Preemptive SetState %s\n", caption);
6064 // Preemptive Set State to ensure proper anchoring
6065 SetStateEx(state, false);
6067 style.hidden = true;
6073 for(child = children.first; child; child = next)
6076 if(!child.created && (child.autoCreate || child.wasCreated))
6083 for(link = slaves.first; link; link = next)
6085 Window slave = link.data;
6087 if(!slave.created && (slave.autoCreate || slave.wasCreated))
6096 if(parent == guiApp.desktop)
6097 Log("Real SetState %s\n", caption);
6100 if(isActiveClient && visible)
6102 parent.numPositions--;
6103 if(state == minimized) parent.numIcons--;
6106 // Real set state & activate for proper display & activation
6107 property::visible = visible;
6108 // SetState(state & 0x00000003, true, 0);
6113 /*if(rootWindow == this)
6114 guiApp.interfaceDriver.ActivateRootWindow(this);
6116 if(creationActivation == activate)
6117 ActivateEx(true, false, true, true, null, null);
6118 else if(creationActivation == flash)
6123 rootWindow.ConsequentialMouseMove(false);
6134 guiApp.LogErrorCode(IERR_WINDOW_CREATION_FAILED, caption);
6140 // Testing this here... Otherwise a failed LoadGraphics stalls the application
6142 //style.hidden = true; // !visible;
6143 style.hidden = !visible;
6144 if(master.modalSlave == this)
6145 master.modalSlave = null;
6152 void WriteCaption(Surface surface, int x, int y)
6155 Interface::WriteKeyedTextDisabled(surface, x,y, caption, hotKey ? hotKey.key : 0, !isEnabled);
6158 void Update(Box region)
6164 rootWindow = this.rootWindow;
6166 // rootWindow.mutex.Wait();
6167 if(!destroyed && visible && display)
6172 // Testing this to avoid repetitve full update to take time...
6173 if(dirtyArea.count == 1)
6175 BoxItem item = (BoxItem)ACCESS_ITEM(dirtyArea, dirtyArea.first);
6176 if(item.box.left <= box.left &&
6177 item.box.top <= box.top &&
6178 item.box.right >= box.right &&
6179 item.box.bottom >= box.bottom)
6181 rootWindow.dirty = true;
6186 if(display.flags.flipping && !rootWindow.dirty)
6188 if(this == rootWindow)
6192 rootWindow.Update(null);
6197 rootWindow.dirty = true;
6202 realBox.left += clientStart.x;
6203 realBox.top += clientStart.y;
6204 realBox.right += clientStart.x;
6205 realBox.bottom += clientStart.y;
6211 if(realBox.right >= realBox.left &&
6212 realBox.bottom >= realBox.top)
6214 // if(!rootWindow.fullRender)
6215 dirtyArea.UnionBox(realBox, rootWindow.tempExtents[0]);
6217 for(child = children.first; child; child = child.next)
6222 box.left -= child.absPosition.x - absPosition.x;
6223 box.top -= child.absPosition.y - absPosition.y;
6224 box.right -= child.absPosition.x - absPosition.x;
6225 box.bottom -= child.absPosition.y - absPosition.y;
6226 if(box.right >= child.box.left && box.left <= child.box.right &&
6227 box.bottom >= child.box.top && box.top <= child.box.bottom)
6229 box.left -= child.clientStart.x;
6230 box.top -= child.clientStart.y;
6231 box.right -= child.clientStart.x;
6232 box.bottom -= child.clientStart.y;
6238 realBox.left += absPosition.x - rootWindow.absPosition.x;
6239 realBox.top += absPosition.y - rootWindow.absPosition.y;
6240 realBox.right += absPosition.x - rootWindow.absPosition.x;
6241 realBox.bottom += absPosition.y - rootWindow.absPosition.y;
6242 rootWindow.dirtyBack.UnionBox(realBox, rootWindow.tempExtents[0]);
6245 else if(this == guiApp.desktop)
6248 for(window = children.first; window; window = window.next)
6254 Box childBox = region;
6256 childBox.left -= window.absPosition.x - guiApp.desktop.absPosition.x;
6257 childBox.top -= window.absPosition.y - guiApp.desktop.absPosition.y;
6258 childBox.right -= window.absPosition.x - guiApp.desktop.absPosition.x;
6259 childBox.bottom -= window.absPosition.y - guiApp.desktop.absPosition.y;
6261 window.Update(childBox);
6264 window.Update(null);
6269 // rootWindow.mutex.Release();
6276 if(guiApp.windowCaptured != this)
6278 if(guiApp.windowCaptured)
6282 //Logf("Captured %s (%s)\n", caption, class.name);
6283 guiApp.interfaceDriver.SetMouseCapture(rootWindow);
6284 guiApp.windowCaptured = this;
6290 bool Destroy(int code)
6295 if(!CloseConfirmation(false)) return false;
6299 // TOCHECK: Should autoCreate be set to false here?
6302 // Is this needed here? DestroyEx should decref already...
6311 void Move(int x, int y, int w, int h)
6313 normalAnchor = Anchor { left = x, top = y };
6314 normalSizeAnchor = SizeAnchor { size = { w, h } };
6316 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6318 if(destroyed) return;
6320 stateAnchor = normalAnchor;
6321 stateSizeAnchor = normalSizeAnchor;
6323 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6324 Position(x,y, w, h, true, true, true, true, false, true);
6328 DialogResult Modal(void)
6334 // FIXES MEMORY LEAK IF Create() FAILED
6340 void SetScrollArea(int width, int height, bool snapToStep)
6342 bool resize = false;
6345 int stepX = sbStep.x, stepY = sbStep.y;
6346 // Needed to make snapped down position match the skin's check of client area
6347 // against realvirtual
6350 SNAPDOWN(stepX, textCellW);
6351 SNAPDOWN(stepY, textCellH);
6352 stepX = Max(stepX, textCellW);
6353 stepY = Max(stepY, textCellH);
6355 if(scrollFlags.snapX)
6356 SNAPUP(width, stepX);
6357 if(scrollFlags.snapY)
6358 SNAPUP(height, stepY);
6361 reqScrollArea.w = width;
6362 reqScrollArea.h = height;
6363 noAutoScrollArea = (width > 0 || height > 0);
6365 UpdateScrollBars(true, true);
6368 void SetScrollPosition(int x, int y)
6371 sbh.Action(setPosition, x, 0);
6375 int seen = clientSize.w, total = reqScrollArea.w;
6377 if(scrollFlags.snapX)
6378 SNAPDOWN(seen, sbStep.x);
6380 if(!total) total = seen;
6381 range = total - seen + 1;
6382 range = Max(range, 1);
6384 if(x >= range) x = range - 1;
6386 if(scrollFlags.snapX)
6387 SNAPUP(x, sbStep.x);
6390 OnHScroll(setPosition, x, 0);
6394 SNAPDOWN(x, textCellW);
6400 sbv.Action(setPosition, y, 0);
6404 int seen = clientSize.h, total = reqScrollArea.h;
6407 if(scrollFlags.snapY)
6408 SNAPDOWN(seen, sbStep.y);
6410 if(!total) total = seen;
6411 range = total - seen + 1;
6412 range = Max(range, 1);
6414 if(y >= range) y = range - 1;
6416 if(scrollFlags.snapY)
6417 SNAPUP(y, sbStep.y);
6420 OnVScroll(setPosition, y, 0);
6423 SNAPDOWN(y, textCellH);
6428 UpdateCaret(false, false);
6431 void SetScrollLineStep(int stepX, int stepY)
6437 SNAPDOWN(stepX, textCellW);
6438 SNAPDOWN(stepY, textCellH);
6439 stepX = Max(stepX, textCellW);
6440 stepY = Max(stepY, textCellH);
6443 sbh.lineStep = stepX;
6445 sbv.lineStep = stepY;
6448 void SetState(WindowState newState, bool activate, Modifiers mods)
6452 if(state == newState || OnStateChange(newState, mods))
6454 WindowState prevState = state;
6458 // This used to be at the end of the brackets... moved for X, testing...
6459 // This has the effect of activating the window through the system...
6460 if(rootWindow == this)
6461 guiApp.interfaceDriver.SetRootWindowState(this, newState, !style.hidden);
6463 SetStateEx(newState, activate);
6465 if(rootWindow == this && !rootWindow.nativeDecorations)
6467 int x = position.x, y = position.y;
6470 x -= guiApp.desktop.absPosition.x;
6471 y -= guiApp.desktop.absPosition.y;
6473 guiApp.interfaceDriver.PositionRootWindow(this, x, y, size.w, size.h, true, true);
6477 //state = prevState;
6479 if(state != maximized && style.hasMaximize)
6482 for(child = parent.children.first; child; child = child.next)
6484 if(child != this && child.state == maximized)
6485 child.SetStateEx(normal, false);
6489 if(!style.nonClient && (sbv || sbh) && this != parent.sbv && this != parent.sbh)
6490 parent.UpdateScrollBars(true, true);
6493 // Do we really need this stuff here?
6494 // Shouldn't the Activate stuff take care of it?
6495 if(parent.rootWindow == parent && style)
6498 parent.FigureCaption(caption);
6499 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
6500 parent.UpdateDecorations();
6504 rootWindow.ConsequentialMouseMove(false);
6511 BitmapResource GetIcon(SkinBitmap iconID)
6513 return guiApp.currentSkin.GetBitmap(iconID);
6516 void SetMouseRange(Box range)
6518 if(range || guiApp.fullScreenMode)
6523 clip.left = range.left + absPosition.x + clientStart.x;
6524 clip.top = range.top + absPosition.y + clientStart.y;
6525 clip.right = range.right + absPosition.x + clientStart.x;
6526 clip.bottom = range.bottom + absPosition.y + clientStart.y;
6530 clip.left = guiApp.desktop.box.left;
6531 clip.top = guiApp.desktop.box.top;
6532 clip.right = guiApp.desktop.box.right;
6533 clip.bottom = guiApp.desktop.box.bottom;
6535 guiApp.interfaceDriver.SetMouseRange(rootWindow, clip);
6538 guiApp.interfaceDriver.SetMouseRange(rootWindow, null);
6541 void SetMouseRangeToClient(void)
6543 if(guiApp.fullScreenMode || this != guiApp.desktop)
6545 Box box {0, 0, clientSize.w - 1, clientSize.h - 1 };
6546 box.Clip(clientArea);
6550 SetMouseRange(null);
6553 void SetMouseRangeToWindow(void)
6555 Box box { -clientStart.x, -clientStart.y, size.w-1, size.h-1 };
6556 if(this == guiApp.desktop)
6557 SetMouseRangeToClient();
6562 // x, y: Desktop Coordinates
6563 void ShowSysMenu(int x, int y)
6566 PopupMenu windowMenu { master = this, interim = true, position = { x + 1 - guiApp.desktop.position.x, y + 1 - guiApp.desktop.position.y }, menu = menu };
6569 menu, "Restore", r, NotifySelect = MenuWindowRestore,
6570 disabled = (!style.hasMaximize && !style.hasMinimize) || state == normal, bitmap = guiApp.currentSkin.GetBitmap(restore)
6574 menu, "Move", m, NotifySelect = MenuWindowMove,
6575 disabled = !style.fixed || state == maximized
6579 menu, "Size", s, NotifySelect = MenuWindowSize,
6580 disabled = !style.sizable || state != normal
6584 menu, "Minimize", n, NotifySelect = MenuWindowMinimize,
6585 disabled = !style.hasMinimize || state == minimized, bitmap = guiApp.currentSkin.GetBitmap(minimize)
6589 menu, "Maximize", KeyCode::x, NotifySelect = MenuWindowMaximize,
6590 disabled = !style.hasMaximize || state == maximized, bitmap = guiApp.currentSkin.GetBitmap(maximize)
6594 menu, "Stay On Top", t, NotifySelect = MenuWindowStayOnTop,
6595 disabled = !style.fixed, checkable = true, checked = style.stayOnTop
6597 MenuDivider { menu };
6600 menu, "Close", c, (parent == guiApp.desktop) ? altF4 : ( style.isActiveClient ? ctrlF4 : 0), NotifySelect = MenuWindowClose,
6601 bold = true, disabled = !style.hasClose, bitmap = guiApp.currentSkin.GetBitmap(close)
6603 windowMenu.Create();
6608 ActivateEx(true, true, true, true, null, null);
6611 void MakeActive(void)
6613 ActivateEx(true, false, true, false, null, null);
6616 void SoftActivate(void)
6618 if(guiApp.desktop.active)
6624 void Deactivate(void)
6626 ActivateEx(false, true, true, true, null, null);
6631 guiApp.interfaceDriver.FlashRootWindow(rootWindow);
6634 bool CycleChildren(bool backward, bool clientOnly, bool tabCycleOnly, bool cycleParents)
6636 bool result = false;
6637 if(activeChild && activeChild.cycle)
6639 Window modalWindow, child = activeChild;
6640 if(!clientOnly /*&& parent.tabCycle*/)
6642 Window next = child;
6645 if(next.cycle == (backward ? childrenCycle.first : childrenCycle.last))
6649 if(parent && parent.CycleChildren(backward, false, true, true))
6657 next = next.cycle.prev.data;
6659 next = next.cycle.next.data;
6660 if(!next.disabled && !next.inactive /*isRemote*/ && next.created && !next.nonClient && (!clientOnly || next.style.isActiveClient) && !next.style.hidden && next.FindModal() != activeChild)
6665 if(!clientOnly && child.cycle == (backward ? childrenCycle.first : childrenCycle.last) &&
6666 parent.tabCycle && parent.CycleChildren(backward, false, false))
6670 if(tabCycleOnly && !tabCycle) return false;
6677 child = child.cycle.prev.data;
6679 child = child.cycle.next.data;
6680 if(child == child.parent.activeChild)
6682 else if(!child.disabled && child.created && (!clientOnly || child.style.isActiveClient) && !child.style.hidden && child.FindModal() != activeChild)
6685 modalWindow = child.FindModal();
6688 // Scroll the window to include the active control
6689 if(sbh && !child.style.dontScrollHorz)
6691 if(child.scrolledPos.x < 0)
6692 sbh.Action(setPosition, scroll.x + child.scrolledPos.x, 0);
6693 else if(child.scrolledPos.x + child.size.w > clientSize.w)
6694 sbh.Action(setPosition, scroll.x + child.scrolledPos.x + child.size.w - clientSize.w, 0);
6696 if(sbv && !child.style.dontScrollVert)
6698 if(child.scrolledPos.y < 0)
6699 sbv.Action(setPosition, scroll.y + child.scrolledPos.y, 0);
6700 else if(child.scrolledPos.y + child.size.h > clientSize.h)
6701 sbv.Action(setPosition, scroll.y + child.scrolledPos.y + child.size.h - clientSize.h, 0);
6705 child = modalWindow ? modalWindow : child;
6706 child.ActivateEx(true, true, true, true, null, null);
6707 if(child.tabCycle && child.childrenCycle.first)
6708 child = ((OldLink)(backward ? child.childrenCycle.first : child.childrenCycle.last)).data;
6716 ConsequentialMouseMove(false);
6720 void AddResource(Resource resource)
6724 ResPtr ptr { resource = resource };
6728 // Load Graphics here if window is created already
6729 if(/*created && */display)
6731 display.Lock(false);
6732 ptr.loaded = display.displaySystem.LoadResource(resource);
6736 // Temporary hack to load font right away for listbox in dropbox ...
6737 else if(master && master.display)
6739 master.display.Lock(false);
6740 master.display.displaySystem.LoadResource(resource);
6741 master.display.Unlock();
6747 void RemoveResource(Resource resource)
6752 for(ptr = resources.first; ptr; ptr = ptr.next)
6754 if(ptr.resource == resource)
6760 // Unload Graphics here if window is created already
6761 if(/*created && */display)
6765 display.Lock(false);
6766 display.displaySystem.UnloadResource(resource, ptr.loaded);
6772 resources.Delete(ptr);
6777 void SetCaret(int x, int y, int size)
6784 if(active && !style.interim)
6786 if(visible || !guiApp.caretOwner)
6787 guiApp.caretOwner = size ? this : null;
6789 UpdateCaret(false, false);
6792 guiApp.interfaceDriver.SetCaret(0,0,0);
6793 UpdateCaret(false, true);
6794 guiApp.caretEnabled = false;
6797 else if(style.inactive && active)
6799 guiApp.interfaceDriver.SetCaret(0,0,0);
6800 UpdateCaret(false, true);
6801 guiApp.caretEnabled = false;
6806 void Scroll(int x, int y)
6808 bool opaque = !style.drawBehind || background.a;
6809 if(opaque && display && display.flags.scrolling)
6811 Box box = clientArea;
6812 box.left += clientStart.x;
6813 box.top += clientStart.y;
6814 box.right += clientStart.x;
6815 box.bottom += clientStart.y;
6817 //scrollExtent.Free(null);
6818 scrollExtent.AddBox(box);
6819 scrolledArea.x += x;
6820 scrolledArea.y += y;
6822 //scrollExtent.Free();
6823 //scrollExtent.AddBox(clientArea);
6824 //scrollExtent.Offset(clientStart.x, clientStart.y);
6825 //scrolledArea.x = x;
6826 //scrolledArea.y = y;
6832 rootWindow.dirty = true;
6835 void ReleaseCapture()
6837 if(guiApp && guiApp.windowCaptured && guiApp.windowCaptured == this)
6839 Window oldCaptured = guiApp.windowCaptured;
6840 guiApp.windowCaptured = null;
6841 guiApp.prevWindow = null;
6844 //guiApp.Log("Released Capture\n");
6846 guiApp.interfaceDriver.SetMouseCapture(null);
6848 //oldCaptured.OnMouseCaptureLost();
6851 oldCaptured.ConsequentialMouseMove(false);
6856 void SetText(char * format, ...)
6863 char caption[MAX_F_STRING];
6865 va_start(args, format);
6866 vsprintf(caption, format, args);
6869 this.caption = new char[strlen(caption)+1];
6871 strcpy(this.caption, caption);
6880 bool Grab(Bitmap bitmap, Box box, bool decorations)
6882 bool result = false;
6883 if(display || this == guiApp.desktop)
6885 Box clip = {MININT, MININT, MAXINT, MAXINT};
6891 clip.Clip(clientArea);
6893 clip.Clip(this.box);
6895 if(rootWindow != this)
6897 clip.left += absPosition.y;
6898 clip.top += absPosition.y;
6899 clip.right += absPosition.x;
6900 clip.bottom += absPosition.y;
6903 clip.left += decorations ? 0 : clientStart.x;
6904 clip.top += decorations ? 0 : clientStart.y;
6905 clip.right += decorations ? 0 : clientStart.x;
6906 clip.bottom += decorations ? 0 : clientStart.y;
6908 if(display && display.flags.flipping)
6910 rootWindow.Update(null);
6911 rootWindow.UpdateDisplay();
6918 result = window.display.displaySystem.driver.GrabScreen(null, bitmap, clip.left, clip.top,
6919 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6923 result = display.Grab(bitmap, clip.left, clip.top,
6924 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6926 if(bitmap.pixelFormat != pixelFormat888 && bitmap.pixelFormat != pixelFormat8)
6928 if(!bitmap.Convert(null, pixelFormat888, null))
6935 void GetMousePosition(int * x, int * y)
6937 int mouseX = 0, mouseY = 0;
6938 if(!guiApp.acquiredWindow && (guiApp.desktop.active || !guiApp.fullScreenMode))
6941 guiApp.interfaceDriver.GetMousePosition(&mouseX, &mouseY);
6942 if(this != guiApp.desktop)
6944 mouseX -= absPosition.x + clientStart.x;
6945 mouseY -= absPosition.y + clientStart.y;
6952 DialogResult DoModal()
6954 DialogResult returnCode = 0;
6955 int terminated = terminateX;
6958 while(!destroyed && guiApp.driver != null)
6960 if(terminateX != terminated)
6962 terminated = terminateX;
6963 guiApp.desktop.Destroy(0);
6964 if(guiApp.desktop.created)
6967 //printf("Resetting terminate X to 0\n");
6973 guiApp.UpdateDisplay();
6974 if(!guiApp.ProcessInput(false))
6977 returnCode = this.returnCode;
6990 return !destroyed && guiApp.driver != null && terminateX < 2;
6993 DialogResult DoModalEnd()
6995 DialogResult returnCode = this.returnCode;
7000 // --- Window manipulation ---
7001 /*bool GetDisabled()
7003 bool disabled = this.disabled;
7005 for(window = this; (window = window.master); )
7016 // --- Mouse Manipulation ---
7017 void GetNCMousePosition(int * x, int * y)
7019 GetMousePosition(x, y);
7020 if(x) *x += clientStart.x;
7021 if(y) *y += clientStart.y;
7024 // --- Carets manipulation ---
7025 void GetCaretPosition(Point caretPos)
7027 caretPos = this.caretPos;
7030 int GetCaretSize(void)
7035 bool ButtonCloseDialog(Button button, int x, int y, Modifiers mods)
7041 bool CloseConfirmation(bool parentClosing)
7054 if(!OnClose(parentClosing))
7057 // If you want to skip this, simply set modifiedDocument to false in OnClose
7058 if(result && (/*fileName || */style.isDocument) && modifiedDocument)
7060 DialogResult dialogRes;
7063 sprintf(message, "Save changes to %s?", fileName);
7065 sprintf(message, "Save changes to Untitled %d?", documentID);
7067 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption, contents = message }.Modal();
7069 if(dialogRes == yes)
7071 // TOFIX: Precomp error if brackets are taken out
7072 result = (DialogResult)MenuFileSave(null, 0) != cancel;
7074 else if(dialogRes == cancel)
7080 for(slave = slaves.first; slave; slave = slave.next)
7081 if(!((Window)slave.data).CloseConfirmation(true))
7083 // ((Window)slave.data).CloseConfirmation(true);
7091 for(child = children.first; child; child = child.next)
7092 if(child.master != this && !child.CloseConfirmation(true))
7102 // Static methods... move them somewhere else?
7103 void ::RestoreCaret()
7105 if(guiApp.caretOwner)
7106 guiApp.caretOwner.UpdateCaret(false, false);
7109 void ::FreeMouseRange()
7111 guiApp.interfaceDriver.SetMouseRange(null, null);
7115 bool MenuFileClose(MenuItem selection, Modifiers mods)
7117 Window document = activeChild;
7119 document.Destroy(0);
7123 bool MenuFileExit(MenuItem selection, Modifiers mods)
7129 bool MenuFileSave(MenuItem selection, Modifiers mods)
7133 fileMonitor.fileName = null;
7136 if(OnSaveFile(fileName))
7138 //if(OnFileModified != Window::OnFileModified)
7141 fileMonitor.fileName = fileName;
7147 MessageBox dialog { master = master, type = yesNoCancel, text = "Error writing file", contents = "Save as a different file?" };
7148 DialogResult answer = dialog.Modal();
7150 if(answer != yes) return (bool)answer;
7153 return MenuFileSaveAs(selection, mods);
7156 bool MenuFileSaveAs(MenuItem selection, Modifiers mods)
7158 DialogResult result = (DialogResult)bool::true;
7159 FileDialog fileDialog = saveDialog;
7162 fileDialog = FileDialog {};
7167 fileDialog.filePath = fileName;
7170 char filePath[MAX_FILENAME];
7171 sprintf(filePath, "Untitled %d", documentID);
7172 fileDialog.filePath = filePath;
7174 fileMonitor.fileName = null;
7176 fileDialog.type = save;
7177 fileDialog.text = "Save As";
7181 fileDialog.master = master.parent ? master : this;
7182 if(fileDialog.Modal() == ok)
7184 char * filePath = fileDialog.filePath;
7186 if(OnSaveFile(filePath))
7189 property::fileName = filePath;
7190 NotifySaved(master, this, filePath);
7195 MessageBox dialog { master = master.parent ? master : this, type = yesNoCancel, text = "Error writing file", contents = "Save as a different file?" };
7196 DialogResult answer = dialog.Modal();
7211 //if(OnFileModified != Window::OnFileModified && fileName)
7214 fileMonitor.fileName = fileName;
7218 return (bool)result; // Actually returning result from Yes/NoCancel message box
7221 bool MenuFileSaveAll(MenuItem selection, Modifiers mods)
7223 Window document = activeChild;
7225 for(document = children.first; document; document = next)
7227 next = document.next;
7228 if(document.style.isDocument || document.fileName)
7229 document.MenuFileSave(selection, mods);
7234 bool MenuWindowArrangeIcons(MenuItem selection, Modifiers mods)
7238 for(document = children.first; document; document = document.next)
7239 //if(document.style.isDocument && document.state == minimized)
7240 if(document.style.isActiveClient && document.state == minimized)
7241 document.SetState(minimized, false, mods);
7245 bool MenuWindowCascade(MenuItem selection, Modifiers mods)
7247 Window document = activeChild;
7250 Window firstDocument = null;
7252 OldLink cycle = document.cycle.prev;
7257 if(child.style.isActiveClient && !child.style.hidden)
7261 firstDocument = child;
7262 if(child.state == minimized)
7263 child.SetState(minimized, false, mods);
7266 child.positionID = id++;
7267 child.SetState(normal, false, mods);
7268 child.anchor.left.type = cascade;
7271 child.normalSizeAnchor = *&child.sizeAnchor;
7272 child.normalAnchor = child.anchor;
7274 // Break the anchors for moveable/resizable windows
7275 if(child.style.fixed)
7277 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7279 (*&child.normalAnchor).left = x;
7280 (*&child.normalAnchor).top = y;
7281 (*&child.normalAnchor).right.type = none;
7282 (*&child.normalAnchor).bottom.type = none;
7284 child.normalSizeAnchor.isClientW = false;
7285 child.normalSizeAnchor.isClientH = false;
7286 child.normalSizeAnchor.size.w = w;
7287 child.normalSizeAnchor.size.h = h;
7288 child.anchored = false;
7291 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7293 child.stateAnchor = child.normalAnchor;
7294 child.stateSizeAnchor = child.normalSizeAnchor;
7296 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7297 child.Position(x, y, w, h, true, true, true, true, false, false);
7302 last = children.last;
7303 if(!child.style.stayOnTop)
7304 for(; last && last.style.stayOnTop; last = last.prev);
7305 children.Move(child, last);
7306 childrenOrder.Move(child.order, childrenOrder.last);
7308 if(cycle == document.cycle) break;
7312 firstDocument.Activate();
7317 bool MenuWindowClose(MenuItem selection, Modifiers mods)
7324 // Close all closes all active clients, not all documents
7325 bool MenuWindowCloseAll(MenuItem selection, Modifiers mods)
7327 Window next, document;
7329 for(document = children.first; document; document = next)
7331 for(next = document.next; next && !(next.style.isActiveClient; next = next.next);
7332 if(document.style.isActiveClient)
7333 if(!document.Destroy(0) && !document.style.hidden)
7339 bool MenuWindowMaximize(MenuItem selection, Modifiers mods)
7341 if(style.hasMaximize && state != maximized)
7342 SetState(maximized, 0, 0);
7346 bool MenuWindowMinimize(MenuItem selection, Modifiers mods)
7348 if(style.hasMinimize && state != minimized)
7350 SetState(minimized, 0, 0);
7351 parent.CycleChildren(false, true, false, true);
7356 bool MenuWindowMove(MenuItem selection, Modifiers mods)
7358 MenuMoveOrSize(false, selection ? true : false);
7362 bool MenuWindowNext(MenuItem selection, Modifiers mods)
7364 CycleChildren(false, true, false, true);
7368 bool MenuWindowPrevious(MenuItem selection, Modifiers mods)
7370 CycleChildren(true, true, false, true);
7374 bool MenuWindowSize(MenuItem selection, Modifiers mods)
7376 MenuMoveOrSize(true, true);
7380 bool MenuWindowRestore(MenuItem selection, Modifiers mods)
7383 SetState(normal, 0, 0);
7387 bool MenuWindowSelectWindow(MenuItem selection, Modifiers mods)
7390 int id = selection.id;
7391 OldLink cycle = activeClient.cycle;
7393 //for(c = 0, cycle = activeChild.cycle; c<id; cycle = cycle.next, c++);
7396 Window sibling = cycle.data;
7397 if(sibling.style.isActiveClient)
7405 document = cycle.data;
7406 document.Activate();
7408 //if(activeChild.state == maximized)
7409 // document.SetState(maximized, false, mods);
7410 //else if(document.state == minimized)
7411 // document.SetState(normal, false, mods);
7415 bool MenuWindowStayOnTop(MenuItem selection, Modifiers mods)
7417 stayOnTop = !style.stayOnTop;
7421 bool MenuWindowTileHorz(MenuItem selection, Modifiers mods)
7423 Window document = activeChild;
7426 Window firstDocument = null;
7427 OldLink cycle = document.cycle;
7431 Window child = cycle.data;
7432 if(child.style.isActiveClient && !child.style.hidden)
7434 if(!firstDocument) firstDocument = child;
7435 if(child.state == minimized)
7436 child.SetState(minimized, false, mods);
7439 child.positionID = id++;
7440 child.SetState(normal, false, mods);
7441 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7443 child.anchor.left.type = hTiled;
7446 child.normalSizeAnchor = *&child.sizeAnchor;
7447 child.normalAnchor = child.anchor;
7449 // Break the anchors for moveable/resizable windows
7450 if(child.style.fixed)
7452 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7454 (*&child.normalAnchor).left = x;
7455 (*&child.normalAnchor).top = y;
7456 (*&child.normalAnchor).right.type = none;
7457 (*&child.normalAnchor).bottom.type = none;
7458 child.normalSizeAnchor.isClientW = false;
7459 child.normalSizeAnchor.isClientH = false;
7460 child.normalSizeAnchor.size.w = w;
7461 child.normalSizeAnchor.size.h = h;
7462 child.anchored = false;
7465 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7467 child.stateAnchor = child.normalAnchor;
7468 child.stateSizeAnchor = child.normalSizeAnchor;
7470 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7471 child.Position(x,y, w, h, true, true, true, true, false, true);
7476 if((cycle = cycle.next) == document.cycle) break;
7479 firstDocument.Activate();
7484 bool MenuWindowTileVert(MenuItem selection, Modifiers mods)
7486 Window document = activeChild;
7489 Window firstDocument = null;
7491 OldLink cycle = document.cycle;
7496 //if(child.style.isDocument)
7497 if(child.style.isActiveClient && !child.style.hidden)
7499 if(!firstDocument) firstDocument = child;
7500 if(child.state == minimized)
7501 child.SetState(minimized, false, mods);
7504 child.positionID = id++;
7505 child.SetState(normal, false, mods);
7506 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7508 child.anchor.left.type = vTiled;
7511 child.normalSizeAnchor = *&child.sizeAnchor;
7512 child.normalAnchor = child.anchor;
7514 // Break the anchors for moveable/resizable windows
7515 if(child.style.fixed)
7517 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7519 (*&child.normalAnchor).left = x;
7520 (*&child.normalAnchor).top = y;
7521 (*&child.normalAnchor).right.type = none;
7522 (*&child.normalAnchor).bottom.type = none;
7523 child.normalSizeAnchor.isClientW = false;
7524 child.normalSizeAnchor.isClientH = false;
7525 child.normalSizeAnchor.size.w = w;
7526 child.normalSizeAnchor.size.h = h;
7527 child.anchored = false;
7530 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7532 child.stateAnchor = child.normalAnchor;
7533 child.stateSizeAnchor = child.normalSizeAnchor;
7535 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7536 child.Position(x,y, w, h, true, true, true, true, false, true);
7541 if((cycle = cycle.next) == document.cycle) break;
7544 firstDocument.Activate();
7549 bool MenuWindowWindows(MenuItem selection, Modifiers mods)
7551 WindowList dialog { master = this };
7552 Window document = (Window)dialog.Modal();
7555 if(activeChild.state == maximized)
7556 document.SetState(maximized, false, mods);
7557 else if(document.state == minimized)
7558 document.SetState(normal, false, mods);
7559 document.Activate();
7565 virtual bool OnCreate(void);
7566 virtual void OnDestroy(void);
7567 virtual void OnDestroyed(void);
7568 virtual bool OnClose(bool parentClosing);
7569 virtual bool OnStateChange(WindowState state, Modifiers mods);
7570 virtual bool OnPostCreate(void);
7571 virtual bool OnMoving(int *x, int *y, int w, int h);
7572 virtual bool OnResizing(int *width, int *height);
7573 virtual void OnResize(int width, int height);
7574 virtual void OnPosition(int x, int y, int width, int height);
7575 virtual bool OnLoadGraphics(void);
7576 virtual void OnApplyGraphics(void);
7577 virtual void OnUnloadGraphics(void);
7578 virtual void OnRedraw(Surface surface);
7579 virtual bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct);
7580 virtual void OnActivateClient(Window client, Window previous);
7581 virtual bool OnKeyDown(Key key, unichar ch);
7582 virtual bool OnKeyUp(Key key, unichar ch);
7583 virtual bool OnKeyHit(Key key, unichar ch);
7584 virtual bool OnSysKeyDown(Key key, unichar ch);
7585 virtual bool OnSysKeyUp(Key key, unichar ch);
7586 virtual bool OnSysKeyHit(Key key, unichar ch);
7587 virtual bool OnMouseOver(int x, int y, Modifiers mods);
7588 virtual bool OnMouseLeave(Modifiers mods);
7589 virtual bool OnMouseMove(int x, int y, Modifiers mods);
7590 virtual bool OnLeftButtonDown(int x, int y, Modifiers mods);
7591 virtual bool OnLeftButtonUp(int x, int y, Modifiers mods);
7592 virtual bool OnLeftDoubleClick(int x, int y, Modifiers mods);
7593 virtual bool OnRightButtonDown(int x, int y, Modifiers mods);
7594 virtual bool OnRightButtonUp(int x, int y, Modifiers mods);
7595 virtual bool OnRightDoubleClick(int x, int y, Modifiers mods);
7596 virtual bool OnMiddleButtonDown(int x, int y, Modifiers mods);
7597 virtual bool OnMiddleButtonUp(int x, int y, Modifiers mods);
7598 virtual bool OnMiddleDoubleClick(int x, int y, Modifiers mods);
7599 virtual void OnMouseCaptureLost(void);
7600 virtual void OnHScroll(ScrollBarAction action, int position, Key key);
7601 virtual void OnVScroll(ScrollBarAction action, int position, Key key);
7602 virtual void OnDrawOverChildren(Surface surface);
7603 virtual bool OnFileModified(FileChange fileChange, char * param);
7604 virtual bool OnSaveFile(char * fileName);
7606 // Skins Virtual Functions
7607 virtual void GetDecorationsSize(MinMaxValue * w, MinMaxValue * h);
7608 virtual void SetWindowMinimum(MinMaxValue * mw, MinMaxValue * mh);
7609 virtual void SetWindowArea(int * x, int * y, MinMaxValue * w, MinMaxValue * h, MinMaxValue * cw, MinMaxValue * ch)
7614 virtual void ShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7615 virtual void PreShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7616 virtual bool IsMouseMoving(int x, int y, int w, int h);
7617 virtual bool IsMouseResizing(int x, int y, int w, int h, bool *resizeX, bool *resizeY, bool *resizeEndX, bool *resizeEndY);
7618 virtual void UpdateNonClient();
7619 virtual void SetBox(Box box);
7620 virtual bool IsInside(int x, int y)
7622 return box.IsPointInside({x, y});
7624 virtual bool IsOpaque()
7626 return (!style.drawBehind || background.a == 255);
7630 virtual bool Window::NotifyActivate(Window window, bool active, Window previous);
7631 virtual void Window::NotifyDestroyed(Window window, DialogResult result);
7632 virtual void Window::NotifySaved(Window window, char * filePath);
7637 property Window parent
7639 property_category "Layout"
7642 if(value || guiApp.desktop)
7645 Window oldParent = parent;
7646 Anchor anchor = this.anchor;
7648 if(value && value.IsDescendantOf(this)) return;
7649 if(value && value == this)
7651 if(!value) value = guiApp.desktop;
7653 if(value == oldParent) return;
7655 if(!master || (master == this.parent && master == guiApp.desktop))
7656 property::master = value;
7660 parent.children.Remove(this);
7664 box.left - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7665 box.top - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y,
7666 box.right - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7667 box.bottom - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y
7671 last = value.children.last;
7673 if(style.isDocument)
7676 parent.numDocuments--;
7677 documentID = value.GetDocumentID();
7680 if(style.isActiveClient && !style.hidden)
7682 if(parent && parent != guiApp.desktop && !(style.hidden))
7684 if(state == minimized) parent.numIcons--;
7685 parent.numPositions--;
7689 if(!style.stayOnTop)
7690 for(; last && last.style.stayOnTop; last = last.prev);
7692 value.children.Insert(last, this);
7694 // *** NEW HERE: ***
7696 parent.childrenCycle.Delete(cycle);
7698 parent.childrenOrder.Delete(order);
7706 int x = position.x, y = position.y, w = size.w, h = size.h;
7710 x += parent.absPosition.x - value.absPosition.x + parent.clientStart.x - value.clientStart.x;
7711 y += parent.absPosition.y - value.absPosition.y + parent.clientStart.y - value.clientStart.y;
7713 vpw = value.clientSize.w;
7714 vph = value.clientSize.h;
7720 else if(style.fixed)
7722 if(!style.dontScrollHorz && value.scrollArea.w) vpw = value.scrollArea.w;
7723 if(!style.dontScrollVert && value.scrollArea.h) vph = value.scrollArea.h;
7726 anchor = this.anchor;
7728 if(anchor.left.type == offset) anchor.left.distance = x;
7729 else if(anchor.left.type == relative) anchor.left.percent = (float)x / vpw;
7730 if(anchor.top.type == offset) anchor.top.distance = y;
7731 else if(anchor.top.type == relative) anchor.top.percent = (float)y / vph;
7732 if(anchor.right.type == offset) anchor.right.distance = vpw - (x + w);
7733 //else if(anchor.right.type == relative) anchor.right.percent = 1.0-(float) (vpw - (x + w)) / vpw;
7734 else if(anchor.right.type == relative) anchor.right.percent = (float) (vpw - (x + w)) / vpw;
7735 if(anchor.bottom.type == offset) anchor.bottom.distance = vph - (y + h);
7736 //else if(anchor.bottom.type == relative) anchor.bottom.percent = 1.0-(float) (vph - (y + h)) / vph;
7737 else if(anchor.bottom.type == relative) anchor.bottom.percent = (float) (vph - (y + h)) / vph;
7739 if(!anchor.left.type && !anchor.right.type)
7741 anchor.horz.distance = (x + w / 2) - (vpw / 2);
7742 //anchor.horz.type = anchor.horz.distance ? AnchorValueOffset : 0;
7744 else if(anchor.horz.type == middleRelative) anchor.horz.percent = (float) ((x + w / 2) - (vpw / 2)) / vpw;
7745 if(!anchor.top.type && !anchor.bottom.type)
7747 anchor.vert.distance = (y + h / 2) - (vph / 2);
7748 //anchor.vert.type = anchor.vert.distance ? AnchorValueOffset : 0;
7750 else if(anchor.vert.type == middleRelative) anchor.vert.percent = (float)((y + h / 2) - (vph / 2)) / vph;
7758 parent.childrenCycle.Insert(
7759 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
7760 cycle = OldLink { data = this });
7761 parent.childrenOrder.Insert(
7762 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
7763 order = OldLink { data = this });
7766 if(!style.hidden && style.isActiveClient)
7768 positionID = parent.GetPositionID(this);
7769 parent.numPositions++;
7770 if(state == minimized) parent.numIcons--;
7773 // *** FONT INHERITANCE ***
7774 if(!setFont && oldParent)
7775 stopwatching(oldParent, font);
7779 RemoveResource(systemFont);
7782 // TESTING WITH WATCHERS:
7783 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7784 // usedFont = setFont ? setFont : (systemFont);
7788 if(guiApp.currentSkin)
7790 systemFont = guiApp.currentSkin.SystemFont();
7793 usedFont = systemFont;
7794 AddResource(systemFont);
7802 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7811 if(value.rootWindow && value.rootWindow.display && rootWindow)
7813 bool reloadGraphics = (oldParent.rootWindow == oldParent && value.rootWindow) || (!value.rootWindow && rootWindow == this) ||
7814 (value.rootWindow.display && value.rootWindow.display.displaySystem != rootWindow.display.displaySystem);
7817 UnloadGraphics(false);
7820 LoadGraphics(false, false);
7823 if(value.rootWindow != rootWindow)
7824 DisplayModeChanged();
7828 scrolledPos.x = MININT; // Prevent parent update
7829 property::anchor = anchor;
7833 if(guiApp.currentSkin)
7834 guiApp.currentSkin.SetWindowMinimum(this, &skinMinSize.w, &skinMinSize.h);
7836 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
7837 Position(x, y, w, h, true, true, true, true, false, true);
7842 // else parent = value;
7845 get { return parent; }
7848 property Window master
7850 property_category "Behavior"
7853 //if(this == value) return;
7854 if(value && value.IsSlaveOf(this)) return;
7860 OldLink slaveHolder;
7861 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
7862 if(slaveHolder.data == this)
7864 master.slaves.Delete(slaveHolder);
7871 value.slaves.Add(OldLink { data = this });
7876 master.hotKeys.Remove(hotKey);
7877 value.hotKeys.Add(hotKey);
7880 if(master && master.defaultControl == this)
7881 master.defaultControl = null;
7883 if(style.isDefault && !value.defaultControl)
7884 value.defaultControl = this;
7890 get { return master ? master : parent; }
7893 property char * text
7895 property_category "Appearance"
7902 caption = new char[strlen(value)+1];
7904 strcpy(caption, value);
7909 get { return caption; }
7914 property_category "Behavior"
7923 master.hotKeys.Add(hotKey = HotKeySlot { });
7927 hotKey.window = this;
7932 master.hotKeys.Delete(hotKey);
7937 get { return hotKey ? hotKey.key : 0; }
7940 property Color background
7942 property_category "Appearance"
7945 background.color = value;
7950 if(this == rootWindow)
7951 guiApp.interfaceDriver.SetRootWindowColor(this);
7954 get { return background.color; }
7957 property Percentage opacity
7959 property_category "Appearance"
7962 background.a = (byte)Min(Max((int)(value * 255), 0), 255);
7963 drawBehind = background.a ? false : true;
7965 get { return background.a / 255.0f; }
7968 property Color foreground
7970 property_category "Appearance"
7978 get { return foreground; }
7981 property BorderStyle borderStyle
7983 property_category "Appearance"
7986 if(!((BorderBits)value).fixed)
7988 style.hasClose = false;
7989 style.hasMaximize = false;
7990 style.hasMinimize = false;
7992 style.borderBits = value;
7996 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
7998 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
7999 Position(x, y, w, h, true, true, true, true, false, true);
8000 CreateSystemChildren();
8003 get { return (BorderStyle)style.borderBits; }
8006 property Size minClientSize
8008 property_category "Layout"
8009 set { minSize = value; }
8010 get { value = minSize; }
8013 property Size maxClientSize
8015 property_category "Layout"
8016 set { maxSize = value; }
8017 get { value = maxSize; }
8020 property bool hasMaximize
8022 property_category "Window Style"
8025 style.hasMaximize = value;
8026 if(value) { style.fixed = true; style.contour = true; }
8030 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8032 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8033 Position(x, y, w, h, true, true, true, true, false, true);
8035 CreateSystemChildren();
8038 get { return style.hasMaximize; }
8041 property bool hasMinimize
8043 property_category "Window Style"
8046 style.hasMinimize = value;
8047 if(value) { style.fixed = true; style.contour = true; }
8051 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8053 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8054 Position(x, y, w, h, true, true, true, true, false, true);
8056 CreateSystemChildren();
8059 get { return style.hasMinimize; }
8062 property bool hasClose
8064 property_category "Window Style"
8067 style.hasClose = value;
8068 if(value) { style.fixed = true; style.contour = true; }
8072 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8073 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8074 Position(x, y, w, h, true, true, true, true, false, true);
8075 CreateSystemChildren();
8078 get { return style.hasClose; }
8081 property bool nonClient
8083 property_category "Layout"
8086 style.nonClient = value;
8088 style.stayOnTop = true;
8090 get { return style.nonClient; }
8093 property bool inactive
8095 property_category "Behavior"
8100 // *** NEW HERE: ***
8104 parent.childrenCycle.Delete(cycle);
8106 parent.childrenOrder.Delete(order);
8113 active = false; // true;
8114 if(parent.activeChild == this)
8115 parent.activeChild = null;
8116 if(parent.activeClient == this)
8117 parent.activeClient = null;
8126 parent.childrenCycle.Insert(
8127 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8128 cycle = OldLink { data = this });
8130 parent.childrenOrder.Insert(
8131 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8132 order = OldLink { data = this });
8135 style.inactive = value;
8137 get { return style.inactive; }
8140 property bool clickThrough
8142 property_category "Behavior"
8143 set { style.clickThrough = value; }
8144 get { return style.clickThrough; }
8147 property bool isRemote
8149 property_category "Behavior"
8150 set { style.isRemote = value; }
8151 get { return style.isRemote; }
8154 property bool noCycle
8156 property_category "Behavior"
8157 set { style.noCycle = value; }
8158 get { return style.noCycle; }
8161 property bool isModal
8163 property_category "Behavior"
8164 set { style.modal = value; }
8165 get { return style.modal; }
8168 property bool interim
8170 property_category "Behavior"
8171 set { style.interim = value; }
8172 get { return style.interim; }
8175 property bool tabCycle
8177 property_category "Behavior"
8178 set { style.tabCycle = value; }
8179 get { return style.tabCycle; }
8182 property bool isDefault
8184 property_category "Behavior"
8192 /*for(sibling = parent.children.first; sibling; sibling = sibling.next)
8193 if(sibling != this && sibling.style.isDefault)
8194 sibling.style.isDefault = false;*/
8195 if(master.defaultControl)
8196 master.defaultControl.style.isDefault = false;
8197 master.defaultControl = this;
8199 else if(master.defaultControl == this)
8200 master.defaultControl = null;
8204 style.isDefault = value;
8206 Position(position.x, position.y, size.w, size.h, true, true, true,true,true, true);
8208 get { return style.isDefault; }
8211 property bool drawBehind
8213 property_category "Window Style"
8214 set { style.drawBehind = value; }
8215 get { return style.drawBehind; }
8218 property bool hasMenuBar
8220 property_category "Window Style"
8230 if(created && !menuBar)
8237 anchor = Anchor { top = 23, left = 1, right = 1 },
8239 inactive = true, nonClient = true
8244 else if(created && menuBar)
8249 style.hasMenuBar = value;
8251 get { return style.hasMenuBar; }
8254 property bool hasStatusBar
8256 property_category "Window Style"
8263 statusBar = StatusBar { this };
8271 style.hasStatusBar = value;
8273 get { return style.hasStatusBar; }
8275 property bool stayOnTop
8277 property_category "Window Style"
8282 if(created && !style.stayOnTop)
8284 if(rootWindow == this)
8285 guiApp.interfaceDriver.OrderRootWindow(this, true);
8286 else if(parent.children.last != this)
8288 parent.children.Move(this, parent.children.last);
8292 style.stayOnTop = true;
8296 if(created && style.stayOnTop)
8298 if(rootWindow == this)
8299 guiApp.interfaceDriver.OrderRootWindow(this, false);
8306 for(order = (this.order == parent.childrenOrder.first) ? null : this.order.prev;
8307 order && ((Window)order.data).style.stayOnTop;
8308 order = (order == parent.childrenOrder.first) ? null : order.prev);
8309 last = order ? order.data : null;
8313 for(last = parent.children.last;
8314 last && last.style.stayOnTop;
8318 parent.children.Move(this, last);
8322 style.stayOnTop = false;
8325 get { return style.stayOnTop; }
8330 property_category "Window Style"
8340 if(menuBar && !value)
8347 if(!menuBar && style.hasMenuBar && value)
8351 this, menu = value, isMenuBar = true,
8352 anchor = Anchor { left = 1, top = 23, right = 1 }, size.h = 24,
8353 inactive = true, nonClient = true
8357 UpdateActiveDocument(null);
8360 get { return menu; }
8363 property FontResource font
8365 property_category "Appearance"
8367 isset { return setFont ? true : false; }
8372 if(value && !setFont) { stopwatching(parent, font); }
8373 else if(!value && setFont)
8379 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8388 RemoveResource(setFont);
8393 RemoveResource(systemFont);
8400 AddResource(setFont);
8403 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
8406 systemFont = guiApp.currentSkin.SystemFont();
8408 usedFont = systemFont;
8409 AddResource(systemFont);
8417 get { return usedFont; }
8420 property SizeAnchor sizeAnchor
8422 property_category "Layout"
8425 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8426 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8427 sizeAnchor.isClientW != sizeAnchor.isClientH;
8434 normalSizeAnchor = sizeAnchor;
8436 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8438 stateAnchor = normalAnchor;
8439 stateSizeAnchor = normalSizeAnchor;
8441 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8442 Position(x,y, w, h, true, true, true, true, false, true);
8449 { sizeAnchor.isClientW ? clientSize.w : size.w, sizeAnchor.isClientH ? clientSize.h : size.h },
8450 sizeAnchor.isClientW,
8451 sizeAnchor.isClientH
8458 property_category "Layout"
8461 Anchor thisAnchor = anchor;
8462 SizeAnchor thisSizeAnchor = sizeAnchor;
8463 bool leftRight = (anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none);
8464 bool topBottom = (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none);
8465 bool isClient = !sizeAnchor.isClientW && !sizeAnchor.isClientH;
8466 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8467 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8468 !sizeAnchor.isClientW && !sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8474 sizeAnchor.isClientW = false;
8475 sizeAnchor.isClientH = false;
8476 sizeAnchor.size = value;
8478 normalSizeAnchor = sizeAnchor;
8480 if(state == normal /*|| state == Hidden*/) // Hidden is new here ...
8482 stateAnchor = normalAnchor;
8483 stateSizeAnchor = normalSizeAnchor;
8485 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8486 Position(x, y, w, h, true, true, true, true, false, true);
8489 get { value = size; }
8492 property Size clientSize
8494 property_category "Layout"
8497 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8498 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8499 sizeAnchor.isClientW && sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8504 sizeAnchor.isClientW = true;
8505 sizeAnchor.isClientH = true;
8506 sizeAnchor.size = value;
8508 normalSizeAnchor = sizeAnchor;
8510 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8512 stateAnchor = normalAnchor;
8513 stateSizeAnchor = normalSizeAnchor;
8515 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8516 Position(x,y, w, h, true, true, true, true, false, true);
8519 get { value = clientSize; }
8522 property Size initSize { get { value = sizeAnchor.size; } };
8524 property Anchor anchor
8526 property_category "Layout"
8527 isset { return (anchor.left.type != offset || anchor.top.type != offset || anchor.right.type || anchor.bottom.type); }
8533 if(anchor.left.type && anchor.right.type && (!value.left.type || !value.right.type))
8535 normalSizeAnchor.isClientW = sizeAnchor.isClientW = false;
8536 normalSizeAnchor.size.w = sizeAnchor.size.w = size.w;
8538 if(anchor.top.type && anchor.bottom.type && (!value.top.type || !value.bottom.type))
8540 normalSizeAnchor.isClientH = sizeAnchor.isClientH = false;
8541 normalSizeAnchor.size.h = sizeAnchor.size.h = size.h;
8545 if(anchor.right.type && (anchor.horz.type == middleRelative || !anchor.left.type))
8547 anchor.left.distance = 0;
8548 anchor.horz.type = 0;
8550 if(anchor.bottom.type && (anchor.vert.type == middleRelative || !anchor.top.type))
8552 anchor.top.distance = 0;
8553 anchor.vert.type = 0;
8562 normalAnchor = anchor;
8564 // Break the anchors for moveable/resizable windows
8565 /*if(style.fixed ) //&& value.left.type == cascade)
8567 ComputeAnchors(anchor, sizeAnchor, &x, &y, &w, &h);
8569 this.anchor = normalAnchor = Anchor { left = x, top = y };
8570 normalSizeAnchor = SizeAnchor { { w, h } };
8573 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8575 stateAnchor = normalAnchor;
8576 stateSizeAnchor = normalSizeAnchor;
8578 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8579 Position(x, y, w, h, true, true, true, true, false, true);
8588 get { value = this ? anchor : Anchor { }; }
8591 property Point position
8593 property_category "Layout"
8596 if(value == null) return;
8598 anchor.left = value.x;
8599 anchor.top = value.y;
8600 anchor.right.type = none;
8601 anchor.bottom.type = none;
8606 normalAnchor = anchor;
8608 // Break the anchors for moveable/resizable windows
8612 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8614 normalAnchor.left = x;
8615 normalAnchor.top = y;
8616 normalAnchor.right.type = none;
8617 normalAnchor.bottom.type = none;
8618 normalSizeAnchor.size.width = w;
8619 normalSizeAnchor.size.height = h;
8623 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8625 stateAnchor = normalAnchor;
8626 stateSizeAnchor = normalSizeAnchor;
8628 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8629 Position(x,y, w, h, true, true, true, true, false, true);
8633 get { value = position; }
8636 property bool disabled
8638 property_category "Behavior"
8641 if(this && disabled != value)
8648 get { return (bool)disabled; }
8651 property bool isEnabled
8656 for(parent = this; parent; parent = parent.parent)
8663 property WindowState state
8665 property_category "Behavior"
8666 set { SetState(value, false, 0); }
8667 get { return this ? state : 0; }
8670 property bool visible
8672 property_category "Behavior"
8675 if(this && !value && !style.hidden && parent)
8677 bool wasActiveChild = parent.activeChild == this;
8678 Window client = null;
8680 style.hidden = true;
8681 if(style.isActiveClient)
8683 parent.numPositions--;
8684 if(state == minimized) parent.numIcons--;
8689 OldLink prevOrder = null;
8691 if(rootWindow == this)
8692 guiApp.interfaceDriver.SetRootWindowState(this, state, false);
8695 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
8698 box.left -= parent.clientStart.x;
8699 box.top -= parent.clientStart.y;
8700 box.right -= parent.clientStart.x;
8701 box.bottom -= parent.clientStart.y;
8705 if(_isModal && master && master.modalSlave == this)
8706 master.modalSlave = null;
8710 OldLink tmpPrev = order.prev;
8711 client = tmpPrev ? tmpPrev.data : null;
8712 if(client && !client.style.hidden && !client.destroyed && client.created)
8713 prevOrder = tmpPrev;
8716 client = tmpPrev ? tmpPrev.data : null;
8717 if(client == this) { client = null; break; }
8718 if(client && ((client.style.hidden) || client.destroyed || !client.created))
8720 tmpPrev = client.order.prev;
8725 prevOrder = tmpPrev;
8730 // If this window can be an active client, make sure the next window we activate can also be one
8731 if(!style.nonClient && style.isActiveClient)
8733 tmpPrev = prevOrder;
8736 client = tmpPrev ? tmpPrev.data : null;
8737 if(client == this) { client = null; break; }
8738 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
8740 tmpPrev = client.order.prev;
8745 prevOrder = tmpPrev;
8749 if(client && client.style.hidden) client = null;
8753 if((wasActiveChild /*parent.activeChild == this*/ || guiApp.interimWindow == this) && true /*activate*/)
8755 if(order && prevOrder && prevOrder.data != this)
8756 ((Window)prevOrder.data).ActivateEx(true, false, false, true, null, null);
8758 ActivateEx(false, false, false, true, null, null);
8760 // TESTING THIS HERE FOR HIDING ACTIVE CLIENT
8761 if(parent.activeClient == this)
8763 parent.activeClient = null;
8764 parent.UpdateActiveDocument(null);
8767 else if(parent.activeClient == this)
8769 parent.activeClient = client;
8770 parent.UpdateActiveDocument(this);
8773 // *** Not doing this anymore ***
8776 parent.childrenCycle.Delete(cycle);
8778 parent.childrenOrder.Delete(order);
8783 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8788 else if(this && value && style.hidden)
8790 style.hidden = false;
8793 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8794 if(rootWindow == this)
8795 guiApp.interfaceDriver.SetRootWindowState(this, state, true);
8797 if(_isModal && master)
8798 master.modalSlave = this;
8800 if(style.isActiveClient)
8802 positionID = parent.GetPositionID(this);
8803 parent.numPositions++;
8804 if(state == minimized) parent.numIcons++;
8807 // *** NOT DOING THIS ANYMORE ***
8809 if(!(style.inactive))
8811 if(!(style.noCycle))
8813 cycle = parent.childrenCycle.AddAfter(
8814 (parent.activeChild && parent.activeChild.cycle) ?
8815 parent.activeChild.cycle.prev : null, sizeof(OldLink));
8818 order = parent.childrenOrder.AddAfter(
8819 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8826 if(true || !parent.activeChild)
8827 ActivateEx(true, false, true, true, null, null);
8829 if(creationActivation == activate)
8830 ActivateEx(true, false, true, true, null, null);
8831 else if(creationActivation == flash && !object)
8834 //SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8838 ConsequentialMouseMove(false);
8844 style.hidden = !value;
8847 get { return (style.hidden || !setVisible) ? false : true; }
8850 property bool isDocument
8852 property_category "Document"
8853 set { style.isDocument = value; }
8854 get { return style.isDocument; }
8857 property bool mergeMenus
8859 property_category "Window Style"
8860 set { mergeMenus = value; }
8861 get { return (bool)mergeMenus; }
8864 property bool hasHorzScroll
8866 property_category "Window Style"
8871 if(!style.hasHorzScroll && created)
8873 CreateSystemChildren();
8874 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8877 else if(style.hasHorzScroll)
8881 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8883 style.hasHorzScroll = value;
8886 get { return style.hasHorzScroll; }
8889 property bool hasVertScroll
8891 property_category "Window Style"
8896 if(!style.hasVertScroll && created)
8898 style.hasVertScroll = true;
8899 CreateSystemChildren();
8900 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8903 else if(style.hasVertScroll)
8907 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8909 style.hasVertScroll = value;
8911 get { return style.hasVertScroll; }
8914 property bool dontHideScroll
8916 property_category "Behavior"
8919 scrollFlags.dontHide = value;
8922 //UpdateScrollBars(true, true);
8923 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
8927 // UpdateScrollBars(true, true);
8928 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
8931 get { return scrollFlags.dontHide; }
8934 property bool dontScrollVert
8936 property_category "Behavior"
8937 set { style.dontScrollVert = value; }
8938 get { return style.dontScrollVert; }
8940 property bool dontScrollHorz
8942 property_category "Behavior"
8943 set { style.dontScrollHorz = value; }
8944 get { return style.dontScrollHorz; }
8947 property bool snapVertScroll
8949 property_category "Behavior"
8952 scrollFlags.snapY = value;
8953 if(sbv) sbv.snap = value;
8955 get { return scrollFlags.snapY; }
8957 property bool snapHorzScroll
8959 property_category "Behavior"
8962 scrollFlags.snapX = value;
8963 if(sbh) sbh.snap = value;
8965 get { return scrollFlags.snapX; }
8968 property Point scroll
8970 property_category "Behavior"
8974 // TESTING THIS IMPLEMENTATION:
8975 SetScrollPosition(value.x, value.y);
8977 get { value = scroll; }
8980 property bool modifyVirtualArea
8982 property_category "Behavior"
8983 set { modifyVirtArea = value; }
8984 get { return (bool)modifyVirtArea; }
8987 property char * fileName
8989 property_category "Document"
8992 if(menu && ((!fileName && value) || (fileName && !value)))
8994 MenuItem item = menu.FindItem(MenuFileSave, 0);
8995 if(item) item.disabled = !modifiedDocument && value;
9000 if(value && value[0])
9001 fileName = CopyString(value);
9003 if(parent && this == parent.activeClient)
9004 parent.UpdateActiveDocument(null);
9008 // if(style.isDocument)
9010 fileMonitor.fileName = value;
9012 get { return fileName; }
9017 property_category "Data"
9022 property bool modifiedDocument
9024 property_category "Document"
9027 if(style.isDocument || fileName)
9031 MenuItem item = menu.FindItem(MenuFileSave, 0);
9032 if(item) item.disabled = !value && fileName;
9036 if(modifiedDocument != value)
9038 modifiedDocument = value;
9039 if(style.isDocument || fileName)
9043 get { return (bool)modifiedDocument; }
9046 property bool showInTaskBar
9048 property_category "Window Style"
9049 set { style.showInTaskBar = value; }
9050 get { return (style.showInTaskBar; }
9052 property FileDialog saveDialog { set { saveDialog = value; } };
9053 property bool isActiveClient
9055 property_category "Behavior"
9056 set { style.isActiveClient = value; }
9057 get { return style.isActiveClient; }
9060 property Cursor cursor
9062 property_category "Appearance"
9066 SelectMouseCursor();
9068 get { return cursor; }
9071 //#if !defined(ECERE_VANILLA)
9072 property char * name
9074 property_category "Design"
9077 return (this && object) ? object.name : null;
9082 activeDesigner.RenameObject(object, value);
9086 property char * displayDriver
9088 property_category "Behavior"
9091 dispDriver = GetDisplayDriver(value);
9092 //DisplayModeChanged();
9096 return dispDriver ? dispDriver.name : null;
9100 // RUNTIME PROPERTIES
9101 property bool autoCreate { set { autoCreate = value; } get { return (bool)autoCreate; } };
9102 property Size scrollArea
9104 property_category "Behavior"
9108 SetScrollArea(value.w, value.h, false);
9110 SetScrollArea(0,0, true);
9112 get { value = scrollArea; }
9115 return scrollArea.w > clientSize.w || scrollArea.h > clientSize.h;
9120 property_category "Layout"
9121 set { if(this) is3D = value; }
9122 get { return (bool)is3D; }
9125 // Runtime Only Properties (No Set, can display the displayable ones depending on the type?)
9127 // Will be merged with font later
9128 property Font fontObject { get { return usedFont ? usedFont.font : null; } };
9129 property Point clientStart { get { value = clientStart; } };
9130 property Point absPosition { get { value = absPosition; } };
9131 property Anchor normalAnchor { get {value = normalAnchor; } };
9132 // property Size normalSizeAnchor { get { value = normalSizeAnchor; } };
9133 property bool active { get { return (bool)active; } };
9134 property bool created { get { return (bool)created; } };
9135 property bool destroyed { get { return (bool)destroyed; } };
9136 property Window firstSlave { get { return slaves.first ? ((OldLink)slaves.first).data : null; } };
9137 property Window firstChild { get { return children.first; } };
9138 property Window lastChild { get { return children.last; } };
9139 property Window activeClient { get { return activeClient; } };
9140 property Window activeChild { get { return activeChild; } };
9141 property Display display { get { return display ? display : ((parent && parent.rootWindow) ? parent.rootWindow.display : null); } };
9142 property DisplaySystem displaySystem { get { return display ? display.displaySystem : null; } };
9143 property ScrollBar horzScroll { get { return sbh; } };
9144 property ScrollBar vertScroll { get { return sbv; } };
9145 property StatusBar statusBar { get { return statusBar; } };
9146 property Window rootWindow { get { return rootWindow; } };
9147 property bool closing { get { return (bool)closing; } set { closing = value; } };
9148 property int documentID { get { return documentID; } };
9149 property Window previous { get { return prev; } }
9150 property Window next { get { return next; } }
9151 property Window nextSlave { get { OldLink link = master ? master.slaves.FindLink(this) : null; return (link && link.next) ? link.next.data : null; } }
9152 property PopupMenu menuBar { get { return menuBar; } }
9153 property ScrollBar sbv { get { return sbv; } }
9154 property ScrollBar sbh { get { return sbh; } }
9155 property bool fullRender { set { fullRender = value; } get { return (bool)fullRender; } }
9156 property void * systemHandle { get { return windowHandle; } }
9157 property Button minimizeButton { get { return sysButtons[0]; } };
9158 property Button maximizeButton { get { return sysButtons[1]; } };
9159 property Button closeButton { get { return sysButtons[2]; } };
9160 property BitmapResource icon
9162 get { return icon; }
9166 if(icon) incref icon;
9168 guiApp.interfaceDriver.SetIcon(this, value);
9171 property bool moveable { get { return (bool)moveable; } set { moveable = value; } };
9172 property bool alphaBlend { get { return (bool)alphaBlend; } set { alphaBlend = value; } };
9173 property bool useSharedMemory { get { return (bool)useSharedMemory; } set { useSharedMemory = value; } };
9174 property CreationActivationOption creationActivation { get { return creationActivation; } set { creationActivation = value; } };
9175 property bool nativeDecorations { get { return (bool)nativeDecorations && (formDesigner || rootWindow == this); } set { nativeDecorations = value; } };
9176 property bool manageDisplay { get { return (bool)manageDisplay; } set { manageDisplay = value; } };
9182 WindowBits style; // Window Style
9183 char * caption; // Name / Caption
9184 Window parent; // Parent window
9185 OldList children; // List of children in Z order
9186 Window activeChild; // Child window having focus
9187 Window activeClient;
9188 Window previousActive; // Child active prior to activating the default child
9189 Window master; // Window owning and receiving notifications concerning this window
9190 OldList slaves; // List of windows belonging to this window
9191 Display display; // Display this window is drawn into
9193 Point position; // Position in parent window client area
9194 Point absPosition; // Absolute position
9195 Point clientStart; // Client area position from (0,0) in this window
9197 Size clientSize; // Client area size
9198 Size scrollArea; // Virtual Scroll area size
9199 Size reqScrollArea; // Requested virtual area size
9200 Point scroll; // Virtual area scrolling position
9201 public ScrollBar sbh, sbv; // Scrollbar window handles
9202 Cursor cursor; // Mouse cursor used for this window
9205 StatusBar statusBar;
9206 Button sysButtons[3];
9208 Box clientArea; // Client Area box clipped to parent
9210 HotKeySlot hotKey; // HotKey for this window
9214 ScrollFlags scrollFlags;// Window Scrollbar Flags
9215 int id; // Control ID
9217 ColorAlpha background; // Background color used to draw the window area
9219 subclass(DisplayDriver) dispDriver; // Display driver name for this window
9220 OldList childrenCycle; // Cycling order
9221 OldLink cycle; // Element of parent's cycling order
9222 OldList childrenOrder; // Circular Z-Order
9223 OldLink order; // Element of parent's circular Z-Order
9224 Window modalSlave; // Slave window blocking this window's interaction
9226 Window rootWindow; // Topmost system managed window
9227 void * windowHandle; // System window handle
9229 DialogResult returnCode;// Return code for modal windows
9231 Point sbStep; // Scrollbar line scrolling steps
9234 SizeAnchor stateSizeAnchor;
9236 Anchor normalAnchor;
9237 SizeAnchor normalSizeAnchor;
9239 Size skinMinSize; // Minimal window size based on style
9240 Point scrolledPos; // Scrolled position
9241 Box box; // Window box clipped to parent
9242 Box * against; // What to clip the box to
9244 Extent dirtyArea { /*first = -1, last = -1, free = -1*/ }; // Area marked for update by Update
9245 Extent renderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered
9246 Extent overRenderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered over children
9247 Extent clipExtent { /*first = -1, last = -1, free = -1*/ }; // Temporary extent against which to clip render area
9248 Extent scrollExtent { /*first = -1, last = -1, free = -1*/ }; // Area to scroll
9249 Point scrolledArea; // Distance to scroll area by
9250 Extent dirtyBack { /*first = -1, last = -1, free = -1*/ }; // Only used by root window
9252 OldList hotKeys; // List of the hotkeys of all children
9253 Window defaultControl; // Default child control
9257 ColorAlpha * palette; // Color palette used for this window
9259 int caretSize; // Size of caret, non zero if a caret is present
9260 Point caretPos; // Caret position
9262 void * systemParent; // Parent System Window for embedded windows
9269 WindowState lastState;
9271 FileMonitor fileMonitor
9273 this, FileChange { modified = true };
9275 bool OnFileNotify(FileChange action, char * param)
9278 fileMonitor.StopMonitoring();
9279 if(OnFileModified(action, param))
9280 fileMonitor.StartMonitoring();
9285 FontResource setFont, systemFont;
9286 FontResource usedFont;
9287 FontResource captionFont;
9289 FileDialog saveDialog;
9291 SizeAnchor sizeAnchor;
9293 // FormDesigner data
9296 Extent * tempExtents; //[4];
9297 BitmapResource icon;
9299 CreationActivationOption creationActivation;
9302 bool active:1; // true if window and ancestors are active
9303 bool acquiredInput:1; // true if the window is processing state based input
9304 bool modifiedDocument:1;
9305 bool disabled:1; // true if window cannot interact
9306 bool isForegroundWindow:1;// true while a root window is being activated
9307 bool visible:1; // Visibility flag
9308 bool destroyed:1; // true if window is being destroyed
9309 bool anchored:1; // true if this window is repositioned when the parent resizes
9310 bool dirty:1; // Flag set to true if any descendant must be redrawn
9316 bool modifyVirtArea:1;
9317 bool noAutoScrollArea:1;
9320 bool setVisible:1; // FOR FORM DESIGNER
9326 bool useSharedMemory:1;
9329 bool nativeDecorations:1;
9330 bool manageDisplay:1;
9331 bool formDesigner:1; // True if we this is running in the form editor
9334 // Checks used internally for them not to take effect in FormDesigner
9335 property bool _isModal { get { return !formDesigner ? style.modal : false; } }
9336 property subclass(DisplayDriver) _displayDriver { get { return !formDesigner ? dispDriver : null; } }
9338 WindowController controller;
9339 public property WindowController controller { get { return controller; } set { delete controller; controller = value; if(controller) incref controller; } }
9342 public class CommonControl : Window
9344 // creationActivation = doNothing;
9347 public property String toolTip
9349 property_category "Appearance"
9353 toolTip = value ? ToolTip { tip = value; } : null;
9356 get { return toolTip ? toolTip.tip : null; }
9362 // (Very) Ugly work around for the fact that the parent watcher
9363 // won't fire when it's already been disconnected...
9364 eInstance_FireSelfWatchers(toolTip,
9365 __ecereProp___ecereNameSpace__ecere__gui__Window_parent);
9371 toolTip.parent = this;
9380 public class Percentage : float
9382 char * OnGetString(char * string, float * fieldData, bool * needClass)
9386 sprintf(string, "%.2f", this);
9387 c = strlen(string)-1;
9390 if(string[c] != '0')
9391 last = Max(last, c);
9392 if(string[c] == '.')
9405 public void ApplySkin(Class c, char * name, void ** vTbl)
9407 char className[1024];
9412 subclass(Window) wc = (subclass(Window))c;
9413 subclass(Window) base = (subclass(Window))c.base;
9415 sprintf(className, "%sSkin_%s", name, c.name);
9416 wc.pureVTbl = c._vTbl;
9417 c._vTbl = new void *[c.vTblSize];
9418 memcpy(c._vTbl, wc.pureVTbl, c.vTblSize * sizeof(void *));
9419 sc = eSystem_FindClass(c.module.application, className);
9423 for(m = 0; m < c.base.vTblSize; m++)
9425 if(c._vTbl[m] == base.pureVTbl[m])
9426 c._vTbl[m] = vTbl[m];
9431 for(m = 0; m < c.vTblSize; m++)
9433 if(sc._vTbl[m] != wc.pureVTbl[m])
9434 c._vTbl[m] = sc._vTbl[m];
9438 for(d = c.derivatives.first; d; d = d.next)
9440 ApplySkin(d.data, name, c._vTbl);
9444 public void UnapplySkin(Class c)
9446 char className[1024];
9448 subclass(Window) wc = (subclass(Window))c;
9449 subclass(Window) base = (subclass(Window))c.base;
9452 if(wc.pureVTbl && c._vTbl != wc.pureVTbl)
9455 c._vTbl = wc.pureVTbl;
9459 for(d = c.derivatives.first; d; d = d.next)
9461 UnapplySkin(d.data);
9465 void CheckFontIntegrity(Window window)
9470 if(window.usedFont && window.usedFont.font == 0xecececec)
9472 FontResource uf = window.usedFont;
9473 char * className = window._class.name;
9474 char * text = window.text;
9477 for(c = window.firstChild; c; c = c.next)
9478 CheckFontIntegrity(c);
9482 public class ControllableWindow : Window
9484 /*WindowController controller;
9485 public property WindowController controller { get { return controller; } set { delete controller; controller = value; incref controller; } }
9486 ~ControllableWindow() { delete controller; }*/
9489 class WindowControllerInterface : ControllableWindow
9491 bool OnKeyDown(Key key, unichar ch)
9493 bool result = ((int(*)())(void *)controller.OnKeyDown)((void *)controller.controlled, (void *)controller, key, ch);
9495 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown](controller.window, key, ch);
9499 bool OnKeyUp(Key key, unichar ch)
9501 bool result = ((int(*)())(void *)controller.OnKeyUp)((void *)controller.controlled, (void *)controller, key, ch);
9503 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp](controller.window, key, ch);
9507 bool OnKeyHit(Key key, unichar ch)
9509 bool result = ((int(*)())(void *)controller.OnKeyHit)((void *)controller.controlled, (void *)controller, key, ch);
9511 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit](controller.window, key, ch);
9515 bool OnMouseMove(int x, int y, Modifiers mods)
9517 bool result = ((int(*)())(void *)controller.OnMouseMove)((void *)controller.controlled, (void *)controller, x, y, mods);
9519 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove](controller.window, x, y, mods);
9523 bool OnLeftButtonDown(int x, int y, Modifiers mods)
9525 bool result = ((int(*)())(void *)controller.OnLeftButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9527 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown](controller.window, x, y, mods);
9531 bool OnLeftButtonUp(int x, int y, Modifiers mods)
9533 bool result = ((int(*)())(void *)controller.OnLeftButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9535 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp](controller.window, x, y, mods);
9539 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
9541 bool result = ((int(*)())(void *)controller.OnLeftDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9543 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick](controller.window, x, y, mods);
9547 bool OnRightButtonDown(int x, int y, Modifiers mods)
9549 bool result = ((int(*)())(void *)controller.OnRightButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9551 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown](controller.window, x, y, mods);
9555 bool OnRightButtonUp(int x, int y, Modifiers mods)
9557 bool result = ((int(*)())(void *)controller.OnRightButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9559 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp](controller.window, x, y, mods);
9563 bool OnRightDoubleClick(int x, int y, Modifiers mods)
9565 bool result = ((int(*)())(void *)controller.OnRightDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9567 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick](controller.window, x, y, mods);
9571 bool OnMiddleButtonDown(int x, int y, Modifiers mods)
9573 bool result = ((int(*)())(void *)controller.OnMiddleButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9575 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown](controller.window, x, y, mods);
9579 bool OnMiddleButtonUp(int x, int y, Modifiers mods)
9581 bool result = ((int(*)())(void *)controller.OnMiddleButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9583 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp](controller.window, x, y, mods);
9587 bool OnMiddleDoubleClick(int x, int y, Modifiers mods)
9589 bool result = ((int(*)())(void *)controller.OnMiddleDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9591 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick](controller.window, x, y, mods);
9595 void OnResize(int width, int height)
9597 ((int(*)())(void *)controller.OnResize)((void *)controller.controlled, (void *)controller, width, height);
9598 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnResize](controller.window, width, height);
9601 void OnRedraw(Surface surface)
9603 ((int(*)())(void *)controller.OnRedraw)((void *)controller.controlled, (void *)controller, surface);
9604 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRedraw](controller.window, surface);
9609 bool result = ((int(*)())(void *)controller.OnCreate)((void *)controller.controlled, (void *)controller);
9611 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnCreate](controller.window);
9616 public class WindowController<class V>
9619 property Window window
9623 uint size = class(Window).vTblSize;
9626 windowVTbl = new void *[size];
9627 memcpy(windowVTbl, value._vTbl, size * sizeof(void *));
9628 if(value._vTbl == value._class._vTbl)
9630 value._vTbl = new void *[value._class.vTblSize];
9631 memcpy(value._vTbl + size, value._class._vTbl + size, (value._class.vTblSize - size) * sizeof(void *));
9635 for(c = 0; c < size; c++)
9637 void * function = class(WindowControllerInterface)._vTbl[c];
9638 if(function != DefaultFunction)
9639 value._vTbl[c] = function;
9641 value._vTbl[c] = windowVTbl[c];
9646 memcpy(value._vTbl, windowVTbl, class(Window).vTblSize * sizeof(void *));
9649 get { return window; }
9651 property V controlled
9653 set { controlled = value; }
9654 get { return controlled; }
9656 virtual bool V::OnKeyDown(WindowController controller, Key key, unichar ch);
9657 virtual bool V::OnKeyUp(WindowController controller, Key key, unichar ch);
9658 virtual bool V::OnKeyHit(WindowController controller, Key key, unichar ch);
9659 virtual bool V::OnMouseMove(WindowController controller, int x, int y, Modifiers mods);
9660 virtual bool V::OnLeftButtonDown(WindowController controller, int x, int y, Modifiers mods);
9661 virtual bool V::OnLeftButtonUp(WindowController controller, int x, int y, Modifiers mods);
9662 virtual bool V::OnLeftDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9663 virtual bool V::OnRightButtonDown(WindowController controller, int x, int y, Modifiers mods);
9664 virtual bool V::OnRightButtonUp(WindowController controller, int x, int y, Modifiers mods);
9665 virtual bool V::OnRightDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9666 virtual bool V::OnMiddleButtonDown(WindowController controller, int x, int y, Modifiers mods);
9667 virtual bool V::OnMiddleButtonUp(WindowController controller, int x, int y, Modifiers mods);
9668 virtual bool V::OnMiddleDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9669 virtual void V::OnResize(WindowController controller, int width, int height);
9670 virtual void V::OnRedraw(WindowController controller, Surface surface);
9671 virtual bool V::OnCreate(WindowController controller);
9674 int (** windowVTbl)();