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(!destroyed && !CloseConfirmation(false)) return false;
6299 // TOCHECK: Should autoCreate be set to false here?
6310 void Move(int x, int y, int w, int h)
6312 normalAnchor = Anchor { left = x, top = y };
6313 normalSizeAnchor = SizeAnchor { size = { w, h } };
6315 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6317 if(destroyed) return;
6319 stateAnchor = normalAnchor;
6320 stateSizeAnchor = normalSizeAnchor;
6322 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6323 Position(x,y, w, h, true, true, true, true, false, true);
6327 DialogResult Modal(void)
6333 // FIXES MEMORY LEAK IF Create() FAILED
6339 void SetScrollArea(int width, int height, bool snapToStep)
6341 bool resize = false;
6344 int stepX = sbStep.x, stepY = sbStep.y;
6345 // Needed to make snapped down position match the skin's check of client area
6346 // against realvirtual
6349 SNAPDOWN(stepX, textCellW);
6350 SNAPDOWN(stepY, textCellH);
6351 stepX = Max(stepX, textCellW);
6352 stepY = Max(stepY, textCellH);
6354 if(scrollFlags.snapX)
6355 SNAPUP(width, stepX);
6356 if(scrollFlags.snapY)
6357 SNAPUP(height, stepY);
6360 reqScrollArea.w = width;
6361 reqScrollArea.h = height;
6362 noAutoScrollArea = (width > 0 || height > 0);
6364 UpdateScrollBars(true, true);
6367 void SetScrollPosition(int x, int y)
6370 sbh.Action(setPosition, x, 0);
6374 int seen = clientSize.w, total = reqScrollArea.w;
6376 if(scrollFlags.snapX)
6377 SNAPDOWN(seen, sbStep.x);
6379 if(!total) total = seen;
6380 range = total - seen + 1;
6381 range = Max(range, 1);
6383 if(x >= range) x = range - 1;
6385 if(scrollFlags.snapX)
6386 SNAPUP(x, sbStep.x);
6389 OnHScroll(setPosition, x, 0);
6393 SNAPDOWN(x, textCellW);
6399 sbv.Action(setPosition, y, 0);
6403 int seen = clientSize.h, total = reqScrollArea.h;
6406 if(scrollFlags.snapY)
6407 SNAPDOWN(seen, sbStep.y);
6409 if(!total) total = seen;
6410 range = total - seen + 1;
6411 range = Max(range, 1);
6413 if(y >= range) y = range - 1;
6415 if(scrollFlags.snapY)
6416 SNAPUP(y, sbStep.y);
6419 OnVScroll(setPosition, y, 0);
6422 SNAPDOWN(y, textCellH);
6427 UpdateCaret(false, false);
6430 void SetScrollLineStep(int stepX, int stepY)
6436 SNAPDOWN(stepX, textCellW);
6437 SNAPDOWN(stepY, textCellH);
6438 stepX = Max(stepX, textCellW);
6439 stepY = Max(stepY, textCellH);
6442 sbh.lineStep = stepX;
6444 sbv.lineStep = stepY;
6447 void SetState(WindowState newState, bool activate, Modifiers mods)
6451 if(state == newState || OnStateChange(newState, mods))
6453 WindowState prevState = state;
6457 // This used to be at the end of the brackets... moved for X, testing...
6458 // This has the effect of activating the window through the system...
6459 if(rootWindow == this)
6460 guiApp.interfaceDriver.SetRootWindowState(this, newState, !style.hidden);
6462 SetStateEx(newState, activate);
6464 if(rootWindow == this && !rootWindow.nativeDecorations)
6466 int x = position.x, y = position.y;
6469 x -= guiApp.desktop.absPosition.x;
6470 y -= guiApp.desktop.absPosition.y;
6472 guiApp.interfaceDriver.PositionRootWindow(this, x, y, size.w, size.h, true, true);
6476 //state = prevState;
6478 if(state != maximized && style.hasMaximize)
6481 for(child = parent.children.first; child; child = child.next)
6483 if(child != this && child.state == maximized)
6484 child.SetStateEx(normal, false);
6488 if(!style.nonClient && (sbv || sbh) && this != parent.sbv && this != parent.sbh)
6489 parent.UpdateScrollBars(true, true);
6492 // Do we really need this stuff here?
6493 // Shouldn't the Activate stuff take care of it?
6494 if(parent.rootWindow == parent && style)
6497 parent.FigureCaption(caption);
6498 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
6499 parent.UpdateDecorations();
6503 rootWindow.ConsequentialMouseMove(false);
6510 BitmapResource GetIcon(SkinBitmap iconID)
6512 return guiApp.currentSkin.GetBitmap(iconID);
6515 void SetMouseRange(Box range)
6517 if(range || guiApp.fullScreenMode)
6522 clip.left = range.left + absPosition.x + clientStart.x;
6523 clip.top = range.top + absPosition.y + clientStart.y;
6524 clip.right = range.right + absPosition.x + clientStart.x;
6525 clip.bottom = range.bottom + absPosition.y + clientStart.y;
6529 clip.left = guiApp.desktop.box.left;
6530 clip.top = guiApp.desktop.box.top;
6531 clip.right = guiApp.desktop.box.right;
6532 clip.bottom = guiApp.desktop.box.bottom;
6534 guiApp.interfaceDriver.SetMouseRange(rootWindow, clip);
6537 guiApp.interfaceDriver.SetMouseRange(rootWindow, null);
6540 void SetMouseRangeToClient(void)
6542 if(guiApp.fullScreenMode || this != guiApp.desktop)
6544 Box box {0, 0, clientSize.w - 1, clientSize.h - 1 };
6545 box.Clip(clientArea);
6549 SetMouseRange(null);
6552 void SetMouseRangeToWindow(void)
6554 Box box { -clientStart.x, -clientStart.y, size.w-1, size.h-1 };
6555 if(this == guiApp.desktop)
6556 SetMouseRangeToClient();
6561 // x, y: Desktop Coordinates
6562 void ShowSysMenu(int x, int y)
6565 PopupMenu windowMenu { master = this, interim = true, position = { x + 1 - guiApp.desktop.position.x, y + 1 - guiApp.desktop.position.y }, menu = menu };
6568 menu, "Restore", r, NotifySelect = MenuWindowRestore,
6569 disabled = (!style.hasMaximize && !style.hasMinimize) || state == normal, bitmap = guiApp.currentSkin.GetBitmap(restore)
6573 menu, "Move", m, NotifySelect = MenuWindowMove,
6574 disabled = !style.fixed || state == maximized
6578 menu, "Size", s, NotifySelect = MenuWindowSize,
6579 disabled = !style.sizable || state != normal
6583 menu, "Minimize", n, NotifySelect = MenuWindowMinimize,
6584 disabled = !style.hasMinimize || state == minimized, bitmap = guiApp.currentSkin.GetBitmap(minimize)
6588 menu, "Maximize", KeyCode::x, NotifySelect = MenuWindowMaximize,
6589 disabled = !style.hasMaximize || state == maximized, bitmap = guiApp.currentSkin.GetBitmap(maximize)
6593 menu, "Stay On Top", t, NotifySelect = MenuWindowStayOnTop,
6594 disabled = !style.fixed, checkable = true, checked = style.stayOnTop
6596 MenuDivider { menu };
6599 menu, "Close", c, (parent == guiApp.desktop) ? altF4 : ( style.isActiveClient ? ctrlF4 : 0), NotifySelect = MenuWindowClose,
6600 bold = true, disabled = !style.hasClose, bitmap = guiApp.currentSkin.GetBitmap(close)
6602 windowMenu.Create();
6607 ActivateEx(true, true, true, true, null, null);
6610 void MakeActive(void)
6612 ActivateEx(true, false, true, false, null, null);
6615 void SoftActivate(void)
6617 if(guiApp.desktop.active)
6623 void Deactivate(void)
6625 ActivateEx(false, true, true, true, null, null);
6630 guiApp.interfaceDriver.FlashRootWindow(rootWindow);
6633 bool CycleChildren(bool backward, bool clientOnly, bool tabCycleOnly, bool cycleParents)
6635 bool result = false;
6636 if(activeChild && activeChild.cycle)
6638 Window modalWindow, child = activeChild;
6639 if(!clientOnly /*&& parent.tabCycle*/)
6641 Window next = child;
6644 if(next.cycle == (backward ? childrenCycle.first : childrenCycle.last))
6648 if(parent && parent.CycleChildren(backward, false, true, true))
6656 next = next.cycle.prev.data;
6658 next = next.cycle.next.data;
6659 if(!next.disabled && !next.inactive /*isRemote*/ && next.created && !next.nonClient && (!clientOnly || next.style.isActiveClient) && !next.style.hidden && next.FindModal() != activeChild)
6664 if(!clientOnly && child.cycle == (backward ? childrenCycle.first : childrenCycle.last) &&
6665 parent.tabCycle && parent.CycleChildren(backward, false, false))
6669 if(tabCycleOnly && !tabCycle) return false;
6676 child = child.cycle.prev.data;
6678 child = child.cycle.next.data;
6679 if(child == child.parent.activeChild)
6681 else if(!child.disabled && child.created && (!clientOnly || child.style.isActiveClient) && !child.style.hidden && child.FindModal() != activeChild)
6684 modalWindow = child.FindModal();
6687 // Scroll the window to include the active control
6688 if(sbh && !child.style.dontScrollHorz)
6690 if(child.scrolledPos.x < 0)
6691 sbh.Action(setPosition, scroll.x + child.scrolledPos.x, 0);
6692 else if(child.scrolledPos.x + child.size.w > clientSize.w)
6693 sbh.Action(setPosition, scroll.x + child.scrolledPos.x + child.size.w - clientSize.w, 0);
6695 if(sbv && !child.style.dontScrollVert)
6697 if(child.scrolledPos.y < 0)
6698 sbv.Action(setPosition, scroll.y + child.scrolledPos.y, 0);
6699 else if(child.scrolledPos.y + child.size.h > clientSize.h)
6700 sbv.Action(setPosition, scroll.y + child.scrolledPos.y + child.size.h - clientSize.h, 0);
6704 child = modalWindow ? modalWindow : child;
6705 child.ActivateEx(true, true, true, true, null, null);
6706 if(child.tabCycle && child.childrenCycle.first)
6707 child = ((OldLink)(backward ? child.childrenCycle.first : child.childrenCycle.last)).data;
6715 ConsequentialMouseMove(false);
6719 void AddResource(Resource resource)
6723 ResPtr ptr { resource = resource };
6727 // Load Graphics here if window is created already
6728 if(/*created && */display)
6730 display.Lock(false);
6731 ptr.loaded = display.displaySystem.LoadResource(resource);
6735 // Temporary hack to load font right away for listbox in dropbox ...
6736 else if(master && master.display)
6738 master.display.Lock(false);
6739 master.display.displaySystem.LoadResource(resource);
6740 master.display.Unlock();
6746 void RemoveResource(Resource resource)
6751 for(ptr = resources.first; ptr; ptr = ptr.next)
6753 if(ptr.resource == resource)
6759 // Unload Graphics here if window is created already
6760 if(/*created && */display)
6764 display.Lock(false);
6765 display.displaySystem.UnloadResource(resource, ptr.loaded);
6771 resources.Delete(ptr);
6776 void SetCaret(int x, int y, int size)
6783 if(active && !style.interim)
6785 if(visible || !guiApp.caretOwner)
6786 guiApp.caretOwner = size ? this : null;
6788 UpdateCaret(false, false);
6791 guiApp.interfaceDriver.SetCaret(0,0,0);
6792 UpdateCaret(false, true);
6793 guiApp.caretEnabled = false;
6796 else if(style.inactive && active)
6798 guiApp.interfaceDriver.SetCaret(0,0,0);
6799 UpdateCaret(false, true);
6800 guiApp.caretEnabled = false;
6805 void Scroll(int x, int y)
6807 bool opaque = !style.drawBehind || background.a;
6808 if(opaque && display && display.flags.scrolling)
6810 Box box = clientArea;
6811 box.left += clientStart.x;
6812 box.top += clientStart.y;
6813 box.right += clientStart.x;
6814 box.bottom += clientStart.y;
6816 //scrollExtent.Free(null);
6817 scrollExtent.AddBox(box);
6818 scrolledArea.x += x;
6819 scrolledArea.y += y;
6821 //scrollExtent.Free();
6822 //scrollExtent.AddBox(clientArea);
6823 //scrollExtent.Offset(clientStart.x, clientStart.y);
6824 //scrolledArea.x = x;
6825 //scrolledArea.y = y;
6831 rootWindow.dirty = true;
6834 void ReleaseCapture()
6836 if(guiApp && guiApp.windowCaptured && guiApp.windowCaptured == this)
6838 Window oldCaptured = guiApp.windowCaptured;
6839 guiApp.windowCaptured = null;
6840 guiApp.prevWindow = null;
6843 //guiApp.Log("Released Capture\n");
6845 guiApp.interfaceDriver.SetMouseCapture(null);
6847 //oldCaptured.OnMouseCaptureLost();
6850 oldCaptured.ConsequentialMouseMove(false);
6855 void SetText(char * format, ...)
6862 char caption[MAX_F_STRING];
6864 va_start(args, format);
6865 vsprintf(caption, format, args);
6868 this.caption = new char[strlen(caption)+1];
6870 strcpy(this.caption, caption);
6879 bool Grab(Bitmap bitmap, Box box, bool decorations)
6881 bool result = false;
6882 if(display || this == guiApp.desktop)
6884 Box clip = {MININT, MININT, MAXINT, MAXINT};
6890 clip.Clip(clientArea);
6892 clip.Clip(this.box);
6894 if(rootWindow != this)
6896 clip.left += absPosition.y;
6897 clip.top += absPosition.y;
6898 clip.right += absPosition.x;
6899 clip.bottom += absPosition.y;
6902 clip.left += decorations ? 0 : clientStart.x;
6903 clip.top += decorations ? 0 : clientStart.y;
6904 clip.right += decorations ? 0 : clientStart.x;
6905 clip.bottom += decorations ? 0 : clientStart.y;
6907 if(display && display.flags.flipping)
6909 rootWindow.Update(null);
6910 rootWindow.UpdateDisplay();
6917 result = window.display.displaySystem.driver.GrabScreen(null, bitmap, clip.left, clip.top,
6918 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6922 result = display.Grab(bitmap, clip.left, clip.top,
6923 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6925 if(bitmap.pixelFormat != pixelFormat888 && bitmap.pixelFormat != pixelFormat8)
6927 if(!bitmap.Convert(null, pixelFormat888, null))
6934 void GetMousePosition(int * x, int * y)
6936 int mouseX = 0, mouseY = 0;
6937 if(!guiApp.acquiredWindow && (guiApp.desktop.active || !guiApp.fullScreenMode))
6940 guiApp.interfaceDriver.GetMousePosition(&mouseX, &mouseY);
6941 if(this != guiApp.desktop)
6943 mouseX -= absPosition.x + clientStart.x;
6944 mouseY -= absPosition.y + clientStart.y;
6951 DialogResult DoModal()
6953 DialogResult returnCode = 0;
6954 int terminated = terminateX;
6957 while(!destroyed && guiApp.driver != null)
6959 if(terminateX != terminated)
6961 terminated = terminateX;
6962 guiApp.desktop.Destroy(0);
6963 if(guiApp.desktop.created)
6966 //printf("Resetting terminate X to 0\n");
6972 guiApp.UpdateDisplay();
6973 if(!guiApp.ProcessInput(false))
6976 returnCode = this.returnCode;
6989 return !destroyed && guiApp.driver != null && terminateX < 2;
6992 DialogResult DoModalEnd()
6994 DialogResult returnCode = this.returnCode;
6999 // --- Window manipulation ---
7000 /*bool GetDisabled()
7002 bool disabled = this.disabled;
7004 for(window = this; (window = window.master); )
7015 // --- Mouse Manipulation ---
7016 void GetNCMousePosition(int * x, int * y)
7018 GetMousePosition(x, y);
7019 if(x) *x += clientStart.x;
7020 if(y) *y += clientStart.y;
7023 // --- Carets manipulation ---
7024 void GetCaretPosition(Point caretPos)
7026 caretPos = this.caretPos;
7029 int GetCaretSize(void)
7034 bool ButtonCloseDialog(Button button, int x, int y, Modifiers mods)
7040 bool CloseConfirmation(bool parentClosing)
7053 if(!OnClose(parentClosing))
7056 // If you want to skip this, simply set modifiedDocument to false in OnClose
7057 if(result && (/*fileName || */style.isDocument) && modifiedDocument)
7059 DialogResult dialogRes;
7062 sprintf(message, "Save changes to %s?", fileName);
7064 sprintf(message, "Save changes to Untitled %d?", documentID);
7066 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption, contents = message }.Modal();
7068 if(dialogRes == yes)
7070 // TOFIX: Precomp error if brackets are taken out
7071 result = (DialogResult)MenuFileSave(null, 0) != cancel;
7073 else if(dialogRes == cancel)
7079 for(slave = slaves.first; slave; slave = slave.next)
7080 if(!((Window)slave.data).CloseConfirmation(true))
7082 // ((Window)slave.data).CloseConfirmation(true);
7090 for(child = children.first; child; child = child.next)
7091 if(child.master != this && !child.CloseConfirmation(true))
7101 // Static methods... move them somewhere else?
7102 void ::RestoreCaret()
7104 if(guiApp.caretOwner)
7105 guiApp.caretOwner.UpdateCaret(false, false);
7108 void ::FreeMouseRange()
7110 guiApp.interfaceDriver.SetMouseRange(null, null);
7114 bool MenuFileClose(MenuItem selection, Modifiers mods)
7116 Window document = activeChild;
7118 document.Destroy(0);
7122 bool MenuFileExit(MenuItem selection, Modifiers mods)
7128 bool MenuFileSave(MenuItem selection, Modifiers mods)
7132 fileMonitor.fileName = null;
7135 if(OnSaveFile(fileName))
7137 //if(OnFileModified != Window::OnFileModified)
7140 fileMonitor.fileName = fileName;
7146 MessageBox dialog { master = master, type = yesNoCancel, text = "Error writing file", contents = "Save as a different file?" };
7147 DialogResult answer = dialog.Modal();
7149 if(answer != yes) return (bool)answer;
7152 return MenuFileSaveAs(selection, mods);
7155 bool MenuFileSaveAs(MenuItem selection, Modifiers mods)
7157 DialogResult result = (DialogResult)bool::true;
7158 FileDialog fileDialog = saveDialog;
7161 fileDialog = FileDialog {};
7166 fileDialog.filePath = fileName;
7169 char filePath[MAX_FILENAME];
7170 sprintf(filePath, "Untitled %d", documentID);
7171 fileDialog.filePath = filePath;
7173 fileMonitor.fileName = null;
7175 fileDialog.type = save;
7176 fileDialog.text = "Save As";
7180 fileDialog.master = master.parent ? master : this;
7181 if(fileDialog.Modal() == ok)
7183 char * filePath = fileDialog.filePath;
7185 if(OnSaveFile(filePath))
7188 property::fileName = filePath;
7189 NotifySaved(master, this, filePath);
7194 MessageBox dialog { master = master.parent ? master : this, type = yesNoCancel, text = "Error writing file", contents = "Save as a different file?" };
7195 DialogResult answer = dialog.Modal();
7210 //if(OnFileModified != Window::OnFileModified && fileName)
7213 fileMonitor.fileName = fileName;
7217 return (bool)result; // Actually returning result from Yes/NoCancel message box
7220 bool MenuFileSaveAll(MenuItem selection, Modifiers mods)
7222 Window document = activeChild;
7224 for(document = children.first; document; document = next)
7226 next = document.next;
7227 if(document.style.isDocument || document.fileName)
7228 document.MenuFileSave(selection, mods);
7233 bool MenuWindowArrangeIcons(MenuItem selection, Modifiers mods)
7237 for(document = children.first; document; document = document.next)
7238 //if(document.style.isDocument && document.state == minimized)
7239 if(document.style.isActiveClient && document.state == minimized)
7240 document.SetState(minimized, false, mods);
7244 bool MenuWindowCascade(MenuItem selection, Modifiers mods)
7246 Window document = activeChild;
7249 Window firstDocument = null;
7251 OldLink cycle = document.cycle.prev;
7256 if(child.style.isActiveClient && !child.style.hidden)
7260 firstDocument = child;
7261 if(child.state == minimized)
7262 child.SetState(minimized, false, mods);
7265 child.positionID = id++;
7266 child.SetState(normal, false, mods);
7267 child.anchor.left.type = cascade;
7270 child.normalSizeAnchor = *&child.sizeAnchor;
7271 child.normalAnchor = child.anchor;
7273 // Break the anchors for moveable/resizable windows
7274 if(child.style.fixed)
7276 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7278 (*&child.normalAnchor).left = x;
7279 (*&child.normalAnchor).top = y;
7280 (*&child.normalAnchor).right.type = none;
7281 (*&child.normalAnchor).bottom.type = none;
7283 child.normalSizeAnchor.isClientW = false;
7284 child.normalSizeAnchor.isClientH = false;
7285 child.normalSizeAnchor.size.w = w;
7286 child.normalSizeAnchor.size.h = h;
7287 child.anchored = false;
7290 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7292 child.stateAnchor = child.normalAnchor;
7293 child.stateSizeAnchor = child.normalSizeAnchor;
7295 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7296 child.Position(x, y, w, h, true, true, true, true, false, false);
7301 last = children.last;
7302 if(!child.style.stayOnTop)
7303 for(; last && last.style.stayOnTop; last = last.prev);
7304 children.Move(child, last);
7305 childrenOrder.Move(child.order, childrenOrder.last);
7307 if(cycle == document.cycle) break;
7311 firstDocument.Activate();
7316 bool MenuWindowClose(MenuItem selection, Modifiers mods)
7323 // Close all closes all active clients, not all documents
7324 bool MenuWindowCloseAll(MenuItem selection, Modifiers mods)
7326 Window next, document;
7328 for(document = children.first; document; document = next)
7330 for(next = document.next; next && !(next.style.isActiveClient; next = next.next);
7331 if(document.style.isActiveClient)
7332 if(!document.Destroy(0) && !document.style.hidden)
7338 bool MenuWindowMaximize(MenuItem selection, Modifiers mods)
7340 if(style.hasMaximize && state != maximized)
7341 SetState(maximized, 0, 0);
7345 bool MenuWindowMinimize(MenuItem selection, Modifiers mods)
7347 if(style.hasMinimize && state != minimized)
7349 SetState(minimized, 0, 0);
7350 parent.CycleChildren(false, true, false, true);
7355 bool MenuWindowMove(MenuItem selection, Modifiers mods)
7357 MenuMoveOrSize(false, selection ? true : false);
7361 bool MenuWindowNext(MenuItem selection, Modifiers mods)
7363 CycleChildren(false, true, false, true);
7367 bool MenuWindowPrevious(MenuItem selection, Modifiers mods)
7369 CycleChildren(true, true, false, true);
7373 bool MenuWindowSize(MenuItem selection, Modifiers mods)
7375 MenuMoveOrSize(true, true);
7379 bool MenuWindowRestore(MenuItem selection, Modifiers mods)
7382 SetState(normal, 0, 0);
7386 bool MenuWindowSelectWindow(MenuItem selection, Modifiers mods)
7389 int id = selection.id;
7390 OldLink cycle = activeClient.cycle;
7392 //for(c = 0, cycle = activeChild.cycle; c<id; cycle = cycle.next, c++);
7395 Window sibling = cycle.data;
7396 if(sibling.style.isActiveClient)
7404 document = cycle.data;
7405 document.Activate();
7407 //if(activeChild.state == maximized)
7408 // document.SetState(maximized, false, mods);
7409 //else if(document.state == minimized)
7410 // document.SetState(normal, false, mods);
7414 bool MenuWindowStayOnTop(MenuItem selection, Modifiers mods)
7416 stayOnTop = !style.stayOnTop;
7420 bool MenuWindowTileHorz(MenuItem selection, Modifiers mods)
7422 Window document = activeChild;
7425 Window firstDocument = null;
7426 OldLink cycle = document.cycle;
7430 Window child = cycle.data;
7431 if(child.style.isActiveClient && !child.style.hidden)
7433 if(!firstDocument) firstDocument = child;
7434 if(child.state == minimized)
7435 child.SetState(minimized, false, mods);
7438 child.positionID = id++;
7439 child.SetState(normal, false, mods);
7440 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7442 child.anchor.left.type = hTiled;
7445 child.normalSizeAnchor = *&child.sizeAnchor;
7446 child.normalAnchor = child.anchor;
7448 // Break the anchors for moveable/resizable windows
7449 if(child.style.fixed)
7451 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7453 (*&child.normalAnchor).left = x;
7454 (*&child.normalAnchor).top = y;
7455 (*&child.normalAnchor).right.type = none;
7456 (*&child.normalAnchor).bottom.type = none;
7457 child.normalSizeAnchor.isClientW = false;
7458 child.normalSizeAnchor.isClientH = false;
7459 child.normalSizeAnchor.size.w = w;
7460 child.normalSizeAnchor.size.h = h;
7461 child.anchored = false;
7464 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7466 child.stateAnchor = child.normalAnchor;
7467 child.stateSizeAnchor = child.normalSizeAnchor;
7469 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7470 child.Position(x,y, w, h, true, true, true, true, false, true);
7475 if((cycle = cycle.next) == document.cycle) break;
7478 firstDocument.Activate();
7483 bool MenuWindowTileVert(MenuItem selection, Modifiers mods)
7485 Window document = activeChild;
7488 Window firstDocument = null;
7490 OldLink cycle = document.cycle;
7495 //if(child.style.isDocument)
7496 if(child.style.isActiveClient && !child.style.hidden)
7498 if(!firstDocument) firstDocument = child;
7499 if(child.state == minimized)
7500 child.SetState(minimized, false, mods);
7503 child.positionID = id++;
7504 child.SetState(normal, false, mods);
7505 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7507 child.anchor.left.type = vTiled;
7510 child.normalSizeAnchor = *&child.sizeAnchor;
7511 child.normalAnchor = child.anchor;
7513 // Break the anchors for moveable/resizable windows
7514 if(child.style.fixed)
7516 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7518 (*&child.normalAnchor).left = x;
7519 (*&child.normalAnchor).top = y;
7520 (*&child.normalAnchor).right.type = none;
7521 (*&child.normalAnchor).bottom.type = none;
7522 child.normalSizeAnchor.isClientW = false;
7523 child.normalSizeAnchor.isClientH = false;
7524 child.normalSizeAnchor.size.w = w;
7525 child.normalSizeAnchor.size.h = h;
7526 child.anchored = false;
7529 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7531 child.stateAnchor = child.normalAnchor;
7532 child.stateSizeAnchor = child.normalSizeAnchor;
7534 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7535 child.Position(x,y, w, h, true, true, true, true, false, true);
7540 if((cycle = cycle.next) == document.cycle) break;
7543 firstDocument.Activate();
7548 bool MenuWindowWindows(MenuItem selection, Modifiers mods)
7550 WindowList dialog { master = this };
7551 Window document = (Window)dialog.Modal();
7554 if(activeChild.state == maximized)
7555 document.SetState(maximized, false, mods);
7556 else if(document.state == minimized)
7557 document.SetState(normal, false, mods);
7558 document.Activate();
7564 virtual bool OnCreate(void);
7565 virtual void OnDestroy(void);
7566 virtual void OnDestroyed(void);
7567 virtual bool OnClose(bool parentClosing);
7568 virtual bool OnStateChange(WindowState state, Modifiers mods);
7569 virtual bool OnPostCreate(void);
7570 virtual bool OnMoving(int *x, int *y, int w, int h);
7571 virtual bool OnResizing(int *width, int *height);
7572 virtual void OnResize(int width, int height);
7573 virtual void OnPosition(int x, int y, int width, int height);
7574 virtual bool OnLoadGraphics(void);
7575 virtual void OnApplyGraphics(void);
7576 virtual void OnUnloadGraphics(void);
7577 virtual void OnRedraw(Surface surface);
7578 virtual bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct);
7579 virtual void OnActivateClient(Window client, Window previous);
7580 virtual bool OnKeyDown(Key key, unichar ch);
7581 virtual bool OnKeyUp(Key key, unichar ch);
7582 virtual bool OnKeyHit(Key key, unichar ch);
7583 virtual bool OnSysKeyDown(Key key, unichar ch);
7584 virtual bool OnSysKeyUp(Key key, unichar ch);
7585 virtual bool OnSysKeyHit(Key key, unichar ch);
7586 virtual bool OnMouseOver(int x, int y, Modifiers mods);
7587 virtual bool OnMouseLeave(Modifiers mods);
7588 virtual bool OnMouseMove(int x, int y, Modifiers mods);
7589 virtual bool OnLeftButtonDown(int x, int y, Modifiers mods);
7590 virtual bool OnLeftButtonUp(int x, int y, Modifiers mods);
7591 virtual bool OnLeftDoubleClick(int x, int y, Modifiers mods);
7592 virtual bool OnRightButtonDown(int x, int y, Modifiers mods);
7593 virtual bool OnRightButtonUp(int x, int y, Modifiers mods);
7594 virtual bool OnRightDoubleClick(int x, int y, Modifiers mods);
7595 virtual bool OnMiddleButtonDown(int x, int y, Modifiers mods);
7596 virtual bool OnMiddleButtonUp(int x, int y, Modifiers mods);
7597 virtual bool OnMiddleDoubleClick(int x, int y, Modifiers mods);
7598 virtual void OnMouseCaptureLost(void);
7599 virtual void OnHScroll(ScrollBarAction action, int position, Key key);
7600 virtual void OnVScroll(ScrollBarAction action, int position, Key key);
7601 virtual void OnDrawOverChildren(Surface surface);
7602 virtual bool OnFileModified(FileChange fileChange, char * param);
7603 virtual bool OnSaveFile(char * fileName);
7605 // Skins Virtual Functions
7606 virtual void GetDecorationsSize(MinMaxValue * w, MinMaxValue * h);
7607 virtual void SetWindowMinimum(MinMaxValue * mw, MinMaxValue * mh);
7608 virtual void SetWindowArea(int * x, int * y, MinMaxValue * w, MinMaxValue * h, MinMaxValue * cw, MinMaxValue * ch)
7613 virtual void ShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7614 virtual void PreShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7615 virtual bool IsMouseMoving(int x, int y, int w, int h);
7616 virtual bool IsMouseResizing(int x, int y, int w, int h, bool *resizeX, bool *resizeY, bool *resizeEndX, bool *resizeEndY);
7617 virtual void UpdateNonClient();
7618 virtual void SetBox(Box box);
7619 virtual bool IsInside(int x, int y)
7621 return box.IsPointInside({x, y});
7623 virtual bool IsOpaque()
7625 return (!style.drawBehind || background.a == 255);
7629 virtual bool Window::NotifyActivate(Window window, bool active, Window previous);
7630 virtual void Window::NotifyDestroyed(Window window, DialogResult result);
7631 virtual void Window::NotifySaved(Window window, char * filePath);
7636 property Window parent
7638 property_category "Layout"
7641 if(value || guiApp.desktop)
7644 Window oldParent = parent;
7645 Anchor anchor = this.anchor;
7647 if(value && value.IsDescendantOf(this)) return;
7648 if(value && value == this)
7650 if(!value) value = guiApp.desktop;
7652 if(value == oldParent) return;
7654 if(!master || (master == this.parent && master == guiApp.desktop))
7655 property::master = value;
7659 parent.children.Remove(this);
7663 box.left - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7664 box.top - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y,
7665 box.right - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7666 box.bottom - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y
7670 last = value.children.last;
7672 if(style.isDocument)
7675 parent.numDocuments--;
7676 documentID = value.GetDocumentID();
7679 if(style.isActiveClient && !style.hidden)
7681 if(parent && parent != guiApp.desktop && !(style.hidden))
7683 if(state == minimized) parent.numIcons--;
7684 parent.numPositions--;
7688 if(!style.stayOnTop)
7689 for(; last && last.style.stayOnTop; last = last.prev);
7691 value.children.Insert(last, this);
7693 // *** NEW HERE: ***
7695 parent.childrenCycle.Delete(cycle);
7697 parent.childrenOrder.Delete(order);
7705 int x = position.x, y = position.y, w = size.w, h = size.h;
7709 x += parent.absPosition.x - value.absPosition.x + parent.clientStart.x - value.clientStart.x;
7710 y += parent.absPosition.y - value.absPosition.y + parent.clientStart.y - value.clientStart.y;
7712 vpw = value.clientSize.w;
7713 vph = value.clientSize.h;
7719 else if(style.fixed)
7721 if(!style.dontScrollHorz && value.scrollArea.w) vpw = value.scrollArea.w;
7722 if(!style.dontScrollVert && value.scrollArea.h) vph = value.scrollArea.h;
7725 anchor = this.anchor;
7727 if(anchor.left.type == offset) anchor.left.distance = x;
7728 else if(anchor.left.type == relative) anchor.left.percent = (float)x / vpw;
7729 if(anchor.top.type == offset) anchor.top.distance = y;
7730 else if(anchor.top.type == relative) anchor.top.percent = (float)y / vph;
7731 if(anchor.right.type == offset) anchor.right.distance = vpw - (x + w);
7732 //else if(anchor.right.type == relative) anchor.right.percent = 1.0-(float) (vpw - (x + w)) / vpw;
7733 else if(anchor.right.type == relative) anchor.right.percent = (float) (vpw - (x + w)) / vpw;
7734 if(anchor.bottom.type == offset) anchor.bottom.distance = vph - (y + h);
7735 //else if(anchor.bottom.type == relative) anchor.bottom.percent = 1.0-(float) (vph - (y + h)) / vph;
7736 else if(anchor.bottom.type == relative) anchor.bottom.percent = (float) (vph - (y + h)) / vph;
7738 if(!anchor.left.type && !anchor.right.type)
7740 anchor.horz.distance = (x + w / 2) - (vpw / 2);
7741 //anchor.horz.type = anchor.horz.distance ? AnchorValueOffset : 0;
7743 else if(anchor.horz.type == middleRelative) anchor.horz.percent = (float) ((x + w / 2) - (vpw / 2)) / vpw;
7744 if(!anchor.top.type && !anchor.bottom.type)
7746 anchor.vert.distance = (y + h / 2) - (vph / 2);
7747 //anchor.vert.type = anchor.vert.distance ? AnchorValueOffset : 0;
7749 else if(anchor.vert.type == middleRelative) anchor.vert.percent = (float)((y + h / 2) - (vph / 2)) / vph;
7757 parent.childrenCycle.Insert(
7758 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
7759 cycle = OldLink { data = this });
7760 parent.childrenOrder.Insert(
7761 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
7762 order = OldLink { data = this });
7765 if(!style.hidden && style.isActiveClient)
7767 positionID = parent.GetPositionID(this);
7768 parent.numPositions++;
7769 if(state == minimized) parent.numIcons--;
7772 // *** FONT INHERITANCE ***
7773 if(!setFont && oldParent)
7774 stopwatching(oldParent, font);
7778 RemoveResource(systemFont);
7781 // TESTING WITH WATCHERS:
7782 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7783 // usedFont = setFont ? setFont : (systemFont);
7787 if(guiApp.currentSkin)
7789 systemFont = guiApp.currentSkin.SystemFont();
7792 usedFont = systemFont;
7793 AddResource(systemFont);
7801 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7810 if(value.rootWindow && value.rootWindow.display && rootWindow)
7812 bool reloadGraphics = (oldParent.rootWindow == oldParent && value.rootWindow) || (!value.rootWindow && rootWindow == this) ||
7813 (value.rootWindow.display && value.rootWindow.display.displaySystem != rootWindow.display.displaySystem);
7816 UnloadGraphics(false);
7819 LoadGraphics(false, false);
7822 if(value.rootWindow != rootWindow)
7823 DisplayModeChanged();
7827 scrolledPos.x = MININT; // Prevent parent update
7828 property::anchor = anchor;
7832 if(guiApp.currentSkin)
7833 guiApp.currentSkin.SetWindowMinimum(this, &skinMinSize.w, &skinMinSize.h);
7835 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
7836 Position(x, y, w, h, true, true, true, true, false, true);
7841 // else parent = value;
7844 get { return parent; }
7847 property Window master
7849 property_category "Behavior"
7852 //if(this == value) return;
7853 if(value && value.IsSlaveOf(this)) return;
7859 OldLink slaveHolder;
7860 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
7861 if(slaveHolder.data == this)
7863 master.slaves.Delete(slaveHolder);
7870 value.slaves.Add(OldLink { data = this });
7875 master.hotKeys.Remove(hotKey);
7876 value.hotKeys.Add(hotKey);
7879 if(master && master.defaultControl == this)
7880 master.defaultControl = null;
7882 if(style.isDefault && !value.defaultControl)
7883 value.defaultControl = this;
7889 get { return master ? master : parent; }
7892 property char * text
7894 property_category "Appearance"
7901 caption = new char[strlen(value)+1];
7903 strcpy(caption, value);
7908 get { return caption; }
7913 property_category "Behavior"
7922 master.hotKeys.Add(hotKey = HotKeySlot { });
7926 hotKey.window = this;
7931 master.hotKeys.Delete(hotKey);
7936 get { return hotKey ? hotKey.key : 0; }
7939 property Color background
7941 property_category "Appearance"
7944 background.color = value;
7949 if(this == rootWindow)
7950 guiApp.interfaceDriver.SetRootWindowColor(this);
7953 get { return background.color; }
7956 property Percentage opacity
7958 property_category "Appearance"
7961 background.a = (byte)Min(Max((int)(value * 255), 0), 255);
7962 drawBehind = background.a ? false : true;
7964 get { return background.a / 255.0f; }
7967 property Color foreground
7969 property_category "Appearance"
7977 get { return foreground; }
7980 property BorderStyle borderStyle
7982 property_category "Appearance"
7985 if(!((BorderBits)value).fixed)
7987 style.hasClose = false;
7988 style.hasMaximize = false;
7989 style.hasMinimize = false;
7991 style.borderBits = value;
7995 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
7997 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
7998 Position(x, y, w, h, true, true, true, true, false, true);
7999 CreateSystemChildren();
8002 get { return (BorderStyle)style.borderBits; }
8005 property Size minClientSize
8007 property_category "Layout"
8008 set { minSize = value; }
8009 get { value = minSize; }
8012 property Size maxClientSize
8014 property_category "Layout"
8015 set { maxSize = value; }
8016 get { value = maxSize; }
8019 property bool hasMaximize
8021 property_category "Window Style"
8024 style.hasMaximize = value;
8025 if(value) { style.fixed = true; style.contour = true; }
8029 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8031 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8032 Position(x, y, w, h, true, true, true, true, false, true);
8034 CreateSystemChildren();
8037 get { return style.hasMaximize; }
8040 property bool hasMinimize
8042 property_category "Window Style"
8045 style.hasMinimize = value;
8046 if(value) { style.fixed = true; style.contour = true; }
8050 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8052 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8053 Position(x, y, w, h, true, true, true, true, false, true);
8055 CreateSystemChildren();
8058 get { return style.hasMinimize; }
8061 property bool hasClose
8063 property_category "Window Style"
8066 style.hasClose = value;
8067 if(value) { style.fixed = true; style.contour = true; }
8071 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8072 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8073 Position(x, y, w, h, true, true, true, true, false, true);
8074 CreateSystemChildren();
8077 get { return style.hasClose; }
8080 property bool nonClient
8082 property_category "Layout"
8085 style.nonClient = value;
8087 style.stayOnTop = true;
8089 get { return style.nonClient; }
8092 property bool inactive
8094 property_category "Behavior"
8099 // *** NEW HERE: ***
8103 parent.childrenCycle.Delete(cycle);
8105 parent.childrenOrder.Delete(order);
8112 active = false; // true;
8113 if(parent.activeChild == this)
8114 parent.activeChild = null;
8115 if(parent.activeClient == this)
8116 parent.activeClient = null;
8125 parent.childrenCycle.Insert(
8126 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8127 cycle = OldLink { data = this });
8129 parent.childrenOrder.Insert(
8130 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8131 order = OldLink { data = this });
8134 style.inactive = value;
8136 get { return style.inactive; }
8139 property bool clickThrough
8141 property_category "Behavior"
8142 set { style.clickThrough = value; }
8143 get { return style.clickThrough; }
8146 property bool isRemote
8148 property_category "Behavior"
8149 set { style.isRemote = value; }
8150 get { return style.isRemote; }
8153 property bool noCycle
8155 property_category "Behavior"
8156 set { style.noCycle = value; }
8157 get { return style.noCycle; }
8160 property bool isModal
8162 property_category "Behavior"
8163 set { style.modal = value; }
8164 get { return style.modal; }
8167 property bool interim
8169 property_category "Behavior"
8170 set { style.interim = value; }
8171 get { return style.interim; }
8174 property bool tabCycle
8176 property_category "Behavior"
8177 set { style.tabCycle = value; }
8178 get { return style.tabCycle; }
8181 property bool isDefault
8183 property_category "Behavior"
8191 /*for(sibling = parent.children.first; sibling; sibling = sibling.next)
8192 if(sibling != this && sibling.style.isDefault)
8193 sibling.style.isDefault = false;*/
8194 if(master.defaultControl)
8195 master.defaultControl.style.isDefault = false;
8196 master.defaultControl = this;
8198 else if(master.defaultControl == this)
8199 master.defaultControl = null;
8203 style.isDefault = value;
8205 Position(position.x, position.y, size.w, size.h, true, true, true,true,true, true);
8207 get { return style.isDefault; }
8210 property bool drawBehind
8212 property_category "Window Style"
8213 set { style.drawBehind = value; }
8214 get { return style.drawBehind; }
8217 property bool hasMenuBar
8219 property_category "Window Style"
8229 if(created && !menuBar)
8236 anchor = Anchor { top = 23, left = 1, right = 1 },
8238 inactive = true, nonClient = true
8243 else if(created && menuBar)
8248 style.hasMenuBar = value;
8250 get { return style.hasMenuBar; }
8253 property bool hasStatusBar
8255 property_category "Window Style"
8262 statusBar = StatusBar { this };
8270 style.hasStatusBar = value;
8272 get { return style.hasStatusBar; }
8274 property bool stayOnTop
8276 property_category "Window Style"
8281 if(created && !style.stayOnTop)
8283 if(rootWindow == this)
8284 guiApp.interfaceDriver.OrderRootWindow(this, true);
8285 else if(parent.children.last != this)
8287 parent.children.Move(this, parent.children.last);
8291 style.stayOnTop = true;
8295 if(created && style.stayOnTop)
8297 if(rootWindow == this)
8298 guiApp.interfaceDriver.OrderRootWindow(this, false);
8305 for(order = (this.order == parent.childrenOrder.first) ? null : this.order.prev;
8306 order && ((Window)order.data).style.stayOnTop;
8307 order = (order == parent.childrenOrder.first) ? null : order.prev);
8308 last = order ? order.data : null;
8312 for(last = parent.children.last;
8313 last && last.style.stayOnTop;
8317 parent.children.Move(this, last);
8321 style.stayOnTop = false;
8324 get { return style.stayOnTop; }
8329 property_category "Window Style"
8339 if(menuBar && !value)
8346 if(!menuBar && style.hasMenuBar && value)
8350 this, menu = value, isMenuBar = true,
8351 anchor = Anchor { left = 1, top = 23, right = 1 }, size.h = 24,
8352 inactive = true, nonClient = true
8356 UpdateActiveDocument(null);
8359 get { return menu; }
8362 property FontResource font
8364 property_category "Appearance"
8366 isset { return setFont ? true : false; }
8371 if(value && !setFont) { stopwatching(parent, font); }
8372 else if(!value && setFont)
8378 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8387 RemoveResource(setFont);
8392 RemoveResource(systemFont);
8399 AddResource(setFont);
8402 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
8405 systemFont = guiApp.currentSkin.SystemFont();
8407 usedFont = systemFont;
8408 AddResource(systemFont);
8416 get { return usedFont; }
8419 property SizeAnchor sizeAnchor
8421 property_category "Layout"
8424 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8425 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8426 sizeAnchor.isClientW != sizeAnchor.isClientH;
8433 normalSizeAnchor = sizeAnchor;
8435 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8437 stateAnchor = normalAnchor;
8438 stateSizeAnchor = normalSizeAnchor;
8440 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8441 Position(x,y, w, h, true, true, true, true, false, true);
8448 { sizeAnchor.isClientW ? clientSize.w : size.w, sizeAnchor.isClientH ? clientSize.h : size.h },
8449 sizeAnchor.isClientW,
8450 sizeAnchor.isClientH
8457 property_category "Layout"
8460 Anchor thisAnchor = anchor;
8461 SizeAnchor thisSizeAnchor = sizeAnchor;
8462 bool leftRight = (anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none);
8463 bool topBottom = (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none);
8464 bool isClient = !sizeAnchor.isClientW && !sizeAnchor.isClientH;
8465 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8466 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8467 !sizeAnchor.isClientW && !sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8473 sizeAnchor.isClientW = false;
8474 sizeAnchor.isClientH = false;
8475 sizeAnchor.size = value;
8477 normalSizeAnchor = sizeAnchor;
8479 if(state == normal /*|| state == Hidden*/) // Hidden is new here ...
8481 stateAnchor = normalAnchor;
8482 stateSizeAnchor = normalSizeAnchor;
8484 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8485 Position(x, y, w, h, true, true, true, true, false, true);
8488 get { value = size; }
8491 property Size clientSize
8493 property_category "Layout"
8496 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8497 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8498 sizeAnchor.isClientW && sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8503 sizeAnchor.isClientW = true;
8504 sizeAnchor.isClientH = true;
8505 sizeAnchor.size = value;
8507 normalSizeAnchor = sizeAnchor;
8509 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8511 stateAnchor = normalAnchor;
8512 stateSizeAnchor = normalSizeAnchor;
8514 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8515 Position(x,y, w, h, true, true, true, true, false, true);
8518 get { value = clientSize; }
8521 property Size initSize { get { value = sizeAnchor.size; } };
8523 property Anchor anchor
8525 property_category "Layout"
8526 isset { return (anchor.left.type != offset || anchor.top.type != offset || anchor.right.type || anchor.bottom.type); }
8532 if(anchor.left.type && anchor.right.type && (!value.left.type || !value.right.type))
8534 normalSizeAnchor.isClientW = sizeAnchor.isClientW = false;
8535 normalSizeAnchor.size.w = sizeAnchor.size.w = size.w;
8537 if(anchor.top.type && anchor.bottom.type && (!value.top.type || !value.bottom.type))
8539 normalSizeAnchor.isClientH = sizeAnchor.isClientH = false;
8540 normalSizeAnchor.size.h = sizeAnchor.size.h = size.h;
8544 if(anchor.right.type && (anchor.horz.type == middleRelative || !anchor.left.type))
8546 anchor.left.distance = 0;
8547 anchor.horz.type = 0;
8549 if(anchor.bottom.type && (anchor.vert.type == middleRelative || !anchor.top.type))
8551 anchor.top.distance = 0;
8552 anchor.vert.type = 0;
8561 normalAnchor = anchor;
8563 // Break the anchors for moveable/resizable windows
8564 /*if(style.fixed ) //&& value.left.type == cascade)
8566 ComputeAnchors(anchor, sizeAnchor, &x, &y, &w, &h);
8568 this.anchor = normalAnchor = Anchor { left = x, top = y };
8569 normalSizeAnchor = SizeAnchor { { w, h } };
8572 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8574 stateAnchor = normalAnchor;
8575 stateSizeAnchor = normalSizeAnchor;
8577 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8578 Position(x, y, w, h, true, true, true, true, false, true);
8587 get { value = this ? anchor : Anchor { }; }
8590 property Point position
8592 property_category "Layout"
8595 if(value == null) return;
8597 anchor.left = value.x;
8598 anchor.top = value.y;
8599 anchor.right.type = none;
8600 anchor.bottom.type = none;
8605 normalAnchor = anchor;
8607 // Break the anchors for moveable/resizable windows
8611 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8613 normalAnchor.left = x;
8614 normalAnchor.top = y;
8615 normalAnchor.right.type = none;
8616 normalAnchor.bottom.type = none;
8617 normalSizeAnchor.size.width = w;
8618 normalSizeAnchor.size.height = h;
8622 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8624 stateAnchor = normalAnchor;
8625 stateSizeAnchor = normalSizeAnchor;
8627 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8628 Position(x,y, w, h, true, true, true, true, false, true);
8632 get { value = position; }
8635 property bool disabled
8637 property_category "Behavior"
8640 if(this && disabled != value)
8647 get { return (bool)disabled; }
8650 property bool isEnabled
8655 for(parent = this; parent; parent = parent.parent)
8662 property WindowState state
8664 property_category "Behavior"
8665 set { SetState(value, false, 0); }
8666 get { return this ? state : 0; }
8669 property bool visible
8671 property_category "Behavior"
8674 if(this && !value && !style.hidden && parent)
8676 bool wasActiveChild = parent.activeChild == this;
8677 Window client = null;
8679 style.hidden = true;
8680 if(style.isActiveClient)
8682 parent.numPositions--;
8683 if(state == minimized) parent.numIcons--;
8688 OldLink prevOrder = null;
8690 if(rootWindow == this)
8691 guiApp.interfaceDriver.SetRootWindowState(this, state, false);
8694 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
8697 box.left -= parent.clientStart.x;
8698 box.top -= parent.clientStart.y;
8699 box.right -= parent.clientStart.x;
8700 box.bottom -= parent.clientStart.y;
8704 if(_isModal && master && master.modalSlave == this)
8705 master.modalSlave = null;
8709 OldLink tmpPrev = order.prev;
8710 client = tmpPrev ? tmpPrev.data : null;
8711 if(client && !client.style.hidden && !client.destroyed && client.created)
8712 prevOrder = tmpPrev;
8715 client = tmpPrev ? tmpPrev.data : null;
8716 if(client == this) { client = null; break; }
8717 if(client && ((client.style.hidden) || client.destroyed || !client.created))
8719 tmpPrev = client.order.prev;
8724 prevOrder = tmpPrev;
8729 // If this window can be an active client, make sure the next window we activate can also be one
8730 if(!style.nonClient && style.isActiveClient)
8732 tmpPrev = prevOrder;
8735 client = tmpPrev ? tmpPrev.data : null;
8736 if(client == this) { client = null; break; }
8737 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
8739 tmpPrev = client.order.prev;
8744 prevOrder = tmpPrev;
8748 if(client && client.style.hidden) client = null;
8752 if((wasActiveChild /*parent.activeChild == this*/ || guiApp.interimWindow == this) && true /*activate*/)
8754 if(order && prevOrder && prevOrder.data != this)
8755 ((Window)prevOrder.data).ActivateEx(true, false, false, true, null, null);
8757 ActivateEx(false, false, false, true, null, null);
8759 // TESTING THIS HERE FOR HIDING ACTIVE CLIENT
8760 if(parent.activeClient == this)
8762 parent.activeClient = null;
8763 parent.UpdateActiveDocument(null);
8766 else if(parent.activeClient == this)
8768 parent.activeClient = client;
8769 parent.UpdateActiveDocument(this);
8772 // *** Not doing this anymore ***
8775 parent.childrenCycle.Delete(cycle);
8777 parent.childrenOrder.Delete(order);
8782 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8787 else if(this && value && style.hidden)
8789 style.hidden = false;
8792 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8793 if(rootWindow == this)
8794 guiApp.interfaceDriver.SetRootWindowState(this, state, true);
8796 if(_isModal && master)
8797 master.modalSlave = this;
8799 if(style.isActiveClient)
8801 positionID = parent.GetPositionID(this);
8802 parent.numPositions++;
8803 if(state == minimized) parent.numIcons++;
8806 // *** NOT DOING THIS ANYMORE ***
8808 if(!(style.inactive))
8810 if(!(style.noCycle))
8812 cycle = parent.childrenCycle.AddAfter(
8813 (parent.activeChild && parent.activeChild.cycle) ?
8814 parent.activeChild.cycle.prev : null, sizeof(OldLink));
8817 order = parent.childrenOrder.AddAfter(
8818 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8825 if(true || !parent.activeChild)
8826 ActivateEx(true, false, true, true, null, null);
8828 if(creationActivation == activate)
8829 ActivateEx(true, false, true, true, null, null);
8830 else if(creationActivation == flash && !object)
8833 //SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8837 ConsequentialMouseMove(false);
8843 style.hidden = !value;
8846 get { return (style.hidden || !setVisible) ? false : true; }
8849 property bool isDocument
8851 property_category "Document"
8852 set { style.isDocument = value; }
8853 get { return style.isDocument; }
8856 property bool mergeMenus
8858 property_category "Window Style"
8859 set { mergeMenus = value; }
8860 get { return (bool)mergeMenus; }
8863 property bool hasHorzScroll
8865 property_category "Window Style"
8870 if(!style.hasHorzScroll && created)
8872 CreateSystemChildren();
8873 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8876 else if(style.hasHorzScroll)
8880 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8882 style.hasHorzScroll = value;
8885 get { return style.hasHorzScroll; }
8888 property bool hasVertScroll
8890 property_category "Window Style"
8895 if(!style.hasVertScroll && created)
8897 style.hasVertScroll = true;
8898 CreateSystemChildren();
8899 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8902 else if(style.hasVertScroll)
8906 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8908 style.hasVertScroll = value;
8910 get { return style.hasVertScroll; }
8913 property bool dontHideScroll
8915 property_category "Behavior"
8918 scrollFlags.dontHide = value;
8921 //UpdateScrollBars(true, true);
8922 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
8926 // UpdateScrollBars(true, true);
8927 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
8930 get { return scrollFlags.dontHide; }
8933 property bool dontScrollVert
8935 property_category "Behavior"
8936 set { style.dontScrollVert = value; }
8937 get { return style.dontScrollVert; }
8939 property bool dontScrollHorz
8941 property_category "Behavior"
8942 set { style.dontScrollHorz = value; }
8943 get { return style.dontScrollHorz; }
8946 property bool snapVertScroll
8948 property_category "Behavior"
8951 scrollFlags.snapY = value;
8952 if(sbv) sbv.snap = value;
8954 get { return scrollFlags.snapY; }
8956 property bool snapHorzScroll
8958 property_category "Behavior"
8961 scrollFlags.snapX = value;
8962 if(sbh) sbh.snap = value;
8964 get { return scrollFlags.snapX; }
8967 property Point scroll
8969 property_category "Behavior"
8973 // TESTING THIS IMPLEMENTATION:
8974 SetScrollPosition(value.x, value.y);
8976 get { value = scroll; }
8979 property bool modifyVirtualArea
8981 property_category "Behavior"
8982 set { modifyVirtArea = value; }
8983 get { return (bool)modifyVirtArea; }
8986 property char * fileName
8988 property_category "Document"
8991 if(menu && ((!fileName && value) || (fileName && !value)))
8993 MenuItem item = menu.FindItem(MenuFileSave, 0);
8994 if(item) item.disabled = !modifiedDocument && value;
8999 if(value && value[0])
9000 fileName = CopyString(value);
9002 if(parent && this == parent.activeClient)
9003 parent.UpdateActiveDocument(null);
9007 // if(style.isDocument)
9009 fileMonitor.fileName = value;
9011 get { return fileName; }
9016 property_category "Data"
9021 property bool modifiedDocument
9023 property_category "Document"
9026 if(style.isDocument || fileName)
9030 MenuItem item = menu.FindItem(MenuFileSave, 0);
9031 if(item) item.disabled = !value && fileName;
9035 if(modifiedDocument != value)
9037 modifiedDocument = value;
9038 if(style.isDocument || fileName)
9042 get { return (bool)modifiedDocument; }
9045 property bool showInTaskBar
9047 property_category "Window Style"
9048 set { style.showInTaskBar = value; }
9049 get { return (style.showInTaskBar; }
9051 property FileDialog saveDialog { set { saveDialog = value; } };
9052 property bool isActiveClient
9054 property_category "Behavior"
9055 set { style.isActiveClient = value; }
9056 get { return style.isActiveClient; }
9059 property Cursor cursor
9061 property_category "Appearance"
9065 SelectMouseCursor();
9067 get { return cursor; }
9070 //#if !defined(ECERE_VANILLA)
9071 property char * name
9073 property_category "Design"
9076 return (this && object) ? object.name : null;
9081 activeDesigner.RenameObject(object, value);
9085 property char * displayDriver
9087 property_category "Behavior"
9090 dispDriver = GetDisplayDriver(value);
9091 //DisplayModeChanged();
9095 return dispDriver ? dispDriver.name : null;
9099 // RUNTIME PROPERTIES
9100 property bool autoCreate { set { autoCreate = value; } get { return (bool)autoCreate; } };
9101 property Size scrollArea
9103 property_category "Behavior"
9107 SetScrollArea(value.w, value.h, false);
9109 SetScrollArea(0,0, true);
9111 get { value = scrollArea; }
9114 return scrollArea.w > clientSize.w || scrollArea.h > clientSize.h;
9119 property_category "Layout"
9120 set { if(this) is3D = value; }
9121 get { return (bool)is3D; }
9124 // Runtime Only Properties (No Set, can display the displayable ones depending on the type?)
9126 // Will be merged with font later
9127 property Font fontObject { get { return usedFont ? usedFont.font : null; } };
9128 property Point clientStart { get { value = clientStart; } };
9129 property Point absPosition { get { value = absPosition; } };
9130 property Anchor normalAnchor { get {value = normalAnchor; } };
9131 // property Size normalSizeAnchor { get { value = normalSizeAnchor; } };
9132 property bool active { get { return (bool)active; } };
9133 property bool created { get { return (bool)created; } };
9134 property bool destroyed { get { return (bool)destroyed; } };
9135 property Window firstSlave { get { return slaves.first ? ((OldLink)slaves.first).data : null; } };
9136 property Window firstChild { get { return children.first; } };
9137 property Window lastChild { get { return children.last; } };
9138 property Window activeClient { get { return activeClient; } };
9139 property Window activeChild { get { return activeChild; } };
9140 property Display display { get { return display ? display : ((parent && parent.rootWindow) ? parent.rootWindow.display : null); } };
9141 property DisplaySystem displaySystem { get { return display ? display.displaySystem : null; } };
9142 property ScrollBar horzScroll { get { return sbh; } };
9143 property ScrollBar vertScroll { get { return sbv; } };
9144 property StatusBar statusBar { get { return statusBar; } };
9145 property Window rootWindow { get { return rootWindow; } };
9146 property bool closing { get { return (bool)closing; } set { closing = value; } };
9147 property int documentID { get { return documentID; } };
9148 property Window previous { get { return prev; } }
9149 property Window next { get { return next; } }
9150 property Window nextSlave { get { OldLink link = master ? master.slaves.FindLink(this) : null; return (link && link.next) ? link.next.data : null; } }
9151 property PopupMenu menuBar { get { return menuBar; } }
9152 property ScrollBar sbv { get { return sbv; } }
9153 property ScrollBar sbh { get { return sbh; } }
9154 property bool fullRender { set { fullRender = value; } get { return (bool)fullRender; } }
9155 property void * systemHandle { get { return windowHandle; } }
9156 property Button minimizeButton { get { return sysButtons[0]; } };
9157 property Button maximizeButton { get { return sysButtons[1]; } };
9158 property Button closeButton { get { return sysButtons[2]; } };
9159 property BitmapResource icon
9161 get { return icon; }
9165 if(icon) incref icon;
9167 guiApp.interfaceDriver.SetIcon(this, value);
9170 property bool moveable { get { return (bool)moveable; } set { moveable = value; } };
9171 property bool alphaBlend { get { return (bool)alphaBlend; } set { alphaBlend = value; } };
9172 property bool useSharedMemory { get { return (bool)useSharedMemory; } set { useSharedMemory = value; } };
9173 property CreationActivationOption creationActivation { get { return creationActivation; } set { creationActivation = value; } };
9174 property bool nativeDecorations { get { return (bool)nativeDecorations && (formDesigner || rootWindow == this); } set { nativeDecorations = value; } };
9175 property bool manageDisplay { get { return (bool)manageDisplay; } set { manageDisplay = value; } };
9181 WindowBits style; // Window Style
9182 char * caption; // Name / Caption
9183 Window parent; // Parent window
9184 OldList children; // List of children in Z order
9185 Window activeChild; // Child window having focus
9186 Window activeClient;
9187 Window previousActive; // Child active prior to activating the default child
9188 Window master; // Window owning and receiving notifications concerning this window
9189 OldList slaves; // List of windows belonging to this window
9190 Display display; // Display this window is drawn into
9192 Point position; // Position in parent window client area
9193 Point absPosition; // Absolute position
9194 Point clientStart; // Client area position from (0,0) in this window
9196 Size clientSize; // Client area size
9197 Size scrollArea; // Virtual Scroll area size
9198 Size reqScrollArea; // Requested virtual area size
9199 Point scroll; // Virtual area scrolling position
9200 public ScrollBar sbh, sbv; // Scrollbar window handles
9201 Cursor cursor; // Mouse cursor used for this window
9204 StatusBar statusBar;
9205 Button sysButtons[3];
9207 Box clientArea; // Client Area box clipped to parent
9209 HotKeySlot hotKey; // HotKey for this window
9213 ScrollFlags scrollFlags;// Window Scrollbar Flags
9214 int id; // Control ID
9216 ColorAlpha background; // Background color used to draw the window area
9218 subclass(DisplayDriver) dispDriver; // Display driver name for this window
9219 OldList childrenCycle; // Cycling order
9220 OldLink cycle; // Element of parent's cycling order
9221 OldList childrenOrder; // Circular Z-Order
9222 OldLink order; // Element of parent's circular Z-Order
9223 Window modalSlave; // Slave window blocking this window's interaction
9225 Window rootWindow; // Topmost system managed window
9226 void * windowHandle; // System window handle
9228 DialogResult returnCode;// Return code for modal windows
9230 Point sbStep; // Scrollbar line scrolling steps
9233 SizeAnchor stateSizeAnchor;
9235 Anchor normalAnchor;
9236 SizeAnchor normalSizeAnchor;
9238 Size skinMinSize; // Minimal window size based on style
9239 Point scrolledPos; // Scrolled position
9240 Box box; // Window box clipped to parent
9241 Box * against; // What to clip the box to
9243 Extent dirtyArea { /*first = -1, last = -1, free = -1*/ }; // Area marked for update by Update
9244 Extent renderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered
9245 Extent overRenderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered over children
9246 Extent clipExtent { /*first = -1, last = -1, free = -1*/ }; // Temporary extent against which to clip render area
9247 Extent scrollExtent { /*first = -1, last = -1, free = -1*/ }; // Area to scroll
9248 Point scrolledArea; // Distance to scroll area by
9249 Extent dirtyBack { /*first = -1, last = -1, free = -1*/ }; // Only used by root window
9251 OldList hotKeys; // List of the hotkeys of all children
9252 Window defaultControl; // Default child control
9256 ColorAlpha * palette; // Color palette used for this window
9258 int caretSize; // Size of caret, non zero if a caret is present
9259 Point caretPos; // Caret position
9261 void * systemParent; // Parent System Window for embedded windows
9268 WindowState lastState;
9270 FileMonitor fileMonitor
9272 this, FileChange { modified = true };
9274 bool OnFileNotify(FileChange action, char * param)
9277 fileMonitor.StopMonitoring();
9278 if(OnFileModified(action, param))
9279 fileMonitor.StartMonitoring();
9284 FontResource setFont, systemFont;
9285 FontResource usedFont;
9286 FontResource captionFont;
9288 FileDialog saveDialog;
9290 SizeAnchor sizeAnchor;
9292 // FormDesigner data
9295 Extent * tempExtents; //[4];
9296 BitmapResource icon;
9298 CreationActivationOption creationActivation;
9301 bool active:1; // true if window and ancestors are active
9302 bool acquiredInput:1; // true if the window is processing state based input
9303 bool modifiedDocument:1;
9304 bool disabled:1; // true if window cannot interact
9305 bool isForegroundWindow:1;// true while a root window is being activated
9306 bool visible:1; // Visibility flag
9307 bool destroyed:1; // true if window is being destroyed
9308 bool anchored:1; // true if this window is repositioned when the parent resizes
9309 bool dirty:1; // Flag set to true if any descendant must be redrawn
9315 bool modifyVirtArea:1;
9316 bool noAutoScrollArea:1;
9319 bool setVisible:1; // FOR FORM DESIGNER
9325 bool useSharedMemory:1;
9328 bool nativeDecorations:1;
9329 bool manageDisplay:1;
9330 bool formDesigner:1; // True if we this is running in the form editor
9333 // Checks used internally for them not to take effect in FormDesigner
9334 property bool _isModal { get { return !formDesigner ? style.modal : false; } }
9335 property subclass(DisplayDriver) _displayDriver { get { return !formDesigner ? dispDriver : null; } }
9337 WindowController controller;
9338 public property WindowController controller { get { return controller; } set { delete controller; controller = value; if(controller) incref controller; } }
9341 public class CommonControl : Window
9343 // creationActivation = doNothing;
9346 public property String toolTip
9348 property_category "Appearance"
9351 if(created) CommonControl::OnDestroy();
9353 toolTip = value ? ToolTip { tip = value; } : null;
9355 if(created) CommonControl::OnCreate();
9357 get { return toolTip ? toolTip.tip : null; }
9363 // (Very) Ugly work around for the fact that the parent watcher
9364 // won't fire when it's already been disconnected...
9365 eInstance_FireSelfWatchers(toolTip,
9366 __ecereProp___ecereNameSpace__ecere__gui__Window_parent);
9372 toolTip.parent = this;
9381 public class Percentage : float
9383 char * OnGetString(char * string, float * fieldData, bool * needClass)
9387 sprintf(string, "%.2f", this);
9388 c = strlen(string)-1;
9391 if(string[c] != '0')
9392 last = Max(last, c);
9393 if(string[c] == '.')
9406 public void ApplySkin(Class c, char * name, void ** vTbl)
9408 char className[1024];
9413 subclass(Window) wc = (subclass(Window))c;
9414 subclass(Window) base = (subclass(Window))c.base;
9416 sprintf(className, "%sSkin_%s", name, c.name);
9417 wc.pureVTbl = c._vTbl;
9418 c._vTbl = new void *[c.vTblSize];
9419 memcpy(c._vTbl, wc.pureVTbl, c.vTblSize * sizeof(void *));
9420 sc = eSystem_FindClass(c.module.application, className);
9424 for(m = 0; m < c.base.vTblSize; m++)
9426 if(c._vTbl[m] == base.pureVTbl[m])
9427 c._vTbl[m] = vTbl[m];
9432 for(m = 0; m < c.vTblSize; m++)
9434 if(sc._vTbl[m] != wc.pureVTbl[m])
9435 c._vTbl[m] = sc._vTbl[m];
9439 for(d = c.derivatives.first; d; d = d.next)
9441 ApplySkin(d.data, name, c._vTbl);
9445 public void UnapplySkin(Class c)
9447 char className[1024];
9449 subclass(Window) wc = (subclass(Window))c;
9450 subclass(Window) base = (subclass(Window))c.base;
9453 if(wc.pureVTbl && c._vTbl != wc.pureVTbl)
9456 c._vTbl = wc.pureVTbl;
9460 for(d = c.derivatives.first; d; d = d.next)
9462 UnapplySkin(d.data);
9466 void CheckFontIntegrity(Window window)
9471 if(window.usedFont && window.usedFont.font == 0xecececec)
9473 FontResource uf = window.usedFont;
9474 char * className = window._class.name;
9475 char * text = window.text;
9478 for(c = window.firstChild; c; c = c.next)
9479 CheckFontIntegrity(c);
9483 public class ControllableWindow : Window
9485 /*WindowController controller;
9486 public property WindowController controller { get { return controller; } set { delete controller; controller = value; incref controller; } }
9487 ~ControllableWindow() { delete controller; }*/
9490 class WindowControllerInterface : ControllableWindow
9492 bool OnKeyDown(Key key, unichar ch)
9494 bool result = ((int(*)())(void *)controller.OnKeyDown)((void *)controller.controlled, (void *)controller, key, ch);
9496 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown](controller.window, key, ch);
9500 bool OnKeyUp(Key key, unichar ch)
9502 bool result = ((int(*)())(void *)controller.OnKeyUp)((void *)controller.controlled, (void *)controller, key, ch);
9504 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp](controller.window, key, ch);
9508 bool OnKeyHit(Key key, unichar ch)
9510 bool result = ((int(*)())(void *)controller.OnKeyHit)((void *)controller.controlled, (void *)controller, key, ch);
9512 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit](controller.window, key, ch);
9516 bool OnMouseMove(int x, int y, Modifiers mods)
9518 bool result = ((int(*)())(void *)controller.OnMouseMove)((void *)controller.controlled, (void *)controller, x, y, mods);
9520 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove](controller.window, x, y, mods);
9524 bool OnLeftButtonDown(int x, int y, Modifiers mods)
9526 bool result = ((int(*)())(void *)controller.OnLeftButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9528 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown](controller.window, x, y, mods);
9532 bool OnLeftButtonUp(int x, int y, Modifiers mods)
9534 bool result = ((int(*)())(void *)controller.OnLeftButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9536 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp](controller.window, x, y, mods);
9540 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
9542 bool result = ((int(*)())(void *)controller.OnLeftDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9544 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick](controller.window, x, y, mods);
9548 bool OnRightButtonDown(int x, int y, Modifiers mods)
9550 bool result = ((int(*)())(void *)controller.OnRightButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9552 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown](controller.window, x, y, mods);
9556 bool OnRightButtonUp(int x, int y, Modifiers mods)
9558 bool result = ((int(*)())(void *)controller.OnRightButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9560 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp](controller.window, x, y, mods);
9564 bool OnRightDoubleClick(int x, int y, Modifiers mods)
9566 bool result = ((int(*)())(void *)controller.OnRightDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9568 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick](controller.window, x, y, mods);
9572 bool OnMiddleButtonDown(int x, int y, Modifiers mods)
9574 bool result = ((int(*)())(void *)controller.OnMiddleButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9576 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown](controller.window, x, y, mods);
9580 bool OnMiddleButtonUp(int x, int y, Modifiers mods)
9582 bool result = ((int(*)())(void *)controller.OnMiddleButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9584 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp](controller.window, x, y, mods);
9588 bool OnMiddleDoubleClick(int x, int y, Modifiers mods)
9590 bool result = ((int(*)())(void *)controller.OnMiddleDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9592 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick](controller.window, x, y, mods);
9596 void OnResize(int width, int height)
9598 ((int(*)())(void *)controller.OnResize)((void *)controller.controlled, (void *)controller, width, height);
9599 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnResize](controller.window, width, height);
9602 void OnRedraw(Surface surface)
9604 ((int(*)())(void *)controller.OnRedraw)((void *)controller.controlled, (void *)controller, surface);
9605 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRedraw](controller.window, surface);
9610 bool result = ((int(*)())(void *)controller.OnCreate)((void *)controller.controlled, (void *)controller);
9612 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnCreate](controller.window);
9617 public class WindowController<class V>
9620 property Window window
9624 uint size = class(Window).vTblSize;
9627 windowVTbl = new void *[size];
9628 memcpy(windowVTbl, value._vTbl, size * sizeof(void *));
9629 if(value._vTbl == value._class._vTbl)
9631 value._vTbl = new void *[value._class.vTblSize];
9632 memcpy(value._vTbl + size, value._class._vTbl + size, (value._class.vTblSize - size) * sizeof(void *));
9636 for(c = 0; c < size; c++)
9638 void * function = class(WindowControllerInterface)._vTbl[c];
9639 if(function != DefaultFunction)
9640 value._vTbl[c] = function;
9642 value._vTbl[c] = windowVTbl[c];
9647 memcpy(value._vTbl, windowVTbl, class(Window).vTblSize * sizeof(void *));
9650 get { return window; }
9652 property V controlled
9654 set { controlled = value; }
9655 get { return controlled; }
9657 virtual bool V::OnKeyDown(WindowController controller, Key key, unichar ch);
9658 virtual bool V::OnKeyUp(WindowController controller, Key key, unichar ch);
9659 virtual bool V::OnKeyHit(WindowController controller, Key key, unichar ch);
9660 virtual bool V::OnMouseMove(WindowController controller, int x, int y, Modifiers mods);
9661 virtual bool V::OnLeftButtonDown(WindowController controller, int x, int y, Modifiers mods);
9662 virtual bool V::OnLeftButtonUp(WindowController controller, int x, int y, Modifiers mods);
9663 virtual bool V::OnLeftDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9664 virtual bool V::OnRightButtonDown(WindowController controller, int x, int y, Modifiers mods);
9665 virtual bool V::OnRightButtonUp(WindowController controller, int x, int y, Modifiers mods);
9666 virtual bool V::OnRightDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9667 virtual bool V::OnMiddleButtonDown(WindowController controller, int x, int y, Modifiers mods);
9668 virtual bool V::OnMiddleButtonUp(WindowController controller, int x, int y, Modifiers mods);
9669 virtual bool V::OnMiddleDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9670 virtual void V::OnResize(WindowController controller, int width, int height);
9671 virtual void V::OnRedraw(WindowController controller, Surface surface);
9672 virtual bool V::OnCreate(WindowController controller);
9675 int (** windowVTbl)();