7 import "GuiApplication"
27 #if !defined(ECERE_VANILLA) && !defined(ECERE_NO3D)
31 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
39 // 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
40 define skinMenuHeight = 25;
41 define statusBarHeight = 18;
43 default extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
45 public enum DialogResult { cancel, yes, no, ok };
47 public class MouseButtons
50 bool left:1, right:1, middle:1;
53 public struct SizeAnchor
56 bool isClientW, isClientH;
61 #define SNAPDOWN(x, d) \
64 if(x < 0) x -= ((d) - Abs(x) % (d)); else x -= x % (d); \
67 #define SNAPUP(x, d) \
70 if(x > 0) x += ((d) - Abs(x) % (d)); else x += x % (d); \
73 /*static */define MAX_DIRTY_BACK = 10;
75 /////////////////////////////////////////////////////////////////////////////
76 ////////// EXTENT MANIPULATION //////////////////////////////////////////////
77 /////////////////////////////////////////////////////////////////////////////
79 #define ACCESS_ITEM(l, id) \
82 #define FASTLIST_LOOP(l, v) \
83 for(v = (BoxItem)l.first; v; v = (BoxItem)v.next)
85 #define FASTLIST_LOOPN(l, v, n) \
86 for(v = (BoxItem)l.first, n = (BoxItem)(v ? v.next : null); v; v = (BoxItem)next, n = (BoxItem)(v ? v.next : null))
89 #define ACCESS_ITEM(l, id) \
90 ((FastItem)(((id) == -1) ? null : (((byte *)((l).items)) + (id) * (l).itemSize)))
92 #define FASTLIST_LOOP(l, v) \
93 for(v = (void *)ACCESS_ITEM((l), (l).first); v; v = (void *)ACCESS_ITEM((l), v.next))
95 #define FASTLIST_LOOPN(l, v, n) \
96 for( v = (void *)ACCESS_ITEM((l), (l).first), \
97 n = v ? ((void *)ACCESS_ITEM((l), v.next)): null; \
98 v; v = n, n = n ? (void *)ACCESS_ITEM((l), n.next) : null)
101 private class FastItem : struct
106 private struct FastList
111 int count, size, itemSize;
118 first = last = free = -1;
126 // FASTLIST_LOOPN(this, item, next) { Delete(item); };
129 FastItem Add(uint itemSize)
132 if(free == -1 || !size)
139 newSize = (size + (size >> 1));
140 items = (FastItem)renew items byte[newSize * itemSize];
145 this.itemSize = itemSize;
146 items = (FastItem)new byte[newSize * itemSize];
149 for(c = size; c<newSize-1; c++)
151 ACCESS_ITEM(this, c).prev = -1;
152 ACCESS_ITEM(this, c).next = c+1;
154 ACCESS_ITEM(this, c).prev = -1;
155 ACCESS_ITEM(this, c).next = -1;
159 item = ACCESS_ITEM(this, free);
162 ACCESS_ITEM(this, item.prev).next = free;
172 void Delete(FastItem item)
175 ACCESS_ITEM(this, item.prev).next = item.next;
177 ACCESS_ITEM(this, item.next).prev = item.prev;
179 if(ACCESS_ITEM(this, first) == item)
181 if(ACCESS_ITEM(this, last) == item)
186 free = ((byte *)item - (byte *)items) / itemSize;
194 free = first = last = -1;
198 private class BoxItem : Item //FastItem
203 public /*private */struct Extent : OldList //FastList
212 //BoxItem extentBox = (BoxItem)Add(sizeof(class BoxItem));
213 Add(BoxItem { box = box });
216 void Copy(Extent source)
222 //FASTLIST_LOOP(source, extentBox)
223 for(extentBox = (BoxItem)source.first; extentBox; extentBox = (BoxItem)extentBox.next)
224 AddBox(extentBox.box);
227 void IntersectBox(Box box)
229 // Clip all boxes of extent against inside of the new box
230 BoxItem extentBox, next;
232 //FASTLIST_LOOPN(this, extentBox, next) // Macros still mess up the parser!
233 for(extentBox = (BoxItem)this.first; extentBox; extentBox = next)
235 next = (BoxItem)extentBox.next;
236 if(box.left > extentBox.box.left) extentBox.box.left = box.left;
237 if(box.top > extentBox.box.top) extentBox.box.top = box.top;
238 if(box.right < extentBox.box.right) extentBox.box.right = box.right;
239 if(box.bottom < extentBox.box.bottom) extentBox.box.bottom = box.bottom;
240 if(extentBox.box.right < extentBox.box.left || extentBox.box.bottom < extentBox.box.top)
245 void ExcludeBox(Box box, Extent temp)
252 for(extentBox = (BoxItem)temp.first; extentBox; extentBox = (BoxItem)extentBox.next)
254 if(extentBox.box.left < box.right && extentBox.box.right > box.left &&
255 extentBox.box.top < box.bottom && extentBox.box.bottom > box.top)
258 if(extentBox.box.top < box.top && extentBox.box.bottom >= box.top)
262 extentBox.box.left, extentBox.box.top,
263 extentBox.box.right, Min(extentBox.box.bottom, box.top -1)
269 if(extentBox.box.bottom > box.bottom && extentBox.box.top <= box.bottom)
273 extentBox.box.left, Max(extentBox.box.top,box.bottom +1),
274 extentBox.box.right, extentBox.box.bottom
280 if(extentBox.box.bottom >= box.top && extentBox.box.top <= box.bottom)
283 if(extentBox.box.left < box.left && extentBox.box.right >= box.left)
287 extentBox.box.left, Max(extentBox.box.top, box.top),
288 Min(extentBox.box.right, box.left-1), Min(extentBox.box.bottom, box.bottom)
294 if(extentBox.box.right > box.right && extentBox.box.left <= box.right)
298 Max(extentBox.box.left, box.right+1), Max(extentBox.box.top, box.top),
299 extentBox.box.right, Min(extentBox.box.bottom, box.bottom)
307 AddBox(extentBox.box);
313 void UnionBox(Box box, Extent temp)
315 BoxItem extentBox, next;
317 // First pass: check if this box is not already covered by one of the extent's box
318 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
320 if(extentBox.box.left <= box.left && extentBox.box.right >= box.right &&
321 extentBox.box.top <= box.top && extentBox.box.bottom >= box.bottom)
328 // Second pass: only keep boxes not completely covered in the new box
329 for(extentBox = (BoxItem)this.first; extentBox; extentBox = next)
331 next = (BoxItem)extentBox.next;
332 if(extentBox.box.left >= box.left && extentBox.box.right <= box.right &&
333 extentBox.box.top >= box.top && extentBox.box.bottom <= box.bottom)
337 // Add the exclusion to the extent
338 ExcludeBox(box, temp);
341 if(box.bottom >= box.top && box.right >= box.left)
343 // Optimization: if the resulting boxes touch, add them smarter
344 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
346 if(box.top == extentBox.box.top && box.bottom == extentBox.box.bottom)
348 if(Abs(box.right - extentBox.box.left) <= 1)
350 extentBox.box.left = box.left;
353 else if(Abs(box.left - extentBox.box.right) <= 1)
355 extentBox.box.right = box.right;
359 else if(box.left == extentBox.box.left && box.right == extentBox.box.right)
361 if(Abs(box.bottom - extentBox.box.top) <= 1)
363 extentBox.box.top = box.top;
366 else if(Abs(box.top - extentBox.box.bottom) <= 1)
368 extentBox.box.bottom = box.bottom;
380 void Union(Extent b, Extent temp)
384 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
385 UnionBox(extentBox.box, temp);
388 void Intersection(Extent b, Extent temp, Extent temp2, Extent temp3)
395 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
398 temp2.IntersectBox(extentBox.box);
405 void Exclusion(Extent b, Extent temp)
408 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
409 ExcludeBox(extentBox.box, temp);
412 void Offset(int x, int y)
415 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
417 extentBox.box.left += x;
418 extentBox.box.top += y;
419 extentBox.box.right += x;
420 extentBox.box.bottom += y;
425 private define MINIMIZED_WIDTH = 160;
426 private define CASCADE_SPACE = 16;
428 // namespace Windows;
430 private class ScrollFlags
432 bool snapX:1, snapY:1, dontHide:1;
435 public class BorderBits { public: bool contour:1, fixed:1, sizable:1, deep:1, bevel:1, thin:1; };
437 class WindowBits : BorderBits
439 BorderBits borderBits:6:0;
440 bool hidden:1, isActiveClient:1, hasHorzScroll:1, hasVertScroll:1, stayOnTop:1, modal:1, isDefault:1, inactive:1, isRemote:1, drawBehind:1;
441 bool interim:1, tabCycle:1, noCycle:1, dontScrollHorz:1, dontScrollVert:1, hasMaximize:1, hasMinimize:1, hasClose:1;
442 bool embedded:1, hasMenuBar:1, isDocument:1, showInTaskBar:1, hasStatusBar:1, nonClient:1, clickThrough:1;
445 public enum BorderStyle : BorderBits
448 contour = BorderBits { contour = true },
449 fixed = BorderBits { fixed = true } | contour,
450 sizable = BorderBits { sizable = true } | fixed,
451 thin = BorderBits { fixed = true, thin = true } | contour,
452 sizableThin = BorderBits { sizable = true } | thin,
453 deep = BorderBits { deep = true },
454 bevel = BorderBits { bevel = true },
455 sizableDeep = sizable|deep,
456 sizableBevel = sizable|bevel,
457 fixedDeep = fixed|deep,
458 fixedBevel = fixed|bevel,
459 deepContour = deep|contour
462 public enum CreationActivationOption
464 activate, flash, doNothing
467 public enum WindowState { normal, minimized, maximized };
469 private class ResPtr : struct
476 private class HotKeySlot : struct
478 HotKeySlot prev, next;
486 class_data char * icon;
488 class_default_property text;
489 // class_initialize GuiApplication::Initialize;
490 class_designer FormDesigner;
491 class_property char * icon
493 set { class_data(icon) = value; }
494 get { return class_data(icon); }
499 if(guiApp) guiApp.Initialize(true);
501 if(guiApp && guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
503 if(_vTbl == ((subclass(Window))_class).pureVTbl)
505 _vTbl = _class._vTbl;
507 else if(_vTbl != _class._vTbl)
510 for(m = 0; m < _class.vTblSize; m++)
512 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
513 _vTbl[m] = _class._vTbl[m];
518 //tempExtents[0] = { /*first = -1, last = -1, free = -1*/ };
519 //tempExtents[1] = { /*first = -1, last = -1, free = -1*/ };
520 //tempExtents[2] = { /*first = -1, last = -1, free = -1*/ };
521 //tempExtents[3] = { /*first = -1, last = -1, free = -1*/ };
525 // caption = CopyString(class.name);
527 children.offset = (byte*)&prev - (byte*)this;
528 childrenOrder.circ = true;
529 childrenCycle.circ = true;
531 maxSize = Size { MAXINT, MAXINT };
535 //style.isActiveClient = true;
538 modifyVirtArea = true;
539 manageDisplay = true;
541 // scrollFlags = ScrollFlags { snapX = true, snapY = true };
542 sbStep.x = sbStep.y = 8;
544 if(guiApp) // dynamic_cast<GuiApplication>(thisModule)
546 cursor = guiApp.GetCursor(arrow);
547 property::parent = guiApp.desktop;
558 stopwatching(parent, font);
562 // Prevent destructor from being called again...
568 /////////////////////////////////
571 OldLink slave = master.slaves.FindLink(this);
572 master.slaves.Delete(slave);
579 parent.childrenCycle.Remove(cycle);
581 parent.childrenOrder.Remove(order);
582 parent.children.Remove(this);
587 /////////////////////////////////
589 while(ptr = resources.first)
592 resources.Delete(ptr);
599 for(child = children.first; child; child = child.next)
601 // child.stopwatching(this, font);
603 eInstance_StopWatching(this, __ecereProp___ecereNameSpace__ecere__gui__Window_font, child);
604 // Don't want property here
605 *&child.parent = null;
608 while(slave = slaves.first)
610 // Don't want property here
611 *&((Window)slave.data).master = null;
612 slaves.Delete(slave);
615 // Because we do a decref in DestroyEx...
623 // Why was this commented?
624 //if(this != guiApp.desktop)
637 if(((subclass(Window))_class).pureVTbl)
639 if(_vTbl == _class._vTbl)
641 _vTbl = ((subclass(Window))_class).pureVTbl;
646 for(m = 0; m < _class.vTblSize; m++)
648 if(_vTbl[m] == _class._vTbl[m])
649 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
653 if(_vTbl == ((subclass(Window))_class).pureVTbl || _vTbl == _class._vTbl)
656 dirtyArea.Free(null);
657 renderArea.Free(null);
658 overRenderArea.Free(null);
659 clipExtent.Free(null);
660 scrollExtent.Free(null);
661 dirtyBack.Free(null);
665 tempExtents[0].Free(null);
666 tempExtents[1].Free(null);
667 tempExtents[2].Free(null);
668 tempExtents[3].Free(null);
673 //#if !defined(ECERE_VANILLA)
674 char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
676 if(this == activeDesigner)
680 char * name = property::name;
681 return name ? name : "";
686 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
687 bool OnGetDataFromString(char * string)
689 FormDesigner designer = (FormDesigner)activeDesigner.classDesigner;
692 if(!strcmp(string, "this") || !strcmp(string, designer.form.name))
693 this = designer.form;
694 else if(!strcmpi(string, "(Desktop)"))
695 this = activeDesigner;
697 return activeDesigner.FindObject(&this, string);
703 // --- Window updates system ---
705 // Setup a bitmap for Redrawing on client area of Window
706 Surface Redraw(Box box)
708 Surface surface = null;
710 Box clientArea = this.clientArea;
714 mox.left -= clientStart.x;
715 mox.top -= clientStart.y;
716 mox.right -= clientStart.x;
717 mox.bottom -= clientStart.y;
719 mox.Clip(clientArea);
720 // mox.ClipOffset(against, scrolledPos.x, scrolledPos.y);
722 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && mox.right >= mox.left && mox.bottom >= mox.top)
724 int x = absPosition.x + clientStart.x;
725 int y = absPosition.y + clientStart.y;
726 if(rootWindow.nativeDecorations)
728 x -= rootWindow.clientStart.x;
729 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
731 if(!guiApp.fullScreenMode || is3D)
733 x -= rootWindow.absPosition.x;
734 y -= rootWindow.absPosition.y;
738 x += rootWindow.parent.clientStart.x;
739 y += rootWindow.parent.clientStart.y;
741 mox.left += rootWindow.parent.clientStart.x;
742 mox.top += rootWindow.parent.clientStart.y;
743 mox.right += rootWindow.parent.clientStart.x;
744 mox.bottom += rootWindow.parent.clientStart.y;
749 surface = display.GetSurface(x, y, mox);
752 surface.width = clientSize.w;
753 surface.height = clientSize.h;
759 // Setup a bitmap for Redrawing on full Window
760 Surface RedrawFull(Box box)
762 Surface surface = null;
770 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && box.right >= box.left && box.bottom >= box.top)
772 int x = absPosition.x;
773 int y = absPosition.y;
774 if(rootWindow.nativeDecorations)
776 x -= rootWindow.clientStart.x;
777 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
779 if(!guiApp.fullScreenMode || is3D)
781 x -= rootWindow.absPosition.x;
782 y -= rootWindow.absPosition.y;
785 x += rootWindow.parent.clientStart.x;
786 y += rootWindow.parent.clientStart.y;
788 mox.left += rootWindow.parent.clientStart.x;
789 mox.top += rootWindow.parent.clientStart.y;
790 mox.right += rootWindow.parent.clientStart.x;
791 mox.bottom += rootWindow.parent.clientStart.y;
796 surface = display.GetSurface(x, y, mox);
799 surface.width = size.w;
800 surface.height = size.h;
806 void FigureCaption(char * caption)
810 strcpy(caption, this.caption);
811 if(style.isDocument || fileName)
813 if(caption[0]) strcat(caption, " - ");
815 strcat(caption, fileName);
819 sprintf(title, "Untitled %d", documentID);
820 strcat(caption, title);
823 strcat(caption, " *");
825 if(activeClient && menuBar &&
826 activeClient.state == maximized)
828 if(activeClient.caption)
830 if(caption[0]) strcat(caption, " - ");
831 strcat(caption, activeClient.caption);
833 if(activeClient.style.isDocument || activeClient.fileName)
835 if(caption[0]) strcat(caption, " - ");
836 strcat(caption, "[");
837 if(activeClient.fileName)
838 strcat(caption, activeClient.fileName);
842 sprintf(title, "Untitled %d", activeClient.documentID);
843 strcat(caption, title);
845 if(activeClient.modifiedDocument)
846 strcat(caption, " *");
847 strcat(caption, "]");
852 // Code for returning dirty from ScrollDisplay:
854 for(d = 0; d<scrollExtent.count; d++)
856 Box * box = &scrollExtent.boxes[d];
862 Min(box.right, box.left-scroll.x),box.bottom
864 dirtyArea.UnionBox(update);
870 Max(box.left, box.right-scroll.x), box.top,
871 box.right, box.bottom
873 dirtyArea.UnionBox(update);
881 box.right, Min(box.bottom, box.top-scroll.y),
883 dirtyArea.UnionBox(update);
889 box.left, Max(box.top, box.bottom-scroll.y),
890 box.right, box.bottom
892 dirtyArea.UnionBox(update);
897 void UpdateDecorations(void)
899 // TODO: *** TEMPORARY HACK ***
906 Update({ -clientStart.x, -clientStart.y, -clientStart.x + size.w-1, 0 });
908 Update({ -clientStart.x, clientSize.h, -clientStart.x + size.w-1, -clientStart.y + size.h-1 });
910 Update({ -clientStart.x,0, -1, clientSize.h-1 });
912 Update({ clientSize.w, 0, -clientStart.x + size.w-1, clientSize.h-1 });
915 // Returns w & h for Position
916 void ComputeAnchors(Anchor anchor, SizeAnchor sizeAnchor, int *ox, int *oy, int *ow, int *oh)
918 Window parent = this.parent ? this.parent : guiApp.desktop;
919 int vpw = parent ? parent.clientSize.w : 0;
920 int vph = parent ? parent.clientSize.h : 0;
921 int pw = parent ? parent.clientSize.w : 0;
922 int ph = parent ? parent.clientSize.h : 0;
923 int w = sizeAnchor.size.w, h = sizeAnchor.size.h;
924 int x = anchor.left.distance, y = anchor.top.distance;
926 MinMaxValue ew = 0, eh = 0;
928 float cascadeW, cascadeH;
930 int tilingW, tilingH, tilingSplit, tilingLastH;
931 int addX = 0, addY = 0;
933 if(parent && rootWindow == this && guiApp && guiApp.interfaceDriver)
935 Window masterWindow = this;
936 Box box { addX, addY, addX + vpw - 1, addY + vph - 1 };
939 if(master == guiApp.desktop)
940 masterWindow = guiApp.desktop.activeChild;
942 masterWindow = master.rootWindow;
943 if(!masterWindow) masterWindow = this;
945 guiApp.interfaceDriver.GetScreenArea(masterWindow, box);
946 if((anchor.left.type == offset && anchor.right.type == offset) || anchor.left.type == none)
949 pw = vpw = box.right - box.left + 1;
951 if((anchor.top.type == offset && anchor.bottom.type == offset) || anchor.top.type == none)
954 ph = vph = box.bottom - box.top + 1;
970 vpw = pw = parent.size.w;
971 vph = ph = parent.size.h;
973 else if(!style.fixed /*|| style.isDocument*/)
975 if(!style.dontScrollHorz && parent.scrollArea.w) vpw = parent.scrollArea.w;
976 if(!style.dontScrollVert && parent.scrollArea.h) vph = parent.scrollArea.h;
978 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
981 Desktop3D_FixSize(&pw, &ph);
982 Desktop3D_FixSize(&vpw, &vph);
985 if(pw < skinMinSize.w) pw = skinMinSize.w;
986 if(ph < skinMinSize.h) ph = skinMinSize.h;
987 if(vpw < skinMinSize.w) vpw = skinMinSize.w;
988 if(vph < skinMinSize.h) vph = skinMinSize.h;
990 // TODO: Must fix what we're snapping
995 SNAPUP(x, textCellW);
997 else if(anchor.right.type)
999 SNAPDOWN(x, textCellW);
1004 SNAPUP(y, textCellH);
1006 else if(anchor.bottom.type)
1008 SNAPDOWN(y, textCellH);
1012 // This is required to get proper initial decoration size using native decorations on Windows
1013 if(nativeDecorations && guiApp && guiApp.interfaceDriver && !visible)
1014 guiApp.interfaceDriver.PositionRootWindow(this, x, y, size.w, size.h, true, true);
1015 GetDecorationsSize(&ew, &eh);
1017 if(anchor.left.type >= cascade && (state == normal /*|| state == Hidden*/))
1019 if(parent.sbv && !parent.sbv.style.hidden)
1020 pw += guiApp.currentSkin.VerticalSBW();
1021 if(parent.sbh && !parent.sbh.style.hidden)
1022 ph += guiApp.currentSkin.HorizontalSBH();
1024 if(anchor.left.type == cascade)
1026 w = (int)(pw * 0.80);
1027 h = (int)(ph * 0.80);
1029 else if(anchor.left.type >= vTiled)
1034 numTiling = parent.numPositions - parent.numIcons;
1035 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1036 if(anchor.left.type == vTiled)
1038 tilingH = (int)sqrt(numTiling);
1039 tilingW = numTiling / tilingH;
1043 tilingW = (int)sqrt(numTiling);
1044 tilingH = numTiling / tilingW;
1047 leftOver = numTiling - tilingH * tilingW;
1050 tilingSplit = (tilingW - leftOver) * tilingH;
1051 tilingLastH = tilingH+1;
1054 tilingSplit = numTiling;
1056 if(positionID >= tilingSplit)
1058 x = pw * (tilingSplit / tilingH + (positionID - tilingSplit) / tilingLastH)/tilingW;
1059 y = ph * ((positionID - tilingSplit) % tilingLastH) / tilingLastH;
1060 x2 = pw * (tilingSplit/tilingH + (positionID - tilingSplit) / tilingLastH + 1)/tilingW;
1061 y2 = ph * (((positionID - tilingSplit) % tilingLastH) + 1) / tilingLastH;
1065 x = pw * (positionID / tilingH) / tilingW;
1066 y = ph * (positionID % tilingH) / tilingH;
1067 x2 = pw * (positionID / tilingH + 1) / tilingW;
1068 y2 = ph * ((positionID % tilingH) + 1) / tilingH;
1072 SNAPDOWN(x, textCellW);
1073 SNAPDOWN(y, textCellH);
1074 SNAPDOWN(x2, textCellW);
1075 SNAPDOWN(y2, textCellH);
1083 if(sizeAnchor.isClientW) w += ew;
1084 if(sizeAnchor.isClientH) h += eh;
1086 if(anchor.left.type == offset)
1087 x = anchor.left.distance;
1088 else if(anchor.left.type == relative)
1089 x = (anchor.left.percent < 0) ? ((int)(vpw * anchor.left.percent - 0.5)) : (int)(vpw * anchor.left.percent + 0.5);
1090 else if(anchor.right.type == relative)
1091 // ex = (anchor.right.percent < 0) ? ((int)(vpw * anchor.right.percent + 0)) : ((int)(vpw * anchor.right.percent + 0));
1092 ex = (anchor.right.percent < 0) ? ((int)(vpw * (1.0-anchor.right.percent) + 0)) : ((int)(vpw * (1.0-anchor.right.percent) + 0));
1093 else if(anchor.right.type == offset)
1094 ex = vpw - anchor.right.distance;
1096 if(anchor.top.type == offset)
1097 y = anchor.top.distance;
1098 else if(anchor.top.type == relative)
1099 y = (anchor.top.percent < 0) ? ((int)(vph * anchor.top.percent - 0.5)) : ((int)(vph * anchor.top.percent + 0.5));
1100 else if(anchor.bottom.type == relative)
1101 //ey = (anchor.bottom.percent < 0) ? ((int)(vph * anchor.bottom.percent + 0)) : ((int)(vph * anchor.bottom.percent + 0));
1102 ey = (anchor.bottom.percent < 0) ? ((int)(vph * (1.0-anchor.bottom.percent) + 0)) : ((int)(vph * (1.0-anchor.bottom.percent) + 0));
1103 else if(anchor.bottom.type == offset)
1104 ey = vph - anchor.bottom.distance;
1106 if(anchor.left.type && anchor.right.type)
1108 switch(anchor.right.type)
1111 ex = pw * (1.0f-anchor.right.percent);
1112 w = Max((int)(ex + 0.5) - x, 0);
1115 ex = vpw - anchor.right.distance;
1116 w = Max((int)(ex + 0.5) - x, 0);
1120 if(anchor.top.type && anchor.bottom.type)
1122 switch(anchor.bottom.type)
1125 ey = ph * (1.0f-anchor.bottom.percent);
1126 h = Max((int)(ey + 0.5) - y, 0);
1129 ey = vph - anchor.bottom.distance;
1130 h = Max((int)(ey + 0.5) - y, 0);
1139 if(state == normal /*|| state == Hidden*/)
1141 bool addSbV = false, addSbH = false;
1143 if(sizeAnchor.isClientW || (anchor.left.type && anchor.right.type)) w = Max(w, 1); else w = Max(w, 0);
1144 if(sizeAnchor.isClientH || (anchor.top.type && anchor.bottom.type)) h = Max(h, 1); else h = Max(h, 0);
1146 w = Max(w, minSize.w);
1147 h = Max(h, minSize.h);
1148 w = Min(w, maxSize.w);
1149 h = Min(h, maxSize.h);
1151 if((sizeAnchor.isClientW || !w || (anchor.left.type && anchor.right.type)) && reqScrollArea.h > h /*&& w*/ && sbv)
1153 if(w) w -= guiApp.currentSkin.VerticalSBW();
1156 if((sizeAnchor.isClientH || !h || (anchor.top.type && anchor.bottom.type)) && reqScrollArea.w > w /*&& h*/ && sbh)
1158 if(h) h -= guiApp.currentSkin.HorizontalSBH();
1162 if(!OnResizing(&w, &h))
1168 if((addSbV)) // || reqScrollArea.h > h) && sbv)
1169 w += guiApp.currentSkin.VerticalSBW();
1170 if((addSbH)) // || reqScrollArea.w > w) && sbh)
1171 h += guiApp.currentSkin.HorizontalSBH();
1173 w = Max(w, skinMinSize.w);
1174 h = Max(h, skinMinSize.h);
1187 SNAPDOWN(w, textCellW);
1188 SNAPDOWN(h, textCellH);
1191 if(anchor.left.type == cascade && (state == normal /*|| state == Hidden*/))
1193 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1196 (pw - w) / CASCADE_SPACE,
1197 (ph - h) / CASCADE_SPACE);
1203 cascW = (pw - w) / (numCascade-1);
1204 cascH = (ph - h) / (numCascade-1);
1205 SNAPDOWN(cascW, textCellW);
1206 SNAPDOWN(cascH, textCellH);
1207 cascadeW = (float)cascW;
1208 cascadeH = (float)cascH;
1212 numCascade = Max(numCascade, 2);
1213 cascadeW = (float)(pw - w) / (numCascade-1);
1214 cascadeH = (float)(ph - h) / (numCascade-1);
1217 x = (int)((positionID % numCascade) * cascadeW);
1218 y = (int)((positionID % numCascade) * cascadeH);
1220 else if(anchor.left.type < vTiled)
1222 if(!anchor.left.type || anchor.horz.type == middleRelative)
1224 if(!anchor.right.type)
1226 if(anchor.horz.type == middleRelative)
1227 x = (int)(vpw * (0.5 + anchor.horz.percent) - w / 2);
1229 x = vpw / 2 + anchor.horz.distance - w / 2;
1235 // case A_EDGE: x = x - w; break;
1237 if(!anchor.top.type || anchor.vert.type == middleRelative)
1239 if(!anchor.bottom.type)
1241 if(anchor.vert.type == middleRelative)
1242 y = (int)(vph * (0.5 + anchor.vert.percent) - h / 2);
1244 y = vph / 2 + anchor.vert.distance - h / 2;
1250 // case A_EDGE: y = y - h; break;
1253 if((state == normal /*|| state == Hidden*/) && !OnMoving(&x, &y, w, h))
1261 SNAPDOWN(x, textCellW);
1262 SNAPDOWN(y, textCellH);
1274 if(anchored && style.fixed && style.isActiveClient)
1279 void UpdateCaret(bool forceUpdate, bool erase)
1281 static Window lastWindow = null;
1282 static int caretX, caretY, caretSize;
1284 if(guiApp && guiApp.caretOwner == this)
1286 int x = caretPos.x - scroll.x;
1287 int y = caretPos.y - scroll.y;
1289 if((erase || this.caretSize) &&
1290 x >= clientArea.left && x <= clientArea.right &&
1291 y >= clientArea.top && y <= clientArea.bottom)
1295 guiApp.interfaceDriver.SetCaret(
1296 x + absPosition.x + clientStart.x,
1297 y + absPosition.y + clientStart.y, this.caretSize);
1298 guiApp.caretEnabled = true;
1300 if(erase || lastWindow != this || caretX != x || caretY != y || caretSize != this.caretSize || forceUpdate)
1304 if(lastWindow != this)
1306 updateBox.left = x + 1;
1308 updateBox.right = x + 2;
1309 updateBox.bottom = y + this.caretSize - 1;
1313 updateBox.left = Min(x + 1, caretX + 1);
1314 updateBox.top = Min(y, caretY);
1315 updateBox.right = Max(x + 2, caretX + 2);
1316 updateBox.bottom = Max(y + this.caretSize - 1, caretY + caretSize - 1);
1319 guiApp.caretOwner.Update(updateBox);
1326 caretSize = this.caretSize;
1332 guiApp.interfaceDriver.SetCaret(0,0,0);
1333 guiApp.caretEnabled = false;
1339 void SetPosition(int x, int y, int w, int h, bool modifyArea, bool modifyThisArea, bool modifyClientArea)
1344 scrolledPos.x = position.x = x;
1345 scrolledPos.y = position.y = y;
1347 clientSize.w = size.w = w;
1348 clientSize.h = size.h = h;
1350 if(parent && !style.nonClient)
1352 //if(!style.fixed || style.isDocument)
1354 if(!style.dontScrollHorz) scrolledPos.x -= parent.scroll.x;
1355 if(!style.dontScrollVert) scrolledPos.y -= parent.scroll.y;
1359 clientStart.x = clientStart.y = 0;
1361 SetWindowArea(&clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1363 //if(!activeClient || activeClient.state != maximized)
1364 if(!noAutoScrollArea)
1366 // Check if scroll area must be modified
1367 if(guiApp && !guiApp.modeSwitching && (sbv || sbh))
1369 bool foundChild = false;
1371 int cw = clientSize.w;// + ((!sbv || sbv.range > 1) ? guiApp.currentSkin.VerticalSBW() : 0);
1372 int ch = clientSize.h;// + ((!sbh || sbh.rangw > 1) ? guiApp.currentSkin.HorizontalSBH() : 0);
1373 for(child = children.first; child; child = child.next)
1375 if(child.modifyVirtArea && !child.style.hidden && child.created && /*!child.anchored &&*/
1376 !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1378 if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == offset)
1379 w = Max(w, child.position.x + child.size.w);
1380 else if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == none)
1381 w = Max(w, Max(child.position.x, 0) + child.size.w);
1382 if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == offset)
1383 h = Max(h, child.position.y + child.size.h);
1384 else if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == none)
1385 h = Max(h, Max(child.position.y, 0) + child.size.h);
1390 if(foundChild && (w > cw || h > ch))
1392 //if((w > reqScrollArea.w) || (h > reqScrollArea.w))
1394 int stepX = sbStep.x, stepY = sbStep.y;
1395 // Needed to make snapped down position match the skin's check of client area
1396 // against realvirtual
1399 SNAPDOWN(stepX, textCellW);
1400 SNAPDOWN(stepY, textCellH);
1401 stepX = Max(stepX, textCellW);
1402 stepY = Max(stepY, textCellH);
1404 if(scrollFlags.snapX)
1406 if(scrollFlags.snapY)
1409 reqScrollArea.w = w;
1410 reqScrollArea.h = h;
1413 else if(reqScrollArea.w || reqScrollArea.h)
1415 reqScrollArea.w = 0;
1416 reqScrollArea.h = 0;
1417 SetScrollPosition(0,0);
1422 // Automatic MDI Client Scrolling Area Adjustment
1423 if(parent && !parent.noAutoScrollArea)
1425 if(modifyArea && modifyVirtArea /*&& !anchored*/ && (parent.sbv || parent.sbh) &&
1426 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient)
1428 Window parent = this.parent;
1429 int w = parent.reqScrollArea.w;
1430 int h = parent.reqScrollArea.h;
1432 if(stateAnchor.right.type == none && stateAnchor.left.type == offset)
1433 w = Max(w, position.x + size.w);
1434 else if(stateAnchor.right.type == none && stateAnchor.left.type == none)
1435 w = Max(w, Max(position.x, 0) + size.w);
1436 if(stateAnchor.bottom.type == none && stateAnchor.top.type == offset)
1437 h = Max(h, position.y + size.h);
1438 else if(stateAnchor.bottom.type == none && stateAnchor.top.type == none)
1439 h = Max(h, Max(position.y, 0) + size.h);
1441 if((w > parent.clientSize.w && w > parent.reqScrollArea.w) ||
1442 (h > parent.clientSize.h && h > parent.reqScrollArea.h))
1444 /*bool resize = false;
1445 int stepX = parent.sbStep.x, stepY = parent.sbStep.y;
1446 // Needed to make snapped down position match the skin's check of client area
1447 // against realvirtual
1450 SNAPDOWN(stepX, textCellW);
1451 SNAPDOWN(stepY, textCellH);
1452 stepX = Max(stepX, textCellW);
1453 stepY = Max(stepY, textCellH);
1455 if(parent.scrollFlags.snapX)
1457 if(parent.scrollFlags.snapY)
1459 if(parent.reqScrollArea.w != w || parent.reqScrollArea.h != h)
1461 parent.reqScrollArea.w = w;
1462 parent.reqScrollArea.h = h;*/
1464 // parent.UpdateScrollBars(true, true);
1465 parent.Position(parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1466 false, true, true, true, false, false);
1471 GetRidOfVirtualArea();
1475 UpdateScrollBars(modifyThisArea, false);
1476 else if(guiApp.currentSkin)
1479 &clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1481 if(sbv && (scrollFlags.dontHide || sbv.range > 1))
1482 clientSize.w -= guiApp.currentSkin.VerticalSBW();
1483 if(sbh && (scrollFlags.dontHide || sbh.range > 1))
1484 clientSize.h -= guiApp.currentSkin.HorizontalSBH();
1487 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1488 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1490 absPosition = scrolledPos;
1491 if(guiApp && guiApp.driver != null && guiApp.interfaceDriver)
1492 guiApp.interfaceDriver.OffsetWindow(this, &absPosition.x, &absPosition.y);
1494 if(this != guiApp.desktop && parent)
1496 absPosition.x += parent.absPosition.x;
1497 absPosition.y += parent.absPosition.y;
1498 if(!style.nonClient && this != guiApp.desktop)
1500 absPosition.x += parent.clientStart.x;
1501 absPosition.y += parent.clientStart.y;
1505 box = Box { 0, 0, size.w - 1, size.h - 1 };
1510 // Clip against parent's client area
1511 box.ClipOffset(against, scrolledPos.x, scrolledPos.y);
1513 // Compute client area in this window coordinate system
1514 clientArea.left = 0;
1516 clientArea.right = clientSize.w - 1;
1517 clientArea.bottom = clientSize.h - 1;
1519 // Clip against parent's client area
1521 clientArea.ClipOffset(against, scrolledPos.x + clientStart.x, scrolledPos.y + clientStart.y);
1525 //absPosition.x -= parent.clientStart.x;
1526 //absPosition.y -= parent.clientStart.y;
1529 // Adjust all children
1530 for(child = children.first; child; child = child.next)
1531 child.SetPosition(child.position.x, child.position.y, child.size.w, child.size.h, false, true, true);
1533 UpdateCaret(false, false);
1536 void GetRidOfVirtualArea(void)
1538 if(parent && !parent.destroyed && style.fixed &&
1539 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient &&
1540 parent.reqScrollArea.w && parent.reqScrollArea.h)
1542 if(!parent.noAutoScrollArea)
1546 for(child = children.first; child; child = child.next)
1548 if(child.modifyVirtArea && !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1550 if(child.position.x + child.size.w > parent.clientSize.w + ((!parent.sbv || parent.sbv.style.hidden) ? 0 : guiApp.currentSkin.VerticalSBW()) ||
1551 child.position.y + child.size.h > parent.clientSize.h + ((!parent.sbh || parent.sbh.style.hidden) ? 0 : guiApp.currentSkin.HorizontalSBH()))
1560 Window parent = this.parent;
1562 parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1563 false, true, true, true, false, false);
1565 parent.SetScrollArea(0,0,true);
1566 parent.SetScrollPosition(0,0);
1572 public void ExternalPosition(int x, int y, int w, int h)
1574 Position(x, y, w, h, false, true, true, true, false, false);
1577 // (w, h): Full window size
1578 bool Position(int x, int y, int w, int h, bool force, bool processAnchors, bool modifyArea, bool updateScrollBars, bool thisOnly, bool changeRootWindow)
1580 bool result = false;
1581 int oldCW = clientSize.w, oldCH = clientSize.h;
1582 bool clientResized, windowResized, windowMoved;
1584 bool realResized = size.w != w || size.h != h;
1586 // TOCHECK: This wasn't in ecere.dll
1587 //if(!parent) return true;
1588 if(destroyed) return false;
1590 windowMoved = position.x != x || position.y != y || force;
1592 // windowResized = realResized || force;
1593 windowResized = size.w != w || size.h != h || force;
1595 if(rootWindow != this && display && !display.flags.flipping && scrolledPos.x != MININT)
1601 scrolledPos.x - parent.clientStart.x + this.box.left, scrolledPos.y - parent.clientStart.y + this.box.top,
1602 scrolledPos.x - parent.clientStart.x + this.box.right,
1603 scrolledPos.y - parent.clientStart.y + this.box.bottom
1609 Box box { scrolledPos.x + this.box.left, scrolledPos.y + this.box.top, scrolledPos.x + this.box.right, scrolledPos.y + this.box.bottom};
1614 SetPosition(x, y, w, h, true, modifyArea, updateScrollBars);
1616 clientResized = oldCW != clientSize.w || oldCH != clientSize.h || force;
1618 if(display && rootWindow != this)
1621 if(guiApp && guiApp.windowMoving)
1623 if(guiApp.windowMoving.style.nonClient)
1624 guiApp.windowMoving.parent.SetMouseRangeToWindow();
1626 guiApp.windowMoving.parent.SetMouseRangeToClient();
1636 // Buttons bitmap resources crash if we do this while switching mode
1637 if(!guiApp || !guiApp.modeSwitching)
1640 // Process Anchored Children
1644 for(child = children.first; child; child = child.next)
1647 ((child.stateAnchor.left.type != offset ||
1648 child.stateAnchor.top.type != offset ||
1649 child.stateAnchor.right.type != none ||
1650 child.stateAnchor.bottom.type != none) ||
1651 child.state == maximized || child.state == minimized))
1653 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor,
1655 // child.Position(x, y, w, h, false, true, true, true, false);
1656 // This must be true cuz otherwise we're gonna miss everything since we SetPosition recursively already
1657 child.Position(x, y, w, h, true, true, true, true, false, true /*false*/);
1663 // Is this gonna cause other problems? Commented out for the FileDialog end bevel bug
1664 //if(updateScrollBars)
1666 OnResize(clientSize.w, clientSize.h);
1668 if((clientResized || windowMoved) && created)
1669 OnPosition(position.x, position.y, clientSize.w, clientSize.h);
1671 if(guiApp.interimWindow && guiApp.interimWindow.master.rootWindow == this)
1673 Window master = guiApp.interimWindow.master;
1674 master.OnPosition(master.position.x, master.position.y, master.clientSize.w, master.clientSize.h);
1677 if(rootWindow == this && !is3D)
1681 x -= guiApp.desktop.absPosition.x;
1682 y -= guiApp.desktop.absPosition.y;
1684 //guiApp.Log("Position %s\n", caption);
1685 if(windowResized || windowMoved)
1686 if(display && !display.flags.memBackBuffer && changeRootWindow)
1687 guiApp.interfaceDriver.PositionRootWindow(this, x, y, w, h, windowMoved, windowResized); //realResized);
1689 if(!guiApp.fullScreenMode && this != guiApp.desktop && (windowResized || windowMoved))
1690 for(child = parent.children.first; child && child != this; child = child.next)
1691 if(child.rootWindow)
1692 guiApp.interfaceDriver.UpdateRootWindow(child.rootWindow);
1696 if(windowMoved || windowResized)
1698 display.Lock(true /*false*/);
1701 display.Position(absPosition.x, absPosition.y);
1702 //display.Position(absPosition.x + clientStart.x, absPosition.y + clientStart.y);
1705 // result = realResized ? display.Resize(size.w, size.h) : true;
1706 if(nativeDecorations)
1708 int w = clientSize.w, h = clientSize.h;
1709 if(hasMenuBar) h += skinMenuHeight;
1710 if(hasStatusBar) h += statusBarHeight;
1711 if(sbv && sbv.visible) w += sbv.size.w;
1712 if(sbh && sbh.visible) h += sbh.size.h;
1713 result = manageDisplay ? display.Resize(w, h) : true;
1716 result = manageDisplay ? display.Resize(size.w, size.h) : true;
1720 else if(clientResized)
1722 // --- Major Slow Down / Fix OpenGL Resizing Main Window Lag
1725 if(!guiApp.fullScreenMode && !guiApp.modeSwitching && this == rootWindow)
1729 if(windowMoved || windowResized)
1734 if(guiApp.driver && changeRootWindow)
1736 if(windowResized || windowMoved)
1737 if(!display || display.flags.memBackBuffer)
1738 guiApp.interfaceDriver.PositionRootWindow(this,
1739 x, y, w, h, windowMoved, windowResized);
1740 guiApp.interfaceDriver.UpdateRootWindow(this);
1742 for(child = children.first; child; child = child.next)
1744 if(child.is3D && child.created)
1746 // Copy Display Content
1747 child.display.displaySystem = display.displaySystem;
1748 child.display.window = display.window;
1749 child.display.current = display.current;
1750 child.display.width = display.width;
1751 child.display.height = display.height;
1752 child.display.driverData = display.driverData;
1753 child.display.mutex = null;
1764 void UpdateScrollBars(bool flag, bool fullThing)
1767 bool resizeH = false, resizeV = false;
1768 bool scrolled = false;
1769 rvw = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.w;
1770 rvh = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.h;
1772 if(destroyed) return;
1773 if(guiApp.currentSkin)
1775 MinMaxValue cw = 0, ch = 0;
1776 bool sbvVisible, sbhVisible;
1778 int positionH, positionV;
1780 // First get client area with no respect to scroll bars
1785 &clientStart.x, &clientStart.y, &size.w, &size.h, &cw, &ch);
1787 if(scrollFlags.dontHide)
1790 cw -= guiApp.currentSkin.VerticalSBW();
1792 ch -= guiApp.currentSkin.HorizontalSBH();
1794 // Update the scrollbar visibility
1800 sbh.disabled = rangeH <= 1;
1801 if(sbh.style.hidden)
1811 sbv.disabled = rangeV <= 1;
1812 if(sbv.style.hidden)
1820 // Then start off with horizontal scrollbar range
1823 positionH = sbh.thumbPosition;
1828 ch -= guiApp.currentSkin.HorizontalSBH();
1831 // Do the same for vertical scrollbar
1834 positionV = sbv.thumbPosition;
1840 cw -= guiApp.currentSkin.VerticalSBW();
1841 // Maybe we need to set the range on the horizontal scrollbar again
1846 sbh.Action(setRange, positionH, 0);
1847 if(rangeH <= 1 && sbh.range > 1)
1849 ch -= guiApp.currentSkin.HorizontalSBH();
1853 sbv.Action(setRange, positionV, 0);
1860 // Update the scrollbar visibility
1861 if(!scrollFlags.dontHide)
1863 if(sbh && ((rangeH <= 1 && !sbh.style.hidden) || (rangeH > 1 && sbh.style.hidden)))
1867 if(sbv && ((rangeV <= 1 && !sbv.style.hidden) || (rangeV > 1 && sbv.style.hidden)))
1874 if(guiApp.currentSkin)
1881 sbhVisible = sbh.style.hidden ? true : false;
1883 sbvVisible = sbv.style.hidden ? true : false;
1885 // Do our resize here
1886 if(flag && (resizeH || resizeV) && fullThing)
1888 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, false);
1893 OnResize(clientSize.w, clientSize.h);
1899 sbh.visible = sbhVisible;
1901 sbv.visible = sbvVisible;
1903 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1904 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1907 sbh.pageStep = clientSize.w;
1909 sbv.pageStep = clientSize.h;
1911 // Notify doesn't handle setRange anymore... process it here
1914 int positionH = sbh.thumbPosition;
1915 if(scroll.x != positionH)
1917 OnHScroll(setRange, positionH, 0);
1921 SNAPDOWN(positionH, textCellW);
1922 scroll.x = positionH;
1928 int seen = clientSize.w, total = reqScrollArea.w;
1931 if(scrollFlags.snapX)
1932 SNAPDOWN(seen, sbStep.x);
1934 if(!total) total = seen;
1935 range = total - seen + 1;
1937 range = Max(range, 1);
1939 if(x >= range) x = range - 1;
1941 if(scrollFlags.snapX)
1942 SNAPUP(x, sbStep.x);
1946 OnHScroll(setRange, x, 0);
1951 SNAPDOWN(x, textCellW);
1957 int positionV = sbv.thumbPosition;
1958 if(scroll.y != positionV)
1960 OnVScroll(setRange, positionV, 0);
1964 SNAPDOWN(positionV, textCellH);
1965 scroll.y = positionV;
1971 int seen = clientSize.h, total = reqScrollArea.h;
1974 if(scrollFlags.snapY)
1975 SNAPDOWN(seen, sbStep.y);
1977 if(!total) total = seen;
1978 range = total - seen + 1;
1979 range = Max(range, 1);
1981 if(y >= range) y = range - 1;
1983 if(scrollFlags.snapY)
1984 SNAPUP(y, sbStep.y);
1988 OnVScroll(setRange, y, 0);
1993 SNAPDOWN(y, textCellH);
1999 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2002 for(child = children.first; child; child = child.next)
2004 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2007 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2008 child.Position(x, y, w, h, false, true, false, true, false, false);
2015 // Process Scrollbars
2017 if(sbh) // && !sbh.style.hidden
2019 sbh.Move(clientStart.x, clientStart.y + clientSize.h, clientSize.w,0);
2020 // Need to set the range again (should improve...) since the scrollbars didn't have
2021 // the right size when UpdateScrollArea set the range on it
2024 sbh.seen = clientSize.w;
2028 if(sbv) // && !sbv.state.hidden
2030 sbv.Move(clientStart.x + clientSize.w, clientStart.y, 0, clientSize.h);
2031 // Need to set the range again (should improve...) since the scrollbars didn't have
2032 // the right size when UpdateScrollArea set the range on it
2035 sbv.seen = clientSize.h;
2040 // TESTING THIS LOWER
2041 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2044 for(child = children.first; child; child = child.next)
2046 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2049 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2050 child.Position(x, y, w, h, false, true, false, true, false, false);
2056 bool MaximizeButtonClicked(Button button, int x, int y, Modifiers mods)
2058 SetState(maximized, false, mods);
2062 bool RestoreButtonClicked(Button button, int x, int y, Modifiers mods)
2064 SetState(normal, false, mods);
2068 bool MinimizeButtonClicked(Button button, int x, int y, Modifiers mods)
2070 SetState(minimized, false, mods);
2071 parent.CycleChildren(false, true, false, true);
2075 void ScrollBarNotification(ScrollBar control, ScrollBarAction action, int position, Key keyFlags)
2078 // Scroll bar notifications
2079 if(action != setRange)
2081 bool changed = false;
2085 if(scroll.x != position)
2087 OnHScroll(action, position, keyFlags);
2092 SNAPDOWN(position, textCellW);
2094 scroll.x = position;
2098 if(scroll.y != position)
2100 OnVScroll(action, position, keyFlags);
2105 SNAPDOWN(position, textCellH);
2107 scroll.y = position;
2111 bool childMove = false;
2112 for(child = children.first; child; child = child.next)
2114 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2117 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2118 child.Position(x, y, w, h, false, true, false, true, false, false);
2122 // Testing this patch out to solve MDI workspace redraw bugs
2123 // We were already supposed to be updating parent's affected area in Position() but it doesn't seem to be working
2124 // Scroll offsets to blame?
2128 UpdateCaret(false, false);
2132 // Testing this patch out to solve MDI workspace redraw bugs
2133 for(child = children.first; child; child = child.next)
2135 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2144 void CreateSystemChildren(void)
2146 Window parent = this;
2147 bool scrollBarChanged = false;
2148 bool hasClose = false, hasMaxMin = false;
2149 Point scroll = this.scroll;
2151 if(state == maximized && this.parent.menuBar)
2153 if(this.parent.activeClient == this)
2154 parent = this.parent.menuBar;
2161 if(style.hasClose) hasClose = true;
2162 if(style.hasMaximize || style.hasMinimize)
2169 if(sysButtons[2] && (!hasClose || sysButtons[2].parent != parent))
2171 sysButtons[2].Destroy(0);
2172 sysButtons[2] = null;
2174 if(sysButtons[1] && (!hasMaxMin || sysButtons[1].parent != parent))
2176 sysButtons[1].Destroy(0);
2177 sysButtons[1] = null;
2179 if(sysButtons[0] && (!hasMaxMin || sysButtons[0].parent != parent))
2181 sysButtons[0].Destroy(0);
2182 sysButtons[0] = null;
2185 if(hasClose && parent)
2192 parent, master = this,
2193 inactive = true, nonClient = true, visible = false;
2195 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
2201 if(this.parent == guiApp.desktop)
2202 sysButtons[2].hotKey = altF4;
2203 else if(style.isActiveClient)
2204 sysButtons[2].hotKey = ctrlF4;
2205 sysButtons[2].Create();
2208 sysButtons[2].symbol = 'X';
2209 sysButtons[2].disabled = !style.hasClose;
2212 if(hasMaxMin && parent)
2216 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2217 if(state == maximized)
2220 method = RestoreButtonClicked;
2226 method = MaximizeButtonClicked;
2234 parent, master = this,
2235 hotKey = altEnter, inactive = true, nonClient = true, visible = false
2237 sysButtons[1].Create();
2239 sysButtons[1].NotifyClicked = method;
2241 sysButtons[1].symbol = symbol;
2242 sysButtons[1].disabled = !style.hasMaximize;
2245 if(hasMaxMin && parent)
2249 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2250 if (state == minimized)
2253 method = RestoreButtonClicked;
2259 method = MinimizeButtonClicked;
2267 parent, master = this,
2268 hotKey = altM, inactive = true, nonClient = true, visible = false
2270 sysButtons[0].Create();
2272 sysButtons[0].NotifyClicked = method;
2274 sysButtons[0].symbol = symbol;
2275 sysButtons[0].disabled = !style.hasMinimize;
2278 // Create the scrollbars
2279 if(style.hasHorzScroll && !sbh)
2285 direction = horizontal,
2289 snap = scrollFlags.snapX,
2290 NotifyScrolling = ScrollBarNotification
2293 scrollBarChanged = true;
2295 else if(sbh && !style.hasHorzScroll)
2301 if(style.hasVertScroll && !sbv)
2307 direction = vertical,
2311 snap = scrollFlags.snapY,
2312 NotifyScrolling = ScrollBarNotification
2315 scrollBarChanged = true;
2317 else if(sbv && !style.hasVertScroll)
2322 if(scrollBarChanged)
2324 SetScrollLineStep(sbStep.x, sbStep.y);
2325 UpdateScrollBars(true, true);
2329 if(scrollBarChanged)
2331 if(sbh) sbh.thumbPosition = scroll.x;
2332 if(sbv) sbv.thumbPosition = scroll.y;
2336 void UpdateCaption(void)
2338 if(rootWindow == this)
2341 FigureCaption(caption);
2342 guiApp.interfaceDriver.SetRootWindowCaption(this, caption);
2344 UpdateDecorations();
2347 if(parent.rootWindow == parent && parent.activeClient == this) // Added this last check
2350 parent.FigureCaption(caption);
2351 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
2353 parent.UpdateDecorations();
2357 void UpdateActiveDocument(Window previous)
2359 Window activeClient = this.activeClient;
2360 Window activeChild = this.activeChild;
2367 activeClient.CreateSystemChildren();
2369 previous.CreateSystemChildren();
2380 if(activeClient && activeClient.menu && activeClient.state != minimized)
2384 //activeClient.menu.Clean(activeClient);
2385 menu.Merge(activeClient.menu, true, activeClient);
2389 if(activeChild && activeChild != activeClient && activeChild.menu && activeChild.state != minimized)
2392 menu.Merge(activeChild.menu, true, activeChild);
2395 // Build window list
2398 Menu windowMenu = menu.FindMenu("Window");
2403 for(id = 0, cycle = activeClient.cycle; cycle && id<10;)
2406 Window document = cycle.data;
2407 if(!document.style.nonClient && document.style.isActiveClient && document.visible)
2409 char name[2048], caption[2048];
2410 document.FigureCaption(caption);
2411 sprintf(name, "%d %s", id+1, caption);
2412 windowMenu.AddDynamic(MenuItem
2414 copyText = true, text = name, hotKey = Key { k1 + id }, id = id++,
2415 NotifySelect = MenuWindowSelectWindow
2419 if(activeClient.cycle == cycle) break;
2424 if((!previous && activeClient) || !activeClient)
2430 item = menu.FindItem(MenuWindowCloseAll, 0);
2431 if(item) item.disabled = false;
2432 item = menu.FindItem(MenuWindowNext, 0);
2433 if(item) item.disabled = false;
2434 item = menu.FindItem(MenuWindowPrevious, 0);
2435 if(item) item.disabled = false;
2436 item = menu.FindItem(MenuWindowCascade, 0);
2437 if(item) item.disabled = false;
2438 item = menu.FindItem(MenuWindowTileHorz, 0);
2439 if(item) item.disabled = false;
2440 item = menu.FindItem(MenuWindowTileVert, 0);
2441 if(item) item.disabled = false;
2442 item = menu.FindItem(MenuWindowArrangeIcons, 0);
2443 if(item) item.disabled = false;
2444 item = menu.FindItem(MenuWindowWindows, 0);
2445 if(item) item.disabled = false;
2448 item = menu.FindItem(MenuFileClose, 0);
2449 if(item) item.disabled = !activeClient || !activeClient.style.hasClose;
2450 item = menu.FindItem(MenuFileSaveAll, 0);
2451 if(item) item.disabled = numDocuments < 1;
2453 // This is called again for a child window change, with same active client
2454 OnActivateClient(activeClient, previous);
2457 void _ShowDecorations(Box box, bool post)
2459 if(rootWindow == this && nativeDecorations) return;
2460 if(visible && this != guiApp.desktop)
2462 Surface surface = RedrawFull(box);
2466 FigureCaption(caption);
2469 ShowDecorations(captionFont.font,
2472 active, //parent.activeClient == this
2473 guiApp.windowMoving == this);
2475 PreShowDecorations(captionFont.font,
2478 active, //parent.activeClient == this
2479 guiApp.windowMoving == this);
2486 void UpdateExtent(Box refresh)
2488 Surface surface = null;
2490 if(!manageDisplay) { OnRedraw(null);return; }
2491 _ShowDecorations(refresh, false);
2493 surface = Redraw(refresh);
2494 // Opaque background: just fill before EW_REDRAW (clear?)
2497 surface.SetBackground(background);
2498 surface.SetForeground(foreground);
2499 surface.DrawingChar(' ');
2500 if(this == rootWindow)
2502 if(style.drawBehind || background.a)
2503 surface.Clear(colorBuffer);
2505 else if(background.a)
2509 background.color = { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2510 surface.SetForeground((background.color.r > 128 || background.color.g > 128) ? black : white);
2513 if(display.flags.alpha && background.a < 255 && background)
2515 surface.Area(0,0,clientSize.w, clientSize.h);
2516 /*if(style.clearDepthBuffer)
2517 surface.Clear(depthBuffer);*/
2519 else if(/*style.clearDepthBuffer || */background.a)
2521 // surface.Clear((style.clearDepthBuffer ? depthBuffer : 0) | (background.a ? colorBuffer : 0));
2522 surface.Clear(colorBuffer);
2527 surface.TextFont(usedFont.font);
2528 surface.TextOpacity(false);
2532 // Draw the caret ...
2533 if(!disabled && this == guiApp.caretOwner && guiApp.caretEnabled /*&& !guiApp.interimWindow*/ && !guiApp.currentSkin.textMode)
2535 // surface.SetBackground(0xFFFFFF - background.color);
2536 surface.SetBackground(~background.color);
2538 caretPos.x - scroll.x + 1, caretPos.y - scroll.y,
2539 caretPos.x - scroll.x + 2, caretPos.y - scroll.y + caretSize - 1);
2545 void DrawOverChildren(Box refresh)
2547 Surface surface = Redraw(refresh);
2551 surface.DrawingChar(' ');
2552 surface.SetBackground(background);
2553 surface.SetForeground(foreground);
2555 surface.TextFont(usedFont.font);
2556 surface.TextOpacity(false);
2558 OnDrawOverChildren(surface);
2563 _ShowDecorations(refresh, true);
2566 void ComputeClipExtents(void)
2569 Extent clipExtent { /*first = -1, last = -1, free = -1*/ };
2571 clipExtent.Copy(this.clipExtent);
2573 for(child = children.last; child; child = child.prev)
2575 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2577 bool opaque = child.IsOpaque(); // TODO: acess background directly
2578 int dx = child.absPosition.x - absPosition.x, dy = child.absPosition.y - absPosition.y;
2580 child.clipExtent.Copy(clipExtent);
2581 child.clipExtent.Offset(-dx, -dy);
2582 child.clipExtent.IntersectBox(child.box);
2584 child.ComputeClipExtents();
2586 if(opaque && !child.style.nonClient)
2588 // Adjust the box for the parent:
2589 Box box { child.box.left + dx, child.box.top + dy, child.box.right + dx, child.box.bottom + dy };
2590 clipExtent.ExcludeBox(box, rootWindow.tempExtents[0]);
2595 // ??? Only do this for overlapped window or if parent has with clip children flag
2597 // Do this if window has clip children flag on (default false?)
2598 // this.clipExtent = clipExtent;
2600 clipExtent.Free(null);
2603 void ComputeRenderAreaNonOpaque(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2605 bool opaque = IsOpaque();
2607 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2608 if(rootWindow.nativeDecorations)
2610 offsetX -= rootWindow.clientStart.x;
2611 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2615 for(child = children.last; child; child = child.prev)
2617 ColorAlpha background = *(ColorAlpha *)&child.background;
2618 bool opaque = child.IsOpaque();
2619 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2623 // Adjust renderArea to the root window level
2624 Extent * renderArea = &rootWindow.tempExtents[1];
2626 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2627 if(child.rootWindow.nativeDecorations)
2629 offsetX -= child.rootWindow.clientStart.x;
2630 offsetY -= child.rootWindow.clientStart.y - (child.rootWindow.hasMenuBar ? skinMenuHeight : 0);
2634 Extent childRenderArea;
2636 if(backBufferUpdate != null)
2638 childRenderArea.Copy(backBufferUpdate);
2639 childRenderArea.Offset(-offsetX, -offsetY);
2642 childRenderArea.Copy(child.dirtyArea);
2644 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2645 renderArea.Copy(dirtyExtent);
2646 renderArea.Offset(-offsetX, -offsetY);
2647 childRenderArea.Union(renderArea);
2650 // Intersect with the clip extent
2651 childRenderArea.Intersection(child.clipExtent);
2654 renderArea->Copy(child.dirtyArea /*childRenderArea*/);
2655 renderArea->Offset(offsetX, offsetY);
2656 dirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2657 // overDirtyExtent.Union(renderArea);
2658 renderArea->Empty();
2659 // childRenderArea.Free();
2661 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2666 for(child = children.last; child; child = child.prev)
2668 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2670 child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2675 void ComputeRenderArea(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2677 bool opaque = IsOpaque();
2678 Extent * dirtyExtentWindow = &rootWindow.tempExtents[1];
2680 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2681 if(rootWindow.nativeDecorations)
2683 offsetX -= rootWindow.clientStart.x;
2684 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2688 for(child = children.last; child; child = child.prev)
2690 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2692 ColorAlpha background = *(ColorAlpha *)&child.background;
2693 bool opaque = child.IsOpaque();
2694 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2698 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2699 // Adjust renderArea to the root window level
2701 renderArea.Copy(child.dirtyArea);
2702 renderArea.Offset(offsetX, offsetY);
2703 dirtyExtent.Union(renderArea);
2704 overDirtyExtent.Union(renderArea);
2710 for(child = children.last; child; child = child.prev)
2712 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2714 child.ComputeRenderArea(dirtyExtent, overDirtyExtent, backBufferUpdate);
2718 if(backBufferUpdate != null)
2720 renderArea.Copy(backBufferUpdate);
2721 renderArea.Offset(-offsetX, -offsetY);
2723 overRenderArea.Copy(backBufferUpdate);
2724 overRenderArea.Offset(-offsetX, -offsetY);
2730 renderArea.Copy(dirtyArea);
2732 overRenderArea.Copy(dirtyArea);
2735 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2736 dirtyExtentWindow->Copy(dirtyExtent);
2737 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2738 renderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2739 dirtyExtentWindow->Empty();
2741 // Intersect with the clip extent
2742 renderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2745 if(renderArea.count > 10)
2748 printf("\nToo many extents (%d):\n", renderArea.count);
2750 //extent.UnionBox({ 112, 6, 304, 7 }, rootWindow.tempExtents[0]);
2751 //extent.UnionBox({ 112, 8, 304, 17 }, rootWindow.tempExtents[0]);
2756 for(c = 0; c<10; c++)
2759 FASTLIST_LOOP(renderArea, extentBox)
2761 extent.UnionBox(extentBox.box, rootWindow.tempExtents[0]);
2763 renderArea.Copy(extent);
2765 FASTLIST_LOOP(renderArea, extentBox)
2768 printf("(%d, %d) - (%d, %d)\n",
2769 extentBox.box.left, extentBox.box.top,
2770 extentBox.box.right, extentBox.box.bottom);
2774 printf("\nNow %d\n", renderArea.count);
2780 // WHY WAS THIS COMMENTED ??
2782 // Add extent forced by DrawOverChildren to the dirty area, adjusting dirty extent to the window
2783 dirtyExtentWindow->Copy(overDirtyExtent);
2784 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2785 overRenderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2786 dirtyExtentWindow->Empty();
2788 // Intersect with the clip extent
2789 overRenderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2795 if(scrollExtent.count)
2797 // Subtract render extent from scrolling extent
2798 scrollExtent.Exclusion(renderArea, rootWindow.tempExtents[0]);
2800 if(backBufferUpdate == null)
2802 Extent * dirty = &rootWindow.tempExtents[3];
2805 // Intersect scrolling extent with clip extent
2806 scrollExtent.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2808 // offset this scroll to be at the root window level
2809 scrollExtent.Offset(offsetX, offsetY);
2810 // Add area that was scrolled to the dirty extents of the back buffer
2811 rootWindow.dirtyBack.Union(scrollExtent, rootWindow.tempExtents[0]);
2815 // Will need scrolledArea.x & scrolledArea.y to support multiple scrolls
2816 for(scrollBox = (BoxItem)scrollExtent.first; scrollBox; scrollBox = (BoxItem)scrollBox.next)
2817 display.Scroll(scrollBox.box, scrolledArea.x, scrolledArea.y, dirty);
2822 scrollExtent.Empty();
2824 // Add the exposed extent to the window render area
2825 dirty->Offset(-offsetX, -offsetY);
2826 renderArea.Union(dirty, rootWindow.tempExtents[0]);
2831 // Subtract the window's box from the transparency forced extent
2832 dirtyExtent.ExcludeBox({box.left + offsetX, box.top + offsetY, box.right + offsetX, box.bottom + offsetY }, rootWindow.tempExtents[0]);
2838 renderArea.Copy(this.renderArea);
2839 renderArea.Offset(offsetX, offsetY);
2840 dirtyExtent.Union(renderArea);
2846 Extent renderArea { };
2848 renderArea.Copy(overRenderArea);
2849 renderArea.Offset(offsetX, offsetY);
2850 overDirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2855 if(backBufferUpdate != null)
2857 // Remove render area from dirty area
2858 dirtyArea.Exclusion(renderArea, rootWindow.tempExtents[0]);
2860 dirtyArea.Exclusion(overRenderArea, rootWindow.tempExtents[0]);
2867 // Remove the window render area from the dirty extents of the back buffer
2868 rootWindow.dirtyBack.Exclusion(renderArea);
2872 void Render(Extent updateExtent)
2876 Window rootWindow = this.rootWindow;
2877 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2878 if(rootWindow.nativeDecorations)
2880 offsetX -= rootWindow.clientStart.x;
2881 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2884 if(rootWindow.fullRender)
2893 background = Color { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2894 foreground = (background.color.r > 128 || background.color.g > 128) ? black : white;
2899 /*if(renderArea.count)
2900 printf("\n\nRendering %s (%x):\n------------------------------------------\n", _class.name, this);*/
2903 for(extentBox = (BoxItem)renderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
2905 Box box = extentBox.box;
2908 /*printf("(%d, %d) - (%d, %d)\n",
2909 extentBox.box.left, extentBox.box.top,
2910 extentBox.box.right, extentBox.box.bottom);*/
2915 box.left += offsetX;
2917 box.right += offsetX;
2918 box.bottom += offsetY;
2920 if(updateExtent != null)
2921 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
2925 for(child = children.first; child; child = child.next)
2926 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && !child.nonClient)
2927 child.Render(updateExtent);
2929 if(rootWindow.fullRender)
2930 DrawOverChildren(box);
2933 // TO DO: There's an issue about draw over children...
2934 // TO DO: Don't wanna go through this if method isn't used
2935 for(extentBox = (BoxItem)overRenderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
2936 //FASTLIST_LOOP(/*renderArea */overRenderArea, extentBox)
2938 Box box = extentBox.box;
2940 DrawOverChildren(box);
2942 box.left += offsetX;
2944 box.right += offsetX;
2945 box.bottom += offsetY;
2947 if(updateExtent != null)
2948 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
2951 for(child = children.first; child; child = child.next)
2952 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && child.nonClient)
2953 child.Render(updateExtent);
2956 overRenderArea.Empty();
2959 public void UpdateDisplay(void)
2961 if(!manageDisplay) { OnRedraw(null);return; }
2962 if(rootWindow && this != rootWindow)
2963 rootWindow.UpdateDisplay();
2966 Extent dirtyExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be forced due to transparency
2967 Extent overExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that forced for DrawOverChildren
2970 dirtyExtent.Clear();
2973 clipExtent.AddBox(box);
2975 display.StartUpdate();
2977 if(!rootWindow.fullRender)
2979 ComputeClipExtents();
2980 ComputeRenderAreaNonOpaque(dirtyExtent, overExtent, null);
2981 ComputeRenderArea(dirtyExtent, overExtent, null);
2984 clipExtent.Free(null);
2986 dirtyExtent.Free(null);
2987 overExtent.Free(null);
2989 if(display.flags.flipping)
2992 display.Update(null);
2996 Extent updateExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be updated
2997 updateExtent.Clear();
2999 Render(updateExtent);
3001 updateExtent.UnionBox(this.box, tempExtents[0]);
3004 //printf("\n\nUpdate:\n------------------------------------------\n");
3007 //FASTLIST_LOOP(updateExtent, extentBox)
3008 for(extentBox = (BoxItem)updateExtent.first; extentBox; extentBox = (BoxItem)extentBox.next)
3011 /*printf("Updating (%d, %d) - (%d, %d)\n",
3012 extentBox.box.left, extentBox.box.top,
3013 extentBox.box.right, extentBox.box.bottom);*/
3016 display.Update(extentBox.box);
3019 updateExtent.Free(null);
3022 display.EndUpdate();
3030 void UpdateBackDisplay(Box box)
3036 Extent intersection { /*first = -1, last = -1, free = -1*/ };
3038 //printf("UpdateBackDisplay going through!\n");
3039 display.StartUpdate();
3043 intersection.Copy(dirtyBack);
3044 intersection.IntersectBox(box);
3046 dirtyExtent.Clear();
3049 clipExtent.AddBox(box);
3051 if(!rootWindow.fullRender)
3053 ComputeClipExtents();
3054 ComputeRenderArea(dirtyExtent, overExtent, intersection);
3057 clipExtent.Free(null);
3059 intersection.Free(null);
3060 dirtyExtent.Free(null);
3061 overExtent.Free(null);
3066 if(display.flags.flipping)
3067 display.Update(null);
3070 rootWindow.display.Update(box);
3073 display.EndUpdate();
3077 dirtyBack.ExcludeBox(box, rootWindow.tempExtents[0]);
3078 if(dirtyBack.count > MAX_DIRTY_BACK)
3080 BoxItem extentBox, next;
3081 BoxItem first = (BoxItem)ACCESS_ITEM(dirtyBack, dirtyBack.first);
3082 for(extentBox = (BoxItem)dirtyBack.first; extentBox; extentBox = next)
3084 next = (BoxItem)extentBox.next;
3085 if(extentBox != first)
3087 if(extentBox.box.left < first.box.left)
3088 first.box.left = extentBox.box.left;
3089 if(extentBox.box.top < first.box.top)
3090 first.box.top = extentBox.box.top;
3091 if(extentBox.box.right > first.box.right)
3092 first.box.right = extentBox.box.right;
3093 if(extentBox.box.bottom > first.box.bottom)
3094 first.box.bottom = extentBox.box.bottom;
3095 dirtyBack.Delete(extentBox);
3104 // --- Window positioning ---
3105 // --- Window identification ---
3107 // Returns window at position "Position"
3108 Window GetAtPosition(int x, int y, bool clickThru, bool acceptDisabled, Window last)
3110 Window child, result = null;
3112 box.left += absPosition.x;
3113 box.right += absPosition.x;
3114 box.top += absPosition.y;
3115 box.bottom += absPosition.y;
3117 if(!destroyed && visible && (acceptDisabled || !disabled))
3119 int lx = x - absPosition.x;
3120 int ly = y - absPosition.y;
3121 if(IsInside(lx, ly))
3122 // if(box.IsPointInside(Point{x, y}))
3124 if(!clickThru || !style.clickThrough) result = (this == last) ? null : this;
3125 // If the window is disabled, stop looking in children (for acceptDisabled mode)
3128 for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
3130 if(child != statusBar && child.rootWindow == rootWindow)
3132 Window childResult = child.GetAtPosition(x, y, clickThru, acceptDisabled, last);
3139 for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
3141 if(child != statusBar && child.rootWindow == rootWindow)
3143 Window childResult = child.GetAtPosition(x, y, false, acceptDisabled, last);
3155 Window FindModal(void)
3157 Window modalWindow = this, check;
3158 Window check2 = null;
3159 for(check = this; check.master; check = check.master)
3161 if(check.master.modalSlave && check.master.modalSlave.created && check != check.master.modalSlave)
3163 modalWindow = check.master.modalSlave;
3164 check = modalWindow;
3166 // TESTING THIS FOR DROPBOX...
3167 if(!rootWindow || !rootWindow.style.interim)
3169 for(check2 = check; check2.activeChild; check2 = check2.activeChild)
3171 if(check2.modalSlave && check2.modalSlave.created)
3173 modalWindow = check2.modalSlave;
3181 if(modalWindow == this)
3183 for(check = this; check.activeChild; check = check.activeChild)
3185 if(check.modalSlave)
3187 modalWindow = check.modalSlave;
3193 for(; modalWindow.modalSlave && modalWindow.modalSlave.created; modalWindow = modalWindow.modalSlave);
3194 return (modalWindow == this || this == guiApp.interimWindow || IsDescendantOf(modalWindow)) ? null : modalWindow;
3197 void StopMoving(void)
3199 if(this == guiApp.windowMoving)
3201 guiApp.windowMoving = null;
3202 UpdateDecorations();
3203 SetMouseRange(null);
3206 if(rootWindow.active)
3207 guiApp.interfaceDriver.StopMoving(rootWindow);
3210 guiApp.resizeX = guiApp.resizeY = guiApp.resizeEndX = guiApp.resizeEndY = false;
3211 guiApp.windowIsResizing = false;
3215 void SelectMouseCursor(void)
3220 Window cursorWindow = null;
3221 bool rx, ry, rex, rey;
3223 guiApp.desktop.GetMousePosition(&x, &y);
3224 mouseWindow = rootWindow ? rootWindow.GetAtPosition(x,y, true, false, null) : null;
3226 if((guiApp.windowMoving && !guiApp.windowIsResizing) || guiApp.windowScrolling)
3227 guiApp.SetCurrentCursor(guiApp.systemCursors[moving]);
3228 else if(mouseWindow)
3230 modalWindow = mouseWindow.FindModal();
3231 x -= mouseWindow.absPosition.x;
3232 y -= mouseWindow.absPosition.y;
3233 if(guiApp.windowIsResizing)
3235 rex = guiApp.resizeEndX;
3236 rey = guiApp.resizeEndY;
3237 rx = guiApp.resizeX;
3238 ry = guiApp.resizeY;
3239 if((rex && rey) || (rx && ry))
3240 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
3241 else if((rex && ry) || (rx && rey))
3242 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
3243 else if((ry || rey) && (!rx && !rex))
3244 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
3245 else if((rx || rex) && (!ry && !rey))
3246 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
3248 else if(!modalWindow && !guiApp.windowCaptured &&
3249 mouseWindow.IsMouseResizing(x, y, mouseWindow.size.w, mouseWindow.size.h,
3250 &rx, &ry, &rex, &rey))
3252 if((rex && rey) || (rx && ry))
3253 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
3254 else if((rex && ry) || (rx && rey))
3255 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
3256 else if((ry || rey) && (!rx && !rex))
3257 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
3258 else if((rx || rex) && (!ry && !rey))
3259 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
3261 else if(!guiApp.windowCaptured && !modalWindow && !guiApp.interimWindow)
3263 if(!mouseWindow.clientArea.IsPointInside({x - mouseWindow.clientStart.x, y - mouseWindow.clientStart.y}))
3264 cursorWindow = mouseWindow.parent;
3266 cursorWindow = mouseWindow;
3268 else if(!guiApp.interimWindow)
3269 cursorWindow = guiApp.windowCaptured;
3272 for(; !cursorWindow.cursor && !cursorWindow.style.nonClient; cursorWindow = cursorWindow.parent);
3273 guiApp.SetCurrentCursor(cursorWindow.cursor ? cursorWindow.cursor : guiApp.systemCursors[arrow]);
3275 else if(modalWindow)
3277 guiApp.SetCurrentCursor(guiApp.systemCursors[arrow]);
3279 else if(guiApp.interimWindow)
3281 if(guiApp.interimWindow.cursor)
3282 guiApp.SetCurrentCursor(guiApp.interimWindow.cursor);
3284 guiApp.SetCurrentCursor(mouseWindow.cursor ? mouseWindow.cursor : guiApp.systemCursors[arrow]);
3289 // --- State based input ---
3290 bool AcquireInputEx(bool state)
3295 guiApp.interfaceDriver.GetMousePosition(&guiApp.acquiredMouseX, &guiApp.acquiredMouseY);
3296 guiApp.interfaceDriver.SetMousePosition(clientSize.w/2 + absPosition.x, clientSize.h/2 + absPosition.y);
3298 result = guiApp.interfaceDriver.AcquireInput(rootWindow, state);
3300 guiApp.acquiredWindow = state ? this : null;
3303 SetMouseRangeToClient();
3304 guiApp.interfaceDriver.SetMouseCursor((SystemCursor)-1);
3309 SelectMouseCursor();
3311 if(!state) guiApp.interfaceDriver.SetMousePosition(guiApp.acquiredMouseX, guiApp.acquiredMouseY);
3315 // --- Window activation ---
3316 bool PropagateActive(bool active, Window previous, bool * goOnWithActivation, bool direct)
3319 if(!parent || !parent.style.inactive)
3321 Window parent = this.parent;
3324 if(rootWindow == this)
3325 Log(active ? "active\n" : "inactive\n");
3328 // Testing this here...
3329 if(!parent || parent == guiApp.desktop || parent.active)
3331 this.active = active;
3334 // TESTING THIS HERE
3335 UpdateDecorations();
3336 if(result = OnActivate(active, previous, goOnWithActivation, direct) && *goOnWithActivation && master)
3337 result = NotifyActivate(master, this, active, previous);
3340 this.active = !active;
3345 if(!parent || parent == guiApp.desktop || parent.active)
3347 this.active = active;
3349 AcquireInputEx(active);
3354 if(guiApp.caretOwner)
3358 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 1,
3359 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + 1,
3360 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 2,
3361 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + guiApp.caretOwner.caretSize - 1
3363 guiApp.caretOwner.Update(extent);
3366 if(visible || !guiApp.caretOwner)
3367 guiApp.caretOwner = this;
3368 UpdateCaret(false, false);
3374 this.active = false;
3376 AcquireInputEx(active);
3378 if(!active && guiApp.caretOwner == this)
3380 UpdateCaret(false, true);
3381 guiApp.caretOwner = null;
3382 guiApp.interfaceDriver.SetCaret(0,0,0);
3383 guiApp.caretEnabled = false;
3388 if(!active && parent && parent.activeChild && parent.activeChild != this)
3389 if(!parent.activeChild.PropagateActive(false, previous, goOnWithActivation, true) || !*goOnWithActivation)
3395 if(!active && menuBar)
3398 menuBar.OnActivate(false, null, &goOn, true);
3399 menuBar.NotifyActivate(menuBar.master, menuBar, false, null);
3403 if(!activeChild.PropagateActive(active, previous, goOnWithActivation, false) || !*goOnWithActivation)
3412 void ConsequentialMouseMove(bool kbMoving)
3416 if(kbMoving || !guiApp.windowMoving)
3420 if(rootWindow == guiApp.desktop || rootWindow.parent == guiApp.desktop)
3422 guiApp.interfaceDriver.GetMousePosition(&x, &y);
3424 if(guiApp.windowMoving || rootWindow.GetAtPosition(x, y, true, false, null))
3425 rootWindow.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove, x, y, &mods, true, false);
3431 bool IsDescendantOf(Window ancestor)
3434 for(window = this; window && window != ancestor; window = window.parent);
3435 return window == ancestor;
3438 bool IsSlaveOf(Window master)
3441 for(window = this; window && window != master; window = window.master);
3442 return window == master;
3445 bool ActivateEx(bool active, bool activateParent, bool moveInactive, bool activateRoot, Window external, Window externalSwap)
3449 if(this && !destroyed /*&& state != Hidden*/)
3451 Window swap = externalSwap;
3459 if(activateParent &&
3460 (parent.activeChild != this ||
3461 (guiApp.interimWindow && !IsDescendantOf(guiApp.interimWindow))) &&
3462 active && _isModal &&
3463 parent != master && master)
3464 master.ActivateEx(true, true, false, activateRoot, external, externalSwap);
3470 bool real = parent.activeChild != this;
3472 // TEST THIS: New activateParent check here!!! CAUSED MENUS NOT GOING AWAY
3473 if(/*activateParent && */guiApp.interimWindow &&
3474 !IsDescendantOf(guiApp.interimWindow) &&
3475 !IsSlaveOf(guiApp.interimWindow))
3477 Window interimWindow = guiApp.interimWindow;
3478 while(interimWindow && interimWindow != this)
3480 Window master = interimWindow.master;
3482 guiApp.interimWindow = null;
3483 if(guiApp.caretOwner)
3484 guiApp.caretOwner.UpdateCaret(false, false);
3486 incref interimWindow;
3487 if(!interimWindow.PropagateActive(false, this, &goOn, true))
3492 delete interimWindow;
3493 interimWindow = (master && master.style.interim) ? master : null;
3498 guiApp.interimWindow = this;
3499 /*guiApp.interfaceDriver.SetCaret(0,0,0);
3500 guiApp.caretEnabled = false;*/
3501 UpdateCaret(false, true);
3506 bool acquireInput = false;
3508 parent.activeChild &&
3509 parent.activeChild.state == maximized &&
3510 parent != guiApp.desktop;
3512 if(!style.inactive) // (!style.isRemote || parent.active || parent.style.hidden))
3517 swap = parent.activeChild;
3518 if(swap && swap.destroyed) swap = null;
3519 if(swap && swap != this)
3522 if(!swap.PropagateActive(false, this, &goOn, true))
3523 swap = parent.activeChild;
3534 if(!parent || parent.activeChild != this || style.interim)
3537 result = PropagateActive(true, swap, &goOn, true);
3538 if(!result && !goOn)
3543 acquireInput = true;
3547 if(style.hasMaximize && parent != guiApp.desktop)
3550 SetState(maximized, false, 0);
3551 else if(state != maximized)
3554 for(child = parent.children.first; child; child = child.next)
3556 if(this != child && child.state == maximized)
3557 child.SetState(normal, false, 0);
3564 if(!style.inactive && !style.interim /*&& (!style.isRemote || parent.active || parent.style.hidden)*/)
3566 Window previous = parent.activeClient;
3567 parent.activeChild = this;
3568 if(!style.nonClient /*&& style.isActiveClient*/)
3570 if(style.isActiveClient && !style.hidden)
3571 parent.activeClient = this;
3572 parent.UpdateActiveDocument(previous);
3577 //if(!style.isRemote)
3579 if(rootWindow != this)
3581 if(activateParent && parent && !parent.active /*parent != parent.parent.activeChild*/)
3582 parent.ActivateEx(true, true, moveInactive, activateRoot, external, externalSwap);
3584 else if(!guiApp.fullScreenMode)
3586 Window modalRoot = FindModal();
3587 if(!modalRoot) modalRoot = this;
3588 if(!modalRoot.isForegroundWindow)
3590 modalRoot.isForegroundWindow = true;
3591 // To check : Why is parent null?
3592 if(activateRoot && modalRoot.parent && !modalRoot.parent.display && external != modalRoot)
3594 guiApp.interfaceDriver.ActivateRootWindow(modalRoot);
3596 modalRoot.isForegroundWindow = false;
3601 if(result && real && (!style.inactive || moveInactive) && parent)
3603 Window last = parent.children.last;
3605 if(!style.stayOnTop)
3606 for(; last && last.style.stayOnTop; last = last.prev);
3608 parent.children.Move(this, last);
3610 // Definitely don't want that: why not?
3614 parent.childrenOrder.Move(order, parent.childrenOrder.last);
3620 if(!parent || style.interim || (parent.activeChild == this && !style.inactive))
3627 parent.activeChild = null;
3628 if(!style.nonClient /*&& style.isActiveClient*/)
3630 Window previous = parent.activeClient;
3631 if(style.isActiveClient)
3632 parent.activeClient = null;
3633 parent.UpdateActiveDocument(previous);
3637 if(this == guiApp.interimWindow)
3639 guiApp.interimWindow = null;
3640 if(guiApp.caretOwner)
3641 guiApp.caretOwner.UpdateCaret(false, false);
3643 if(!PropagateActive(false, externalSwap, &goOn, true) || !goOn)
3650 if(!active || !swap)
3651 UpdateDecorations();
3653 swap.UpdateDecorations();
3655 if(active && rootWindow != this)
3656 ConsequentialMouseMove(false);
3663 // --- Input Messages ---
3664 void ::UpdateMouseMove(int mouseX, int mouseY, bool consequential)
3666 static bool reEntrancy = false;
3667 if(reEntrancy) return;
3671 guiApp.cursorUpdate = true;
3672 if(guiApp.windowScrolling && !consequential)
3674 guiApp.windowScrolling.SetScrollPosition(
3675 (guiApp.windowScrolling.sbh) ?
3676 (guiApp.windowScrollingBefore.x - mouseX + guiApp.windowScrollingStart.x) : 0,
3677 (guiApp.windowScrolling.sbv) ?
3678 (guiApp.windowScrollingBefore.y - mouseY + guiApp.windowScrollingStart.y) : 0);
3680 if(guiApp.windowMoving)
3682 if(mouseX != guiApp.movingLast.x || mouseY != guiApp.movingLast.y)
3684 Window window = guiApp.windowMoving;
3686 int w = window.size.w;
3687 int h = window.size.h;
3692 rx = mouseX - guiApp.windowMovingStart.x;
3693 ry = mouseY - guiApp.windowMovingStart.y;
3696 window.GetDecorationsSize(&ew, &eh);
3698 if(guiApp.windowIsResizing)
3700 x = window.scrolledPos.x;
3701 y = window.scrolledPos.y;
3705 aw = Max(guiApp.windowResizingBefore.w - rx,window.skinMinSize.w);
3706 rx = guiApp.windowResizingBefore.w - aw;
3707 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3708 w = guiApp.windowResizingBefore.w - rx;
3712 ah = Max(guiApp.windowResizingBefore.h - ry,window.skinMinSize.h);
3713 ry = guiApp.windowResizingBefore.h - ah;
3714 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3715 ry = Max(ry, -guiApp.windowMovingBefore.y);
3716 h = guiApp.windowResizingBefore.h - ry;
3718 if(guiApp.resizeEndX)
3720 w = guiApp.windowResizingBefore.w + rx;
3723 if(guiApp.resizeEndY) h = guiApp.windowResizingBefore.h + ry;
3731 w = Max(w, window.minSize.w);
3732 h = Max(h, window.minSize.h);
3733 w = Min(w, window.maxSize.w);
3734 h = Min(h, window.maxSize.h);
3736 if(!window.OnResizing(&w, &h))
3738 w = window.clientSize.w;
3739 h = window.clientSize.h;
3742 w = Max(w, window.skinMinSize.w);
3743 h = Max(h, window.skinMinSize.h);
3750 SNAPDOWN(w, textCellW);
3751 SNAPDOWN(h, textCellH);
3756 aw = Max(w,window.skinMinSize.w);
3757 rx = guiApp.windowResizingBefore.w - aw;
3758 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3759 w = guiApp.windowResizingBefore.w - rx;
3763 ah = Max(h,window.skinMinSize.h);
3764 ry = guiApp.windowResizingBefore.h - ah;
3765 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3766 ry = Max(ry, -guiApp.windowMovingBefore.y);
3767 h = guiApp.windowResizingBefore.h - ry;
3772 if(!guiApp.windowIsResizing || guiApp.resizeX)
3773 x = guiApp.windowMovingBefore.x + rx;
3774 if(!guiApp.windowIsResizing || guiApp.resizeY)
3775 y = guiApp.windowMovingBefore.y + ry;
3777 if(!guiApp.windowIsResizing)
3780 if(window.parent == guiApp.desktop && guiApp.virtualScreen.w)
3782 x = Min(x, (guiApp.virtualScreen.w + guiApp.virtualScreenPos.x) -1);
3783 y = Min(y, (guiApp.virtualScreen.h + guiApp.virtualScreenPos.y) -1);
3784 x = Max(x,-(w-1) + guiApp.virtualScreenPos.x);
3785 y = Max(y,-(h-1) + guiApp.virtualScreenPos.y);
3789 x = Min(x, (window.parent.reqScrollArea.w ? window.parent.reqScrollArea.w : window.parent.clientSize.w) -1);
3790 y = Min(y, (window.parent.reqScrollArea.h ? window.parent.reqScrollArea.h : window.parent.clientSize.h) -1);
3796 if(!guiApp.windowIsResizing || (guiApp.resizeX || guiApp.resizeY))
3798 if(!window.OnMoving(&x, &y, w, h))
3800 x = window.scrolledPos.x;
3801 y = window.scrolledPos.y;
3807 SNAPDOWN(x, textCellW);
3808 SNAPDOWN(y, textCellH);
3811 if(!window.style.nonClient)
3813 if(!window.style.fixed /*|| window.style.isDocument*/)
3815 if(!window.style.dontScrollHorz)
3816 x += window.parent.scroll.x;
3817 if(!window.style.dontScrollVert)
3818 y += window.parent.scroll.y;
3822 // Break the anchors for moveable/resizable windows
3823 // Will probably cause problem with IDE windows... Will probably need a way to specify if anchors should break
3824 if(window.style.fixed)
3826 if(window.state == normal)
3828 window.normalAnchor = Anchor { left = x, top = y };
3829 window.normalSizeAnchor = SizeAnchor { { w, h } };
3830 window.anchored = false;
3834 window.stateAnchor = Anchor { left = x, top = y };
3835 window.stateSizeAnchor = SizeAnchor { { w, h } };
3837 window.Position(x, y, w, h, false, true, guiApp.windowIsResizing, guiApp.windowIsResizing, false, true);
3838 // TOCHECK: Investigate why the following only redraws the scrollbars
3839 //window.Position(x, y, w, h, false, true, true, true, false, true);
3841 guiApp.movingLast.x = mouseX;
3842 guiApp.movingLast.y = mouseY;
3848 public bool MouseMessage(uint method, int x, int y, Modifiers * mods, bool consequential, bool activate)
3851 bool wasMoving = guiApp.windowMoving ? true : false;
3852 bool wasScrolling = guiApp.windowScrolling ? true : false;
3854 while(result && w != this)
3856 Window msgWindow = GetAtPosition(x,y, false, true, w);
3857 Window trueWindow = GetAtPosition(x,y, false, false, w);
3858 bool windowDragged = false;
3863 window = (w && !w.disabled) ? w : null;
3865 if(trueWindow) incref trueWindow;
3867 if(consequential) mods->isSideEffect = true;
3869 UpdateMouseMove(x, y, consequential);
3871 if(guiApp.windowCaptured && (guiApp.windowCaptured.rootWindow == this))
3873 if(!guiApp.windowCaptured.isEnabled)
3874 guiApp.windowCaptured.ReleaseCapture();
3876 window = guiApp.windowCaptured;
3879 if(trueWindow && activate &&
3880 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
3881 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
3882 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
3883 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
3885 if(mods->alt && !mods->ctrl && !mods->shift)
3887 Window moved = trueWindow;
3888 for(moved = trueWindow; moved; moved = moved.parent)
3889 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
3894 windowDragged = true;
3896 // Cancel the ALT menu toggling...
3897 window.rootWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
3902 if(window && activate &&
3903 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
3904 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
3905 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
3906 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
3908 Window modalWindow = window.FindModal();
3910 /*if(mods->alt && !mods->shift && !mods->ctrl)
3912 Window moved = window;
3913 for(moved = window; moved; moved = moved.parent)
3914 if(method == OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
3919 windowDragged = true;
3921 // Cancel the ALT menu toggling...
3922 window.rootWindow.KeyMessage(OnKeyDown, 0, 0);
3928 Window activateWindow = modalWindow ? modalWindow : window;
3929 if(activateWindow && !activateWindow.isRemote)
3931 bool doActivation = true;
3932 //bool needToDoActivation = false;
3933 Window check = activateWindow;
3935 for(check = activateWindow; check && check != guiApp.desktop; check = check.parent)
3937 if(!check.style.inactive)
3939 //needToDoActivation = true;
3941 doActivation = false;
3946 if(!needToDoActivation)
3947 doActivation = false;
3950 if((doActivation && (activateWindow.parent != guiApp.desktop || guiApp.fullScreen)) ||
3951 (guiApp.interimWindow && !window.IsDescendantOf(guiApp.interimWindow)))
3953 // Let the OnLeftButtonDown do the activating instead
3954 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
3962 incref activateWindow;
3963 if(!activateWindow.ActivateEx(true, true, false, true, null, null))
3965 delete activateWindow;
3969 if(activateWindow._refCount == 1)
3971 delete activateWindow;
3975 delete activateWindow;
3977 mods->isActivate = true;
3981 if(!modalWindow && window && !window.destroyed)
3983 if(!guiApp.windowCaptured || windowDragged)
3985 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown)
3987 bool moving = ((window.state != maximized &&
3988 window.IsMouseMoving(
3989 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
3990 || (guiApp.windowMoving && !guiApp.windowIsResizing);
3992 if(!moving && window.IsMouseResizing(
3993 x - window.absPosition.x,
3994 y - window.absPosition.y,
3995 window.size.w, window.size.h,
3996 &guiApp.resizeX, &guiApp.resizeY, &guiApp.resizeEndX, &guiApp.resizeEndY))
3998 guiApp.windowIsResizing = true;
3999 guiApp.windowResizingBefore.w = window.size.w;
4000 guiApp.windowResizingBefore.h = window.size.h;
4002 if(guiApp.windowIsResizing || windowDragged || moving)
4005 guiApp.windowMoving = window;
4006 guiApp.windowMovingStart.x = guiApp.movingLast.x = x;
4007 guiApp.windowMovingStart.y = guiApp.movingLast.y = y;
4008 guiApp.windowMovingBefore.x = window.position.x;//s;
4009 guiApp.windowMovingBefore.y = window.position.y;//s;
4010 if(guiApp.windowMoving == guiApp.windowMoving.rootWindow)
4011 guiApp.interfaceDriver.StartMoving(guiApp.windowMoving.rootWindow, 0,0,false);
4014 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown)
4016 if(window.style.fixed &&
4018 window.IsMouseMoving(
4019 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4021 window.ShowSysMenu(x, y);
4025 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown)
4027 if(window.sbv || window.sbh)
4030 guiApp.windowScrolling = window;
4031 guiApp.windowScrollingStart.x = x;
4032 guiApp.windowScrollingStart.y = y;
4033 guiApp.windowScrollingBefore.x = window.scroll.x;
4034 guiApp.windowScrollingBefore.y = window.scroll.y;
4037 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4039 if(window.style.hasMaximize &&
4040 window.IsMouseMoving(
4041 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h))
4044 (window.state == maximized) ? normal : maximized, false, *mods);
4052 if(guiApp.windowMoving)
4054 if(guiApp.windowMoving.parent)
4056 if(guiApp.windowMoving.style.nonClient)
4057 guiApp.windowMoving.parent.SetMouseRangeToWindow();
4059 guiApp.windowMoving.parent.SetMouseRangeToClient();
4063 window.UpdateDecorations();
4066 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp)
4068 // Log("\n*** LEFT BUTTON UP ***\n");
4069 if(guiApp.windowMoving)
4070 guiApp.windowMoving.StopMoving();
4072 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp)
4074 if(guiApp.windowScrolling)
4076 Window windowScrolling = guiApp.windowScrolling;
4077 guiApp.windowScrolling = null;
4078 windowScrolling.ReleaseCapture();
4082 if(!result || (window && window.destroyed)) window = null;
4084 if(window && window.FindModal())
4087 if(trueWindow && trueWindow.FindModal())
4095 msgWindow = GetAtPosition(x,y, true, false);
4097 msgWindow.SelectMouseCursor();
4100 if(guiApp.windowCaptured || trueWindow)
4102 Window prevWindow = guiApp.prevWindow;
4103 if(guiApp.prevWindow && trueWindow != guiApp.prevWindow)
4105 guiApp.prevWindow.mouseInside = false;
4106 guiApp.prevWindow = null;
4108 // Eventually fix this not to include captured?
4109 if(!prevWindow.OnMouseLeave(*mods))
4112 if(result && trueWindow && !trueWindow.destroyed/* && trueWindow == window*/)
4114 Box box = trueWindow.box;
4115 box.left += trueWindow.absPosition.x;
4116 box.right += trueWindow.absPosition.x;
4117 box.top += trueWindow.absPosition.y;
4118 box.bottom += trueWindow.absPosition.y;
4120 if(box.IsPointInside({x, y}) && trueWindow != /*guiApp.*/prevWindow /*!trueWindow.mouseInside*/)
4122 int overX = x - (trueWindow.absPosition.x + trueWindow.clientStart.x);
4123 int overY = y - (trueWindow.absPosition.y + trueWindow.clientStart.y);
4125 overX = Max(Min(overX, 32767),-32768);
4126 overY = Max(Min(overY, 32767),-32768);
4128 trueWindow.mouseInside = true;
4129 if(!trueWindow.OnMouseOver(overX, overY, *mods))
4133 if(trueWindow && trueWindow._refCount > 1 && !trueWindow.destroyed)
4134 guiApp.prevWindow = trueWindow;
4136 guiApp.prevWindow = null;
4138 SelectMouseCursor();
4140 if(window && !guiApp.windowMoving && !wasMoving && !wasScrolling)
4142 int clientX = x - (window.absPosition.x + window.clientStart.x);
4143 int clientY = y - (window.absPosition.y + window.clientStart.y);
4145 bool (* MouseMethod)(Window instance, int x, int y, Modifiers mods);
4147 clientX = Max(Min(clientX, 32767),-32768);
4148 clientY = Max(Min(clientY, 32767),-32768);
4150 MouseMethod = (void *)window._vTbl[method];
4152 if(MouseMethod /*&& !consequential*/ && !window.disabled)
4155 if(!MouseMethod(window, clientX, clientY, *mods))
4162 if(result && w && w.clickThrough && w.parent)
4167 if(!result || !w || !w.clickThrough)
4174 // --- Mouse cursor management ---
4176 bool KeyMessage(uint method, Key key, unichar character)
4181 if(guiApp.interimWindow)
4182 this = guiApp.interimWindow;
4185 if((SmartKey)key != alt && (SmartKey)key != Key::control && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && parent && this != parent.menuBar)
4189 if(!style.inactive || rootWindow != this)
4191 bool (*KeyMethod)(Window window, Key key, unichar ch) = (void *)_vTbl[method];
4192 Window modalWindow = FindModal();
4193 Window interimMaster = master ? master.rootWindow : null;
4197 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4198 status = OnSysKeyDown(key, character);
4199 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4200 status = OnSysKeyHit(key, character);
4201 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4202 status = OnSysKeyUp(key, character);
4209 // Process Key Message for Internal UI Keyboard actions
4210 if(status && !destroyed && menuBar && state != minimized)
4213 if((SmartKey)key != alt)
4214 menuBar.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4217 SmartKey sk = (SmartKey) key;
4218 if((character && !key.alt && !key.ctrl) || sk == left || sk == right || sk == up || sk == down || sk == home || sk == end || sk == escape || sk == alt)
4220 status = menuBar.KeyMessage(method, key, character);
4225 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4226 menuBar.OnKeyHit(escape, 0);
4228 if(!menuBar.focus && guiApp.caretOwner)
4229 guiApp.caretOwner.UpdateCaret(true, false);
4232 if(!destroyed && status)
4234 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4238 case left: case up: case right: case down:
4239 if(guiApp.windowMoving == this)
4242 int w = guiApp.windowMoving.size.w;
4243 int h = guiApp.windowMoving.size.h;
4244 int x = guiApp.windowMoving.scrolledPos.x;
4245 int y = guiApp.windowMoving.scrolledPos.y;
4249 if(key == down || key == up)
4250 step = Max(step, textCellH);
4252 step = Max(step, textCellW);
4255 if(guiApp.windowIsResizing)
4259 case left: w-=step; break;
4260 case right: w+=step; break;
4261 case up: h-=step; break;
4262 case down: h+=step; break;
4269 case left: x-=step; break;
4270 case right: x+=step; break;
4271 case up: y-=step; break;
4272 case down: y+=step; break;
4276 if(guiApp.resizeX) x += w - guiApp.windowMoving.size.w;
4277 if(guiApp.resizeY) y += h - guiApp.windowMoving.size.h;
4279 if(!guiApp.windowIsResizing || guiApp.resizeX)
4280 x = (x - guiApp.windowMovingBefore.x) + guiApp.windowMovingStart.x;
4282 x = (w - guiApp.windowResizingBefore.w) + guiApp.windowMovingStart.x;
4284 if(!guiApp.windowIsResizing || guiApp.resizeY)
4285 y = (y - guiApp.windowMovingBefore.y) + guiApp.windowMovingStart.y;
4287 y = (h - guiApp.windowResizingBefore.h) + guiApp.windowMovingStart.y;
4289 guiApp.interfaceDriver.SetMousePosition(x, y);
4290 ConsequentialMouseMove(true);
4298 if(guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4300 guiApp.windowMoving.StopMoving();
4301 ConsequentialMouseMove(false);
4309 ShowSysMenu(absPosition.x, absPosition.y);
4317 if(!destroyed && status && state != minimized)
4319 // Process all the way down the children
4320 if(activeChild && !activeChild.disabled)
4322 status = activeChild.KeyMessage(method, key, character);
4324 if(status && activeClient && activeChild != activeClient && !activeClient.disabled && (key.alt || key.ctrl) &&
4325 key.code != left && key.code != right && key.code != up && key.code != down)
4327 status = activeClient.KeyMessage(method, key, character);
4331 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4333 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && !defaultControl.disabled && state != minimized)
4334 // && defaultControl != activeChild)
4336 delete previousActive;
4337 previousActive = activeChild;
4338 if(previousActive) incref previousActive;
4340 ConsequentialMouseMove(false);
4341 if((defaultControl.active ||
4342 defaultControl.ActivateEx(true, true, false, true, null, null)) && !defaultControl.disabled)
4343 defaultControl.KeyMessage(method, defaultKey, character);
4349 if(!destroyed && status && (!modalWindow || this == guiApp.desktop))
4351 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4358 ShowSysMenu(absPosition.x, absPosition.y);
4365 if(this != guiApp.desktop)
4367 if(!guiApp.windowMoving && !guiApp.windowCaptured)
4369 if(state != maximized && (key.shift ? style.sizeable : style.fixed))
4371 MenuMoveOrSize(key.shift, true);
4375 else if(guiApp.windowMoving)
4377 guiApp.windowMoving.StopMoving();
4378 ConsequentialMouseMove(false);
4386 if(!destroyed && status && state != minimized)
4388 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4392 case tab: case shiftTab:
4394 Window cycleParent = this;
4395 if(this == guiApp.interimWindow && !master.style.interim && !cycleParent.style.tabCycle)
4396 cycleParent = master.parent;
4398 if(!guiApp.windowCaptured && cycleParent.style.tabCycle)
4400 if(cycleParent.CycleChildren(!key.shift, false, false, true))
4402 Window child = cycleParent.activeChild;
4404 // Scroll the window to include the active control
4406 if(cycleParent.sbh && !child.style.dontScrollHorz)
4408 if(child.scrolledPos.x < 0)
4409 cycleParent.sbh.Action(Position,
4410 cycleParent.scroll.x + child.scrolledPos.x, 0);
4411 else if(child.scrolledPos.x + child.size.w > cycleParent.clientSize.w)
4412 cycleParent.sbh.Action(Position,
4413 cycleParent.scroll.x + child.scrolledPos.x + child.size.w - cycleParent.clientSize.w, 0);
4415 if(cycleParent.sbv && !child.style.dontScrollVert)
4417 if(child.scrolledPos.y < 0)
4418 cycleParent.sbv.Action(Position,
4419 cycleParent.scroll.y + child.scrolledPos.y, 0);
4420 else if(child.scrolledPos.y + child.size.w > window.clientSize.h)
4421 cycleParent.sbv.Action(Position,
4422 cycleParent.scroll.y + child.scrolledPos.y+child.size.h - cycleParent.clientSize.h, 0);
4425 cycleParent.ConsequentialMouseMove(false);
4431 case f6: case shiftF6:
4432 if(!guiApp.windowMoving /*!guiApp.windowCaptured*/)
4434 // NOT NEEDED... guiApp.windowMoving.ReleaseCapture();
4435 if(parent == guiApp.desktop)
4436 if(guiApp.desktop.CycleChildren(key.shift, true, false, true))
4441 if(style.tabCycle ||
4442 CycleChildren(key.shift, true, false, true))
4450 // mIRC Style Window Shortcuts
4451 case alt1: case alt2: case alt3: case alt4: case alt5:
4452 case alt6: case alt7: case alt8: case alt9: case alt0:
4457 for(document = children.first; document; document = document.next)
4459 if(document.style.isDocument && document.documentID - 1 == key.code - k1)
4461 if(document == activeChild)
4463 if(document.state == minimized)
4464 document.SetState(normal, false, key);
4467 document.SetState(minimized, false, key);
4468 CycleChildren(false, true, false);
4473 if(activeChild.state == maximized && document.style.hasMaximize)
4474 document.SetState(maximized, false, key);
4475 else if(document.state == minimized)
4476 document.SetState(normal, false, key);
4477 document.Activate();
4492 if(!destroyed && status)
4494 if(state == minimized)
4499 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4501 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && previousActive)
4503 if(defaultControl.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, key, character))
4504 previousActive.ActivateEx(true, false, false, true, null, null);
4505 delete previousActive;
4511 if(!destroyed && status)
4513 status = ProcessHotKeys(method, key, character);
4515 if(!destroyed && status && !modalWindow && state != minimized)
4518 status = KeyMethod(this, key, character);
4519 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4520 status = OnKeyHit(key, character);
4521 if(!destroyed && status && (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit))
4523 bool result = false;
4526 case ctrlUp: case ctrlDown:
4527 if(sbv && !guiApp.windowScrolling)
4528 result = sbv.Action((key == ctrlUp) ? up : down, 0, key);
4530 case wheelUp: case wheelDown:
4531 if(sbv && !guiApp.windowScrolling)
4533 result = sbv.Action((key == wheelUp) ? wheelUp : wheelDown, 0, key);
4534 // Do we want to do a consequential move regardless of result in this case?
4535 ConsequentialMouseMove(false);
4538 case ctrlPageUp: case ctrlPageDown:
4539 if(sbh && !guiApp.windowScrolling)
4540 result = sbh.Action((key == ctrlPageUp) ? up : down, 0, key);
4545 ConsequentialMouseMove(false);
4550 if(status && !destroyed && menuBar && state != minimized)
4551 status = menuBar.KeyMessage(method, key, character);
4553 if(style.interim && /*destroyed && */status && interimMaster)
4555 // Testing this... for Ctrl-O to open dialog when autocompletion listbox is popped...
4556 status = interimMaster.KeyMessage(method, key, character);
4563 bool ProcessHotKeys(uint method, Key key, unichar character)
4568 for(hotKey = hotKeys.first; hotKey; hotKey = hotKey.next)
4569 if((hotKey.key == key || (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp && hotKey.key.code == key.code)) &&
4570 !hotKey.window.disabled && (hotKey.window.style.nonClient || state != minimized))
4572 Window hotKeyWindow = hotKey.window;
4573 Window parent = hotKeyWindow.parent;
4574 Window prevActiveWindow = activeChild;
4576 // Don't process non-visible buttons, but make an exception for the Alt-F4 with Native Decorations turned on
4577 if(hotKeyWindow.style.hidden && (!hotKeyWindow.style.nonClient || !parent || !parent.nativeDecorations || (hotKeyWindow != parent.sysButtons[2] && hotKeyWindow != parent.sysButtons[1] )))
4580 if(prevActiveWindow) incref prevActiveWindow;
4581 incref hotKeyWindow;
4582 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && !hotKeyWindow.style.nonClient)
4583 if(!hotKeyWindow.ActivateEx(true, true, false, true, null, null))
4586 delete hotKeyWindow;
4587 delete prevActiveWindow;
4591 if(hotKeyWindow.style.nonClient && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4592 method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
4593 if(!hotKeyWindow.KeyMessage(method, Key::hotKey, character))
4595 // ********* WORKING ON THIS ***********
4596 if(prevActiveWindow && !guiApp.interimWindow)
4597 prevActiveWindow.ActivateEx(true, false, false, false, null, null);
4600 else if(hotKeyWindow.style.inactive)
4601 status = hotKeyWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, Key::hotKey, character);
4603 delete prevActiveWindow;
4604 delete hotKeyWindow;
4605 // For Key Ups, don't set status to false... (e.g.: Releasing Enter vs AltEnter hot key)
4606 if(method != __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4610 if(status && tabCycle)
4613 for(child = children.first; child; child = child.next)
4615 if(child.tabCycle && !child.ProcessHotKeys(method, key, character))
4626 // --- Windows and graphics initialization / termination ---
4627 bool SetupRoot(void)
4631 // Setup relationship with outside world (bb root || !bb)
4632 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || this == guiApp.desktop ||
4633 (_displayDriver && dispDriver != parent.dispDriver))
4637 tempExtents = new0 Extent[4];
4642 /*if(guiApp.fullScreenMode)
4643 rootWindow = guiApp.desktop;
4645 //rootWindow = parent.created ? parent.rootWindow : null;
4646 rootWindow = parent.rootWindow;
4649 against = &parent.box;
4651 against = &parent.clientArea;
4654 for(child = children.first; child; child = child.next)
4657 return (rootWindow && (rootWindow == this || rootWindow.created)) ? true : false;
4660 bool Setup(bool positionChildren)
4662 bool result = false;
4665 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || (guiApp.fullScreenMode && (this == guiApp.desktop || (_displayDriver && dispDriver != parent.dispDriver))))
4667 subclass(DisplayDriver) dDriver = (dispDriver && !formDesigner) ? dispDriver : GetDisplayDriver(guiApp.defaultDisplayDriver);
4668 DisplaySystem displaySystem = dDriver ? dDriver.displaySystem : null;
4670 windowHandle = dDriver.printer ? null : guiApp.interfaceDriver.CreateRootWindow(this);
4672 // This was here, is it really needed?
4673 //guiApp.interfaceDriver.ActivateRootWindow(this);
4677 displaySystem = DisplaySystem {};
4678 if(!displaySystem.Create(dDriver.name, guiApp.fullScreenMode ? windowHandle : windowHandle /*null*/, guiApp.fullScreenMode))
4680 delete displaySystem;
4685 display = Display { alphaBlend = alphaBlend, useSharedMemory = useSharedMemory, windowDriverData = windowData };
4686 if(display.Create(displaySystem, windowHandle))
4693 guiApp.interfaceDriver.SetIcon(this, icon);
4695 else if(this != guiApp.desktop)
4697 display = rootWindow ? rootWindow.display : null;
4703 if(guiApp.acquiredWindow && rootWindow == guiApp.acquiredWindow.rootWindow)
4704 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, true);
4706 for(child = children.first; child; child = child.next)
4708 if(child.created && !child.Setup(false))
4714 bool SetupDisplay(void)
4716 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
4717 if(is3D) return Window3D_SetupDisplay(this); else
4724 class_data void ** pureVTbl;
4726 bool LoadGraphics(bool creation, bool resetAnchors)
4728 bool result = false;
4729 bool success = false;
4731 WindowState stateBackup = state;
4734 if(!rootWindow.created)
4738 if(((subclass(Window))_class).pureVTbl)
4740 if(_vTbl == _class._vTbl)
4742 _vTbl = ((subclass(Window))_class).pureVTbl;
4747 for(m = 0; m < _class.vTblSize; m++)
4749 if(_vTbl[m] == _class._vTbl[m])
4750 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
4754 if(guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
4756 if(_vTbl == ((subclass(Window))_class).pureVTbl)
4758 _vTbl = _class._vTbl;
4763 for(m = 0; m < _class.vTblSize; m++)
4765 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
4766 _vTbl[m] = _class._vTbl[m];
4771 if(guiApp.fullScreenMode || this != guiApp.desktop)
4773 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
4779 display.Lock(false);
4780 if(rootWindow == this)
4782 // Set Color Palette
4783 display.SetPalette(palette, true);
4787 if(guiApp.fullScreenMode && this == guiApp.desktop)
4792 for(c=0; c<SystemCursor::enumSize; c++)
4793 if(!guiApp.systemCursors[c].bitmap)
4795 guiApp.systemCursors[c].bitmapName = guiApp.currentSkin.CursorsBitmaps(c,
4796 &guiApp.systemCursors[c].hotSpotX,&guiApp.systemCursors[c].hotSpotY, &guiApp.systemCursors[c].paletteShades);
4797 if(guiApp.systemCursors[c].bitmapName)
4799 guiApp.systemCursors[c].bitmap = eBitmap_LoadT(guiApp.systemCursors[c].bitmapName, null,
4800 guiApp.systemCursors[c].paletteShades ? null : guiApp.desktop.display.displaySystem);
4801 if(guiApp.systemCursors[c].bitmap)
4802 guiApp.systemCursors[c].bitmap.paletteShades = guiApp.systemCursors[c].paletteShades;
4807 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
4809 cursor.bitmap = eBitmap_LoadT(cursor.bitmapName, null,
4810 cursor.paletteShades ? null : guiApp.desktop.display.displaySystem);
4812 cursor.bitmap.paletteShades = cursor.paletteShades;
4816 guiApp.cursorUpdate = true;
4819 ConsequentialMouseMove(false);
4825 // Load Window Graphic Resources
4828 if(usedFont == setFont || usedFont == window.systemFont)
4829 RemoveResource(usedFont);
4832 RemoveResource(setFont); // TESTING setFont instead of usedFont);
4835 RemoveResource(systemFont);
4838 RemoveResource(captionFont);
4840 for(ptr = resources.first; ptr; ptr = ptr.next)
4842 ptr.loaded = display.displaySystem.LoadResource(ptr.resource);
4845 AddResource(setFont);
4847 AddResource(systemFont);
4849 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
4856 //if(master && master.font)
4857 if(parent && parent.font)
4861 faceName = parent.font.faceName,
4862 size = parent.font.size,
4863 bold = parent.font.bold,
4864 italic = parent.font.italic,
4865 underline = parent.font.underline
4867 //font = parent.font;
4868 watch(parent) { font { } };
4871 font = guiApp.currentSkin.SystemFont();
4878 captionFont = guiApp.currentSkin.CaptionFont();
4879 AddResource(captionFont);
4881 if(OnLoadGraphics())
4887 //SetScrollLineStep(sbStep.x, sbStep.y);
4889 if(this != guiApp.desktop)
4893 normalAnchor = anchor;
4894 normalSizeAnchor = sizeAnchor;
4897 // Break the anchors for moveable/resizable windows
4899 if(style.fixed && style.isDocument)
4901 ComputeAnchors(ax, ay, aw, ah, &x, &y, &w, &h);
4913 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
4914 stateSizeAnchor = SizeAnchor {};
4919 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
4924 left = (iconID % maxIcons) * MINIMIZED_WIDTH,
4925 bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24)
4928 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
4932 stateAnchor = normalAnchor;
4933 stateSizeAnchor = normalSizeAnchor;
4936 position = Point { };
4937 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
4948 if(Position(x, y, w, h, true, false, true, true, true, true))
4950 if((this != guiApp.desktop || guiApp.fullScreenMode) && rootWindow == this)
4953 guiApp.interfaceDriver.SetRootWindowState(this, normal, true);
4970 success = result = true;
4973 if(!creation && result)
4975 // Load menu bar first because sys buttons are on it...
4978 if(!menuBar.LoadGraphics(false, resetAnchors))
4984 for(child = children.first; child; child = child.next)
4986 if(child.created && child != menuBar && !child.LoadGraphics(false, resetAnchors))
4993 CreateSystemChildren();
4997 if(this == guiApp.desktop && !guiApp.fullScreenMode)
5000 guiApp.interfaceDriver.ActivateRootWindow(activeChild);
5005 //guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, caption);
5006 guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, class.name);
5009 // Do this here to avoid problems on Windows
5010 if(stateBackup == maximized)
5011 property::state = maximized;
5015 void UnloadGraphics(bool destroyWindows)
5019 // Free children's graphics
5020 for(child = children.first; child; child = child.next)
5021 child.UnloadGraphics(destroyWindows);
5024 display.Lock(false);
5027 if(guiApp.fullScreenMode && this == guiApp.desktop)
5032 for(c=0; c<SystemCursor::enumSize; c++)
5033 if(guiApp.systemCursors[c].bitmap)
5034 delete guiApp.systemCursors[c].bitmap;
5036 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5037 delete cursor.bitmap;
5039 guiApp.cursorBackground.Free();
5042 if(display && display.displaySystem)
5046 for(ptr = resources.first; ptr; ptr = ptr.next)
5050 display.displaySystem.UnloadResource(ptr.resource, ptr.loaded);
5055 // Free window graphics
5058 // Free skin graphics
5059 if(rootWindow == this)
5061 DisplaySystem displaySystem = display.displaySystem;
5064 display.driverData = null;
5065 display.displaySystem = null;
5069 if(displaySystem && !displaySystem.numDisplays && !is3D)
5070 delete displaySystem;
5079 if(guiApp.acquiredWindow && this == guiApp.acquiredWindow.rootWindow)
5080 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, false);
5082 if(this == guiApp.desktop || parent == guiApp.desktop)
5084 if((guiApp.fullScreenMode || this != guiApp.desktop) && rootWindow == this && windowHandle && destroyWindows)
5085 guiApp.interfaceDriver.DestroyRootWindow(this);
5089 // --- Window Hiding ---
5091 void SetVisibility(bool state)
5093 bool visible = (style.hidden || !created) ? false : state;
5094 if(visible != this.visible)
5098 this.visible = visible;
5099 for(child = children.first; child; child = child.next)
5100 child.SetVisibility(visible);
5102 ConsequentialMouseMove(false);
5106 // --- Windows and graphics initialization / termination ---
5108 bool DisplayModeChanged(void)
5110 bool result = false;
5111 if(!guiApp.fullScreenMode && !guiApp.modeSwitching/* && guiApp.desktop.active*/)
5113 guiApp.modeSwitching = true;
5114 UnloadGraphics(false);
5116 if(LoadGraphics(false, false))
5118 guiApp.modeSwitching = false;
5123 // --- Window updates system ---
5125 void UpdateDirty(Box updateBox)
5127 if(!manageDisplay) { OnRedraw(null);return; }
5130 if(display && (!guiApp.fullScreenMode || guiApp.desktop.active) && !guiApp.modeSwitching)
5133 if(display.flags.flipping)
5136 rootWindow.UpdateDisplay();
5139 UpdateBackDisplay(updateBox);
5141 if(guiApp.fullScreenMode)
5143 guiApp.cursorUpdate = true;
5144 guiApp.PreserveAndDrawCursor();
5146 if(guiApp.fullScreenMode)
5147 guiApp.RestoreCursorBackground();
5153 // This function is strictly called as a result of system window activation
5154 bool ExternalActivate(bool active, bool activateRoot, Window window, Window swap)
5157 Window interimMaster = null;
5158 Window interimWindow = guiApp.interimWindow;
5159 if(interimWindow && interimWindow.master)
5160 interimMaster = interimWindow.master.rootWindow;
5162 if(active && state == minimized) // && (!window.nativeDecorations || window.rootWindow != window)
5163 // SetState(normal, false, 0);
5164 SetState(lastState, false, 0);
5166 if(interimMaster && swap == interimMaster && interimMaster.IsSlaveOf(window))
5170 /* WTH is this doing here?
5171 while(swap && swap.activeChild)
5173 swap = swap.activeChild;
5176 // TESTING THIS BEFORE...
5177 if(interimWindow && this == interimMaster)
5181 // Window interimSwap = this;
5182 Window menuBar = this.menuBar;
5183 if(menuBar && interimWindow.master == menuBar)
5186 while(interimSwap && interimSwap.activeChild)
5187 interimSwap = interimSwap.activeChild;
5189 result = interimWindow.ActivateEx(false, false, false, activateRoot, null,
5190 (menuBar && interimWindow.master == menuBar) ? menuBar : interimSwap);
5192 result = /*interimWindow.*/ActivateEx(false, false, false, activateRoot, null, menuBar);
5193 //result = ActivateEx(true, true, false, activateRoot, window, null);
5198 // Testing & FindModal() here: broke reactivating when a modal dialog is up (didn't root activate dialog)
5199 result = ActivateEx(active, active, false, activateRoot /*&& FindModal()*/, window, swap);
5201 if(interimWindow == this && interimMaster && !active)
5203 while(interimMaster && interimMaster.interim && interimMaster.master)
5205 // printf("Going up one master %s\n", interimMaster._class.name);
5206 interimMaster = interimMaster.master.rootWindow;
5208 // printf("Unactivating interim master %s (%x)\n", interimMaster._class.name, interimMaster);
5209 interimMaster.ActivateEx(active, active, false, activateRoot, window, swap);
5215 bool DestroyEx(int returnCode)
5218 Timer timer, nextTimer;
5220 OldLink prevOrder = null;
5221 Window client = null;
5223 if(parent) stopwatching(parent, font);
5225 // if(window.modalSlave) return false;
5226 if(destroyed || !created)
5233 OldLink slave = master.slaves.FindLink(this);
5234 master.slaves.Delete(slave);
5237 // TOFIX IMMEDIATELY: COMMENTED THIS OUT... causes problem second time creating file dialog
5243 this.returnCode = (DialogResult)returnCode;
5245 AcquireInput(false);
5250 master.hotKeys.Delete(hotKey);
5254 if(guiApp.prevWindow == this)
5256 guiApp.prevWindow = null;
5259 if(guiApp.caretOwner == this)
5261 guiApp.interfaceDriver.SetCaret(0,0,0);
5262 UpdateCaret(false, true);
5263 guiApp.caretEnabled = false;
5268 parent.childrenCycle.Remove(cycle);
5272 OldLink tmpPrev = order.prev;
5273 if(tmpPrev && !(((Window)tmpPrev.data).style.hidden) && !(((Window)tmpPrev.data).destroyed) && (((Window)tmpPrev.data).created))
5274 prevOrder = tmpPrev;
5277 client = tmpPrev ? tmpPrev.data : null;
5278 if(client == this) { client = null; break; }
5279 if(client && (client.style.hidden || client.destroyed || !client.created))
5280 tmpPrev = client.order.prev;
5284 prevOrder = tmpPrev;
5289 // If this window can be an active client, make sure the next window we activate can also be one
5290 if(!style.nonClient && style.isActiveClient)
5292 tmpPrev = prevOrder;
5295 client = tmpPrev ? tmpPrev.data : null;
5296 if(client == this) { client = null; break; }
5297 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
5298 tmpPrev = client.order.prev;
5302 prevOrder = tmpPrev;
5306 if(client && client.style.hidden) client = null;
5308 // parent.childrenOrder.Remove(order);
5311 if(parent && style.isActiveClient && visible)
5313 if(state == minimized) parent.numIcons--;
5314 parent.numPositions--;
5317 // TESTING THIS HERE!
5321 // If no display, don't bother deactivating stuff (causes unneeded problems when trying
5322 // to create a window inside a rootwindow that's being destroyed)
5323 // DISABLED THIS BECAUSE OF CREATING WINDOW IN DESKTOP IN WINDOWED MODE
5325 if(master && !master.destroyed /*&&
5326 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5328 if(master.defaultControl == this)
5329 master.defaultControl = null;
5331 if(parent && !parent.destroyed /*&&
5332 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5334 if((parent.activeChild == this /*|| parent.activeClient == this */|| guiApp.interimWindow == this))
5336 if(order && prevOrder && prevOrder.data != this && active)
5338 //((Window)prevOrder.data).ActivateEx(true, false, false, false /*true*/, null);
5340 ((Window)prevOrder.data).ActivateEx(true, false, false, (rootWindow == this) ? true : false, null, null);
5341 if(parent.activeClient == this)
5343 parent.activeClient = null;
5344 parent.UpdateActiveDocument(null);
5349 if(guiApp.interimWindow == this)
5352 PropagateActive(false, null, &goOn, true);
5356 //if(window.parent.activeChild == window)
5357 parent.activeChild = null;
5358 if(!style.nonClient /*&& style.isActiveClient*/)
5360 Window previous = parent.activeClient;
5361 if(style.isActiveClient)
5362 parent.activeClient = null;
5363 parent.UpdateActiveDocument(previous);
5368 else if(parent.activeClient == this)
5370 parent.activeClient = client;
5371 parent.UpdateActiveDocument(this);
5375 if(guiApp.interimWindow == this)
5377 guiApp.interimWindow = null;
5378 if(guiApp.caretOwner)
5380 Window desktop = guiApp.desktop;
5381 if(desktop.activeChild && desktop.activeChild.menuBar && !desktop.activeChild.menuBar.focus)
5382 guiApp.caretOwner.UpdateCaret(false, false);
5387 if(_isModal && master && master.modalSlave == this)
5388 master.modalSlave = null;
5392 if(!guiApp.caretOwner && parent.caretSize)
5394 guiApp.caretOwner = parent;
5395 parent.UpdateCaret(false, false);
5396 parent.Update(null);
5399 // Why was this commented out?
5400 GetRidOfVirtualArea();
5406 dirtyArea.Free(null);
5407 dirtyBack.Free(null);
5408 scrollExtent.Free(null);
5410 /* ATTEMPTING TO MOVE THAT ABOVE
5419 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5420 for(;(child = window.children.first);)
5422 for(; child && (child.destroyed || !child.created); child = child.next);
5431 UnloadGraphics(true);
5434 delete previousActive;
5437 // statusBar = null;
5440 if(master && !master.destroyed)
5442 //master.NotifyDestroyed(this, this.returnCode);
5443 NotifyDestroyed(master, this, this.returnCode);
5446 for(timer = guiApp.windowTimers.first; timer; timer = nextTimer)
5448 nextTimer = timer.next;
5449 if(timer.window == this)
5451 // WHY WERE WE SETTING THIS TO NULL? NO MORE WINDOW WHEN RECREATING...
5452 // timer.window = null;
5458 if(this == guiApp.windowMoving)
5461 if(guiApp.windowCaptured == this)
5463 //guiApp.windowCaptured = null;
5465 if(rootWindow != this && rootWindow)
5466 rootWindow.ConsequentialMouseMove(false);
5474 //for(child = children.first; next = child ? child.next : null, child; child = next)
5475 for(;(child = children.first); )
5477 for(; child && (child.destroyed || !child.created); child = child.next);
5487 /* // MOVED THIS UP...
5490 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5491 for(;(child = window.children.first); )
5493 for(; child && (child.destroyed || !child.created); child = child.next);
5502 while((slave = slaves.first))
5504 for(; slave && (((Window)slave.data).destroyed || !((Window)slave.data).created); slave = slave.next);
5506 ((Window)slave.data).DestroyEx(0);
5511 if(guiApp.caretOwner == this)
5512 guiApp.caretOwner = null;
5514 sysButtons[0] = null;
5515 sysButtons[1] = null;
5516 sysButtons[2] = null;
5519 if(rootWindow != this)
5521 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
5524 box.left -= parent.clientStart.x;
5525 box.top -= parent.clientStart.y;
5526 box.right -= parent.clientStart.x;
5527 box.bottom -= parent.clientStart.y;
5529 if(parent) parent.Update(box);
5534 OldLink slave = master.slaves.FindVoid(this);
5535 master.slaves.Delete(slave);
5541 parent.children.Remove(this);
5546 //autoCreate = false;
5549 // SHOULD THIS BE HERE? FIXED CRASH WITH GOTO DIALOG
5550 if(((subclass(Window))_class).pureVTbl)
5552 if(_vTbl == _class._vTbl)
5554 _vTbl = ((subclass(Window))_class).pureVTbl;
5559 for(m = 0; m < _class.vTblSize; m++)
5561 if(_vTbl[m] == _class._vTbl[m])
5562 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5571 void SetStateEx(WindowState newState, bool activate)
5574 WindowState prevState = state;
5578 if(prevState != newState)
5579 lastState = prevState;
5581 if(rootWindow != this || !nativeDecorations)
5583 if(style.isActiveClient && !style.hidden && prevState == minimized)
5586 // This block used to be at the end of the function... moved it for flicker problem in X
5587 // ------------------------------------------------------
5591 stateAnchor = normalAnchor;
5592 stateSizeAnchor = normalSizeAnchor;
5595 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5596 stateSizeAnchor = SizeAnchor {};
5600 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5603 byte * idBuffer = new0 byte[size];
5605 for(child = parent.children.first; child; child = child.next)
5607 if(child != this && child.state == minimized)
5609 if(child.iconID > size - 2)
5611 idBuffer = renew0 idBuffer byte[size*2];
5612 memset(idBuffer + size, 0, size);
5615 idBuffer[child.iconID] = (byte)bool::true;
5618 for(c = 0; c<size; c++)
5623 if(style.isActiveClient && !style.hidden)
5626 stateAnchor = Anchor { left = (iconID % maxIcons) * MINIMIZED_WIDTH, bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24) };
5627 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
5631 // TOCHECK: Why was this here?
5632 //position.x = (tx > 0) ? tx & 0xFFFFF : tx;
5633 //position.y = (ty > 0) ? ty & 0xFFFFF : ty;
5634 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5636 Position(x, y, w, h, true, true, true, true, false, true);
5638 if(!style.inactive && !style.interim && this == parent.activeClient)
5639 parent.UpdateActiveDocument(null);
5642 CreateSystemChildren();
5643 // ------------------------------------------------------
5646 int GetPositionID(Window forChild)
5650 byte * idBuffer = new0 byte[size];
5653 for(child = children.first; child; child = child.next)
5655 if(child.style.isActiveClient && !child.style.hidden && child != forChild)
5657 if(child.positionID > size - 2)
5659 idBuffer = renew0 idBuffer byte[size*2];
5660 memset(idBuffer + size, 0, size);
5663 idBuffer[child.positionID] = (byte)bool::true;
5666 for(c = 0; c<size; c++)
5673 // --- Window related graphics ---
5675 void SetPalette(ColorAlpha * newPalette, bool colorMatch)
5677 palette = newPalette;
5678 if(rootWindow.display)
5679 rootWindow.display.SetPalette(palette, colorMatch);
5682 public bool AcquireInput(bool acquired)
5685 if(acquiredInput != acquired)
5687 if(active || (!visible && creationActivation == activate))
5688 result = AcquireInputEx(acquired);
5693 acquiredInput = acquired ? result : !result;
5698 void ListChildren(ListBox listBox)
5702 for(child = children.first; child; child = child.next)
5704 if(child.cycle && !child.style.nonClient && child.style.isActiveClient && child.visible)
5706 DataRow row = listBox.AddRow();
5707 row.tag = (int)child;
5708 child.FigureCaption(caption);
5709 row.SetData(null, caption);
5714 void UpdateVisual(Box extent)
5716 if(guiApp.driver != null)
5718 if(guiApp.fullScreenMode && guiApp.desktop.display)
5720 guiApp.desktop.mutex.Wait();
5721 guiApp.desktop.display.Lock(true);
5724 if(guiApp.desktop.active)
5726 if(guiApp.desktop.dirty || guiApp.cursorUpdate)
5728 if(guiApp.desktop.display.flags.flipping)
5729 guiApp.desktop.Update(null);
5730 guiApp.desktop.UpdateDisplay();
5731 guiApp.cursorUpdate = true;
5733 if(guiApp.cursorUpdate || guiApp.desktop.dirty)
5735 guiApp.PreserveAndDrawCursor();
5736 // guiApp.desktop.display.ShowScreen();
5737 guiApp.cursorUpdate = false;
5738 guiApp.desktop.dirty = false;
5739 guiApp.RestoreCursorBackground();
5743 guiApp.desktop.display.Unlock();
5744 guiApp.desktop.mutex.Release();
5748 Window rootWindow = this.rootWindow;
5749 rootWindow.mutex.Wait();
5754 guiApp.SignalEvent();
5757 guiApp.waitMutex.Wait();
5758 guiApp.interfaceDriver.Lock(rootWindow);
5759 if(!rootWindow.style.hidden && rootWindow.dirty)
5761 if(rootWindow.display)
5763 rootWindow.UpdateDisplay();
5764 //rootWindow.display.ShowScreen(null);
5766 rootWindow.dirty = false;
5768 guiApp.interfaceDriver.Unlock(rootWindow);
5769 guiApp.waitMutex.Release();
5772 rootWindow.mutex.Release();
5777 void UnlockDisplay(void)
5779 guiApp.interfaceDriver.Unlock(rootWindow);
5782 void LockDisplay(void)
5784 guiApp.interfaceDriver.Lock(rootWindow);
5787 Surface GetSurface(Box box)
5789 return Redraw((box == null) ? this.box : box);
5792 void SetMousePosition(int x, int y)
5794 guiApp.interfaceDriver.SetMousePosition(x + absPosition.x + clientStart.x, y + absPosition.y + clientStart.y);
5798 void IntegrationActivate(bool active)
5800 if(!guiApp.modeSwitching && !guiApp.fullScreenMode)
5802 isForegroundWindow = true;
5803 ActivateEx(active, active, false, false, null, null);
5804 isForegroundWindow = false;
5809 Window QueryCapture(void)
5811 return guiApp.windowCaptured;
5814 int GetDocumentID(void)
5818 byte * idBuffer = new0 byte[size];
5821 for(child = children.first; child; child = child.next)
5823 if(child.style.isDocument)
5825 if(child.documentID-1 > size - 2)
5827 idBuffer = renew0 idBuffer byte[size*2];
5828 memset(idBuffer + size, 0, size);
5831 idBuffer[child.documentID-1] = 1;
5834 for(c = 0; c<size; c++)
5842 void SetInitSize(Size size)
5845 sizeAnchor.size = size;
5846 normalSizeAnchor = sizeAnchor;
5848 // Break the anchors for moveable/resizable windows
5849 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
5851 stateAnchor = normalAnchor;
5852 stateSizeAnchor = normalSizeAnchor;
5854 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5855 Position(x,y, w, h, true, true, true, true, false, true);
5859 void MenuMoveOrSize(bool resize, bool setCursorPosition)
5861 if(this != guiApp.desktop && state != maximized && (resize ? (state != minimized && style.sizable) : (style.fixed || moveable)))
5863 guiApp.windowIsResizing = resize;
5864 guiApp.windowMoving = this;
5865 guiApp.windowMovingStart = guiApp.movingLast = absPosition;
5866 if(guiApp.windowIsResizing)
5868 guiApp.windowMovingStart.x += size.w - 1;
5869 guiApp.windowMovingStart.y += size.h - 1;
5871 guiApp.windowMovingBefore = scrolledPos;
5872 guiApp.windowResizingBefore = size;
5873 guiApp.windowMoving.UpdateDecorations();
5874 if(guiApp.windowIsResizing)
5875 guiApp.resizeEndX = guiApp.resizeEndY = true;
5877 if(setCursorPosition)
5878 guiApp.interfaceDriver.SetMousePosition(guiApp.windowMovingStart.x, guiApp.windowMovingStart.y);
5882 guiApp.interfaceDriver.GetMousePosition(&x, &y);
5883 guiApp.windowMovingStart.x += x - absPosition.x;
5884 guiApp.windowMovingStart.y += y - absPosition.y;
5887 if(guiApp.windowMoving)
5889 if(guiApp.windowMoving.style.nonClient)
5890 guiApp.windowMoving.parent.SetMouseRangeToWindow();
5892 guiApp.windowMoving.parent.SetMouseRangeToClient();
5897 if(this == rootWindow)
5898 guiApp.interfaceDriver.StartMoving(rootWindow, guiApp.windowMovingStart.x, guiApp.windowMovingStart.y, true);
5906 bool result = false;
5910 else if(guiApp && guiApp.driver != null)
5912 void * systemParent = null;
5913 OldLink slaveHolder;
5915 bool visible = !style.hidden;
5919 systemParent = parent;
5920 parent = guiApp.desktop;
5922 last = parent ? parent.children.last : null;
5924 if((parent && parent != guiApp.desktop && !parent.created) ||
5925 (master && master != guiApp.desktop && !master.created))
5929 property::parent = guiApp.desktop;
5930 if(!master) master = parent;
5932 if(_isModal && master.modalSlave)
5933 property::master = master.modalSlave;
5937 parent.children.Remove(this);
5940 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
5941 if(slaveHolder.data == this)
5943 master.slaves.Delete(slaveHolder);
5948 if(parent == guiApp.desktop && !mutex)
5951 if(style.isDocument)
5954 parent.numDocuments--;
5955 documentID = parent.GetDocumentID();
5958 if(!style.stayOnTop)
5959 for(; last && last.style.stayOnTop; last = last.prev);
5961 parent.children.Insert((last == this) ? null : last, this);
5962 //parent.children.Add(this);
5965 dispDriver = parent.dispDriver;
5968 master.modalSlave = this;
5970 box = Box { MAXINT, MAXINT, MININT, MININT }; //-MAXINT, -MAXINT };
5975 master.slaves.Add(slaveHolder = OldLink { data = this });
5980 master.hotKeys.Add(hotKey = HotKeySlot { key = setHotKey, window = this });
5982 if(style.isDefault && !master.defaultControl)
5983 master.defaultControl = this;
5985 stateAnchor = normalAnchor = anchor;
5986 stateSizeAnchor = normalSizeAnchor = sizeAnchor;
5988 // TOCHECK: Why is this here?
5989 //position.x = (ax > 0) ? ax & 0xFFFFF : ax;
5990 //position.y = (ay > 0) ? ay & 0xFFFFF : ay;
5992 this.visible = false;
5993 style.hidden = true;
5996 // autoCreate = true;
6004 if(parent == guiApp.desktop)
6005 Log("LoadGraphics %s\n", caption);
6007 if(LoadGraphics(true, false))
6015 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
6022 if(style.hasMenuBar /*&& menu*/)
6028 menu = menu, isMenuBar = true, anchor = Anchor { top = 23, left = 1, right = 1 },
6029 interim = false, inactive = true, nonClient = true, size.h = 24
6037 // Create the system buttons
6038 CreateSystemChildren();
6040 UpdateActiveDocument(null);
6042 if(style.isDocument)
6046 MenuItem item = menu.FindItem(MenuFileSave, 0);
6047 if(item) item.disabled = !modifiedDocument && fileName;
6052 if(parent == guiApp.desktop)
6053 Log("Preemptive SetState %s\n", caption);
6056 // Preemptive Set State to ensure proper anchoring
6057 SetStateEx(state, false);
6059 style.hidden = true;
6065 for(child = children.first; child; child = next)
6068 if(!child.created && (child.autoCreate || child.wasCreated))
6075 for(link = slaves.first; link; link = next)
6077 Window slave = link.data;
6079 if(!slave.created && (slave.autoCreate || slave.wasCreated))
6088 if(parent == guiApp.desktop)
6089 Log("Real SetState %s\n", caption);
6092 if(isActiveClient && visible)
6094 parent.numPositions--;
6095 if(state == minimized) parent.numIcons--;
6098 // Real set state & activate for proper display & activation
6099 property::visible = visible;
6100 // SetState(state & 0x00000003, true, 0);
6105 /*if(rootWindow == this)
6106 guiApp.interfaceDriver.ActivateRootWindow(this);
6108 if(creationActivation == activate)
6109 ActivateEx(true, false, true, true, null, null);
6110 else if(creationActivation == flash)
6115 rootWindow.ConsequentialMouseMove(false);
6126 guiApp.LogErrorCode(IERR_WINDOW_CREATION_FAILED, caption);
6132 // Testing this here... Otherwise a failed LoadGraphics stalls the application
6134 //style.hidden = true; // !visible;
6135 style.hidden = !visible;
6136 if(master.modalSlave == this)
6137 master.modalSlave = null;
6144 void WriteCaption(Surface surface, int x, int y)
6147 Interface::WriteKeyedTextDisabled(surface, x,y, caption, hotKey ? hotKey.key : 0, !isEnabled);
6150 void Update(Box region)
6156 rootWindow = this.rootWindow;
6158 // rootWindow.mutex.Wait();
6159 if(!destroyed && visible && display)
6164 // Testing this to avoid repetitve full update to take time...
6165 if(dirtyArea.count == 1)
6167 BoxItem item = (BoxItem)ACCESS_ITEM(dirtyArea, dirtyArea.first);
6168 if(item.box.left <= box.left &&
6169 item.box.top <= box.top &&
6170 item.box.right >= box.right &&
6171 item.box.bottom >= box.bottom)
6173 rootWindow.dirty = true;
6178 if(display.flags.flipping && !rootWindow.dirty)
6180 if(this == rootWindow)
6184 rootWindow.Update(null);
6189 rootWindow.dirty = true;
6194 realBox.left += clientStart.x;
6195 realBox.top += clientStart.y;
6196 realBox.right += clientStart.x;
6197 realBox.bottom += clientStart.y;
6203 if(realBox.right >= realBox.left &&
6204 realBox.bottom >= realBox.top)
6206 // if(!rootWindow.fullRender)
6207 dirtyArea.UnionBox(realBox, rootWindow.tempExtents[0]);
6209 for(child = children.first; child; child = child.next)
6214 box.left -= child.absPosition.x - absPosition.x;
6215 box.top -= child.absPosition.y - absPosition.y;
6216 box.right -= child.absPosition.x - absPosition.x;
6217 box.bottom -= child.absPosition.y - absPosition.y;
6218 if(box.right >= child.box.left && box.left <= child.box.right &&
6219 box.bottom >= child.box.top && box.top <= child.box.bottom)
6221 box.left -= child.clientStart.x;
6222 box.top -= child.clientStart.y;
6223 box.right -= child.clientStart.x;
6224 box.bottom -= child.clientStart.y;
6230 realBox.left += absPosition.x - rootWindow.absPosition.x;
6231 realBox.top += absPosition.y - rootWindow.absPosition.y;
6232 realBox.right += absPosition.x - rootWindow.absPosition.x;
6233 realBox.bottom += absPosition.y - rootWindow.absPosition.y;
6234 rootWindow.dirtyBack.UnionBox(realBox, rootWindow.tempExtents[0]);
6237 else if(this == guiApp.desktop)
6240 for(window = children.first; window; window = window.next)
6246 Box childBox = region;
6248 childBox.left -= window.absPosition.x - guiApp.desktop.absPosition.x;
6249 childBox.top -= window.absPosition.y - guiApp.desktop.absPosition.y;
6250 childBox.right -= window.absPosition.x - guiApp.desktop.absPosition.x;
6251 childBox.bottom -= window.absPosition.y - guiApp.desktop.absPosition.y;
6253 window.Update(childBox);
6256 window.Update(null);
6261 // rootWindow.mutex.Release();
6268 if(guiApp.windowCaptured != this)
6270 if(guiApp.windowCaptured)
6274 //Logf("Captured %s (%s)\n", caption, class.name);
6275 guiApp.interfaceDriver.SetMouseCapture(rootWindow);
6276 guiApp.windowCaptured = this;
6282 bool Destroy(int code)
6287 if(!CloseConfirmation(false)) return false;
6291 // TOCHECK: Should autoCreate be set to false here?
6294 // Is this needed here? DestroyEx should decref already...
6303 void Move(int x, int y, int w, int h)
6305 normalAnchor = Anchor { left = x, top = y };
6306 normalSizeAnchor = SizeAnchor { size = { w, h } };
6308 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6310 if(destroyed) return;
6312 stateAnchor = normalAnchor;
6313 stateSizeAnchor = normalSizeAnchor;
6315 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6316 Position(x,y, w, h, true, true, true, true, false, true);
6320 DialogResult Modal(void)
6326 // FIXES MEMORY LEAK IF Create() FAILED
6332 void SetScrollArea(int width, int height, bool snapToStep)
6334 bool resize = false;
6337 int stepX = sbStep.x, stepY = sbStep.y;
6338 // Needed to make snapped down position match the skin's check of client area
6339 // against realvirtual
6342 SNAPDOWN(stepX, textCellW);
6343 SNAPDOWN(stepY, textCellH);
6344 stepX = Max(stepX, textCellW);
6345 stepY = Max(stepY, textCellH);
6347 if(scrollFlags.snapX)
6348 SNAPUP(width, stepX);
6349 if(scrollFlags.snapY)
6350 SNAPUP(height, stepY);
6353 reqScrollArea.w = width;
6354 reqScrollArea.h = height;
6355 noAutoScrollArea = (width > 0 || height > 0);
6357 UpdateScrollBars(true, true);
6360 void SetScrollPosition(int x, int y)
6363 sbh.Action(setPosition, x, 0);
6367 int seen = clientSize.w, total = reqScrollArea.w;
6369 if(scrollFlags.snapX)
6370 SNAPDOWN(seen, sbStep.x);
6372 if(!total) total = seen;
6373 range = total - seen + 1;
6374 range = Max(range, 1);
6376 if(x >= range) x = range - 1;
6378 if(scrollFlags.snapX)
6379 SNAPUP(x, sbStep.x);
6382 OnHScroll(setPosition, x, 0);
6386 SNAPDOWN(x, textCellW);
6392 sbv.Action(setPosition, y, 0);
6396 int seen = clientSize.h, total = reqScrollArea.h;
6399 if(scrollFlags.snapY)
6400 SNAPDOWN(seen, sbStep.y);
6402 if(!total) total = seen;
6403 range = total - seen + 1;
6404 range = Max(range, 1);
6406 if(y >= range) y = range - 1;
6408 if(scrollFlags.snapY)
6409 SNAPUP(y, sbStep.y);
6412 OnVScroll(setPosition, y, 0);
6415 SNAPDOWN(y, textCellH);
6420 UpdateCaret(false, false);
6423 void SetScrollLineStep(int stepX, int stepY)
6429 SNAPDOWN(stepX, textCellW);
6430 SNAPDOWN(stepY, textCellH);
6431 stepX = Max(stepX, textCellW);
6432 stepY = Max(stepY, textCellH);
6435 sbh.lineStep = stepX;
6437 sbv.lineStep = stepY;
6440 void SetState(WindowState newState, bool activate, Modifiers mods)
6444 if(state == newState || OnStateChange(newState, mods))
6446 WindowState prevState = state;
6450 // This used to be at the end of the brackets... moved for X, testing...
6451 // This has the effect of activating the window through the system...
6452 if(rootWindow == this)
6453 guiApp.interfaceDriver.SetRootWindowState(this, newState, !style.hidden);
6455 SetStateEx(newState, activate);
6457 if(rootWindow == this && !rootWindow.nativeDecorations)
6459 int x = position.x, y = position.y;
6462 x -= guiApp.desktop.absPosition.x;
6463 y -= guiApp.desktop.absPosition.y;
6465 guiApp.interfaceDriver.PositionRootWindow(this, x, y, size.w, size.h, true, true);
6469 //state = prevState;
6471 if(state != maximized && style.hasMaximize)
6474 for(child = parent.children.first; child; child = child.next)
6476 if(child != this && child.state == maximized)
6477 child.SetStateEx(normal, false);
6481 if(!style.nonClient && (sbv || sbh) && this != parent.sbv && this != parent.sbh)
6482 parent.UpdateScrollBars(true, true);
6485 // Do we really need this stuff here?
6486 // Shouldn't the Activate stuff take care of it?
6487 if(parent.rootWindow == parent && style)
6490 parent.FigureCaption(caption);
6491 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
6492 parent.UpdateDecorations();
6496 rootWindow.ConsequentialMouseMove(false);
6503 BitmapResource GetIcon(SkinBitmap iconID)
6505 return guiApp.currentSkin.GetBitmap(iconID);
6508 void SetMouseRange(Box range)
6510 if(range || guiApp.fullScreenMode)
6515 clip.left = range.left + absPosition.x + clientStart.x;
6516 clip.top = range.top + absPosition.y + clientStart.y;
6517 clip.right = range.right + absPosition.x + clientStart.x;
6518 clip.bottom = range.bottom + absPosition.y + clientStart.y;
6522 clip.left = guiApp.desktop.box.left;
6523 clip.top = guiApp.desktop.box.top;
6524 clip.right = guiApp.desktop.box.right;
6525 clip.bottom = guiApp.desktop.box.bottom;
6527 guiApp.interfaceDriver.SetMouseRange(rootWindow, clip);
6530 guiApp.interfaceDriver.SetMouseRange(rootWindow, null);
6533 void SetMouseRangeToClient(void)
6535 if(guiApp.fullScreenMode || this != guiApp.desktop)
6537 Box box {0, 0, clientSize.w - 1, clientSize.h - 1 };
6538 box.Clip(clientArea);
6542 SetMouseRange(null);
6545 void SetMouseRangeToWindow(void)
6547 Box box { -clientStart.x, -clientStart.y, size.w-1, size.h-1 };
6548 if(this == guiApp.desktop)
6549 SetMouseRangeToClient();
6554 // x, y: Desktop Coordinates
6555 void ShowSysMenu(int x, int y)
6558 PopupMenu windowMenu { master = this, interim = true, position = { x + 1 - guiApp.desktop.position.x, y + 1 - guiApp.desktop.position.y }, menu = menu };
6561 menu, "Restore", r, NotifySelect = MenuWindowRestore,
6562 disabled = (!style.hasMaximize && !style.hasMinimize) || state == normal, bitmap = guiApp.currentSkin.GetBitmap(restore)
6566 menu, "Move", m, NotifySelect = MenuWindowMove,
6567 disabled = !style.fixed || state == maximized
6571 menu, "Size", s, NotifySelect = MenuWindowSize,
6572 disabled = !style.sizable || state != normal
6576 menu, "Minimize", n, NotifySelect = MenuWindowMinimize,
6577 disabled = !style.hasMinimize || state == minimized, bitmap = guiApp.currentSkin.GetBitmap(minimize)
6581 menu, "Maximize", KeyCode::x, NotifySelect = MenuWindowMaximize,
6582 disabled = !style.hasMaximize || state == maximized, bitmap = guiApp.currentSkin.GetBitmap(maximize)
6586 menu, "Stay On Top", t, NotifySelect = MenuWindowStayOnTop,
6587 disabled = !style.fixed, checkable = true, checked = style.stayOnTop
6589 MenuDivider { menu };
6592 menu, "Close", c, (parent == guiApp.desktop) ? altF4 : ( style.isActiveClient ? ctrlF4 : 0), NotifySelect = MenuWindowClose,
6593 bold = true, disabled = !style.hasClose, bitmap = guiApp.currentSkin.GetBitmap(close)
6595 windowMenu.Create();
6600 ActivateEx(true, true, true, true, null, null);
6603 void MakeActive(void)
6605 ActivateEx(true, false, true, false, null, null);
6608 void SoftActivate(void)
6610 if(guiApp.desktop.active)
6616 void Deactivate(void)
6618 ActivateEx(false, true, true, true, null, null);
6623 guiApp.interfaceDriver.FlashRootWindow(rootWindow);
6626 bool CycleChildren(bool backward, bool clientOnly, bool tabCycleOnly, bool cycleParents)
6628 bool result = false;
6629 if(activeChild && activeChild.cycle)
6631 Window modalWindow, child = activeChild;
6632 if(!clientOnly /*&& parent.tabCycle*/)
6634 Window next = child;
6637 if(next.cycle == (backward ? childrenCycle.first : childrenCycle.last))
6641 if(parent && parent.CycleChildren(backward, false, true, true))
6649 next = next.cycle.prev.data;
6651 next = next.cycle.next.data;
6652 if(!next.disabled && !next.inactive /*isRemote*/ && next.created && !next.nonClient && (!clientOnly || next.style.isActiveClient) && !next.style.hidden && next.FindModal() != activeChild)
6657 if(!clientOnly && child.cycle == (backward ? childrenCycle.first : childrenCycle.last) &&
6658 parent.tabCycle && parent.CycleChildren(backward, false, false))
6662 if(tabCycleOnly && !tabCycle) return false;
6669 child = child.cycle.prev.data;
6671 child = child.cycle.next.data;
6672 if(child == child.parent.activeChild)
6674 else if(!child.disabled && child.created && (!clientOnly || child.style.isActiveClient) && !child.style.hidden && child.FindModal() != activeChild)
6677 modalWindow = child.FindModal();
6680 // Scroll the window to include the active control
6681 if(sbh && !child.style.dontScrollHorz)
6683 if(child.scrolledPos.x < 0)
6684 sbh.Action(setPosition, scroll.x + child.scrolledPos.x, 0);
6685 else if(child.scrolledPos.x + child.size.w > clientSize.w)
6686 sbh.Action(setPosition, scroll.x + child.scrolledPos.x + child.size.w - clientSize.w, 0);
6688 if(sbv && !child.style.dontScrollVert)
6690 if(child.scrolledPos.y < 0)
6691 sbv.Action(setPosition, scroll.y + child.scrolledPos.y, 0);
6692 else if(child.scrolledPos.y + child.size.h > clientSize.h)
6693 sbv.Action(setPosition, scroll.y + child.scrolledPos.y + child.size.h - clientSize.h, 0);
6697 child = modalWindow ? modalWindow : child;
6698 child.ActivateEx(true, true, true, true, null, null);
6699 if(child.tabCycle && child.childrenCycle.first)
6700 child = ((OldLink)(backward ? child.childrenCycle.first : child.childrenCycle.last)).data;
6708 ConsequentialMouseMove(false);
6712 void AddResource(Resource resource)
6716 ResPtr ptr { resource = resource };
6720 // Load Graphics here if window is created already
6721 if(/*created && */display)
6723 display.Lock(false);
6724 ptr.loaded = display.displaySystem.LoadResource(resource);
6728 // Temporary hack to load font right away for listbox in dropbox ...
6729 else if(master && master.display)
6731 master.display.Lock(false);
6732 master.display.displaySystem.LoadResource(resource);
6733 master.display.Unlock();
6739 void RemoveResource(Resource resource)
6744 for(ptr = resources.first; ptr; ptr = ptr.next)
6746 if(ptr.resource == resource)
6752 // Unload Graphics here if window is created already
6753 if(/*created && */display)
6757 display.Lock(false);
6758 display.displaySystem.UnloadResource(resource, ptr.loaded);
6764 resources.Delete(ptr);
6769 void SetCaret(int x, int y, int size)
6776 if(active && !style.interim)
6778 if(visible || !guiApp.caretOwner)
6779 guiApp.caretOwner = size ? this : null;
6781 UpdateCaret(false, false);
6784 guiApp.interfaceDriver.SetCaret(0,0,0);
6785 UpdateCaret(false, true);
6786 guiApp.caretEnabled = false;
6789 else if(style.inactive && active)
6791 guiApp.interfaceDriver.SetCaret(0,0,0);
6792 UpdateCaret(false, true);
6793 guiApp.caretEnabled = false;
6798 void Scroll(int x, int y)
6800 bool opaque = !style.drawBehind || background.a;
6801 if(opaque && display && display.flags.scrolling)
6803 Box box = clientArea;
6804 box.left += clientStart.x;
6805 box.top += clientStart.y;
6806 box.right += clientStart.x;
6807 box.bottom += clientStart.y;
6809 //scrollExtent.Free(null);
6810 scrollExtent.AddBox(box);
6811 scrolledArea.x += x;
6812 scrolledArea.y += y;
6814 //scrollExtent.Free();
6815 //scrollExtent.AddBox(clientArea);
6816 //scrollExtent.Offset(clientStart.x, clientStart.y);
6817 //scrolledArea.x = x;
6818 //scrolledArea.y = y;
6824 rootWindow.dirty = true;
6827 void ReleaseCapture()
6829 if(guiApp && guiApp.windowCaptured && guiApp.windowCaptured == this)
6831 Window oldCaptured = guiApp.windowCaptured;
6832 guiApp.windowCaptured = null;
6833 guiApp.prevWindow = null;
6836 //guiApp.Log("Released Capture\n");
6838 guiApp.interfaceDriver.SetMouseCapture(null);
6840 //oldCaptured.OnMouseCaptureLost();
6843 oldCaptured.ConsequentialMouseMove(false);
6848 void SetText(char * format, ...)
6855 char caption[MAX_F_STRING];
6857 va_start(args, format);
6858 vsprintf(caption, format, args);
6861 this.caption = new char[strlen(caption)+1];
6863 strcpy(this.caption, caption);
6872 bool Grab(Bitmap bitmap, Box box, bool decorations)
6874 bool result = false;
6875 if(display || this == guiApp.desktop)
6877 Box clip = {MININT, MININT, MAXINT, MAXINT};
6883 clip.Clip(clientArea);
6885 clip.Clip(this.box);
6887 if(rootWindow != this)
6889 clip.left += absPosition.y;
6890 clip.top += absPosition.y;
6891 clip.right += absPosition.x;
6892 clip.bottom += absPosition.y;
6895 clip.left += decorations ? 0 : clientStart.x;
6896 clip.top += decorations ? 0 : clientStart.y;
6897 clip.right += decorations ? 0 : clientStart.x;
6898 clip.bottom += decorations ? 0 : clientStart.y;
6900 if(display && display.flags.flipping)
6902 rootWindow.Update(null);
6903 rootWindow.UpdateDisplay();
6910 result = window.display.displaySystem.driver.GrabScreen(null, bitmap, clip.left, clip.top,
6911 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6915 result = display.Grab(bitmap, clip.left, clip.top,
6916 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6918 if(bitmap.pixelFormat != pixelFormat888 && bitmap.pixelFormat != pixelFormat8)
6920 if(!bitmap.Convert(null, pixelFormat888, null))
6927 void GetMousePosition(int * x, int * y)
6929 int mouseX = 0, mouseY = 0;
6930 if(!guiApp.acquiredWindow && (guiApp.desktop.active || !guiApp.fullScreenMode))
6933 guiApp.interfaceDriver.GetMousePosition(&mouseX, &mouseY);
6934 if(this != guiApp.desktop)
6936 mouseX -= absPosition.x + clientStart.x;
6937 mouseY -= absPosition.y + clientStart.y;
6944 DialogResult DoModal()
6946 DialogResult returnCode = 0;
6947 int terminated = terminateX;
6950 while(!destroyed && guiApp.driver != null)
6952 if(terminateX != terminated)
6954 terminated = terminateX;
6955 guiApp.desktop.Destroy(0);
6956 if(guiApp.desktop.created)
6959 //printf("Resetting terminate X to 0\n");
6965 guiApp.UpdateDisplay();
6966 if(!guiApp.ProcessInput(false))
6969 returnCode = this.returnCode;
6982 return !destroyed && guiApp.driver != null && terminateX < 2;
6985 DialogResult DoModalEnd()
6987 DialogResult returnCode = this.returnCode;
6992 // --- Window manipulation ---
6993 /*bool GetDisabled()
6995 bool disabled = this.disabled;
6997 for(window = this; (window = window.master); )
7008 // --- Mouse Manipulation ---
7009 void GetNCMousePosition(int * x, int * y)
7011 GetMousePosition(x, y);
7012 if(x) *x += clientStart.x;
7013 if(y) *y += clientStart.y;
7016 // --- Carets manipulation ---
7017 void GetCaretPosition(Point caretPos)
7019 caretPos = this.caretPos;
7022 int GetCaretSize(void)
7027 bool ButtonCloseDialog(Button button, int x, int y, Modifiers mods)
7033 bool CloseConfirmation(bool parentClosing)
7046 if(!OnClose(parentClosing))
7049 // If you want to skip this, simply set modifiedDocument to false in OnClose
7050 if(result && (/*fileName || */style.isDocument) && modifiedDocument)
7052 DialogResult dialogRes;
7055 sprintf(message, "Save changes to %s?", fileName);
7057 sprintf(message, "Save changes to Untitled %d?", documentID);
7059 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption, contents = message }.Modal();
7061 if(dialogRes == yes)
7063 // TOFIX: Precomp error if brackets are taken out
7064 result = (DialogResult)MenuFileSave(null, 0) != cancel;
7066 else if(dialogRes == cancel)
7072 for(slave = slaves.first; slave; slave = slave.next)
7073 if(!((Window)slave.data).CloseConfirmation(true))
7075 // ((Window)slave.data).CloseConfirmation(true);
7083 for(child = children.first; child; child = child.next)
7084 if(child.master != this && !child.CloseConfirmation(true))
7094 // Static methods... move them somewhere else?
7095 void ::RestoreCaret()
7097 if(guiApp.caretOwner)
7098 guiApp.caretOwner.UpdateCaret(false, false);
7101 void ::FreeMouseRange()
7103 guiApp.interfaceDriver.SetMouseRange(null, null);
7107 bool MenuFileClose(MenuItem selection, Modifiers mods)
7109 Window document = activeChild;
7111 document.Destroy(0);
7115 bool MenuFileExit(MenuItem selection, Modifiers mods)
7121 bool MenuFileSave(MenuItem selection, Modifiers mods)
7125 fileMonitor.fileName = null;
7128 if(OnSaveFile(fileName))
7130 //if(OnFileModified != Window::OnFileModified)
7133 fileMonitor.fileName = fileName;
7139 MessageBox dialog { master = master, type = yesNoCancel, text = "Error writing file", contents = "Save as a different file?" };
7140 DialogResult answer = dialog.Modal();
7142 if(answer != yes) return (bool)answer;
7145 return MenuFileSaveAs(selection, mods);
7148 bool MenuFileSaveAs(MenuItem selection, Modifiers mods)
7150 DialogResult result = (DialogResult)bool::true;
7151 FileDialog fileDialog = saveDialog;
7154 fileDialog = FileDialog {};
7159 fileDialog.filePath = fileName;
7162 char filePath[MAX_FILENAME];
7163 sprintf(filePath, "Untitled %d", documentID);
7164 fileDialog.filePath = filePath;
7166 fileMonitor.fileName = null;
7168 fileDialog.type = save;
7169 fileDialog.text = "Save As";
7173 fileDialog.master = master.parent ? master : this;
7174 if(fileDialog.Modal() == ok)
7176 char * filePath = fileDialog.filePath;
7178 if(OnSaveFile(filePath))
7181 property::fileName = filePath;
7182 NotifySaved(master, this, filePath);
7187 MessageBox dialog { master = master.parent ? master : this, type = yesNoCancel, text = "Error writing file", contents = "Save as a different file?" };
7188 DialogResult answer = dialog.Modal();
7203 //if(OnFileModified != Window::OnFileModified && fileName)
7206 fileMonitor.fileName = fileName;
7210 return (bool)result; // Actually returning result from Yes/NoCancel message box
7213 bool MenuFileSaveAll(MenuItem selection, Modifiers mods)
7215 Window document = activeChild;
7217 for(document = children.first; document; document = next)
7219 next = document.next;
7220 if(document.style.isDocument || document.fileName)
7221 document.MenuFileSave(selection, mods);
7226 bool MenuWindowArrangeIcons(MenuItem selection, Modifiers mods)
7230 for(document = children.first; document; document = document.next)
7231 //if(document.style.isDocument && document.state == minimized)
7232 if(document.style.isActiveClient && document.state == minimized)
7233 document.SetState(minimized, false, mods);
7237 bool MenuWindowCascade(MenuItem selection, Modifiers mods)
7239 Window document = activeChild;
7242 Window firstDocument = null;
7244 OldLink cycle = document.cycle.prev;
7249 if(child.style.isActiveClient && !child.style.hidden)
7253 firstDocument = child;
7254 if(child.state == minimized)
7255 child.SetState(minimized, false, mods);
7258 child.positionID = id++;
7259 child.SetState(normal, false, mods);
7260 child.anchor.left.type = cascade;
7263 child.normalSizeAnchor = *&child.sizeAnchor;
7264 child.normalAnchor = child.anchor;
7266 // Break the anchors for moveable/resizable windows
7267 if(child.style.fixed)
7269 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7271 (*&child.normalAnchor).left = x;
7272 (*&child.normalAnchor).top = y;
7273 (*&child.normalAnchor).right.type = none;
7274 (*&child.normalAnchor).bottom.type = none;
7276 child.normalSizeAnchor.isClientW = false;
7277 child.normalSizeAnchor.isClientH = false;
7278 child.normalSizeAnchor.size.w = w;
7279 child.normalSizeAnchor.size.h = h;
7280 child.anchored = false;
7283 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7285 child.stateAnchor = child.normalAnchor;
7286 child.stateSizeAnchor = child.normalSizeAnchor;
7288 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7289 child.Position(x, y, w, h, true, true, true, true, false, false);
7294 last = children.last;
7295 if(!child.style.stayOnTop)
7296 for(; last && last.style.stayOnTop; last = last.prev);
7297 children.Move(child, last);
7298 childrenOrder.Move(child.order, childrenOrder.last);
7300 if(cycle == document.cycle) break;
7304 firstDocument.Activate();
7309 bool MenuWindowClose(MenuItem selection, Modifiers mods)
7316 // Close all closes all active clients, not all documents
7317 bool MenuWindowCloseAll(MenuItem selection, Modifiers mods)
7319 Window next, document;
7321 for(document = children.first; document; document = next)
7323 for(next = document.next; next && !(next.style.isActiveClient; next = next.next);
7324 if(document.style.isActiveClient)
7325 if(!document.Destroy(0) && !document.style.hidden)
7331 bool MenuWindowMaximize(MenuItem selection, Modifiers mods)
7333 if(style.hasMaximize && state != maximized)
7334 SetState(maximized, 0, 0);
7338 bool MenuWindowMinimize(MenuItem selection, Modifiers mods)
7340 if(style.hasMinimize && state != minimized)
7342 SetState(minimized, 0, 0);
7343 parent.CycleChildren(false, true, false, true);
7348 bool MenuWindowMove(MenuItem selection, Modifiers mods)
7350 MenuMoveOrSize(false, selection ? true : false);
7354 bool MenuWindowNext(MenuItem selection, Modifiers mods)
7356 CycleChildren(false, true, false, true);
7360 bool MenuWindowPrevious(MenuItem selection, Modifiers mods)
7362 CycleChildren(true, true, false, true);
7366 bool MenuWindowSize(MenuItem selection, Modifiers mods)
7368 MenuMoveOrSize(true, true);
7372 bool MenuWindowRestore(MenuItem selection, Modifiers mods)
7375 SetState(normal, 0, 0);
7379 bool MenuWindowSelectWindow(MenuItem selection, Modifiers mods)
7382 int id = selection.id;
7383 OldLink cycle = activeClient.cycle;
7385 //for(c = 0, cycle = activeChild.cycle; c<id; cycle = cycle.next, c++);
7388 Window sibling = cycle.data;
7389 if(sibling.style.isActiveClient)
7397 document = cycle.data;
7398 document.Activate();
7400 //if(activeChild.state == maximized)
7401 // document.SetState(maximized, false, mods);
7402 //else if(document.state == minimized)
7403 // document.SetState(normal, false, mods);
7407 bool MenuWindowStayOnTop(MenuItem selection, Modifiers mods)
7409 stayOnTop = !style.stayOnTop;
7413 bool MenuWindowTileHorz(MenuItem selection, Modifiers mods)
7415 Window document = activeChild;
7418 Window firstDocument = null;
7419 OldLink cycle = document.cycle;
7423 Window child = cycle.data;
7424 if(child.style.isActiveClient && !child.style.hidden)
7426 if(!firstDocument) firstDocument = child;
7427 if(child.state == minimized)
7428 child.SetState(minimized, false, mods);
7431 child.positionID = id++;
7432 child.SetState(normal, false, mods);
7433 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7435 child.anchor.left.type = hTiled;
7438 child.normalSizeAnchor = *&child.sizeAnchor;
7439 child.normalAnchor = child.anchor;
7441 // Break the anchors for moveable/resizable windows
7442 if(child.style.fixed)
7444 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7446 (*&child.normalAnchor).left = x;
7447 (*&child.normalAnchor).top = y;
7448 (*&child.normalAnchor).right.type = none;
7449 (*&child.normalAnchor).bottom.type = none;
7450 child.normalSizeAnchor.isClientW = false;
7451 child.normalSizeAnchor.isClientH = false;
7452 child.normalSizeAnchor.size.w = w;
7453 child.normalSizeAnchor.size.h = h;
7454 child.anchored = false;
7457 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7459 child.stateAnchor = child.normalAnchor;
7460 child.stateSizeAnchor = child.normalSizeAnchor;
7462 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7463 child.Position(x,y, w, h, true, true, true, true, false, true);
7468 if((cycle = cycle.next) == document.cycle) break;
7471 firstDocument.Activate();
7476 bool MenuWindowTileVert(MenuItem selection, Modifiers mods)
7478 Window document = activeChild;
7481 Window firstDocument = null;
7483 OldLink cycle = document.cycle;
7488 //if(child.style.isDocument)
7489 if(child.style.isActiveClient && !child.style.hidden)
7491 if(!firstDocument) firstDocument = child;
7492 if(child.state == minimized)
7493 child.SetState(minimized, false, mods);
7496 child.positionID = id++;
7497 child.SetState(normal, false, mods);
7498 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7500 child.anchor.left.type = vTiled;
7503 child.normalSizeAnchor = *&child.sizeAnchor;
7504 child.normalAnchor = child.anchor;
7506 // Break the anchors for moveable/resizable windows
7507 if(child.style.fixed)
7509 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7511 (*&child.normalAnchor).left = x;
7512 (*&child.normalAnchor).top = y;
7513 (*&child.normalAnchor).right.type = none;
7514 (*&child.normalAnchor).bottom.type = none;
7515 child.normalSizeAnchor.isClientW = false;
7516 child.normalSizeAnchor.isClientH = false;
7517 child.normalSizeAnchor.size.w = w;
7518 child.normalSizeAnchor.size.h = h;
7519 child.anchored = false;
7522 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7524 child.stateAnchor = child.normalAnchor;
7525 child.stateSizeAnchor = child.normalSizeAnchor;
7527 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7528 child.Position(x,y, w, h, true, true, true, true, false, true);
7533 if((cycle = cycle.next) == document.cycle) break;
7536 firstDocument.Activate();
7541 bool MenuWindowWindows(MenuItem selection, Modifiers mods)
7543 WindowList dialog { master = this };
7544 Window document = (Window)dialog.Modal();
7547 if(activeChild.state == maximized)
7548 document.SetState(maximized, false, mods);
7549 else if(document.state == minimized)
7550 document.SetState(normal, false, mods);
7551 document.Activate();
7557 virtual bool OnCreate(void);
7558 virtual void OnDestroy(void);
7559 virtual void OnDestroyed(void);
7560 virtual bool OnClose(bool parentClosing);
7561 virtual bool OnStateChange(WindowState state, Modifiers mods);
7562 virtual bool OnPostCreate(void);
7563 virtual bool OnMoving(int *x, int *y, int w, int h);
7564 virtual bool OnResizing(int *width, int *height);
7565 virtual void OnResize(int width, int height);
7566 virtual void OnPosition(int x, int y, int width, int height);
7567 virtual bool OnLoadGraphics(void);
7568 virtual void OnApplyGraphics(void);
7569 virtual void OnUnloadGraphics(void);
7570 virtual void OnRedraw(Surface surface);
7571 virtual bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct);
7572 virtual void OnActivateClient(Window client, Window previous);
7573 virtual bool OnKeyDown(Key key, unichar ch);
7574 virtual bool OnKeyUp(Key key, unichar ch);
7575 virtual bool OnKeyHit(Key key, unichar ch);
7576 virtual bool OnSysKeyDown(Key key, unichar ch);
7577 virtual bool OnSysKeyUp(Key key, unichar ch);
7578 virtual bool OnSysKeyHit(Key key, unichar ch);
7579 virtual bool OnMouseOver(int x, int y, Modifiers mods);
7580 virtual bool OnMouseLeave(Modifiers mods);
7581 virtual bool OnMouseMove(int x, int y, Modifiers mods);
7582 virtual bool OnLeftButtonDown(int x, int y, Modifiers mods);
7583 virtual bool OnLeftButtonUp(int x, int y, Modifiers mods);
7584 virtual bool OnLeftDoubleClick(int x, int y, Modifiers mods);
7585 virtual bool OnRightButtonDown(int x, int y, Modifiers mods);
7586 virtual bool OnRightButtonUp(int x, int y, Modifiers mods);
7587 virtual bool OnRightDoubleClick(int x, int y, Modifiers mods);
7588 virtual bool OnMiddleButtonDown(int x, int y, Modifiers mods);
7589 virtual bool OnMiddleButtonUp(int x, int y, Modifiers mods);
7590 virtual bool OnMiddleDoubleClick(int x, int y, Modifiers mods);
7591 virtual void OnMouseCaptureLost(void);
7592 virtual void OnHScroll(ScrollBarAction action, int position, Key key);
7593 virtual void OnVScroll(ScrollBarAction action, int position, Key key);
7594 virtual void OnDrawOverChildren(Surface surface);
7595 virtual bool OnFileModified(FileChange fileChange, char * param);
7596 virtual bool OnSaveFile(char * fileName);
7598 // Skins Virtual Functions
7599 virtual void GetDecorationsSize(MinMaxValue * w, MinMaxValue * h);
7600 virtual void SetWindowMinimum(MinMaxValue * mw, MinMaxValue * mh);
7601 virtual void SetWindowArea(int * x, int * y, MinMaxValue * w, MinMaxValue * h, MinMaxValue * cw, MinMaxValue * ch)
7606 virtual void ShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7607 virtual void PreShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7608 virtual bool IsMouseMoving(int x, int y, int w, int h);
7609 virtual bool IsMouseResizing(int x, int y, int w, int h, bool *resizeX, bool *resizeY, bool *resizeEndX, bool *resizeEndY);
7610 virtual void UpdateNonClient();
7611 virtual void SetBox(Box box);
7612 virtual bool IsInside(int x, int y)
7614 return box.IsPointInside({x, y});
7616 virtual bool IsOpaque()
7618 return (!style.drawBehind || background.a == 255);
7622 virtual bool Window::NotifyActivate(Window window, bool active, Window previous);
7623 virtual void Window::NotifyDestroyed(Window window, DialogResult result);
7624 virtual void Window::NotifySaved(Window window, char * filePath);
7629 property Window parent
7631 property_category "Layout"
7634 if(value || guiApp.desktop)
7637 Window oldParent = parent;
7638 Anchor anchor = this.anchor;
7640 if(value && value.IsDescendantOf(this)) return;
7641 if(value && value == this)
7643 if(!value) value = guiApp.desktop;
7645 if(value == oldParent) return;
7647 if(!master || (master == this.parent && master == guiApp.desktop))
7648 property::master = value;
7652 parent.children.Remove(this);
7656 box.left - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7657 box.top - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y,
7658 box.right - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7659 box.bottom - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y
7663 last = value.children.last;
7665 if(style.isDocument)
7668 parent.numDocuments--;
7669 documentID = value.GetDocumentID();
7672 if(style.isActiveClient && !style.hidden)
7674 if(parent && parent != guiApp.desktop && !(style.hidden))
7676 if(state == minimized) parent.numIcons--;
7677 parent.numPositions--;
7681 if(!style.stayOnTop)
7682 for(; last && last.style.stayOnTop; last = last.prev);
7684 value.children.Insert(last, this);
7686 // *** NEW HERE: ***
7688 parent.childrenCycle.Delete(cycle);
7690 parent.childrenOrder.Delete(order);
7698 int x = position.x, y = position.y, w = size.w, h = size.h;
7702 x += parent.absPosition.x - value.absPosition.x + parent.clientStart.x - value.clientStart.x;
7703 y += parent.absPosition.y - value.absPosition.y + parent.clientStart.y - value.clientStart.y;
7705 vpw = value.clientSize.w;
7706 vph = value.clientSize.h;
7712 else if(style.fixed)
7714 if(!style.dontScrollHorz && value.scrollArea.w) vpw = value.scrollArea.w;
7715 if(!style.dontScrollVert && value.scrollArea.h) vph = value.scrollArea.h;
7718 anchor = this.anchor;
7720 if(anchor.left.type == offset) anchor.left.distance = x;
7721 else if(anchor.left.type == relative) anchor.left.percent = (float)x / vpw;
7722 if(anchor.top.type == offset) anchor.top.distance = y;
7723 else if(anchor.top.type == relative) anchor.top.percent = (float)y / vph;
7724 if(anchor.right.type == offset) anchor.right.distance = vpw - (x + w);
7725 //else if(anchor.right.type == relative) anchor.right.percent = 1.0-(float) (vpw - (x + w)) / vpw;
7726 else if(anchor.right.type == relative) anchor.right.percent = (float) (vpw - (x + w)) / vpw;
7727 if(anchor.bottom.type == offset) anchor.bottom.distance = vph - (y + h);
7728 //else if(anchor.bottom.type == relative) anchor.bottom.percent = 1.0-(float) (vph - (y + h)) / vph;
7729 else if(anchor.bottom.type == relative) anchor.bottom.percent = (float) (vph - (y + h)) / vph;
7731 if(!anchor.left.type && !anchor.right.type)
7733 anchor.horz.distance = (x + w / 2) - (vpw / 2);
7734 //anchor.horz.type = anchor.horz.distance ? AnchorValueOffset : 0;
7736 else if(anchor.horz.type == middleRelative) anchor.horz.percent = (float) ((x + w / 2) - (vpw / 2)) / vpw;
7737 if(!anchor.top.type && !anchor.bottom.type)
7739 anchor.vert.distance = (y + h / 2) - (vph / 2);
7740 //anchor.vert.type = anchor.vert.distance ? AnchorValueOffset : 0;
7742 else if(anchor.vert.type == middleRelative) anchor.vert.percent = (float)((y + h / 2) - (vph / 2)) / vph;
7750 parent.childrenCycle.Insert(
7751 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
7752 cycle = OldLink { data = this });
7753 parent.childrenOrder.Insert(
7754 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
7755 order = OldLink { data = this });
7758 if(!style.hidden && style.isActiveClient)
7760 positionID = parent.GetPositionID(this);
7761 parent.numPositions++;
7762 if(state == minimized) parent.numIcons--;
7765 // *** FONT INHERITANCE ***
7766 if(!setFont && oldParent)
7767 stopwatching(oldParent, font);
7771 RemoveResource(systemFont);
7774 // TESTING WITH WATCHERS:
7775 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7776 // usedFont = setFont ? setFont : (systemFont);
7780 if(guiApp.currentSkin)
7782 systemFont = guiApp.currentSkin.SystemFont();
7785 usedFont = systemFont;
7786 AddResource(systemFont);
7794 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7803 if(value.rootWindow && value.rootWindow.display && rootWindow)
7805 bool reloadGraphics = (oldParent.rootWindow == oldParent && value.rootWindow) || (!value.rootWindow && rootWindow == this) ||
7806 (value.rootWindow.display && value.rootWindow.display.displaySystem != rootWindow.display.displaySystem);
7809 UnloadGraphics(false);
7812 LoadGraphics(false, false);
7815 if(value.rootWindow != rootWindow)
7816 DisplayModeChanged();
7820 scrolledPos.x = MININT; // Prevent parent update
7821 property::anchor = anchor;
7825 if(guiApp.currentSkin)
7826 guiApp.currentSkin.SetWindowMinimum(this, &skinMinSize.w, &skinMinSize.h);
7828 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
7829 Position(x, y, w, h, true, true, true, true, false, true);
7834 // else parent = value;
7837 get { return parent; }
7840 property Window master
7842 property_category "Behavior"
7845 //if(this == value) return;
7846 if(value && value.IsSlaveOf(this)) return;
7852 OldLink slaveHolder;
7853 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
7854 if(slaveHolder.data == this)
7856 master.slaves.Delete(slaveHolder);
7863 value.slaves.Add(OldLink { data = this });
7868 master.hotKeys.Remove(hotKey);
7869 value.hotKeys.Add(hotKey);
7872 if(master && master.defaultControl == this)
7873 master.defaultControl = null;
7875 if(style.isDefault && !value.defaultControl)
7876 value.defaultControl = this;
7882 get { return master ? master : parent; }
7885 property char * text
7887 property_category "Appearance"
7894 caption = new char[strlen(value)+1];
7896 strcpy(caption, value);
7901 get { return caption; }
7906 property_category "Behavior"
7915 master.hotKeys.Add(hotKey = HotKeySlot { });
7919 hotKey.window = this;
7924 master.hotKeys.Delete(hotKey);
7929 get { return hotKey ? hotKey.key : 0; }
7932 property Color background
7934 property_category "Appearance"
7937 background.color = value;
7942 if(this == rootWindow)
7943 guiApp.interfaceDriver.SetRootWindowColor(this);
7946 get { return background.color; }
7949 property Percentage opacity
7951 property_category "Appearance"
7954 background.a = (byte)Min(Max((int)(value * 255), 0), 255);
7955 drawBehind = background.a ? false : true;
7957 get { return background.a / 255.0f; }
7960 property Color foreground
7962 property_category "Appearance"
7970 get { return foreground; }
7973 property BorderStyle borderStyle
7975 property_category "Appearance"
7978 if(!((BorderBits)value).fixed)
7980 style.hasClose = false;
7981 style.hasMaximize = false;
7982 style.hasMinimize = false;
7984 style.borderBits = value;
7988 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
7990 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
7991 Position(x, y, w, h, true, true, true, true, false, true);
7992 CreateSystemChildren();
7995 get { return (BorderStyle)style.borderBits; }
7998 property Size minClientSize
8000 property_category "Layout"
8001 set { minSize = value; }
8002 get { value = minSize; }
8005 property Size maxClientSize
8007 property_category "Layout"
8008 set { maxSize = value; }
8009 get { value = maxSize; }
8012 property bool hasMaximize
8014 property_category "Window Style"
8017 style.hasMaximize = value;
8018 if(value) { style.fixed = true; style.contour = true; }
8022 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8024 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8025 Position(x, y, w, h, true, true, true, true, false, true);
8027 CreateSystemChildren();
8030 get { return style.hasMaximize; }
8033 property bool hasMinimize
8035 property_category "Window Style"
8038 style.hasMinimize = value;
8039 if(value) { style.fixed = true; style.contour = true; }
8043 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8045 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8046 Position(x, y, w, h, true, true, true, true, false, true);
8048 CreateSystemChildren();
8051 get { return style.hasMinimize; }
8054 property bool hasClose
8056 property_category "Window Style"
8059 style.hasClose = value;
8060 if(value) { style.fixed = true; style.contour = true; }
8064 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8065 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8066 Position(x, y, w, h, true, true, true, true, false, true);
8067 CreateSystemChildren();
8070 get { return style.hasClose; }
8073 property bool nonClient
8075 property_category "Layout"
8078 style.nonClient = value;
8080 style.stayOnTop = true;
8082 get { return style.nonClient; }
8085 property bool inactive
8087 property_category "Behavior"
8092 // *** NEW HERE: ***
8096 parent.childrenCycle.Delete(cycle);
8098 parent.childrenOrder.Delete(order);
8105 active = false; // true;
8106 if(parent.activeChild == this)
8107 parent.activeChild = null;
8108 if(parent.activeClient == this)
8109 parent.activeClient = null;
8118 parent.childrenCycle.Insert(
8119 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8120 cycle = OldLink { data = this });
8122 parent.childrenOrder.Insert(
8123 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8124 order = OldLink { data = this });
8127 style.inactive = value;
8129 get { return style.inactive; }
8132 property bool clickThrough
8134 property_category "Behavior"
8135 set { style.clickThrough = value; }
8136 get { return style.clickThrough; }
8139 property bool isRemote
8141 property_category "Behavior"
8142 set { style.isRemote = value; }
8143 get { return style.isRemote; }
8146 property bool noCycle
8148 property_category "Behavior"
8149 set { style.noCycle = value; }
8150 get { return style.noCycle; }
8153 property bool isModal
8155 property_category "Behavior"
8156 set { style.modal = value; }
8157 get { return style.modal; }
8160 property bool interim
8162 property_category "Behavior"
8163 set { style.interim = value; }
8164 get { return style.interim; }
8167 property bool tabCycle
8169 property_category "Behavior"
8170 set { style.tabCycle = value; }
8171 get { return style.tabCycle; }
8174 property bool isDefault
8176 property_category "Behavior"
8184 /*for(sibling = parent.children.first; sibling; sibling = sibling.next)
8185 if(sibling != this && sibling.style.isDefault)
8186 sibling.style.isDefault = false;*/
8187 if(master.defaultControl)
8188 master.defaultControl.style.isDefault = false;
8189 master.defaultControl = this;
8191 else if(master.defaultControl == this)
8192 master.defaultControl = null;
8196 style.isDefault = value;
8198 Position(position.x, position.y, size.w, size.h, true, true, true,true,true, true);
8200 get { return style.isDefault; }
8203 property bool drawBehind
8205 property_category "Window Style"
8206 set { style.drawBehind = value; }
8207 get { return style.drawBehind; }
8210 property bool hasMenuBar
8212 property_category "Window Style"
8222 if(created && !menuBar)
8229 anchor = Anchor { top = 23, left = 1, right = 1 },
8231 inactive = true, nonClient = true
8236 else if(created && menuBar)
8241 style.hasMenuBar = value;
8243 get { return style.hasMenuBar; }
8246 property bool hasStatusBar
8248 property_category "Window Style"
8255 statusBar = StatusBar { this };
8263 style.hasStatusBar = value;
8265 get { return style.hasStatusBar; }
8267 property bool stayOnTop
8269 property_category "Window Style"
8274 if(created && !style.stayOnTop)
8276 if(rootWindow == this)
8277 guiApp.interfaceDriver.OrderRootWindow(this, true);
8278 else if(parent.children.last != this)
8280 parent.children.Move(this, parent.children.last);
8284 style.stayOnTop = true;
8288 if(created && style.stayOnTop)
8290 if(rootWindow == this)
8291 guiApp.interfaceDriver.OrderRootWindow(this, false);
8298 for(order = (this.order == parent.childrenOrder.first) ? null : this.order.prev;
8299 order && ((Window)order.data).style.stayOnTop;
8300 order = (order == parent.childrenOrder.first) ? null : order.prev);
8301 last = order ? order.data : null;
8305 for(last = parent.children.last;
8306 last && last.style.stayOnTop;
8310 parent.children.Move(this, last);
8314 style.stayOnTop = false;
8317 get { return style.stayOnTop; }
8322 property_category "Window Style"
8332 if(menuBar && !value)
8339 if(!menuBar && style.hasMenuBar && value)
8343 this, menu = value, isMenuBar = true,
8344 anchor = Anchor { left = 1, top = 23, right = 1 }, size.h = 24,
8345 inactive = true, nonClient = true
8349 UpdateActiveDocument(null);
8352 get { return menu; }
8355 property FontResource font
8357 property_category "Appearance"
8359 isset { return setFont ? true : false; }
8364 if(value && !setFont) { stopwatching(parent, font); }
8365 else if(!value && setFont)
8371 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8380 RemoveResource(setFont);
8385 RemoveResource(systemFont);
8392 AddResource(setFont);
8395 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
8398 systemFont = guiApp.currentSkin.SystemFont();
8400 usedFont = systemFont;
8401 AddResource(systemFont);
8409 get { return usedFont; }
8412 property SizeAnchor sizeAnchor
8414 property_category "Layout"
8417 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8418 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8419 sizeAnchor.isClientW != sizeAnchor.isClientH;
8426 normalSizeAnchor = sizeAnchor;
8428 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8430 stateAnchor = normalAnchor;
8431 stateSizeAnchor = normalSizeAnchor;
8433 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8434 Position(x,y, w, h, true, true, true, true, false, true);
8441 { sizeAnchor.isClientW ? clientSize.w : size.w, sizeAnchor.isClientH ? clientSize.h : size.h },
8442 sizeAnchor.isClientW,
8443 sizeAnchor.isClientH
8450 property_category "Layout"
8453 Anchor thisAnchor = anchor;
8454 SizeAnchor thisSizeAnchor = sizeAnchor;
8455 bool leftRight = (anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none);
8456 bool topBottom = (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none);
8457 bool isClient = !sizeAnchor.isClientW && !sizeAnchor.isClientH;
8458 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8459 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8460 !sizeAnchor.isClientW && !sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8466 sizeAnchor.isClientW = false;
8467 sizeAnchor.isClientH = false;
8468 sizeAnchor.size = value;
8470 normalSizeAnchor = sizeAnchor;
8472 if(state == normal /*|| state == Hidden*/) // Hidden is new here ...
8474 stateAnchor = normalAnchor;
8475 stateSizeAnchor = normalSizeAnchor;
8477 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8478 Position(x, y, w, h, true, true, true, true, false, true);
8481 get { value = size; }
8484 property Size clientSize
8486 property_category "Layout"
8489 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8490 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8491 sizeAnchor.isClientW && sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8496 sizeAnchor.isClientW = true;
8497 sizeAnchor.isClientH = true;
8498 sizeAnchor.size = value;
8500 normalSizeAnchor = sizeAnchor;
8502 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8504 stateAnchor = normalAnchor;
8505 stateSizeAnchor = normalSizeAnchor;
8507 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8508 Position(x,y, w, h, true, true, true, true, false, true);
8511 get { value = clientSize; }
8514 property Size initSize { get { value = sizeAnchor.size; } };
8516 property Anchor anchor
8518 property_category "Layout"
8519 isset { return (anchor.left.type != offset || anchor.top.type != offset || anchor.right.type || anchor.bottom.type); }
8525 if(anchor.left.type && anchor.right.type && (!value.left.type || !value.right.type))
8527 normalSizeAnchor.isClientW = sizeAnchor.isClientW = false;
8528 normalSizeAnchor.size.w = sizeAnchor.size.w = size.w;
8530 if(anchor.top.type && anchor.bottom.type && (!value.top.type || !value.bottom.type))
8532 normalSizeAnchor.isClientH = sizeAnchor.isClientH = false;
8533 normalSizeAnchor.size.h = sizeAnchor.size.h = size.h;
8537 if(anchor.right.type && (anchor.horz.type == middleRelative || !anchor.left.type))
8539 anchor.left.distance = 0;
8540 anchor.horz.type = 0;
8542 if(anchor.bottom.type && (anchor.vert.type == middleRelative || !anchor.top.type))
8544 anchor.top.distance = 0;
8545 anchor.vert.type = 0;
8554 normalAnchor = anchor;
8556 // Break the anchors for moveable/resizable windows
8557 /*if(style.fixed ) //&& value.left.type == cascade)
8559 ComputeAnchors(anchor, sizeAnchor, &x, &y, &w, &h);
8561 this.anchor = normalAnchor = Anchor { left = x, top = y };
8562 normalSizeAnchor = SizeAnchor { { w, h } };
8565 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8567 stateAnchor = normalAnchor;
8568 stateSizeAnchor = normalSizeAnchor;
8570 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8571 Position(x, y, w, h, true, true, true, true, false, true);
8580 get { value = this ? anchor : Anchor { }; }
8583 property Point position
8585 property_category "Layout"
8588 if(value == null) return;
8590 anchor.left = value.x;
8591 anchor.top = value.y;
8592 anchor.right.type = none;
8593 anchor.bottom.type = none;
8598 normalAnchor = anchor;
8600 // Break the anchors for moveable/resizable windows
8604 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8606 normalAnchor.left = x;
8607 normalAnchor.top = y;
8608 normalAnchor.right.type = none;
8609 normalAnchor.bottom.type = none;
8610 normalSizeAnchor.size.width = w;
8611 normalSizeAnchor.size.height = h;
8615 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8617 stateAnchor = normalAnchor;
8618 stateSizeAnchor = normalSizeAnchor;
8620 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8621 Position(x,y, w, h, true, true, true, true, false, true);
8625 get { value = position; }
8628 property bool disabled
8630 property_category "Behavior"
8633 if(this && disabled != value)
8640 get { return (bool)disabled; }
8643 property bool isEnabled
8648 for(parent = this; parent; parent = parent.parent)
8655 property WindowState state
8657 property_category "Behavior"
8658 set { SetState(value, false, 0); }
8659 get { return this ? state : 0; }
8662 property bool visible
8664 property_category "Behavior"
8667 if(this && !value && !style.hidden && parent)
8669 bool wasActiveChild = parent.activeChild == this;
8670 Window client = null;
8672 style.hidden = true;
8673 if(style.isActiveClient)
8675 parent.numPositions--;
8676 if(state == minimized) parent.numIcons--;
8681 OldLink prevOrder = null;
8683 if(rootWindow == this)
8684 guiApp.interfaceDriver.SetRootWindowState(this, state, false);
8687 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
8690 box.left -= parent.clientStart.x;
8691 box.top -= parent.clientStart.y;
8692 box.right -= parent.clientStart.x;
8693 box.bottom -= parent.clientStart.y;
8697 if(_isModal && master && master.modalSlave == this)
8698 master.modalSlave = null;
8702 OldLink tmpPrev = order.prev;
8703 client = tmpPrev ? tmpPrev.data : null;
8704 if(client && !client.style.hidden && !client.destroyed && client.created)
8705 prevOrder = tmpPrev;
8708 client = tmpPrev ? tmpPrev.data : null;
8709 if(client == this) { client = null; break; }
8710 if(client && ((client.style.hidden) || client.destroyed || !client.created))
8712 tmpPrev = client.order.prev;
8717 prevOrder = tmpPrev;
8722 // If this window can be an active client, make sure the next window we activate can also be one
8723 if(!style.nonClient && style.isActiveClient)
8725 tmpPrev = prevOrder;
8728 client = tmpPrev ? tmpPrev.data : null;
8729 if(client == this) { client = null; break; }
8730 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
8732 tmpPrev = client.order.prev;
8737 prevOrder = tmpPrev;
8741 if(client && client.style.hidden) client = null;
8745 if((wasActiveChild /*parent.activeChild == this*/ || guiApp.interimWindow == this) && true /*activate*/)
8747 if(order && prevOrder && prevOrder.data != this)
8748 ((Window)prevOrder.data).ActivateEx(true, false, false, true, null, null);
8750 ActivateEx(false, false, false, true, null, null);
8752 // TESTING THIS HERE FOR HIDING ACTIVE CLIENT
8753 if(parent.activeClient == this)
8755 parent.activeClient = null;
8756 parent.UpdateActiveDocument(null);
8759 else if(parent.activeClient == this)
8761 parent.activeClient = client;
8762 parent.UpdateActiveDocument(this);
8765 // *** Not doing this anymore ***
8768 parent.childrenCycle.Delete(cycle);
8770 parent.childrenOrder.Delete(order);
8775 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8780 else if(this && value && style.hidden)
8782 style.hidden = false;
8785 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8786 if(rootWindow == this)
8787 guiApp.interfaceDriver.SetRootWindowState(this, state, true);
8789 if(_isModal && master)
8790 master.modalSlave = this;
8792 if(style.isActiveClient)
8794 positionID = parent.GetPositionID(this);
8795 parent.numPositions++;
8796 if(state == minimized) parent.numIcons++;
8799 // *** NOT DOING THIS ANYMORE ***
8801 if(!(style.inactive))
8803 if(!(style.noCycle))
8805 cycle = parent.childrenCycle.AddAfter(
8806 (parent.activeChild && parent.activeChild.cycle) ?
8807 parent.activeChild.cycle.prev : null, sizeof(OldLink));
8810 order = parent.childrenOrder.AddAfter(
8811 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8818 if(true || !parent.activeChild)
8819 ActivateEx(true, false, true, true, null, null);
8821 if(creationActivation == activate)
8822 ActivateEx(true, false, true, true, null, null);
8823 else if(creationActivation == flash && !object)
8826 //SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8830 ConsequentialMouseMove(false);
8836 style.hidden = !value;
8839 get { return (style.hidden || !setVisible) ? false : true; }
8842 property bool isDocument
8844 property_category "Document"
8845 set { style.isDocument = value; }
8846 get { return style.isDocument; }
8849 property bool mergeMenus
8851 property_category "Window Style"
8852 set { mergeMenus = value; }
8853 get { return (bool)mergeMenus; }
8856 property bool hasHorzScroll
8858 property_category "Window Style"
8863 if(!style.hasHorzScroll && created)
8865 CreateSystemChildren();
8866 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8869 else if(style.hasHorzScroll)
8873 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8875 style.hasHorzScroll = value;
8878 get { return style.hasHorzScroll; }
8881 property bool hasVertScroll
8883 property_category "Window Style"
8888 if(!style.hasVertScroll && created)
8890 style.hasVertScroll = true;
8891 CreateSystemChildren();
8892 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8895 else if(style.hasVertScroll)
8899 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8901 style.hasVertScroll = value;
8903 get { return style.hasVertScroll; }
8906 property bool dontHideScroll
8908 property_category "Behavior"
8911 scrollFlags.dontHide = value;
8914 //UpdateScrollBars(true, true);
8915 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
8919 // UpdateScrollBars(true, true);
8920 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
8923 get { return scrollFlags.dontHide; }
8926 property bool dontScrollVert
8928 property_category "Behavior"
8929 set { style.dontScrollVert = value; }
8930 get { return style.dontScrollVert; }
8932 property bool dontScrollHorz
8934 property_category "Behavior"
8935 set { style.dontScrollHorz = value; }
8936 get { return style.dontScrollHorz; }
8939 property bool snapVertScroll
8941 property_category "Behavior"
8944 scrollFlags.snapY = value;
8945 if(sbv) sbv.snap = value;
8947 get { return scrollFlags.snapY; }
8949 property bool snapHorzScroll
8951 property_category "Behavior"
8954 scrollFlags.snapX = value;
8955 if(sbh) sbh.snap = value;
8957 get { return scrollFlags.snapX; }
8960 property Point scroll
8962 property_category "Behavior"
8966 // TESTING THIS IMPLEMENTATION:
8967 SetScrollPosition(value.x, value.y);
8969 get { value = scroll; }
8972 property bool modifyVirtualArea
8974 property_category "Behavior"
8975 set { modifyVirtArea = value; }
8976 get { return (bool)modifyVirtArea; }
8979 property char * fileName
8981 property_category "Document"
8984 if(menu && ((!fileName && value) || (fileName && !value)))
8986 MenuItem item = menu.FindItem(MenuFileSave, 0);
8987 if(item) item.disabled = !modifiedDocument && value;
8992 if(value && value[0])
8993 fileName = CopyString(value);
8995 if(parent && this == parent.activeClient)
8996 parent.UpdateActiveDocument(null);
9000 // if(style.isDocument)
9002 fileMonitor.fileName = value;
9004 get { return fileName; }
9009 property_category "Data"
9014 property bool modifiedDocument
9016 property_category "Document"
9019 if(style.isDocument || fileName)
9023 MenuItem item = menu.FindItem(MenuFileSave, 0);
9024 if(item) item.disabled = !value && fileName;
9028 if(modifiedDocument != value)
9030 modifiedDocument = value;
9031 if(style.isDocument || fileName)
9035 get { return (bool)modifiedDocument; }
9038 property bool showInTaskBar
9040 property_category "Window Style"
9041 set { style.showInTaskBar = value; }
9042 get { return (style.showInTaskBar; }
9044 property FileDialog saveDialog { set { saveDialog = value; } };
9045 property bool isActiveClient
9047 property_category "Behavior"
9048 set { style.isActiveClient = value; }
9049 get { return style.isActiveClient; }
9052 property Cursor cursor
9054 property_category "Appearance"
9058 SelectMouseCursor();
9060 get { return cursor; }
9063 //#if !defined(ECERE_VANILLA)
9064 property char * name
9066 property_category "Design"
9069 return (this && object) ? object.name : null;
9074 activeDesigner.RenameObject(object, value);
9078 property char * displayDriver
9080 property_category "Behavior"
9083 dispDriver = GetDisplayDriver(value);
9084 //DisplayModeChanged();
9088 return dispDriver ? dispDriver.name : null;
9092 // RUNTIME PROPERTIES
9093 property bool autoCreate { set { autoCreate = value; } get { return (bool)autoCreate; } };
9094 property Size scrollArea
9096 property_category "Behavior"
9100 SetScrollArea(value.w, value.h, false);
9102 SetScrollArea(0,0, true);
9104 get { value = scrollArea; }
9107 return scrollArea.w > clientSize.w || scrollArea.h > clientSize.h;
9112 property_category "Layout"
9113 set { if(this) is3D = value; }
9114 get { return (bool)is3D; }
9117 // Runtime Only Properties (No Set, can display the displayable ones depending on the type?)
9119 // Will be merged with font later
9120 property Font fontObject { get { return usedFont ? usedFont.font : null; } };
9121 property Point clientStart { get { value = clientStart; } };
9122 property Point absPosition { get { value = absPosition; } };
9123 property Anchor normalAnchor { get {value = normalAnchor; } };
9124 // property Size normalSizeAnchor { get { value = normalSizeAnchor; } };
9125 property bool active { get { return (bool)active; } };
9126 property bool created { get { return (bool)created; } };
9127 property bool destroyed { get { return (bool)destroyed; } };
9128 property Window firstSlave { get { return slaves.first ? ((OldLink)slaves.first).data : null; } };
9129 property Window firstChild { get { return children.first; } };
9130 property Window lastChild { get { return children.last; } };
9131 property Window activeClient { get { return activeClient; } };
9132 property Window activeChild { get { return activeChild; } };
9133 property Display display { get { return display ? display : ((parent && parent.rootWindow) ? parent.rootWindow.display : null); } };
9134 property DisplaySystem displaySystem { get { return display ? display.displaySystem : null; } };
9135 property ScrollBar horzScroll { get { return sbh; } };
9136 property ScrollBar vertScroll { get { return sbv; } };
9137 property StatusBar statusBar { get { return statusBar; } };
9138 property Window rootWindow { get { return rootWindow; } };
9139 property bool closing { get { return (bool)closing; } set { closing = value; } };
9140 property int documentID { get { return documentID; } };
9141 property Window previous { get { return prev; } }
9142 property Window next { get { return next; } }
9143 property Window nextSlave { get { OldLink link = master ? master.slaves.FindLink(this) : null; return (link && link.next) ? link.next.data : null; } }
9144 property PopupMenu menuBar { get { return menuBar; } }
9145 property ScrollBar sbv { get { return sbv; } }
9146 property ScrollBar sbh { get { return sbh; } }
9147 property bool fullRender { set { fullRender = value; } get { return (bool)fullRender; } }
9148 property void * systemHandle { get { return windowHandle; } }
9149 property Button minimizeButton { get { return sysButtons[0]; } };
9150 property Button maximizeButton { get { return sysButtons[1]; } };
9151 property Button closeButton { get { return sysButtons[2]; } };
9152 property BitmapResource icon
9154 get { return icon; }
9158 if(icon) incref icon;
9160 guiApp.interfaceDriver.SetIcon(this, value);
9163 property bool moveable { get { return (bool)moveable; } set { moveable = value; } };
9164 property bool alphaBlend { get { return (bool)alphaBlend; } set { alphaBlend = value; } };
9165 property bool useSharedMemory { get { return (bool)useSharedMemory; } set { useSharedMemory = value; } };
9166 property CreationActivationOption creationActivation { get { return creationActivation; } set { creationActivation = value; } };
9167 property bool nativeDecorations { get { return (bool)nativeDecorations && (formDesigner || rootWindow == this); } set { nativeDecorations = value; } };
9168 property bool manageDisplay { get { return (bool)manageDisplay; } set { manageDisplay = value; } };
9174 WindowBits style; // Window Style
9175 char * caption; // Name / Caption
9176 Window parent; // Parent window
9177 OldList children; // List of children in Z order
9178 Window activeChild; // Child window having focus
9179 Window activeClient;
9180 Window previousActive; // Child active prior to activating the default child
9181 Window master; // Window owning and receiving notifications concerning this window
9182 OldList slaves; // List of windows belonging to this window
9183 Display display; // Display this window is drawn into
9185 Point position; // Position in parent window client area
9186 Point absPosition; // Absolute position
9187 Point clientStart; // Client area position from (0,0) in this window
9189 Size clientSize; // Client area size
9190 Size scrollArea; // Virtual Scroll area size
9191 Size reqScrollArea; // Requested virtual area size
9192 Point scroll; // Virtual area scrolling position
9193 public ScrollBar sbh, sbv; // Scrollbar window handles
9194 Cursor cursor; // Mouse cursor used for this window
9197 StatusBar statusBar;
9198 Button sysButtons[3];
9200 Box clientArea; // Client Area box clipped to parent
9202 HotKeySlot hotKey; // HotKey for this window
9206 ScrollFlags scrollFlags;// Window Scrollbar Flags
9207 int id; // Control ID
9209 ColorAlpha background; // Background color used to draw the window area
9211 subclass(DisplayDriver) dispDriver; // Display driver name for this window
9212 OldList childrenCycle; // Cycling order
9213 OldLink cycle; // Element of parent's cycling order
9214 OldList childrenOrder; // Circular Z-Order
9215 OldLink order; // Element of parent's circular Z-Order
9216 Window modalSlave; // Slave window blocking this window's interaction
9218 Window rootWindow; // Topmost system managed window
9219 void * windowHandle; // System window handle
9221 DialogResult returnCode;// Return code for modal windows
9223 Point sbStep; // Scrollbar line scrolling steps
9226 SizeAnchor stateSizeAnchor;
9228 Anchor normalAnchor;
9229 SizeAnchor normalSizeAnchor;
9231 Size skinMinSize; // Minimal window size based on style
9232 Point scrolledPos; // Scrolled position
9233 Box box; // Window box clipped to parent
9234 Box * against; // What to clip the box to
9236 Extent dirtyArea { /*first = -1, last = -1, free = -1*/ }; // Area marked for update by Update
9237 Extent renderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered
9238 Extent overRenderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered over children
9239 Extent clipExtent { /*first = -1, last = -1, free = -1*/ }; // Temporary extent against which to clip render area
9240 Extent scrollExtent { /*first = -1, last = -1, free = -1*/ }; // Area to scroll
9241 Point scrolledArea; // Distance to scroll area by
9242 Extent dirtyBack { /*first = -1, last = -1, free = -1*/ }; // Only used by root window
9244 OldList hotKeys; // List of the hotkeys of all children
9245 Window defaultControl; // Default child control
9249 ColorAlpha * palette; // Color palette used for this window
9251 int caretSize; // Size of caret, non zero if a caret is present
9252 Point caretPos; // Caret position
9254 void * systemParent; // Parent System Window for embedded windows
9261 WindowState lastState;
9263 FileMonitor fileMonitor
9265 this, FileChange { modified = true };
9267 bool OnFileNotify(FileChange action, char * param)
9270 fileMonitor.StopMonitoring();
9271 if(OnFileModified(action, param))
9272 fileMonitor.StartMonitoring();
9277 FontResource setFont, systemFont;
9278 FontResource usedFont;
9279 FontResource captionFont;
9281 FileDialog saveDialog;
9283 SizeAnchor sizeAnchor;
9285 // FormDesigner data
9288 Extent * tempExtents; //[4];
9289 BitmapResource icon;
9291 CreationActivationOption creationActivation;
9294 bool active:1; // true if window and ancestors are active
9295 bool acquiredInput:1; // true if the window is processing state based input
9296 bool modifiedDocument:1;
9297 bool disabled:1; // true if window cannot interact
9298 bool isForegroundWindow:1;// true while a root window is being activated
9299 bool visible:1; // Visibility flag
9300 bool destroyed:1; // true if window is being destroyed
9301 bool anchored:1; // true if this window is repositioned when the parent resizes
9302 bool dirty:1; // Flag set to true if any descendant must be redrawn
9308 bool modifyVirtArea:1;
9309 bool noAutoScrollArea:1;
9312 bool setVisible:1; // FOR FORM DESIGNER
9318 bool useSharedMemory:1;
9321 bool nativeDecorations:1;
9322 bool manageDisplay:1;
9323 bool formDesigner:1; // True if we this is running in the form editor
9326 // Checks used internally for them not to take effect in FormDesigner
9327 property bool _isModal { get { return !formDesigner ? style.modal : false; } }
9328 property subclass(DisplayDriver) _displayDriver { get { return !formDesigner ? dispDriver : null; } }
9330 WindowController controller;
9331 public property WindowController controller { get { return controller; } set { delete controller; controller = value; if(controller) incref controller; } }
9334 public class CommonControl : Window
9336 // creationActivation = doNothing;
9339 public class Percentage : float
9341 char * OnGetString(char * string, float * fieldData, bool * needClass)
9345 sprintf(string, "%.2f", this);
9346 c = strlen(string)-1;
9349 if(string[c] != '0')
9350 last = Max(last, c);
9351 if(string[c] == '.')
9364 public void ApplySkin(Class c, char * name, void ** vTbl)
9366 char className[1024];
9371 subclass(Window) wc = (subclass(Window))c;
9372 subclass(Window) base = (subclass(Window))c.base;
9374 sprintf(className, "%sSkin_%s", name, c.name);
9375 wc.pureVTbl = c._vTbl;
9376 c._vTbl = new void *[c.vTblSize];
9377 memcpy(c._vTbl, wc.pureVTbl, c.vTblSize * sizeof(void *));
9378 sc = eSystem_FindClass(c.module.application, className);
9382 for(m = 0; m < c.base.vTblSize; m++)
9384 if(c._vTbl[m] == base.pureVTbl[m])
9385 c._vTbl[m] = vTbl[m];
9390 for(m = 0; m < c.vTblSize; m++)
9392 if(sc._vTbl[m] != wc.pureVTbl[m])
9393 c._vTbl[m] = sc._vTbl[m];
9397 for(d = c.derivatives.first; d; d = d.next)
9399 ApplySkin(d.data, name, c._vTbl);
9403 public void UnapplySkin(Class c)
9405 char className[1024];
9407 subclass(Window) wc = (subclass(Window))c;
9408 subclass(Window) base = (subclass(Window))c.base;
9411 if(wc.pureVTbl && c._vTbl != wc.pureVTbl)
9414 c._vTbl = wc.pureVTbl;
9418 for(d = c.derivatives.first; d; d = d.next)
9420 UnapplySkin(d.data);
9424 void CheckFontIntegrity(Window window)
9429 if(window.usedFont && window.usedFont.font == 0xecececec)
9431 FontResource uf = window.usedFont;
9432 char * className = window._class.name;
9433 char * text = window.text;
9436 for(c = window.firstChild; c; c = c.next)
9437 CheckFontIntegrity(c);
9441 public class ControllableWindow : Window
9443 /*WindowController controller;
9444 public property WindowController controller { get { return controller; } set { delete controller; controller = value; incref controller; } }
9445 ~ControllableWindow() { delete controller; }*/
9448 class WindowControllerInterface : ControllableWindow
9450 bool OnKeyDown(Key key, unichar ch)
9452 bool result = ((int(*)())(void *)controller.OnKeyDown)((void *)controller.controlled, (void *)controller, key, ch);
9454 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown](controller.window, key, ch);
9458 bool OnKeyUp(Key key, unichar ch)
9460 bool result = ((int(*)())(void *)controller.OnKeyUp)((void *)controller.controlled, (void *)controller, key, ch);
9462 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp](controller.window, key, ch);
9466 bool OnKeyHit(Key key, unichar ch)
9468 bool result = ((int(*)())(void *)controller.OnKeyHit)((void *)controller.controlled, (void *)controller, key, ch);
9470 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit](controller.window, key, ch);
9474 bool OnMouseMove(int x, int y, Modifiers mods)
9476 bool result = ((int(*)())(void *)controller.OnMouseMove)((void *)controller.controlled, (void *)controller, x, y, mods);
9478 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove](controller.window, x, y, mods);
9482 bool OnLeftButtonDown(int x, int y, Modifiers mods)
9484 bool result = ((int(*)())(void *)controller.OnLeftButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9486 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown](controller.window, x, y, mods);
9490 bool OnLeftButtonUp(int x, int y, Modifiers mods)
9492 bool result = ((int(*)())(void *)controller.OnLeftButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9494 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp](controller.window, x, y, mods);
9498 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
9500 bool result = ((int(*)())(void *)controller.OnLeftDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9502 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick](controller.window, x, y, mods);
9506 bool OnRightButtonDown(int x, int y, Modifiers mods)
9508 bool result = ((int(*)())(void *)controller.OnRightButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9510 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown](controller.window, x, y, mods);
9514 bool OnRightButtonUp(int x, int y, Modifiers mods)
9516 bool result = ((int(*)())(void *)controller.OnRightButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9518 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp](controller.window, x, y, mods);
9522 bool OnRightDoubleClick(int x, int y, Modifiers mods)
9524 bool result = ((int(*)())(void *)controller.OnRightDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9526 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick](controller.window, x, y, mods);
9530 bool OnMiddleButtonDown(int x, int y, Modifiers mods)
9532 bool result = ((int(*)())(void *)controller.OnMiddleButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9534 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown](controller.window, x, y, mods);
9538 bool OnMiddleButtonUp(int x, int y, Modifiers mods)
9540 bool result = ((int(*)())(void *)controller.OnMiddleButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9542 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp](controller.window, x, y, mods);
9546 bool OnMiddleDoubleClick(int x, int y, Modifiers mods)
9548 bool result = ((int(*)())(void *)controller.OnMiddleDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9550 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick](controller.window, x, y, mods);
9554 void OnResize(int width, int height)
9556 ((int(*)())(void *)controller.OnResize)((void *)controller.controlled, (void *)controller, width, height);
9557 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnResize](controller.window, width, height);
9560 void OnRedraw(Surface surface)
9562 ((int(*)())(void *)controller.OnRedraw)((void *)controller.controlled, (void *)controller, surface);
9563 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRedraw](controller.window, surface);
9568 bool result = ((int(*)())(void *)controller.OnCreate)((void *)controller.controlled, (void *)controller);
9570 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnCreate](controller.window);
9575 public class WindowController<class V>
9578 property Window window
9582 uint size = class(Window).vTblSize;
9585 windowVTbl = new void *[size];
9586 memcpy(windowVTbl, value._vTbl, size * sizeof(void *));
9587 if(value._vTbl == value._class._vTbl)
9589 value._vTbl = new void *[value._class.vTblSize];
9590 memcpy(value._vTbl + size, value._class._vTbl + size, (value._class.vTblSize - size) * sizeof(void *));
9594 for(c = 0; c < size; c++)
9596 void * function = class(WindowControllerInterface)._vTbl[c];
9597 if(function != DefaultFunction)
9598 value._vTbl[c] = function;
9600 value._vTbl[c] = windowVTbl[c];
9605 memcpy(value._vTbl, windowVTbl, class(Window).vTblSize * sizeof(void *));
9608 get { return window; }
9610 property V controlled
9612 set { controlled = value; }
9613 get { return controlled; }
9615 virtual bool V::OnKeyDown(WindowController controller, Key key, unichar ch);
9616 virtual bool V::OnKeyUp(WindowController controller, Key key, unichar ch);
9617 virtual bool V::OnKeyHit(WindowController controller, Key key, unichar ch);
9618 virtual bool V::OnMouseMove(WindowController controller, int x, int y, Modifiers mods);
9619 virtual bool V::OnLeftButtonDown(WindowController controller, int x, int y, Modifiers mods);
9620 virtual bool V::OnLeftButtonUp(WindowController controller, int x, int y, Modifiers mods);
9621 virtual bool V::OnLeftDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9622 virtual bool V::OnRightButtonDown(WindowController controller, int x, int y, Modifiers mods);
9623 virtual bool V::OnRightButtonUp(WindowController controller, int x, int y, Modifiers mods);
9624 virtual bool V::OnRightDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9625 virtual bool V::OnMiddleButtonDown(WindowController controller, int x, int y, Modifiers mods);
9626 virtual bool V::OnMiddleButtonUp(WindowController controller, int x, int y, Modifiers mods);
9627 virtual bool V::OnMiddleDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9628 virtual void V::OnResize(WindowController controller, int width, int height);
9629 virtual void V::OnRedraw(WindowController controller, Surface surface);
9630 virtual bool V::OnCreate(WindowController controller);
9633 int (** windowVTbl)();