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 AddBox(extentBox.box);
226 void IntersectBox(Box box)
228 // Clip all boxes of extent against inside of the new box
229 BoxItem extentBox, next;
231 FASTLIST_LOOPN(this, extentBox, next)
233 if(box.left > extentBox.box.left) extentBox.box.left = box.left;
234 if(box.top > extentBox.box.top) extentBox.box.top = box.top;
235 if(box.right < extentBox.box.right) extentBox.box.right = box.right;
236 if(box.bottom < extentBox.box.bottom) extentBox.box.bottom = box.bottom;
237 if(extentBox.box.right < extentBox.box.left || extentBox.box.bottom < extentBox.box.top)
242 void ExcludeBox(Box box, Extent temp)
249 FASTLIST_LOOP(temp, extentBox)
251 if(extentBox.box.left < box.right && extentBox.box.right > box.left &&
252 extentBox.box.top < box.bottom && extentBox.box.bottom > box.top)
255 if(extentBox.box.top < box.top && extentBox.box.bottom >= box.top)
259 extentBox.box.left, extentBox.box.top,
260 extentBox.box.right, Min(extentBox.box.bottom, box.top -1)
266 if(extentBox.box.bottom > box.bottom && extentBox.box.top <= box.bottom)
270 extentBox.box.left, Max(extentBox.box.top,box.bottom +1),
271 extentBox.box.right, extentBox.box.bottom
277 if(extentBox.box.bottom >= box.top && extentBox.box.top <= box.bottom)
280 if(extentBox.box.left < box.left && extentBox.box.right >= box.left)
284 extentBox.box.left, Max(extentBox.box.top, box.top),
285 Min(extentBox.box.right, box.left-1), Min(extentBox.box.bottom, box.bottom)
291 if(extentBox.box.right > box.right && extentBox.box.left <= box.right)
295 Max(extentBox.box.left, box.right+1), Max(extentBox.box.top, box.top),
296 extentBox.box.right, Min(extentBox.box.bottom, box.bottom)
304 AddBox(extentBox.box);
310 void UnionBox(Box box, Extent temp)
312 BoxItem extentBox, next;
314 // First pass: check if this box is not already covered by one of the extent's box
315 FASTLIST_LOOP(this, extentBox)
317 if(extentBox.box.left <= box.left && extentBox.box.right >= box.right &&
318 extentBox.box.top <= box.top && extentBox.box.bottom >= box.bottom)
325 // Second pass: only keep boxes not completely covered in the new box
326 FASTLIST_LOOPN(this, extentBox, next)
328 if(extentBox.box.left >= box.left && extentBox.box.right <= box.right &&
329 extentBox.box.top >= box.top && extentBox.box.bottom <= box.bottom)
333 // Add the exclusion to the extent
334 ExcludeBox(box, temp);
337 if(box.bottom >= box.top && box.right >= box.left)
339 // Optimization: if the resulting boxes touch, add them smarter
340 FASTLIST_LOOP(this, extentBox)
342 if(box.top == extentBox.box.top && box.bottom == extentBox.box.bottom)
344 if(Abs(box.right - extentBox.box.left) <= 1)
346 extentBox.box.left = box.left;
349 else if(Abs(box.left - extentBox.box.right) <= 1)
351 extentBox.box.right = box.right;
355 else if(box.left == extentBox.box.left && box.right == extentBox.box.right)
357 if(Abs(box.bottom - extentBox.box.top) <= 1)
359 extentBox.box.top = box.top;
362 else if(Abs(box.top - extentBox.box.bottom) <= 1)
364 extentBox.box.bottom = box.bottom;
376 void Union(Extent b, Extent temp)
380 FASTLIST_LOOP(b, extentBox)
381 UnionBox(extentBox.box, temp);
384 void Intersection(Extent b, Extent temp, Extent temp2, Extent temp3)
391 FASTLIST_LOOP(b, extentBox)
394 temp2.IntersectBox(extentBox.box);
401 void Exclusion(Extent b, Extent temp)
404 FASTLIST_LOOP(b, extentBox)
405 ExcludeBox(extentBox.box, temp);
408 void Offset(int x, int y)
411 FASTLIST_LOOP(this, extentBox)
413 extentBox.box.left += x;
414 extentBox.box.top += y;
415 extentBox.box.right += x;
416 extentBox.box.bottom += y;
421 private define MINIMIZED_WIDTH = 160;
422 private define CASCADE_SPACE = 16;
424 // namespace Windows;
426 private class ScrollFlags
428 bool snapX:1, snapY:1, dontHide:1;
431 public class BorderBits { public: bool contour:1, fixed:1, sizable:1, deep:1, bevel:1; };
433 class WindowBits : BorderBits
435 BorderBits borderBits:5:0;
436 bool hidden:1, isActiveClient:1, hasHorzScroll:1, hasVertScroll:1, stayOnTop:1, modal:1, unused1:1, isDefault:1, inactive:1, isRemote:1, drawBehind:1;
437 bool interim:1, tabCycle:1, noCycle:1, dontScrollHorz:1, dontScrollVert:1, hasMaximize:1, hasMinimize:1, hasClose:1;
438 bool embedded:1, unused2:1, hasMenuBar:1, isDocument:1, showInTaskBar:1, hasStatusBar:1, nonClient:1, clickThrough:1;
441 public enum BorderStyle : BorderBits
444 contour = BorderBits { contour = true },
445 fixed = BorderBits { fixed = true } | contour,
446 sizable = BorderBits { sizable = true } | fixed,
447 deep = BorderBits { deep = true },
448 bevel = BorderBits { bevel = true },
449 sizableDeep = sizable|deep,
450 sizableBevel = sizable|bevel,
451 fixedDeep = fixed|deep,
452 fixedBevel = fixed|bevel,
453 deepContour = deep|contour
456 public enum CreationActivationOption
458 activate, flash, doNothing
461 public enum WindowState { normal, minimized, maximized };
463 private class ResPtr : struct
470 private class HotKeySlot : struct
472 HotKeySlot prev, next;
480 class_data char * icon;
482 class_default_property text;
483 // class_initialize GuiApplication::Initialize;
484 class_designer FormDesigner;
485 class_property char * icon
487 set { class_data(icon) = value; }
488 get { return class_data(icon); }
493 if(guiApp) guiApp.Initialize(true);
495 if(guiApp && guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
497 if(_vTbl == ((subclass(Window))_class).pureVTbl)
499 _vTbl = _class._vTbl;
501 else if(_vTbl != _class._vTbl)
504 for(m = 0; m < _class.vTblSize; m++)
506 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
507 _vTbl[m] = _class._vTbl[m];
512 //tempExtents[0] = { /*first = -1, last = -1, free = -1*/ };
513 //tempExtents[1] = { /*first = -1, last = -1, free = -1*/ };
514 //tempExtents[2] = { /*first = -1, last = -1, free = -1*/ };
515 //tempExtents[3] = { /*first = -1, last = -1, free = -1*/ };
519 // caption = CopyString(class.name);
521 children.offset = (byte*)&prev - (byte*)this;
522 childrenOrder.circ = true;
523 childrenCycle.circ = true;
525 maxSize = Size { MAXINT, MAXINT };
529 //style.isActiveClient = true;
532 modifyVirtArea = true;
533 manageDisplay = true;
535 // scrollFlags = ScrollFlags { snapX = true, snapY = true };
536 sbStep.x = sbStep.y = 8;
538 if(guiApp) // dynamic_cast<GuiApplication>(thisModule)
540 cursor = guiApp.GetCursor(arrow);
541 property::parent = guiApp.desktop;
552 stopwatching(parent, font);
556 // Prevent destructor from being called again...
562 /////////////////////////////////
565 OldLink slave = master.slaves.FindLink(this);
566 master.slaves.Delete(slave);
573 parent.childrenCycle.Remove(cycle);
575 parent.childrenOrder.Remove(order);
576 parent.children.Remove(this);
581 /////////////////////////////////
583 while(ptr = resources.first)
586 resources.Delete(ptr);
593 for(child = children.first; child; child = child.next)
595 // child.stopwatching(this, font);
597 eInstance_StopWatching(this, __ecereProp___ecereNameSpace__ecere__gui__Window_font, child);
598 // Don't want property here
599 *&child.parent = null;
602 while(slave = slaves.first)
604 // Don't want property here
605 *&((Window)slave.data).master = null;
606 slaves.Delete(slave);
609 // Because we do a decref in DestroyEx...
617 // Why was this commented?
618 //if(this != guiApp.desktop)
631 if(((subclass(Window))_class).pureVTbl)
633 if(_vTbl == _class._vTbl)
635 _vTbl = ((subclass(Window))_class).pureVTbl;
640 for(m = 0; m < _class.vTblSize; m++)
642 if(_vTbl[m] == _class._vTbl[m])
643 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
647 if(_vTbl == ((subclass(Window))_class).pureVTbl || _vTbl == _class._vTbl)
650 dirtyArea.Free(null);
651 renderArea.Free(null);
652 overRenderArea.Free(null);
653 clipExtent.Free(null);
654 scrollExtent.Free(null);
655 dirtyBack.Free(null);
659 tempExtents[0].Free(null);
660 tempExtents[1].Free(null);
661 tempExtents[2].Free(null);
662 tempExtents[3].Free(null);
667 //#if !defined(ECERE_VANILLA)
668 char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
670 if(this == activeDesigner)
674 char * name = property::name;
675 return name ? name : "";
680 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
681 bool OnGetDataFromString(char * string)
683 FormDesigner designer = (FormDesigner)activeDesigner.classDesigner;
686 if(!strcmp(string, "this") || !strcmp(string, designer.form.name))
687 this = designer.form;
688 else if(!strcmpi(string, "(Desktop)"))
689 this = activeDesigner;
691 return activeDesigner.FindObject(&this, string);
697 // --- Window updates system ---
699 // Setup a bitmap for Redrawing on client area of Window
700 Surface Redraw(Box box)
702 Surface surface = null;
704 Box clientArea = this.clientArea;
708 mox.left -= clientStart.x;
709 mox.top -= clientStart.y;
710 mox.right -= clientStart.x;
711 mox.bottom -= clientStart.y;
713 mox.Clip(clientArea);
714 // mox.ClipOffset(against, scrolledPos.x, scrolledPos.y);
716 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && mox.right >= mox.left && mox.bottom >= mox.top)
718 int x = absPosition.x + clientStart.x;
719 int y = absPosition.y + clientStart.y;
720 if(rootWindow.nativeDecorations)
722 x -= rootWindow.clientStart.x;
723 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
725 if(!guiApp.fullScreenMode || is3D)
727 x -= rootWindow.absPosition.x;
728 y -= rootWindow.absPosition.y;
732 x += rootWindow.parent.clientStart.x;
733 y += rootWindow.parent.clientStart.y;
735 mox.left += rootWindow.parent.clientStart.x;
736 mox.top += rootWindow.parent.clientStart.y;
737 mox.right += rootWindow.parent.clientStart.x;
738 mox.bottom += rootWindow.parent.clientStart.y;
743 surface = display.GetSurface(x, y, mox);
746 surface.width = clientSize.w;
747 surface.height = clientSize.h;
753 // Setup a bitmap for Redrawing on full Window
754 Surface RedrawFull(Box box)
756 Surface surface = null;
764 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && box.right >= box.left && box.bottom >= box.top)
766 int x = absPosition.x;
767 int y = absPosition.y;
768 if(rootWindow.nativeDecorations)
770 x -= rootWindow.clientStart.x;
771 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
773 if(!guiApp.fullScreenMode || is3D)
775 x -= rootWindow.absPosition.x;
776 y -= rootWindow.absPosition.y;
779 x += rootWindow.parent.clientStart.x;
780 y += rootWindow.parent.clientStart.y;
782 mox.left += rootWindow.parent.clientStart.x;
783 mox.top += rootWindow.parent.clientStart.y;
784 mox.right += rootWindow.parent.clientStart.x;
785 mox.bottom += rootWindow.parent.clientStart.y;
790 surface = display.GetSurface(x, y, mox);
793 surface.width = size.w;
794 surface.height = size.h;
800 void FigureCaption(char * caption)
804 strcpy(caption, this.caption);
805 if(style.isDocument || fileName)
807 if(caption[0]) strcat(caption, " - ");
809 strcat(caption, fileName);
813 sprintf(title, "Untitled %d", documentID);
814 strcat(caption, title);
817 strcat(caption, " *");
819 if(activeClient && menuBar &&
820 activeClient.state == maximized)
822 if(activeClient.caption)
824 if(caption[0]) strcat(caption, " - ");
825 strcat(caption, activeClient.caption);
827 if(activeClient.style.isDocument || activeClient.fileName)
829 if(caption[0]) strcat(caption, " - ");
830 strcat(caption, "[");
831 if(activeClient.fileName)
832 strcat(caption, activeClient.fileName);
836 sprintf(title, "Untitled %d", activeClient.documentID);
837 strcat(caption, title);
839 if(activeClient.modifiedDocument)
840 strcat(caption, " *");
841 strcat(caption, "]");
846 // Code for returning dirty from ScrollDisplay:
848 for(d = 0; d<scrollExtent.count; d++)
850 Box * box = &scrollExtent.boxes[d];
856 Min(box.right, box.left-scroll.x),box.bottom
858 dirtyArea.UnionBox(update);
864 Max(box.left, box.right-scroll.x), box.top,
865 box.right, box.bottom
867 dirtyArea.UnionBox(update);
875 box.right, Min(box.bottom, box.top-scroll.y),
877 dirtyArea.UnionBox(update);
883 box.left, Max(box.top, box.bottom-scroll.y),
884 box.right, box.bottom
886 dirtyArea.UnionBox(update);
891 void UpdateDecorations(void)
893 // TODO: *** TEMPORARY HACK ***
900 Update({ -clientStart.x, -clientStart.y, -clientStart.x + size.w-1, 0 });
902 Update({ -clientStart.x, clientSize.h, -clientStart.x + size.w-1, -clientStart.y + size.h-1 });
904 Update({ -clientStart.x,0, -1, clientSize.h-1 });
906 Update({ clientSize.w, 0, -clientStart.x + size.w-1, clientSize.h-1 });
909 // Returns w & h for Position
910 void ComputeAnchors(Anchor anchor, SizeAnchor sizeAnchor, int *ox, int *oy, int *ow, int *oh)
912 Window parent = this.parent ? this.parent : guiApp.desktop;
913 int vpw = parent ? parent.clientSize.w : 0;
914 int vph = parent ? parent.clientSize.h : 0;
915 int pw = parent ? parent.clientSize.w : 0;
916 int ph = parent ? parent.clientSize.h : 0;
917 int w = sizeAnchor.size.w, h = sizeAnchor.size.h;
918 int x = anchor.left.distance, y = anchor.top.distance;
920 MinMaxValue ew = 0, eh = 0;
922 float cascadeW, cascadeH;
924 int tilingW, tilingH, tilingSplit, tilingLastH;
925 int addX = 0, addY = 0;
927 if(parent && rootWindow == this && guiApp && guiApp.interfaceDriver)
929 Window masterWindow = this;
930 Box box { addX, addY, addX + vpw - 1, addY + vph - 1 };
933 if(master == guiApp.desktop)
934 masterWindow = guiApp.desktop.activeChild;
936 masterWindow = master.rootWindow;
937 if(!masterWindow) masterWindow = this;
939 guiApp.interfaceDriver.GetScreenArea(masterWindow, box);
940 if((anchor.left.type == offset && anchor.right.type == offset) || anchor.left.type == none)
943 pw = vpw = box.right - box.left + 1;
945 if((anchor.top.type == offset && anchor.bottom.type == offset) || anchor.top.type == none)
948 ph = vph = box.bottom - box.top + 1;
964 vpw = pw = parent.size.w;
965 vph = ph = parent.size.h;
967 else if(!style.fixed /*|| style.isDocument*/)
969 if(!style.dontScrollHorz && parent.scrollArea.w) vpw = parent.scrollArea.w;
970 if(!style.dontScrollVert && parent.scrollArea.h) vph = parent.scrollArea.h;
972 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
975 Desktop3D_FixSize(&pw, &ph);
976 Desktop3D_FixSize(&vpw, &vph);
979 if(pw < skinMinSize.w) pw = skinMinSize.w;
980 if(ph < skinMinSize.h) ph = skinMinSize.h;
981 if(vpw < skinMinSize.w) vpw = skinMinSize.w;
982 if(vph < skinMinSize.h) vph = skinMinSize.h;
984 // TODO: Must fix what we're snapping
989 SNAPUP(x, textCellW);
991 else if(anchor.right.type)
993 SNAPDOWN(x, textCellW);
998 SNAPUP(y, textCellH);
1000 else if(anchor.bottom.type)
1002 SNAPDOWN(y, textCellH);
1006 // This is required to get proper initial decoration size using native decorations on Windows
1007 if(nativeDecorations && guiApp && guiApp.interfaceDriver && !visible)
1008 guiApp.interfaceDriver.PositionRootWindow(this, x, y, size.w, size.h, true, true);
1009 GetDecorationsSize(&ew, &eh);
1011 if(anchor.left.type >= cascade && (state == normal /*|| state == Hidden*/))
1013 if(parent.sbv && !parent.sbv.style.hidden)
1014 pw += guiApp.currentSkin.VerticalSBW();
1015 if(parent.sbh && !parent.sbh.style.hidden)
1016 ph += guiApp.currentSkin.HorizontalSBH();
1018 if(anchor.left.type == cascade)
1020 w = (int)(pw * 0.80);
1021 h = (int)(ph * 0.80);
1023 else if(anchor.left.type >= vTiled)
1028 numTiling = parent.numPositions - parent.numIcons;
1029 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1030 if(anchor.left.type == vTiled)
1032 tilingH = (int)sqrt(numTiling);
1033 tilingW = numTiling / tilingH;
1037 tilingW = (int)sqrt(numTiling);
1038 tilingH = numTiling / tilingW;
1041 leftOver = numTiling - tilingH * tilingW;
1044 tilingSplit = (tilingW - leftOver) * tilingH;
1045 tilingLastH = tilingH+1;
1048 tilingSplit = numTiling;
1050 if(positionID >= tilingSplit)
1052 x = pw * (tilingSplit / tilingH + (positionID - tilingSplit) / tilingLastH)/tilingW;
1053 y = ph * ((positionID - tilingSplit) % tilingLastH) / tilingLastH;
1054 x2 = pw * (tilingSplit/tilingH + (positionID - tilingSplit) / tilingLastH + 1)/tilingW;
1055 y2 = ph * (((positionID - tilingSplit) % tilingLastH) + 1) / tilingLastH;
1059 x = pw * (positionID / tilingH) / tilingW;
1060 y = ph * (positionID % tilingH) / tilingH;
1061 x2 = pw * (positionID / tilingH + 1) / tilingW;
1062 y2 = ph * ((positionID % tilingH) + 1) / tilingH;
1066 SNAPDOWN(x, textCellW);
1067 SNAPDOWN(y, textCellH);
1068 SNAPDOWN(x2, textCellW);
1069 SNAPDOWN(y2, textCellH);
1077 if(sizeAnchor.isClientW) w += ew;
1078 if(sizeAnchor.isClientH) h += eh;
1080 if(anchor.left.type == offset)
1081 x = anchor.left.distance;
1082 else if(anchor.left.type == relative)
1083 x = (anchor.left.percent < 0) ? ((int)(vpw * anchor.left.percent - 0.5)) : (int)(vpw * anchor.left.percent + 0.5);
1084 else if(anchor.right.type == relative)
1085 // ex = (anchor.right.percent < 0) ? ((int)(vpw * anchor.right.percent + 0)) : ((int)(vpw * anchor.right.percent + 0));
1086 ex = (anchor.right.percent < 0) ? ((int)(vpw * (1.0-anchor.right.percent) + 0)) : ((int)(vpw * (1.0-anchor.right.percent) + 0));
1087 else if(anchor.right.type == offset)
1088 ex = vpw - anchor.right.distance;
1090 if(anchor.top.type == offset)
1091 y = anchor.top.distance;
1092 else if(anchor.top.type == relative)
1093 y = (anchor.top.percent < 0) ? ((int)(vph * anchor.top.percent - 0.5)) : ((int)(vph * anchor.top.percent + 0.5));
1094 else if(anchor.bottom.type == relative)
1095 //ey = (anchor.bottom.percent < 0) ? ((int)(vph * anchor.bottom.percent + 0)) : ((int)(vph * anchor.bottom.percent + 0));
1096 ey = (anchor.bottom.percent < 0) ? ((int)(vph * (1.0-anchor.bottom.percent) + 0)) : ((int)(vph * (1.0-anchor.bottom.percent) + 0));
1097 else if(anchor.bottom.type == offset)
1098 ey = vph - anchor.bottom.distance;
1100 if(anchor.left.type && anchor.right.type)
1102 switch(anchor.right.type)
1105 ex = pw * (1.0f-anchor.right.percent);
1106 w = Max((int)(ex + 0.5) - x, 0);
1109 ex = vpw - anchor.right.distance;
1110 w = Max((int)(ex + 0.5) - x, 0);
1114 if(anchor.top.type && anchor.bottom.type)
1116 switch(anchor.bottom.type)
1119 ey = ph * (1.0f-anchor.bottom.percent);
1120 h = Max((int)(ey + 0.5) - y, 0);
1123 ey = vph - anchor.bottom.distance;
1124 h = Max((int)(ey + 0.5) - y, 0);
1133 if(state == normal /*|| state == Hidden*/)
1135 bool addSbV = false, addSbH = false;
1137 if(sizeAnchor.isClientW || (anchor.left.type && anchor.right.type)) w = Max(w, 1); else w = Max(w, 0);
1138 if(sizeAnchor.isClientH || (anchor.top.type && anchor.bottom.type)) h = Max(h, 1); else h = Max(h, 0);
1140 w = Max(w, minSize.w);
1141 h = Max(h, minSize.h);
1142 w = Min(w, maxSize.w);
1143 h = Min(h, maxSize.h);
1145 if((sizeAnchor.isClientW || !w || (anchor.left.type && anchor.right.type)) && reqScrollArea.h > h /*&& w*/ && sbv)
1147 if(w) w -= guiApp.currentSkin.VerticalSBW();
1150 if((sizeAnchor.isClientH || !h || (anchor.top.type && anchor.bottom.type)) && reqScrollArea.w > w /*&& h*/ && sbh)
1152 if(h) h -= guiApp.currentSkin.HorizontalSBH();
1156 if(!OnResizing(&w, &h))
1162 if((addSbV)) // || reqScrollArea.h > h) && sbv)
1163 w += guiApp.currentSkin.VerticalSBW();
1164 if((addSbH)) // || reqScrollArea.w > w) && sbh)
1165 h += guiApp.currentSkin.HorizontalSBH();
1167 w = Max(w, skinMinSize.w);
1168 h = Max(h, skinMinSize.h);
1181 SNAPDOWN(w, textCellW);
1182 SNAPDOWN(h, textCellH);
1185 if(anchor.left.type == cascade && (state == normal /*|| state == Hidden*/))
1187 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1190 (pw - w) / CASCADE_SPACE,
1191 (ph - h) / CASCADE_SPACE);
1197 cascW = (pw - w) / (numCascade-1);
1198 cascH = (ph - h) / (numCascade-1);
1199 SNAPDOWN(cascW, textCellW);
1200 SNAPDOWN(cascH, textCellH);
1201 cascadeW = (float)cascW;
1202 cascadeH = (float)cascH;
1206 numCascade = Max(numCascade, 2);
1207 cascadeW = (float)(pw - w) / (numCascade-1);
1208 cascadeH = (float)(ph - h) / (numCascade-1);
1211 x = (int)((positionID % numCascade) * cascadeW);
1212 y = (int)((positionID % numCascade) * cascadeH);
1214 else if(anchor.left.type < vTiled)
1216 if(!anchor.left.type || anchor.horz.type == middleRelative)
1218 if(!anchor.right.type)
1220 if(anchor.horz.type == middleRelative)
1221 x = (int)(vpw * (0.5 + anchor.horz.percent) - w / 2);
1223 x = vpw / 2 + anchor.horz.distance - w / 2;
1229 // case A_EDGE: x = x - w; break;
1231 if(!anchor.top.type || anchor.vert.type == middleRelative)
1233 if(!anchor.bottom.type)
1235 if(anchor.vert.type == middleRelative)
1236 y = (int)(vph * (0.5 + anchor.vert.percent) - h / 2);
1238 y = vph / 2 + anchor.vert.distance - h / 2;
1244 // case A_EDGE: y = y - h; break;
1247 if((state == normal /*|| state == Hidden*/) && !OnMoving(&x, &y, w, h))
1255 SNAPDOWN(x, textCellW);
1256 SNAPDOWN(y, textCellH);
1268 if(anchored && style.fixed && style.isActiveClient)
1273 void UpdateCaret(bool forceUpdate, bool erase)
1275 static Window lastWindow = null;
1276 static int caretX, caretY, caretSize;
1278 if(guiApp && guiApp.caretOwner == this)
1280 int x = caretPos.x - scroll.x;
1281 int y = caretPos.y - scroll.y;
1283 if((erase || this.caretSize) &&
1284 x >= clientArea.left && x <= clientArea.right &&
1285 y >= clientArea.top && y <= clientArea.bottom)
1289 guiApp.interfaceDriver.SetCaret(
1290 x + absPosition.x + clientStart.x,
1291 y + absPosition.y + clientStart.y, this.caretSize);
1292 guiApp.caretEnabled = true;
1294 if(erase || lastWindow != this || caretX != x || caretY != y || caretSize != this.caretSize || forceUpdate)
1298 if(lastWindow != this)
1300 updateBox.left = x + 1;
1302 updateBox.right = x + 2;
1303 updateBox.bottom = y + this.caretSize - 1;
1307 updateBox.left = Min(x + 1, caretX + 1);
1308 updateBox.top = Min(y, caretY);
1309 updateBox.right = Max(x + 2, caretX + 2);
1310 updateBox.bottom = Max(y + this.caretSize - 1, caretY + caretSize - 1);
1313 guiApp.caretOwner.Update(updateBox);
1320 caretSize = this.caretSize;
1326 guiApp.interfaceDriver.SetCaret(0,0,0);
1327 guiApp.caretEnabled = false;
1333 void SetPosition(int x, int y, int w, int h, bool modifyArea, bool modifyThisArea, bool modifyClientArea)
1338 scrolledPos.x = position.x = x;
1339 scrolledPos.y = position.y = y;
1341 clientSize.w = size.w = w;
1342 clientSize.h = size.h = h;
1344 if(parent && !style.nonClient)
1346 //if(!style.fixed || style.isDocument)
1348 if(!style.dontScrollHorz) scrolledPos.x -= parent.scroll.x;
1349 if(!style.dontScrollVert) scrolledPos.y -= parent.scroll.y;
1353 clientStart.x = clientStart.y = 0;
1355 SetWindowArea(&clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1357 //if(!activeClient || activeClient.state != maximized)
1358 if(!noAutoScrollArea)
1360 // Check if scroll area must be modified
1361 if(guiApp && !guiApp.modeSwitching && (sbv || sbh))
1363 bool foundChild = false;
1365 int cw = clientSize.w;// + ((!sbv || sbv.range > 1) ? guiApp.currentSkin.VerticalSBW() : 0);
1366 int ch = clientSize.h;// + ((!sbh || sbh.rangw > 1) ? guiApp.currentSkin.HorizontalSBH() : 0);
1367 for(child = children.first; child; child = child.next)
1369 if(child.modifyVirtArea && !child.style.hidden && child.created && /*!child.anchored &&*/
1370 !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1372 if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == offset)
1373 w = Max(w, child.position.x + child.size.w);
1374 else if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == none)
1375 w = Max(w, Max(child.position.x, 0) + child.size.w);
1376 if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == offset)
1377 h = Max(h, child.position.y + child.size.h);
1378 else if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == none)
1379 h = Max(h, Max(child.position.y, 0) + child.size.h);
1384 if(foundChild && (w > cw || h > ch))
1386 //if((w > reqScrollArea.w) || (h > reqScrollArea.w))
1388 int stepX = sbStep.x, stepY = sbStep.y;
1389 // Needed to make snapped down position match the skin's check of client area
1390 // against realvirtual
1393 SNAPDOWN(stepX, textCellW);
1394 SNAPDOWN(stepY, textCellH);
1395 stepX = Max(stepX, textCellW);
1396 stepY = Max(stepY, textCellH);
1398 if(scrollFlags.snapX)
1400 if(scrollFlags.snapY)
1403 reqScrollArea.w = w;
1404 reqScrollArea.h = h;
1407 else if(reqScrollArea.w || reqScrollArea.h)
1409 reqScrollArea.w = 0;
1410 reqScrollArea.h = 0;
1411 SetScrollPosition(0,0);
1416 // Automatic MDI Client Scrolling Area Adjustment
1417 if(parent && !parent.noAutoScrollArea)
1419 if(modifyArea && modifyVirtArea /*&& !anchored*/ && (parent.sbv || parent.sbh) &&
1420 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient)
1422 Window parent = this.parent;
1423 int w = parent.reqScrollArea.w;
1424 int h = parent.reqScrollArea.h;
1426 if(stateAnchor.right.type == none && stateAnchor.left.type == offset)
1427 w = Max(w, position.x + size.w);
1428 else if(stateAnchor.right.type == none && stateAnchor.left.type == none)
1429 w = Max(w, Max(position.x, 0) + size.w);
1430 if(stateAnchor.bottom.type == none && stateAnchor.top.type == offset)
1431 h = Max(h, position.y + size.h);
1432 else if(stateAnchor.bottom.type == none && stateAnchor.top.type == none)
1433 h = Max(h, Max(position.y, 0) + size.h);
1435 if((w > parent.clientSize.w && w > parent.reqScrollArea.w) ||
1436 (h > parent.clientSize.h && h > parent.reqScrollArea.h))
1438 /*bool resize = false;
1439 int stepX = parent.sbStep.x, stepY = parent.sbStep.y;
1440 // Needed to make snapped down position match the skin's check of client area
1441 // against realvirtual
1444 SNAPDOWN(stepX, textCellW);
1445 SNAPDOWN(stepY, textCellH);
1446 stepX = Max(stepX, textCellW);
1447 stepY = Max(stepY, textCellH);
1449 if(parent.scrollFlags.snapX)
1451 if(parent.scrollFlags.snapY)
1453 if(parent.reqScrollArea.w != w || parent.reqScrollArea.h != h)
1455 parent.reqScrollArea.w = w;
1456 parent.reqScrollArea.h = h;*/
1458 // parent.UpdateScrollBars(true, true);
1459 parent.Position(parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1460 false, true, true, true, false, false);
1465 GetRidOfVirtualArea();
1469 UpdateScrollBars(modifyThisArea, false);
1470 else if(guiApp.currentSkin)
1473 &clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1475 if(sbv && (scrollFlags.dontHide || sbv.range > 1))
1476 clientSize.w -= guiApp.currentSkin.VerticalSBW();
1477 if(sbh && (scrollFlags.dontHide || sbh.range > 1))
1478 clientSize.h -= guiApp.currentSkin.HorizontalSBH();
1481 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1482 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1484 absPosition = scrolledPos;
1485 if(guiApp && guiApp.driver != null && guiApp.interfaceDriver)
1486 guiApp.interfaceDriver.OffsetWindow(this, &absPosition.x, &absPosition.y);
1488 if(this != guiApp.desktop && parent)
1490 absPosition.x += parent.absPosition.x;
1491 absPosition.y += parent.absPosition.y;
1492 if(!style.nonClient && this != guiApp.desktop)
1494 absPosition.x += parent.clientStart.x;
1495 absPosition.y += parent.clientStart.y;
1499 box = Box { 0, 0, size.w - 1, size.h - 1 };
1504 // Clip against parent's client area
1505 box.ClipOffset(against, scrolledPos.x, scrolledPos.y);
1507 // Compute client area in this window coordinate system
1508 clientArea.left = 0;
1510 clientArea.right = clientSize.w - 1;
1511 clientArea.bottom = clientSize.h - 1;
1513 // Clip against parent's client area
1515 clientArea.ClipOffset(against, scrolledPos.x + clientStart.x, scrolledPos.y + clientStart.y);
1519 //absPosition.x -= parent.clientStart.x;
1520 //absPosition.y -= parent.clientStart.y;
1523 // Adjust all children
1524 for(child = children.first; child; child = child.next)
1525 child.SetPosition(child.position.x, child.position.y, child.size.w, child.size.h, false, true, true);
1527 UpdateCaret(false, false);
1530 void GetRidOfVirtualArea(void)
1532 if(parent && !parent.destroyed && style.fixed &&
1533 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient &&
1534 parent.reqScrollArea.w && parent.reqScrollArea.h)
1536 if(!parent.noAutoScrollArea)
1540 for(child = children.first; child; child = child.next)
1542 if(child.modifyVirtArea && !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1544 if(child.position.x + child.size.w > parent.clientSize.w + ((!parent.sbv || parent.sbv.style.hidden) ? 0 : guiApp.currentSkin.VerticalSBW()) ||
1545 child.position.y + child.size.h > parent.clientSize.h + ((!parent.sbh || parent.sbh.style.hidden) ? 0 : guiApp.currentSkin.HorizontalSBH()))
1554 Window parent = this.parent;
1556 parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1557 false, true, true, true, false, false);
1559 parent.SetScrollArea(0,0,true);
1560 parent.SetScrollPosition(0,0);
1566 public void ExternalPosition(int x, int y, int w, int h)
1568 Position(x, y, w, h, false, true, true, true, false, false);
1571 // (w, h): Full window size
1572 bool Position(int x, int y, int w, int h, bool force, bool processAnchors, bool modifyArea, bool updateScrollBars, bool thisOnly, bool changeRootWindow)
1574 bool result = false;
1575 int oldCW = clientSize.w, oldCH = clientSize.h;
1576 bool clientResized, windowResized, windowMoved;
1578 bool realResized = size.w != w || size.h != h;
1580 // TOCHECK: This wasn't in ecere.dll
1581 //if(!parent) return true;
1582 if(destroyed) return false;
1584 windowMoved = position.x != x || position.y != y || force;
1586 // windowResized = realResized || force;
1587 windowResized = size.w != w || size.h != h || force;
1589 if(rootWindow != this && display && !display.flags.flipping && scrolledPos.x != MININT)
1595 scrolledPos.x - parent.clientStart.x + this.box.left, scrolledPos.y - parent.clientStart.y + this.box.top,
1596 scrolledPos.x - parent.clientStart.x + this.box.right,
1597 scrolledPos.y - parent.clientStart.y + this.box.bottom
1603 Box box { scrolledPos.x + this.box.left, scrolledPos.y + this.box.top, scrolledPos.x + this.box.right, scrolledPos.y + this.box.bottom};
1608 SetPosition(x, y, w, h, true, modifyArea, updateScrollBars);
1610 clientResized = oldCW != clientSize.w || oldCH != clientSize.h || force;
1612 if(display && rootWindow != this)
1615 if(guiApp && guiApp.windowMoving)
1617 if(guiApp.windowMoving.style.nonClient)
1618 guiApp.windowMoving.parent.SetMouseRangeToWindow();
1620 guiApp.windowMoving.parent.SetMouseRangeToClient();
1632 // Process Anchored Children
1636 for(child = children.first; child; child = child.next)
1639 ((child.stateAnchor.left.type != offset ||
1640 child.stateAnchor.top.type != offset ||
1641 child.stateAnchor.right.type != none ||
1642 child.stateAnchor.bottom.type != none) ||
1643 child.state == maximized || child.state == minimized))
1645 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor,
1647 // child.Position(x, y, w, h, false, true, true, true, false);
1648 // This must be true cuz otherwise we're gonna miss everything since we SetPosition recursively already
1649 child.Position(x, y, w, h, true, true, true, true, false, true /*false*/);
1655 // Is this gonna cause other problems? Commented out for the FileDialog end bevel bug
1656 //if(updateScrollBars)
1658 OnResize(clientSize.w, clientSize.h);
1660 if((clientResized || windowMoved) && created)
1661 OnPosition(position.x, position.y, clientSize.w, clientSize.h);
1663 if(guiApp.interimWindow && guiApp.interimWindow.master.rootWindow == this)
1665 Window master = guiApp.interimWindow.master;
1666 master.OnPosition(master.position.x, master.position.y, master.clientSize.w, master.clientSize.h);
1669 if(rootWindow == this && !is3D)
1673 x -= guiApp.desktop.absPosition.x;
1674 y -= guiApp.desktop.absPosition.y;
1676 //guiApp.Log("Position %s\n", caption);
1677 if(windowResized || windowMoved)
1678 if(display && !display.flags.memBackBuffer && changeRootWindow)
1679 guiApp.interfaceDriver.PositionRootWindow(this, x, y, w, h, windowMoved, windowResized); //realResized);
1681 if(!guiApp.fullScreenMode && this != guiApp.desktop && (windowResized || windowMoved))
1682 for(child = parent.children.first; child && child != this; child = child.next)
1683 if(child.rootWindow)
1684 guiApp.interfaceDriver.UpdateRootWindow(child.rootWindow);
1688 if(windowMoved || windowResized)
1690 display.Lock(true /*false*/);
1693 display.Position(absPosition.x, absPosition.y);
1694 //display.Position(absPosition.x + clientStart.x, absPosition.y + clientStart.y);
1697 // result = realResized ? display.Resize(size.w, size.h) : true;
1698 if(nativeDecorations)
1700 int w = clientSize.w, h = clientSize.h;
1701 if(hasMenuBar) h += skinMenuHeight;
1702 if(hasStatusBar) h += statusBarHeight;
1703 if(sbv && sbv.visible) w += sbv.size.w;
1704 if(sbh && sbh.visible) h += sbh.size.h;
1705 result = manageDisplay ? display.Resize(w, h) : true;
1708 result = manageDisplay ? display.Resize(size.w, size.h) : true;
1712 else if(clientResized)
1714 // --- Major Slow Down / Fix OpenGL Resizing Main Window Lag
1717 if(!guiApp.fullScreenMode && !guiApp.modeSwitching && this == rootWindow)
1721 if(windowMoved || windowResized)
1726 if(guiApp.driver && changeRootWindow)
1728 if(windowResized || windowMoved)
1729 if(!display || display.flags.memBackBuffer)
1730 guiApp.interfaceDriver.PositionRootWindow(this,
1731 x, y, w, h, windowMoved, windowResized);
1732 guiApp.interfaceDriver.UpdateRootWindow(this);
1734 for(child = children.first; child; child = child.next)
1736 if(child.is3D && child.created)
1738 // Copy Display Content
1739 child.display.displaySystem = display.displaySystem;
1740 child.display.window = display.window;
1741 child.display.current = display.current;
1742 child.display.width = display.width;
1743 child.display.height = display.height;
1744 child.display.driverData = display.driverData;
1745 child.display.mutex = null;
1756 void UpdateScrollBars(bool flag, bool fullThing)
1759 bool resizeH = false, resizeV = false;
1760 bool scrolled = false;
1761 rvw = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.w;
1762 rvh = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.h;
1764 if(destroyed) return;
1765 if(guiApp.currentSkin)
1767 MinMaxValue cw = 0, ch = 0;
1768 bool sbvVisible, sbhVisible;
1770 int positionH, positionV;
1772 // First get client area with no respect to scroll bars
1777 &clientStart.x, &clientStart.y, &size.w, &size.h, &cw, &ch);
1779 if(scrollFlags.dontHide)
1782 cw -= guiApp.currentSkin.VerticalSBW();
1784 ch -= guiApp.currentSkin.HorizontalSBH();
1786 // Update the scrollbar visibility
1792 sbh.disabled = rangeH <= 1;
1793 if(sbh.style.hidden)
1803 sbv.disabled = rangeV <= 1;
1804 if(sbv.style.hidden)
1812 // Then start off with horizontal scrollbar range
1815 positionH = sbh.thumbPosition;
1820 ch -= guiApp.currentSkin.HorizontalSBH();
1823 // Do the same for vertical scrollbar
1826 positionV = sbv.thumbPosition;
1832 cw -= guiApp.currentSkin.VerticalSBW();
1833 // Maybe we need to set the range on the horizontal scrollbar again
1838 sbh.Action(setRange, positionH, 0);
1839 if(rangeH <= 1 && sbh.range > 1)
1841 ch -= guiApp.currentSkin.HorizontalSBH();
1845 sbv.Action(setRange, positionV, 0);
1852 // Update the scrollbar visibility
1853 if(!scrollFlags.dontHide)
1855 if(sbh && ((rangeH <= 1 && !sbh.style.hidden) || (rangeH > 1 && sbh.style.hidden)))
1859 if(sbv && ((rangeV <= 1 && !sbv.style.hidden) || (rangeV > 1 && sbv.style.hidden)))
1866 if(guiApp.currentSkin)
1873 sbhVisible = sbh.style.hidden ? true : false;
1875 sbvVisible = sbv.style.hidden ? true : false;
1877 // Do our resize here
1878 if(flag && (resizeH || resizeV) && fullThing)
1880 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, false);
1885 OnResize(clientSize.w, clientSize.h);
1891 sbh.visible = sbhVisible;
1893 sbv.visible = sbvVisible;
1895 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1896 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1899 sbh.pageStep = clientSize.w;
1901 sbv.pageStep = clientSize.h;
1903 // Notify doesn't handle setRange anymore... process it here
1906 int positionH = sbh.thumbPosition;
1907 if(scroll.x != positionH)
1909 OnHScroll(setRange, positionH, 0);
1913 SNAPDOWN(positionH, textCellW);
1914 scroll.x = positionH;
1920 int seen = clientSize.w, total = reqScrollArea.w;
1923 if(scrollFlags.snapX)
1924 SNAPDOWN(seen, sbStep.x);
1926 if(!total) total = seen;
1927 range = total - seen + 1;
1929 range = Max(range, 1);
1931 if(x >= range) x = range - 1;
1933 if(scrollFlags.snapX)
1934 SNAPUP(x, sbStep.x);
1938 OnHScroll(setRange, x, 0);
1943 SNAPDOWN(x, textCellW);
1949 int positionV = sbv.thumbPosition;
1950 if(scroll.y != positionV)
1952 OnVScroll(setRange, positionV, 0);
1956 SNAPDOWN(positionV, textCellH);
1957 scroll.y = positionV;
1963 int seen = clientSize.h, total = reqScrollArea.h;
1966 if(scrollFlags.snapY)
1967 SNAPDOWN(seen, sbStep.y);
1969 if(!total) total = seen;
1970 range = total - seen + 1;
1971 range = Max(range, 1);
1973 if(y >= range) y = range - 1;
1975 if(scrollFlags.snapY)
1976 SNAPUP(y, sbStep.y);
1980 OnVScroll(setRange, y, 0);
1985 SNAPDOWN(y, textCellH);
1991 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
1994 for(child = children.first; child; child = child.next)
1996 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
1999 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2000 child.Position(x, y, w, h, false, true, false, true, false, false);
2007 // Process Scrollbars
2009 if(sbh) // && !sbh.style.hidden
2011 sbh.Move(clientStart.x, clientStart.y + clientSize.h, clientSize.w,0);
2012 // Need to set the range again (should improve...) since the scrollbars didn't have
2013 // the right size when UpdateScrollArea set the range on it
2016 sbh.seen = clientSize.w;
2020 if(sbv) // && !sbv.state.hidden
2022 sbv.Move(clientStart.x + clientSize.w, clientStart.y, 0, clientSize.h);
2023 // Need to set the range again (should improve...) since the scrollbars didn't have
2024 // the right size when UpdateScrollArea set the range on it
2027 sbv.seen = clientSize.h;
2032 // TESTING THIS LOWER
2033 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2036 for(child = children.first; child; child = child.next)
2038 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2041 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2042 child.Position(x, y, w, h, false, true, false, true, false, false);
2048 bool MaximizeButtonClicked(Button button, int x, int y, Modifiers mods)
2050 SetState(maximized, false, mods);
2054 bool RestoreButtonClicked(Button button, int x, int y, Modifiers mods)
2056 SetState(normal, false, mods);
2060 bool MinimizeButtonClicked(Button button, int x, int y, Modifiers mods)
2062 SetState(minimized, false, mods);
2063 parent.CycleChildren(false, true, false, true);
2067 void ScrollBarNotification(ScrollBar control, ScrollBarAction action, int position, Key keyFlags)
2070 // Scroll bar notifications
2071 if(action != setRange)
2073 bool changed = false;
2077 if(scroll.x != position)
2079 OnHScroll(action, position, keyFlags);
2084 SNAPDOWN(position, textCellW);
2086 scroll.x = position;
2090 if(scroll.y != position)
2092 OnVScroll(action, position, keyFlags);
2097 SNAPDOWN(position, textCellH);
2099 scroll.y = position;
2103 bool childMove = false;
2104 for(child = children.first; child; child = child.next)
2106 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2109 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2110 child.Position(x, y, w, h, false, true, false, true, false, false);
2114 // Testing this patch out to solve MDI workspace redraw bugs
2115 // We were already supposed to be updating parent's affected area in Position() but it doesn't seem to be working
2116 // Scroll offsets to blame?
2120 UpdateCaret(false, false);
2124 // Testing this patch out to solve MDI workspace redraw bugs
2125 for(child = children.first; child; child = child.next)
2127 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2136 void CreateSystemChildren(void)
2138 Window parent = this;
2139 bool scrollBarChanged = false;
2140 bool hasClose = false, hasMaxMin = false;
2141 Point scroll = this.scroll;
2143 if(state == maximized && this.parent.menuBar)
2145 if(this.parent.activeClient == this)
2146 parent = this.parent.menuBar;
2153 if(style.hasClose) hasClose = true;
2154 if(style.hasMaximize || style.hasMinimize)
2161 if(sysButtons[2] && (!hasClose || sysButtons[2].parent != parent))
2163 sysButtons[2].Destroy(0);
2164 sysButtons[2] = null;
2166 if(sysButtons[1] && (!hasMaxMin || sysButtons[1].parent != parent))
2168 sysButtons[1].Destroy(0);
2169 sysButtons[1] = null;
2171 if(sysButtons[0] && (!hasMaxMin || sysButtons[0].parent != parent))
2173 sysButtons[0].Destroy(0);
2174 sysButtons[0] = null;
2177 if(hasClose && parent)
2184 parent, master = this,
2185 inactive = true, nonClient = true, visible = false;
2187 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
2193 if(this.parent == guiApp.desktop)
2194 sysButtons[2].hotKey = altF4;
2195 else if(style.isActiveClient)
2196 sysButtons[2].hotKey = ctrlF4;
2197 sysButtons[2].Create();
2200 sysButtons[2].symbol = 'X';
2201 sysButtons[2].disabled = !style.hasClose;
2204 if(hasMaxMin && parent)
2208 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2209 if(state == maximized)
2212 method = RestoreButtonClicked;
2218 method = MaximizeButtonClicked;
2226 parent, master = this,
2227 hotKey = altEnter, inactive = true, nonClient = true, visible = false
2229 sysButtons[1].Create();
2231 sysButtons[1].NotifyClicked = method;
2233 sysButtons[1].symbol = symbol;
2234 sysButtons[1].disabled = !style.hasMaximize;
2237 if(hasMaxMin && parent)
2241 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2242 if (state == minimized)
2245 method = RestoreButtonClicked;
2251 method = MinimizeButtonClicked;
2259 parent, master = this,
2260 hotKey = altM, inactive = true, nonClient = true, visible = false
2262 sysButtons[0].Create();
2264 sysButtons[0].NotifyClicked = method;
2266 sysButtons[0].symbol = symbol;
2267 sysButtons[0].disabled = !style.hasMinimize;
2270 // Create the scrollbars
2271 if(style.hasHorzScroll && !sbh)
2277 direction = horizontal,
2281 snap = scrollFlags.snapX,
2282 NotifyScrolling = ScrollBarNotification
2285 scrollBarChanged = true;
2287 else if(sbh && !style.hasHorzScroll)
2293 if(style.hasVertScroll && !sbv)
2299 direction = vertical,
2303 snap = scrollFlags.snapY,
2304 NotifyScrolling = ScrollBarNotification
2307 scrollBarChanged = true;
2309 else if(sbv && !style.hasVertScroll)
2314 if(scrollBarChanged)
2316 SetScrollLineStep(sbStep.x, sbStep.y);
2317 UpdateScrollBars(true, true);
2321 if(scrollBarChanged)
2323 if(sbh) sbh.thumbPosition = scroll.x;
2324 if(sbv) sbv.thumbPosition = scroll.y;
2328 void UpdateCaption(void)
2330 if(rootWindow == this)
2333 FigureCaption(caption);
2334 guiApp.interfaceDriver.SetRootWindowCaption(this, caption);
2336 UpdateDecorations();
2339 if(parent.rootWindow == parent && parent.activeClient == this) // Added this last check
2342 parent.FigureCaption(caption);
2343 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
2345 parent.UpdateDecorations();
2349 void UpdateActiveDocument(Window previous)
2351 Window activeClient = this.activeClient;
2352 Window activeChild = this.activeChild;
2359 activeClient.CreateSystemChildren();
2361 previous.CreateSystemChildren();
2372 if(activeClient && activeClient.menu && activeClient.state != minimized)
2376 //activeClient.menu.Clean(activeClient);
2377 menu.Merge(activeClient.menu, true, activeClient);
2381 if(activeChild && activeChild != activeClient && activeChild.menu && activeChild.state != minimized)
2384 menu.Merge(activeChild.menu, true, activeChild);
2387 // Build window list
2390 Menu windowMenu = menu.FindMenu("Window");
2395 for(id = 0, cycle = activeClient.cycle; cycle && id<10;)
2398 Window document = cycle.data;
2399 if(!document.style.nonClient && document.style.isActiveClient)
2401 char name[2048], caption[2048];
2402 document.FigureCaption(caption);
2403 sprintf(name, "%d %s", id+1, caption);
2404 windowMenu.AddDynamic(MenuItem
2406 copyText = true, text = name, hotKey = Key { k1 + id }, id = id++,
2407 NotifySelect = MenuWindowSelectWindow
2411 if(activeClient.cycle == cycle) break;
2416 if((!previous && activeClient) || !activeClient)
2422 item = menu.FindItem(MenuWindowCloseAll, 0);
2423 if(item) item.disabled = false;
2424 item = menu.FindItem(MenuWindowNext, 0);
2425 if(item) item.disabled = false;
2426 item = menu.FindItem(MenuWindowPrevious, 0);
2427 if(item) item.disabled = false;
2428 item = menu.FindItem(MenuWindowCascade, 0);
2429 if(item) item.disabled = false;
2430 item = menu.FindItem(MenuWindowTileHorz, 0);
2431 if(item) item.disabled = false;
2432 item = menu.FindItem(MenuWindowTileVert, 0);
2433 if(item) item.disabled = false;
2434 item = menu.FindItem(MenuWindowArrangeIcons, 0);
2435 if(item) item.disabled = false;
2436 item = menu.FindItem(MenuWindowWindows, 0);
2437 if(item) item.disabled = false;
2440 item = menu.FindItem(MenuFileClose, 0);
2441 if(item) item.disabled = !activeClient || !activeClient.style.hasClose;
2442 item = menu.FindItem(MenuFileSaveAll, 0);
2443 if(item) item.disabled = numDocuments < 1;
2445 // This is called again for a child window change, with same active client
2446 OnActivateClient(activeClient, previous);
2449 void _ShowDecorations(Box box, bool post)
2451 if(rootWindow == this && nativeDecorations) return;
2452 if(visible && this != guiApp.desktop)
2454 Surface surface = RedrawFull(box);
2458 FigureCaption(caption);
2461 ShowDecorations(captionFont.font,
2464 active, //parent.activeClient == this
2465 guiApp.windowMoving == this);
2467 PreShowDecorations(captionFont.font,
2470 active, //parent.activeClient == this
2471 guiApp.windowMoving == this);
2478 void UpdateExtent(Box refresh)
2480 Surface surface = null;
2482 if(!manageDisplay) { OnRedraw(null);return; }
2483 _ShowDecorations(refresh, false);
2485 surface = Redraw(refresh);
2486 // Opaque background: just fill before EW_REDRAW (clear?)
2489 surface.SetBackground(background);
2490 surface.SetForeground(foreground);
2491 surface.DrawingChar(' ');
2492 if(this == rootWindow)
2494 if(style.drawBehind || background.a)
2495 surface.Clear(colorBuffer);
2497 else if(background.a)
2501 background.color = { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2502 surface.SetForeground((background.color.r > 128 || background.color.g > 128) ? black : white);
2505 if(display.flags.alpha && background.a < 255 && background)
2507 surface.Area(0,0,clientSize.w, clientSize.h);
2508 /*if(style.clearDepthBuffer)
2509 surface.Clear(depthBuffer);*/
2511 else if(/*style.clearDepthBuffer || */background.a)
2513 // surface.Clear((style.clearDepthBuffer ? depthBuffer : 0) | (background.a ? colorBuffer : 0));
2514 surface.Clear(colorBuffer);
2519 surface.TextFont(usedFont.font);
2520 surface.TextOpacity(false);
2524 // Draw the caret ...
2525 if(!disabled && this == guiApp.caretOwner && guiApp.caretEnabled /*&& !guiApp.interimWindow*/ && !guiApp.currentSkin.textMode)
2527 // surface.SetBackground(0xFFFFFF - background.color);
2528 surface.SetBackground(~background.color);
2530 caretPos.x - scroll.x + 1, caretPos.y - scroll.y,
2531 caretPos.x - scroll.x + 2, caretPos.y - scroll.y + caretSize - 1);
2537 void DrawOverChildren(Box refresh)
2539 Surface surface = Redraw(refresh);
2543 surface.DrawingChar(' ');
2544 surface.SetBackground(background);
2545 surface.SetForeground(foreground);
2547 surface.TextFont(usedFont.font);
2548 surface.TextOpacity(false);
2550 OnDrawOverChildren(surface);
2555 _ShowDecorations(refresh, true);
2558 void ComputeClipExtents(void)
2561 Extent clipExtent { /*first = -1, last = -1, free = -1*/ };
2563 clipExtent.Copy(this.clipExtent);
2565 for(child = children.last; child; child = child.prev)
2567 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2569 bool opaque = child.IsOpaque(); // TODO: acess background directly
2570 int dx = child.absPosition.x - absPosition.x, dy = child.absPosition.y - absPosition.y;
2572 child.clipExtent.Copy(clipExtent);
2573 child.clipExtent.Offset(-dx, -dy);
2574 child.clipExtent.IntersectBox(child.box);
2576 child.ComputeClipExtents();
2578 if(opaque && !child.style.nonClient)
2580 // Adjust the box for the parent:
2581 Box box { child.box.left + dx, child.box.top + dy, child.box.right + dx, child.box.bottom + dy };
2582 clipExtent.ExcludeBox(box, rootWindow.tempExtents[0]);
2587 // ??? Only do this for overlapped window or if parent has with clip children flag
2589 // Do this if window has clip children flag on (default false?)
2590 // this.clipExtent = clipExtent;
2592 clipExtent.Free(null);
2595 void ComputeRenderAreaNonOpaque(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2597 bool opaque = IsOpaque();
2599 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2600 if(rootWindow.nativeDecorations)
2602 offsetX -= rootWindow.clientStart.x;
2603 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2607 for(child = children.last; child; child = child.prev)
2609 ColorAlpha background = *(ColorAlpha *)&child.background;
2610 bool opaque = child.IsOpaque();
2611 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2615 // Adjust renderArea to the root window level
2616 Extent * renderArea = &rootWindow.tempExtents[1];
2618 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2619 if(child.rootWindow.nativeDecorations)
2621 offsetX -= child.rootWindow.clientStart.x;
2622 offsetY -= child.rootWindow.clientStart.y - (child.rootWindow.hasMenuBar ? skinMenuHeight : 0);
2626 Extent childRenderArea;
2628 if(backBufferUpdate != null)
2630 childRenderArea.Copy(backBufferUpdate);
2631 childRenderArea.Offset(-offsetX, -offsetY);
2634 childRenderArea.Copy(child.dirtyArea);
2636 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2637 renderArea.Copy(dirtyExtent);
2638 renderArea.Offset(-offsetX, -offsetY);
2639 childRenderArea.Union(renderArea);
2642 // Intersect with the clip extent
2643 childRenderArea.Intersection(child.clipExtent);
2646 renderArea->Copy(child.dirtyArea /*childRenderArea*/);
2647 renderArea->Offset(offsetX, offsetY);
2648 dirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2649 // overDirtyExtent.Union(renderArea);
2650 renderArea->Empty();
2651 // childRenderArea.Free();
2653 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2658 for(child = children.last; child; child = child.prev)
2660 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2662 child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2667 void ComputeRenderArea(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2669 bool opaque = IsOpaque();
2670 Extent * dirtyExtentWindow = &rootWindow.tempExtents[1];
2672 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2673 if(rootWindow.nativeDecorations)
2675 offsetX -= rootWindow.clientStart.x;
2676 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2680 for(child = children.last; child; child = child.prev)
2682 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2684 ColorAlpha background = *(ColorAlpha *)&child.background;
2685 bool opaque = child.IsOpaque();
2686 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2690 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2691 // Adjust renderArea to the root window level
2693 renderArea.Copy(child.dirtyArea);
2694 renderArea.Offset(offsetX, offsetY);
2695 dirtyExtent.Union(renderArea);
2696 overDirtyExtent.Union(renderArea);
2702 for(child = children.last; child; child = child.prev)
2704 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2706 child.ComputeRenderArea(dirtyExtent, overDirtyExtent, backBufferUpdate);
2710 if(backBufferUpdate != null)
2712 renderArea.Copy(backBufferUpdate);
2713 renderArea.Offset(-offsetX, -offsetY);
2715 overRenderArea.Copy(backBufferUpdate);
2716 overRenderArea.Offset(-offsetX, -offsetY);
2722 renderArea.Copy(dirtyArea);
2724 overRenderArea.Copy(dirtyArea);
2727 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2728 dirtyExtentWindow->Copy(dirtyExtent);
2729 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2730 renderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2731 dirtyExtentWindow->Empty();
2733 // Intersect with the clip extent
2734 renderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2737 if(renderArea.count > 10)
2740 printf("\nToo many extents (%d):\n", renderArea.count);
2742 //extent.UnionBox({ 112, 6, 304, 7 }, rootWindow.tempExtents[0]);
2743 //extent.UnionBox({ 112, 8, 304, 17 }, rootWindow.tempExtents[0]);
2748 for(c = 0; c<10; c++)
2751 FASTLIST_LOOP(renderArea, extentBox)
2753 extent.UnionBox(extentBox.box, rootWindow.tempExtents[0]);
2755 renderArea.Copy(extent);
2757 FASTLIST_LOOP(renderArea, extentBox)
2760 printf("(%d, %d) - (%d, %d)\n",
2761 extentBox.box.left, extentBox.box.top,
2762 extentBox.box.right, extentBox.box.bottom);
2766 printf("\nNow %d\n", renderArea.count);
2772 // WHY WAS THIS COMMENTED ??
2774 // Add extent forced by DrawOverChildren to the dirty area, adjusting dirty extent to the window
2775 dirtyExtentWindow->Copy(overDirtyExtent);
2776 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2777 overRenderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2778 dirtyExtentWindow->Empty();
2780 // Intersect with the clip extent
2781 overRenderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2787 if(scrollExtent.count)
2789 // Subtract render extent from scrolling extent
2790 scrollExtent.Exclusion(renderArea, rootWindow.tempExtents[0]);
2792 if(backBufferUpdate == null)
2794 Extent * dirty = &rootWindow.tempExtents[3];
2797 // Intersect scrolling extent with clip extent
2798 scrollExtent.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2800 // offset this scroll to be at the root window level
2801 scrollExtent.Offset(offsetX, offsetY);
2802 // Add area that was scrolled to the dirty extents of the back buffer
2803 rootWindow.dirtyBack.Union(scrollExtent, rootWindow.tempExtents[0]);
2807 // Will need scrolledArea.x & scrolledArea.y to support multiple scrolls
2808 FASTLIST_LOOP(scrollExtent, scrollBox)
2809 display.Scroll(scrollBox.box, scrolledArea.x, scrolledArea.y, dirty);
2814 scrollExtent.Empty();
2816 // Add the exposed extent to the window render area
2817 dirty->Offset(-offsetX, -offsetY);
2818 renderArea.Union(dirty, rootWindow.tempExtents[0]);
2823 // Subtract the window's box from the transparency forced extent
2824 dirtyExtent.ExcludeBox({box.left + offsetX, box.top + offsetY, box.right + offsetX, box.bottom + offsetY }, rootWindow.tempExtents[0]);
2830 renderArea.Copy(this.renderArea);
2831 renderArea.Offset(offsetX, offsetY);
2832 dirtyExtent.Union(renderArea);
2838 Extent renderArea { };
2840 renderArea.Copy(overRenderArea);
2841 renderArea.Offset(offsetX, offsetY);
2842 overDirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2847 if(backBufferUpdate != null)
2849 // Remove render area from dirty area
2850 dirtyArea.Exclusion(renderArea, rootWindow.tempExtents[0]);
2852 dirtyArea.Exclusion(overRenderArea, rootWindow.tempExtents[0]);
2859 // Remove the window render area from the dirty extents of the back buffer
2860 rootWindow.dirtyBack.Exclusion(renderArea);
2864 void Render(Extent updateExtent)
2868 Window rootWindow = this.rootWindow;
2869 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2870 if(rootWindow.nativeDecorations)
2872 offsetX -= rootWindow.clientStart.x;
2873 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2876 if(rootWindow.fullRender)
2885 background = Color { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2886 foreground = (background.color.r > 128 || background.color.g > 128) ? black : white;
2891 /*if(renderArea.count)
2892 printf("\n\nRendering %s (%x):\n------------------------------------------\n", _class.name, this);*/
2895 FASTLIST_LOOP(renderArea, extentBox)
2897 Box box = extentBox.box;
2900 /*printf("(%d, %d) - (%d, %d)\n",
2901 extentBox.box.left, extentBox.box.top,
2902 extentBox.box.right, extentBox.box.bottom);*/
2907 box.left += offsetX;
2909 box.right += offsetX;
2910 box.bottom += offsetY;
2912 if(updateExtent != null)
2913 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
2917 for(child = children.first; child; child = child.next)
2918 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && !child.nonClient)
2919 child.Render(updateExtent);
2921 if(rootWindow.fullRender)
2922 DrawOverChildren(box);
2925 // TO DO: There's an issue about draw over children...
2926 // TO DO: Don't wanna go through this if method isn't used
2927 FASTLIST_LOOP(/*renderArea */overRenderArea, extentBox)
2929 Box box = extentBox.box;
2931 DrawOverChildren(box);
2933 box.left += offsetX;
2935 box.right += offsetX;
2936 box.bottom += offsetY;
2938 if(updateExtent != null)
2939 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
2942 for(child = children.first; child; child = child.next)
2943 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && child.nonClient)
2944 child.Render(updateExtent);
2947 overRenderArea.Empty();
2950 public void UpdateDisplay(void)
2952 if(!manageDisplay) { OnRedraw(null);return; }
2953 if(rootWindow && this != rootWindow)
2954 rootWindow.UpdateDisplay();
2957 Extent dirtyExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be forced due to transparency
2958 Extent overExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that forced for DrawOverChildren
2961 dirtyExtent.Clear();
2964 clipExtent.AddBox(box);
2966 display.StartUpdate();
2968 if(!rootWindow.fullRender)
2970 ComputeClipExtents();
2971 ComputeRenderAreaNonOpaque(dirtyExtent, overExtent, null);
2972 ComputeRenderArea(dirtyExtent, overExtent, null);
2975 clipExtent.Free(null);
2977 dirtyExtent.Free(null);
2978 overExtent.Free(null);
2980 if(display.flags.flipping)
2983 display.Update(null);
2987 Extent updateExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be updated
2988 updateExtent.Clear();
2990 Render(updateExtent);
2992 updateExtent.UnionBox(this.box, tempExtents[0]);
2995 //printf("\n\nUpdate:\n------------------------------------------\n");
2998 FASTLIST_LOOP(updateExtent, extentBox)
3001 /*printf("Updating (%d, %d) - (%d, %d)\n",
3002 extentBox.box.left, extentBox.box.top,
3003 extentBox.box.right, extentBox.box.bottom);*/
3006 display.Update(extentBox.box);
3009 updateExtent.Free(null);
3012 display.EndUpdate();
3020 void UpdateBackDisplay(Box box)
3026 Extent intersection { /*first = -1, last = -1, free = -1*/ };
3028 //printf("UpdateBackDisplay going through!\n");
3029 display.StartUpdate();
3033 intersection.Copy(dirtyBack);
3034 intersection.IntersectBox(box);
3036 dirtyExtent.Clear();
3039 clipExtent.AddBox(box);
3041 if(!rootWindow.fullRender)
3043 ComputeClipExtents();
3044 ComputeRenderArea(dirtyExtent, overExtent, intersection);
3047 clipExtent.Free(null);
3049 intersection.Free(null);
3050 dirtyExtent.Free(null);
3051 overExtent.Free(null);
3056 if(display.flags.flipping)
3057 display.Update(null);
3060 rootWindow.display.Update(box);
3063 display.EndUpdate();
3067 dirtyBack.ExcludeBox(box, rootWindow.tempExtents[0]);
3068 if(dirtyBack.count > MAX_DIRTY_BACK)
3070 BoxItem extentBox, next;
3071 BoxItem first = (BoxItem)ACCESS_ITEM(dirtyBack, dirtyBack.first);
3072 FASTLIST_LOOPN(dirtyBack, extentBox, next)
3074 if(extentBox != first)
3076 if(extentBox.box.left < first.box.left)
3077 first.box.left = extentBox.box.left;
3078 if(extentBox.box.top < first.box.top)
3079 first.box.top = extentBox.box.top;
3080 if(extentBox.box.right > first.box.right)
3081 first.box.right = extentBox.box.right;
3082 if(extentBox.box.bottom > first.box.bottom)
3083 first.box.bottom = extentBox.box.bottom;
3084 dirtyBack.Delete(extentBox);
3093 // --- Window positioning ---
3094 // --- Window identification ---
3096 // Returns window at position "Position"
3097 Window GetAtPosition(int x, int y, bool clickThru, bool acceptDisabled, Window last)
3099 Window child, result = null;
3101 box.left += absPosition.x;
3102 box.right += absPosition.x;
3103 box.top += absPosition.y;
3104 box.bottom += absPosition.y;
3106 if(!destroyed && visible && (acceptDisabled || !disabled))
3108 int lx = x - absPosition.x;
3109 int ly = y - absPosition.y;
3110 if(IsInside(lx, ly))
3111 // if(box.IsPointInside(Point{x, y}))
3113 if(!clickThru || !style.clickThrough) result = (this == last) ? null : this;
3114 // If the window is disabled, stop looking in children (for acceptDisabled mode)
3117 for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
3119 if(child != statusBar && child.rootWindow == rootWindow)
3121 Window childResult = child.GetAtPosition(x, y, clickThru, acceptDisabled, last);
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, false, acceptDisabled, last);
3144 Window FindModal(void)
3146 Window modalWindow = this, check;
3147 Window check2 = null;
3148 for(check = this; check.master; check = check.master)
3150 if(check.master.modalSlave && check.master.modalSlave.created && check != check.master.modalSlave)
3152 modalWindow = check.master.modalSlave;
3153 check = modalWindow;
3155 // TESTING THIS FOR DROPBOX...
3156 if(!rootWindow || !rootWindow.style.interim)
3158 for(check2 = check; check2.activeChild; check2 = check2.activeChild)
3160 if(check2.modalSlave && check2.modalSlave.created)
3162 modalWindow = check2.modalSlave;
3170 if(modalWindow == this)
3172 for(check = this; check.activeChild; check = check.activeChild)
3174 if(check.modalSlave)
3176 modalWindow = check.modalSlave;
3182 for(; modalWindow.modalSlave && modalWindow.modalSlave.created; modalWindow = modalWindow.modalSlave);
3183 return (modalWindow == this || this == guiApp.interimWindow || IsDescendantOf(modalWindow)) ? null : modalWindow;
3186 void StopMoving(void)
3188 if(this == guiApp.windowMoving)
3190 guiApp.windowMoving = null;
3191 UpdateDecorations();
3192 SetMouseRange(null);
3195 if(rootWindow.active)
3196 guiApp.interfaceDriver.StopMoving(rootWindow);
3199 guiApp.resizeX = guiApp.resizeY = guiApp.resizeEndX = guiApp.resizeEndY = false;
3200 guiApp.windowIsResizing = false;
3204 void SelectMouseCursor(void)
3209 Window cursorWindow = null;
3210 bool rx, ry, rex, rey;
3212 guiApp.desktop.GetMousePosition(&x, &y);
3213 mouseWindow = rootWindow ? rootWindow.GetAtPosition(x,y, true, false, null) : null;
3215 if((guiApp.windowMoving && !guiApp.windowIsResizing) || guiApp.windowScrolling)
3216 guiApp.SetCurrentCursor(guiApp.systemCursors[moving]);
3217 else if(mouseWindow)
3219 modalWindow = mouseWindow.FindModal();
3220 x -= mouseWindow.absPosition.x;
3221 y -= mouseWindow.absPosition.y;
3222 if(guiApp.windowIsResizing)
3224 rex = guiApp.resizeEndX;
3225 rey = guiApp.resizeEndY;
3226 rx = guiApp.resizeX;
3227 ry = guiApp.resizeY;
3228 if((rex && rey) || (rx && ry))
3229 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
3230 else if((rex && ry) || (rx && rey))
3231 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
3232 else if((ry || rey) && (!rx && !rex))
3233 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
3234 else if((rx || rex) && (!ry && !rey))
3235 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
3237 else if(!modalWindow && !guiApp.windowCaptured &&
3238 mouseWindow.IsMouseResizing(x, y, mouseWindow.size.w, mouseWindow.size.h,
3239 &rx, &ry, &rex, &rey))
3241 if((rex && rey) || (rx && ry))
3242 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
3243 else if((rex && ry) || (rx && rey))
3244 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
3245 else if((ry || rey) && (!rx && !rex))
3246 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
3247 else if((rx || rex) && (!ry && !rey))
3248 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
3250 else if(!guiApp.windowCaptured && !modalWindow && !guiApp.interimWindow)
3252 if(!mouseWindow.clientArea.IsPointInside({x - mouseWindow.clientStart.x, y - mouseWindow.clientStart.y}))
3253 cursorWindow = mouseWindow.parent;
3255 cursorWindow = mouseWindow;
3257 else if(!guiApp.interimWindow)
3258 cursorWindow = guiApp.windowCaptured;
3261 for(; !cursorWindow.cursor && !cursorWindow.style.nonClient; cursorWindow = cursorWindow.parent);
3262 guiApp.SetCurrentCursor(cursorWindow.cursor ? cursorWindow.cursor : guiApp.systemCursors[arrow]);
3264 else if(modalWindow)
3266 guiApp.SetCurrentCursor(guiApp.systemCursors[arrow]);
3268 else if(guiApp.interimWindow)
3270 if(guiApp.interimWindow.cursor)
3271 guiApp.SetCurrentCursor(guiApp.interimWindow.cursor);
3273 guiApp.SetCurrentCursor(mouseWindow.cursor ? mouseWindow.cursor : guiApp.systemCursors[arrow]);
3278 // --- State based input ---
3279 bool AcquireInputEx(bool state)
3284 guiApp.interfaceDriver.GetMousePosition(&guiApp.acquiredMouseX, &guiApp.acquiredMouseY);
3285 guiApp.interfaceDriver.SetMousePosition(clientSize.w/2 + absPosition.x, clientSize.h/2 + absPosition.y);
3287 result = guiApp.interfaceDriver.AcquireInput(rootWindow, state);
3289 guiApp.acquiredWindow = state ? this : null;
3292 SetMouseRangeToClient();
3293 guiApp.interfaceDriver.SetMouseCursor((SystemCursor)-1);
3298 SelectMouseCursor();
3300 if(!state) guiApp.interfaceDriver.SetMousePosition(guiApp.acquiredMouseX, guiApp.acquiredMouseY);
3304 // --- Window activation ---
3305 bool PropagateActive(bool active, Window previous, bool * goOnWithActivation, bool direct)
3308 if(!parent || !parent.style.inactive)
3310 Window parent = this.parent;
3313 if(rootWindow == this)
3314 Log(active ? "active\n" : "inactive\n");
3317 // Testing this here...
3318 if(!parent || parent == guiApp.desktop || parent.active)
3320 this.active = active;
3323 // TESTING THIS HERE
3324 UpdateDecorations();
3325 if(result = OnActivate(active, previous, goOnWithActivation, direct) && *goOnWithActivation && master)
3326 result = NotifyActivate(master, this, active, previous);
3329 this.active = !active;
3334 if(!parent || parent == guiApp.desktop || parent.active)
3336 this.active = active;
3338 AcquireInputEx(active);
3343 if(guiApp.caretOwner)
3347 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 1,
3348 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + 1,
3349 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 2,
3350 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + guiApp.caretOwner.caretSize - 1
3352 guiApp.caretOwner.Update(extent);
3355 if(visible || !guiApp.caretOwner)
3356 guiApp.caretOwner = this;
3357 UpdateCaret(false, false);
3363 this.active = false;
3365 AcquireInputEx(active);
3367 if(!active && guiApp.caretOwner == this)
3369 UpdateCaret(false, true);
3370 guiApp.caretOwner = null;
3371 guiApp.interfaceDriver.SetCaret(0,0,0);
3372 guiApp.caretEnabled = false;
3377 if(!active && parent && parent.activeChild && parent.activeChild != this)
3378 if(!parent.activeChild.PropagateActive(false, previous, goOnWithActivation, true) || !*goOnWithActivation)
3384 if(!active && menuBar)
3387 menuBar.OnActivate(false, null, &goOn, true);
3388 menuBar.NotifyActivate(menuBar.master, menuBar, false, null);
3392 if(!activeChild.PropagateActive(active, previous, goOnWithActivation, false) || !*goOnWithActivation)
3401 void ConsequentialMouseMove(bool kbMoving)
3405 if(kbMoving || !guiApp.windowMoving)
3409 if(rootWindow == guiApp.desktop || rootWindow.parent == guiApp.desktop)
3411 guiApp.interfaceDriver.GetMousePosition(&x, &y);
3413 if(guiApp.windowMoving || rootWindow.GetAtPosition(x, y, true, false, null))
3414 rootWindow.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove, x, y, &mods, true, false);
3420 bool IsDescendantOf(Window ancestor)
3423 for(window = this; window && window != ancestor; window = window.parent);
3424 return window == ancestor;
3427 bool IsSlaveOf(Window master)
3430 for(window = this; window && window != master; window = window.master);
3431 return window == master;
3434 bool ActivateEx(bool active, bool activateParent, bool moveInactive, bool activateRoot, Window external, Window externalSwap)
3438 if(this && !destroyed /*&& state != Hidden*/)
3440 Window swap = externalSwap;
3448 if(activateParent &&
3449 (parent.activeChild != this ||
3450 (guiApp.interimWindow && !IsDescendantOf(guiApp.interimWindow))) &&
3451 active && style.modal &&
3452 parent != master && master)
3453 master.ActivateEx(true, true, false, activateRoot, external, externalSwap);
3459 bool real = parent.activeChild != this;
3461 // TEST THIS: New activateParent check here!!! CAUSED MENUS NOT GOING AWAY
3462 if(/*activateParent && */guiApp.interimWindow &&
3463 !IsDescendantOf(guiApp.interimWindow) &&
3464 !IsSlaveOf(guiApp.interimWindow))
3466 Window interimWindow = guiApp.interimWindow;
3467 while(interimWindow && interimWindow != this)
3469 Window master = interimWindow.master;
3471 guiApp.interimWindow = null;
3472 if(guiApp.caretOwner)
3473 guiApp.caretOwner.UpdateCaret(false, false);
3475 incref interimWindow;
3476 if(!interimWindow.PropagateActive(false, this, &goOn, true))
3481 delete interimWindow;
3482 interimWindow = (master && master.style.interim) ? master : null;
3487 guiApp.interimWindow = this;
3488 /*guiApp.interfaceDriver.SetCaret(0,0,0);
3489 guiApp.caretEnabled = false;*/
3490 UpdateCaret(false, true);
3495 bool acquireInput = false;
3497 parent.activeChild &&
3498 parent.activeChild.state == maximized &&
3499 parent != guiApp.desktop;
3501 if(!style.inactive) // (!style.isRemote || parent.active || parent.style.hidden))
3506 swap = parent.activeChild;
3507 if(swap && swap.destroyed) swap = null;
3508 if(swap && swap != this)
3511 if(!swap.PropagateActive(false, this, &goOn, true))
3512 swap = parent.activeChild;
3523 if(!parent || parent.activeChild != this || style.interim)
3526 result = PropagateActive(true, swap, &goOn, true);
3527 if(!result && !goOn)
3532 acquireInput = true;
3536 if(style.hasMaximize && parent != guiApp.desktop)
3539 SetState(maximized, false, 0);
3540 else if(state != maximized)
3543 for(child = parent.children.first; child; child = child.next)
3545 if(this != child && child.state == maximized)
3546 child.SetState(normal, false, 0);
3553 if(!style.inactive && !style.interim /*&& (!style.isRemote || parent.active || parent.style.hidden)*/)
3555 Window previous = parent.activeClient;
3556 parent.activeChild = this;
3557 if(!style.nonClient /*&& style.isActiveClient*/)
3559 if(style.isActiveClient && !style.hidden)
3560 parent.activeClient = this;
3561 parent.UpdateActiveDocument(previous);
3566 //if(!style.isRemote)
3568 if(rootWindow != this)
3570 if(activateParent && !parent.active /*parent != parent.parent.activeChild*/)
3571 parent.ActivateEx(true, true, moveInactive, activateRoot, external, externalSwap);
3573 else if(!guiApp.fullScreenMode)
3575 Window modalRoot = FindModal();
3576 if(!modalRoot) modalRoot = this;
3577 if(!modalRoot.isForegroundWindow)
3579 modalRoot.isForegroundWindow = true;
3580 // To check : Why is parent null?
3581 if(activateRoot && modalRoot.parent && !modalRoot.parent.display && external != modalRoot)
3583 guiApp.interfaceDriver.ActivateRootWindow(modalRoot);
3585 modalRoot.isForegroundWindow = false;
3590 if(result && real && (!style.inactive || moveInactive) && parent)
3592 Window last = parent.children.last;
3594 if(!style.stayOnTop)
3595 for(; last && last.style.stayOnTop; last = last.prev);
3597 parent.children.Move(this, last);
3599 // Definitely don't want that: why not?
3603 parent.childrenOrder.Move(order, parent.childrenOrder.last);
3609 if(!parent || style.interim || (parent.activeChild == this && !style.inactive))
3616 parent.activeChild = null;
3617 if(!style.nonClient /*&& style.isActiveClient*/)
3619 Window previous = parent.activeClient;
3620 if(style.isActiveClient)
3621 parent.activeClient = null;
3622 parent.UpdateActiveDocument(previous);
3626 if(this == guiApp.interimWindow)
3628 guiApp.interimWindow = null;
3629 if(guiApp.caretOwner)
3630 guiApp.caretOwner.UpdateCaret(false, false);
3632 if(!PropagateActive(false, externalSwap, &goOn, true) || !goOn)
3639 if(!active || !swap)
3640 UpdateDecorations();
3642 swap.UpdateDecorations();
3644 if(active && rootWindow != this)
3645 ConsequentialMouseMove(false);
3652 // --- Input Messages ---
3653 void ::UpdateMouseMove(int mouseX, int mouseY, bool consequential)
3655 static bool reEntrancy = false;
3656 if(reEntrancy) return;
3660 guiApp.cursorUpdate = true;
3661 if(guiApp.windowScrolling && !consequential)
3663 guiApp.windowScrolling.SetScrollPosition(
3664 (guiApp.windowScrolling.sbh) ?
3665 (guiApp.windowScrollingBefore.x - mouseX + guiApp.windowScrollingStart.x) : 0,
3666 (guiApp.windowScrolling.sbv) ?
3667 (guiApp.windowScrollingBefore.y - mouseY + guiApp.windowScrollingStart.y) : 0);
3669 if(guiApp.windowMoving)
3671 if(mouseX != guiApp.movingLast.x || mouseY != guiApp.movingLast.y)
3673 Window window = guiApp.windowMoving;
3675 int w = window.size.w;
3676 int h = window.size.h;
3681 rx = mouseX - guiApp.windowMovingStart.x;
3682 ry = mouseY - guiApp.windowMovingStart.y;
3685 window.GetDecorationsSize(&ew, &eh);
3687 if(guiApp.windowIsResizing)
3689 x = window.scrolledPos.x;
3690 y = window.scrolledPos.y;
3694 aw = Max(guiApp.windowResizingBefore.w - rx,window.skinMinSize.w);
3695 rx = guiApp.windowResizingBefore.w - aw;
3696 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3697 w = guiApp.windowResizingBefore.w - rx;
3701 ah = Max(guiApp.windowResizingBefore.h - ry,window.skinMinSize.h);
3702 ry = guiApp.windowResizingBefore.h - ah;
3703 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3704 ry = Max(ry, -guiApp.windowMovingBefore.y);
3705 h = guiApp.windowResizingBefore.h - ry;
3707 if(guiApp.resizeEndX)
3709 w = guiApp.windowResizingBefore.w + rx;
3712 if(guiApp.resizeEndY) h = guiApp.windowResizingBefore.h + ry;
3720 w = Max(w, window.minSize.w);
3721 h = Max(h, window.minSize.h);
3722 w = Min(w, window.maxSize.w);
3723 h = Min(h, window.maxSize.h);
3725 if(!window.OnResizing(&w, &h))
3727 w = window.clientSize.w;
3728 h = window.clientSize.h;
3731 w = Max(w, window.skinMinSize.w);
3732 h = Max(h, window.skinMinSize.h);
3739 SNAPDOWN(w, textCellW);
3740 SNAPDOWN(h, textCellH);
3745 aw = Max(w,window.skinMinSize.w);
3746 rx = guiApp.windowResizingBefore.w - aw;
3747 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3748 w = guiApp.windowResizingBefore.w - rx;
3752 ah = Max(h,window.skinMinSize.h);
3753 ry = guiApp.windowResizingBefore.h - ah;
3754 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3755 ry = Max(ry, -guiApp.windowMovingBefore.y);
3756 h = guiApp.windowResizingBefore.h - ry;
3761 if(!guiApp.windowIsResizing || guiApp.resizeX)
3762 x = guiApp.windowMovingBefore.x + rx;
3763 if(!guiApp.windowIsResizing || guiApp.resizeY)
3764 y = guiApp.windowMovingBefore.y + ry;
3766 if(!guiApp.windowIsResizing)
3769 if(window.parent == guiApp.desktop && guiApp.virtualScreen.w)
3771 x = Min(x, (guiApp.virtualScreen.w + guiApp.virtualScreenPos.x) -1);
3772 y = Min(y, (guiApp.virtualScreen.h + guiApp.virtualScreenPos.y) -1);
3773 x = Max(x,-(w-1) + guiApp.virtualScreenPos.x);
3774 y = Max(y,-(h-1) + guiApp.virtualScreenPos.y);
3778 x = Min(x, (window.parent.reqScrollArea.w ? window.parent.reqScrollArea.w : window.parent.clientSize.w) -1);
3779 y = Min(y, (window.parent.reqScrollArea.h ? window.parent.reqScrollArea.h : window.parent.clientSize.h) -1);
3785 if(!guiApp.windowIsResizing || (guiApp.resizeX || guiApp.resizeY))
3787 if(!window.OnMoving(&x, &y, w, h))
3789 x = window.scrolledPos.x;
3790 y = window.scrolledPos.y;
3796 SNAPDOWN(x, textCellW);
3797 SNAPDOWN(y, textCellH);
3800 if(!window.style.nonClient)
3802 if(!window.style.fixed /*|| window.style.isDocument*/)
3804 if(!window.style.dontScrollHorz)
3805 x += window.parent.scroll.x;
3806 if(!window.style.dontScrollVert)
3807 y += window.parent.scroll.y;
3811 // Break the anchors for moveable/resizable windows
3812 // Will probably cause problem with IDE windows... Will probably need a way to specify if anchors should break
3813 if(window.style.fixed)
3815 if(window.state == normal)
3817 window.normalAnchor = Anchor { left = x, top = y };
3818 window.normalSizeAnchor = SizeAnchor { { w, h } };
3819 window.anchored = false;
3823 window.stateAnchor = Anchor { left = x, top = y };
3824 window.stateSizeAnchor = SizeAnchor { { w, h } };
3826 window.Position(x, y, w, h, false, true, guiApp.windowIsResizing, guiApp.windowIsResizing, false, true);
3827 // TOCHECK: Investigate why the following only redraws the scrollbars
3828 //window.Position(x, y, w, h, false, true, true, true, false, true);
3830 guiApp.movingLast.x = mouseX;
3831 guiApp.movingLast.y = mouseY;
3837 public bool MouseMessage(uint method, int x, int y, Modifiers * mods, bool consequential, bool activate)
3840 bool wasMoving = guiApp.windowMoving ? true : false;
3841 bool wasScrolling = guiApp.windowScrolling ? true : false;
3843 while(result && w != this)
3845 Window msgWindow = GetAtPosition(x,y, false, true, w);
3846 Window trueWindow = GetAtPosition(x,y, false, false, w);
3847 bool windowDragged = false;
3852 window = (w && !w.disabled) ? w : null;
3854 if(trueWindow) incref trueWindow;
3856 if(consequential) mods->isSideEffect = true;
3858 UpdateMouseMove(x, y, consequential);
3860 if(guiApp.windowCaptured && (guiApp.windowCaptured.rootWindow == this))
3862 if(!guiApp.windowCaptured.isEnabled)
3863 guiApp.windowCaptured.ReleaseCapture();
3865 window = guiApp.windowCaptured;
3868 if(trueWindow && activate &&
3869 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
3870 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
3871 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
3872 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
3874 Window modalWindow = trueWindow.FindModal();
3876 if(mods->alt && !mods->ctrl && !mods->shift)
3878 Window moved = trueWindow;
3879 for(moved = trueWindow; moved; moved = moved.parent)
3880 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
3885 windowDragged = true;
3887 // Cancel the ALT menu toggling...
3888 window.rootWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
3893 if(window && activate &&
3894 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
3895 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
3896 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
3897 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
3899 Window modalWindow = window.FindModal();
3901 /*if(mods->alt && !mods->shift && !mods->ctrl)
3903 Window moved = window;
3904 for(moved = window; moved; moved = moved.parent)
3905 if(method == OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
3910 windowDragged = true;
3912 // Cancel the ALT menu toggling...
3913 window.rootWindow.KeyMessage(OnKeyDown, 0, 0);
3919 Window activateWindow = modalWindow ? modalWindow : window;
3920 if(activateWindow && !activateWindow.isRemote)
3922 bool doActivation = true;
3923 //bool needToDoActivation = false;
3924 Window check = activateWindow;
3926 for(check = activateWindow; check && check != guiApp.desktop; check = check.parent)
3928 if(!check.style.inactive)
3930 //needToDoActivation = true;
3932 doActivation = false;
3937 if(!needToDoActivation)
3938 doActivation = false;
3941 if((doActivation && (activateWindow.parent != guiApp.desktop || guiApp.fullScreen)) ||
3942 (guiApp.interimWindow && !window.IsDescendantOf(guiApp.interimWindow)))
3946 incref activateWindow;
3947 if(!activateWindow.ActivateEx(true, true, false, true, null, null))
3949 delete activateWindow;
3953 if(activateWindow._refCount == 1)
3955 delete activateWindow;
3959 delete activateWindow;
3961 mods->isActivate = true;
3965 if(!modalWindow && window && !window.destroyed)
3967 if(!guiApp.windowCaptured || windowDragged)
3969 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown)
3971 bool moving = ((window.state != maximized &&
3972 window.IsMouseMoving(
3973 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
3974 || (guiApp.windowMoving && !guiApp.windowIsResizing);
3976 if(!moving && window.IsMouseResizing(
3977 x - window.absPosition.x,
3978 y - window.absPosition.y,
3979 window.size.w, window.size.h,
3980 &guiApp.resizeX, &guiApp.resizeY, &guiApp.resizeEndX, &guiApp.resizeEndY))
3982 guiApp.windowIsResizing = true;
3983 guiApp.windowResizingBefore.w = window.size.w;
3984 guiApp.windowResizingBefore.h = window.size.h;
3986 if(guiApp.windowIsResizing || windowDragged || moving)
3989 guiApp.windowMoving = window;
3990 guiApp.windowMovingStart.x = guiApp.movingLast.x = x;
3991 guiApp.windowMovingStart.y = guiApp.movingLast.y = y;
3992 guiApp.windowMovingBefore.x = window.position.x;//s;
3993 guiApp.windowMovingBefore.y = window.position.y;//s;
3994 if(guiApp.windowMoving == guiApp.windowMoving.rootWindow)
3995 guiApp.interfaceDriver.StartMoving(guiApp.windowMoving.rootWindow, 0,0,false);
3998 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown)
4000 if(window.style.fixed &&
4002 window.IsMouseMoving(
4003 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4005 window.ShowSysMenu(x, y);
4009 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown)
4011 if(window.sbv || window.sbh)
4014 guiApp.windowScrolling = window;
4015 guiApp.windowScrollingStart.x = x;
4016 guiApp.windowScrollingStart.y = y;
4017 guiApp.windowScrollingBefore.x = window.scroll.x;
4018 guiApp.windowScrollingBefore.y = window.scroll.y;
4021 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4023 if(window.style.hasMaximize &&
4024 window.IsMouseMoving(
4025 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h))
4028 (window.state == maximized) ? normal : maximized, false, *mods);
4036 if(guiApp.windowMoving)
4038 if(guiApp.windowMoving.parent)
4040 if(guiApp.windowMoving.style.nonClient)
4041 guiApp.windowMoving.parent.SetMouseRangeToWindow();
4043 guiApp.windowMoving.parent.SetMouseRangeToClient();
4047 window.UpdateDecorations();
4050 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp)
4052 // Log("\n*** LEFT BUTTON UP ***\n");
4053 if(guiApp.windowMoving)
4054 guiApp.windowMoving.StopMoving();
4056 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp)
4058 if(guiApp.windowScrolling)
4060 Window windowScrolling = guiApp.windowScrolling;
4061 guiApp.windowScrolling = null;
4062 windowScrolling.ReleaseCapture();
4066 if(!result || (window && window.destroyed)) window = null;
4068 if(window && window.FindModal())
4071 if(trueWindow && trueWindow.FindModal())
4079 msgWindow = GetAtPosition(x,y, true, false);
4081 msgWindow.SelectMouseCursor();
4084 if(guiApp.windowCaptured || trueWindow)
4086 Window prevWindow = guiApp.prevWindow;
4087 if(guiApp.prevWindow && trueWindow != guiApp.prevWindow)
4089 guiApp.prevWindow.mouseInside = false;
4090 guiApp.prevWindow = null;
4092 // Eventually fix this not to include captured?
4093 if(!prevWindow.OnMouseLeave(*mods))
4096 if(result && trueWindow && !trueWindow.destroyed/* && trueWindow == window*/)
4098 Box box = trueWindow.box;
4099 box.left += trueWindow.absPosition.x;
4100 box.right += trueWindow.absPosition.x;
4101 box.top += trueWindow.absPosition.y;
4102 box.bottom += trueWindow.absPosition.y;
4104 if(box.IsPointInside({x, y}) && trueWindow != /*guiApp.*/prevWindow /*!trueWindow.mouseInside*/)
4106 int overX = x - (trueWindow.absPosition.x + trueWindow.clientStart.x);
4107 int overY = y - (trueWindow.absPosition.y + trueWindow.clientStart.y);
4109 overX = Max(Min(overX, 32767),-32768);
4110 overY = Max(Min(overY, 32767),-32768);
4112 trueWindow.mouseInside = true;
4113 if(!trueWindow.OnMouseOver(overX, overY, *mods))
4117 if(trueWindow && trueWindow._refCount > 1 && !trueWindow.destroyed)
4118 guiApp.prevWindow = trueWindow;
4120 guiApp.prevWindow = null;
4122 SelectMouseCursor();
4124 if(window && !guiApp.windowMoving && !wasMoving && !wasScrolling)
4126 int clientX = x - (window.absPosition.x + window.clientStart.x);
4127 int clientY = y - (window.absPosition.y + window.clientStart.y);
4129 bool (* MouseMethod)(Window instance, int x, int y, Modifiers mods);
4131 clientX = Max(Min(clientX, 32767),-32768);
4132 clientY = Max(Min(clientY, 32767),-32768);
4134 MouseMethod = (void *)window._vTbl[method];
4136 if(MouseMethod /*&& !consequential*/ && !window.disabled)
4139 if(!MouseMethod(window, clientX, clientY, *mods))
4146 if(result && w && w.clickThrough && w.parent)
4151 if(!result || !w || !w.clickThrough)
4158 // --- Mouse cursor management ---
4160 bool KeyMessage(uint method, Key key, unichar character)
4165 if(guiApp.interimWindow)
4166 this = guiApp.interimWindow;
4169 if((SmartKey)key != alt && (SmartKey)key != Key::control && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && parent && this != parent.menuBar)
4173 if(!style.inactive || rootWindow != this)
4175 bool (*KeyMethod)(Window window, Key key, unichar ch) = (void *)_vTbl[method];
4176 Window modalWindow = FindModal();
4177 Window interimMaster = master ? master.rootWindow : null;
4181 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4182 status = OnSysKeyDown(key, character);
4183 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4184 status = OnSysKeyHit(key, character);
4185 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4186 status = OnSysKeyUp(key, character);
4193 // Process Key Message for Internal UI Keyboard actions
4194 if(status && !destroyed && menuBar && state != minimized)
4197 if((SmartKey)key != alt)
4198 menuBar.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4201 SmartKey sk = (SmartKey) key;
4202 if((character && !key.alt && !key.ctrl) || sk == left || sk == right || sk == up || sk == down || sk == home || sk == end || sk == escape || sk == alt)
4204 status = menuBar.KeyMessage(method, key, character);
4209 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4210 menuBar.OnKeyHit(escape, 0);
4212 if(!menuBar.focus && guiApp.caretOwner)
4213 guiApp.caretOwner.UpdateCaret(true, false);
4216 if(!destroyed && status)
4218 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4222 case left: case up: case right: case down:
4223 if(guiApp.windowMoving == this)
4226 int w = guiApp.windowMoving.size.w;
4227 int h = guiApp.windowMoving.size.h;
4228 int x = guiApp.windowMoving.scrolledPos.x;
4229 int y = guiApp.windowMoving.scrolledPos.y;
4233 if(key == down || key == up)
4234 step = Max(step, textCellH);
4236 step = Max(step, textCellW);
4239 if(guiApp.windowIsResizing)
4243 case left: w-=step; break;
4244 case right: w+=step; break;
4245 case up: h-=step; break;
4246 case down: h+=step; break;
4253 case left: x-=step; break;
4254 case right: x+=step; break;
4255 case up: y-=step; break;
4256 case down: y+=step; break;
4260 if(guiApp.resizeX) x += w - guiApp.windowMoving.size.w;
4261 if(guiApp.resizeY) y += h - guiApp.windowMoving.size.h;
4263 if(!guiApp.windowIsResizing || guiApp.resizeX)
4264 x = (x - guiApp.windowMovingBefore.x) + guiApp.windowMovingStart.x;
4266 x = (w - guiApp.windowResizingBefore.w) + guiApp.windowMovingStart.x;
4268 if(!guiApp.windowIsResizing || guiApp.resizeY)
4269 y = (y - guiApp.windowMovingBefore.y) + guiApp.windowMovingStart.y;
4271 y = (h - guiApp.windowResizingBefore.h) + guiApp.windowMovingStart.y;
4273 guiApp.interfaceDriver.SetMousePosition(x, y);
4274 ConsequentialMouseMove(true);
4282 if(guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4284 guiApp.windowMoving.StopMoving();
4285 ConsequentialMouseMove(false);
4293 ShowSysMenu(absPosition.x, absPosition.y);
4301 if(!destroyed && status && state != minimized)
4303 // Process all the way down the children
4304 if(activeChild && !activeChild.disabled)
4306 status = activeChild.KeyMessage(method, key, character);
4308 if(status && activeClient && activeChild != activeClient && !activeClient.disabled && (key.alt || key.ctrl) &&
4309 key.code != left && key.code != right && key.code != up && key.code != down)
4311 status = activeClient.KeyMessage(method, key, character);
4315 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4317 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && !defaultControl.disabled && state != minimized)
4318 // && defaultControl != activeChild)
4320 delete previousActive;
4321 previousActive = activeChild;
4322 if(previousActive) incref previousActive;
4324 ConsequentialMouseMove(false);
4325 if((defaultControl.active ||
4326 defaultControl.ActivateEx(true, true, false, true, null, null)) && !defaultControl.disabled)
4327 defaultControl.KeyMessage(method, defaultKey, character);
4333 if(!destroyed && status && (!modalWindow || this == guiApp.desktop))
4335 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4342 ShowSysMenu(absPosition.x, absPosition.y);
4349 if(this != guiApp.desktop)
4351 if(!guiApp.windowMoving && !guiApp.windowCaptured)
4353 if(state != maximized && (key.shift ? style.sizeable : style.fixed))
4355 MenuMoveOrSize(key.shift, true);
4359 else if(guiApp.windowMoving)
4361 guiApp.windowMoving.StopMoving();
4362 ConsequentialMouseMove(false);
4370 if(!destroyed && status && state != minimized)
4372 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4376 case tab: case shiftTab:
4378 Window cycleParent = this;
4379 if(this == guiApp.interimWindow && !master.style.interim && !cycleParent.style.tabCycle)
4380 cycleParent = master.parent;
4382 if(!guiApp.windowCaptured && cycleParent.style.tabCycle)
4384 if(cycleParent.CycleChildren(!key.shift, false, false, true))
4386 Window child = cycleParent.activeChild;
4388 // Scroll the window to include the active control
4390 if(cycleParent.sbh && !child.style.dontScrollHorz)
4392 if(child.scrolledPos.x < 0)
4393 cycleParent.sbh.Action(Position,
4394 cycleParent.scroll.x + child.scrolledPos.x, 0);
4395 else if(child.scrolledPos.x + child.size.w > cycleParent.clientSize.w)
4396 cycleParent.sbh.Action(Position,
4397 cycleParent.scroll.x + child.scrolledPos.x + child.size.w - cycleParent.clientSize.w, 0);
4399 if(cycleParent.sbv && !child.style.dontScrollVert)
4401 if(child.scrolledPos.y < 0)
4402 cycleParent.sbv.Action(Position,
4403 cycleParent.scroll.y + child.scrolledPos.y, 0);
4404 else if(child.scrolledPos.y + child.size.w > window.clientSize.h)
4405 cycleParent.sbv.Action(Position,
4406 cycleParent.scroll.y + child.scrolledPos.y+child.size.h - cycleParent.clientSize.h, 0);
4409 cycleParent.ConsequentialMouseMove(false);
4415 case f6: case shiftF6:
4416 if(!guiApp.windowMoving /*!guiApp.windowCaptured*/)
4418 // NOT NEEDED... guiApp.windowMoving.ReleaseCapture();
4419 if(parent == guiApp.desktop)
4420 if(guiApp.desktop.CycleChildren(key.shift, true, false, true))
4425 if(style.tabCycle ||
4426 CycleChildren(key.shift, true, false, true))
4434 // mIRC Style Window Shortcuts
4435 case alt1: case alt2: case alt3: case alt4: case alt5:
4436 case alt6: case alt7: case alt8: case alt9: case alt0:
4441 for(document = children.first; document; document = document.next)
4443 if(document.style.isDocument && document.documentID - 1 == key.code - k1)
4445 if(document == activeChild)
4447 if(document.state == minimized)
4448 document.SetState(normal, false, key);
4451 document.SetState(minimized, false, key);
4452 CycleChildren(false, true, false);
4457 if(activeChild.state == maximized && document.style.hasMaximize)
4458 document.SetState(maximized, false, key);
4459 else if(document.state == minimized)
4460 document.SetState(normal, false, key);
4461 document.Activate();
4476 if(!destroyed && status)
4478 if(state == minimized)
4483 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4485 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && previousActive)
4487 if(defaultControl.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, key, character))
4488 previousActive.ActivateEx(true, false, false, true, null, null);
4489 delete previousActive;
4495 if(!destroyed && status)
4497 status = ProcessHotKeys(method, key, character);
4499 if(!destroyed && status && !modalWindow && state != minimized)
4502 status = KeyMethod(this, key, character);
4503 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4504 status = OnKeyHit(key, character);
4505 if(!destroyed && status && (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit))
4507 bool result = false;
4510 case ctrlUp: case ctrlDown:
4511 if(sbv && !guiApp.windowScrolling)
4512 result = sbv.Action((key == ctrlUp) ? up : down, 0, key);
4514 case wheelUp: case wheelDown:
4515 if(sbv && !guiApp.windowScrolling)
4517 result = sbv.Action((key == wheelUp) ? wheelUp : wheelDown, 0, key);
4518 // Do we want to do a consequential move regardless of result in this case?
4519 ConsequentialMouseMove(false);
4522 case ctrlPageUp: case ctrlPageDown:
4523 if(sbh && !guiApp.windowScrolling)
4524 result = sbh.Action((key == ctrlPageUp) ? up : down, 0, key);
4529 ConsequentialMouseMove(false);
4534 if(status && !destroyed && menuBar && state != minimized)
4535 status = menuBar.KeyMessage(method, key, character);
4537 if(style.interim && /*destroyed && */status && interimMaster)
4539 // Testing this... for Ctrl-O to open dialog when autocompletion listbox is popped...
4540 status = interimMaster.KeyMessage(method, key, character);
4547 bool ProcessHotKeys(uint method, Key key, unichar character)
4552 for(hotKey = hotKeys.first; hotKey; hotKey = hotKey.next)
4553 if((hotKey.key == key || (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp && hotKey.key.code == key.code)) &&
4554 !hotKey.window.disabled && (hotKey.window.style.nonClient || state != minimized))
4556 Window hotKeyWindow = hotKey.window;
4557 Window parent = hotKeyWindow.parent;
4558 Window prevActiveWindow = activeChild;
4560 // Don't process non-visible buttons, but make an exception for the Alt-F4 with Native Decorations turned on
4561 if(hotKeyWindow.style.hidden && (!hotKeyWindow.style.nonClient || !parent || !parent.nativeDecorations || hotKeyWindow != parent.sysButtons[2]))
4564 if(prevActiveWindow) incref prevActiveWindow;
4565 incref hotKeyWindow;
4566 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && !hotKeyWindow.style.nonClient)
4567 if(!hotKeyWindow.ActivateEx(true, true, false, true, null, null))
4570 delete hotKeyWindow;
4571 delete prevActiveWindow;
4575 if(hotKeyWindow.style.nonClient && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4576 method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
4577 if(!hotKeyWindow.KeyMessage(method, Key::hotKey, character))
4579 // ********* WORKING ON THIS ***********
4580 if(prevActiveWindow && !guiApp.interimWindow)
4581 prevActiveWindow.ActivateEx(true, false, false, false, null, null);
4584 else if(hotKeyWindow.style.inactive)
4585 status = hotKeyWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, Key::hotKey, character);
4587 delete prevActiveWindow;
4588 delete hotKeyWindow;
4589 // For Key Ups, don't set status to false... (e.g.: Releasing Enter vs AltEnter hot key)
4590 if(method != __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4594 if(status && tabCycle)
4597 for(child = children.first; child; child = child.next)
4599 if(child.tabCycle && !child.ProcessHotKeys(method, key, character))
4610 // --- Windows and graphics initialization / termination ---
4611 bool SetupRoot(void)
4615 // Setup relationship with outside world (bb root || !bb)
4616 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || this == guiApp.desktop ||
4617 (displayDriver && displayDriver != parent.displayDriver))
4621 tempExtents = new0 Extent[4];
4626 /*if(guiApp.fullScreenMode)
4627 rootWindow = guiApp.desktop;
4629 //rootWindow = parent.created ? parent.rootWindow : null;
4630 rootWindow = parent.rootWindow;
4633 against = &parent.box;
4635 against = &parent.clientArea;
4638 for(child = children.first; child; child = child.next)
4641 return (rootWindow && (rootWindow == this || rootWindow.created)) ? true : false;
4644 bool Setup(bool positionChildren)
4646 bool result = false;
4649 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || (guiApp.fullScreenMode && (this == guiApp.desktop || (displayDriver && displayDriver != parent.displayDriver))))
4651 subclass(DisplayDriver) dDriver = dispDriver ? dispDriver : GetDisplayDriver(guiApp.defaultDisplayDriver);
4652 DisplaySystem displaySystem = dDriver ? dDriver.displaySystem : null;
4654 windowHandle = dDriver.printer ? null : guiApp.interfaceDriver.CreateRootWindow(this);
4656 // This was here, is it really needed?
4657 //guiApp.interfaceDriver.ActivateRootWindow(this);
4661 displaySystem = DisplaySystem {};
4662 if(!displaySystem.Create(dDriver.name, guiApp.fullScreenMode ? windowHandle : windowHandle /*null*/, guiApp.fullScreenMode))
4664 delete displaySystem;
4669 display = Display { alphaBlend = alphaBlend, useSharedMemory = useSharedMemory, windowDriverData = windowData };
4670 if(display.Create(displaySystem, windowHandle))
4677 guiApp.interfaceDriver.SetIcon(this, icon);
4679 else if(this != guiApp.desktop)
4681 display = rootWindow ? rootWindow.display : null;
4687 if(guiApp.acquiredWindow && rootWindow == guiApp.acquiredWindow.rootWindow)
4688 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, true);
4690 for(child = children.first; child; child = child.next)
4692 if(child.created && !child.Setup(false))
4698 bool SetupDisplay(void)
4700 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
4701 if(is3D) return Window3D_SetupDisplay(this); else
4708 class_data void ** pureVTbl;
4710 bool LoadGraphics(bool creation, bool resetAnchors)
4712 bool result = false;
4713 bool success = false;
4715 WindowState stateBackup = state;
4718 if(!rootWindow.created)
4722 if(((subclass(Window))_class).pureVTbl)
4724 if(_vTbl == _class._vTbl)
4726 _vTbl = ((subclass(Window))_class).pureVTbl;
4731 for(m = 0; m < _class.vTblSize; m++)
4733 if(_vTbl[m] == _class._vTbl[m])
4734 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
4738 if(guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
4740 if(_vTbl == ((subclass(Window))_class).pureVTbl)
4742 _vTbl = _class._vTbl;
4747 for(m = 0; m < _class.vTblSize; m++)
4749 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
4750 _vTbl[m] = _class._vTbl[m];
4755 if(guiApp.fullScreenMode || this != guiApp.desktop)
4757 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
4763 display.Lock(false);
4764 if(rootWindow == this)
4766 // Set Color Palette
4767 display.SetPalette(palette, true);
4771 if(guiApp.fullScreenMode && this == guiApp.desktop)
4776 for(c=0; c<SystemCursor::enumSize; c++)
4777 if(!guiApp.systemCursors[c].bitmap)
4779 guiApp.systemCursors[c].bitmapName = guiApp.currentSkin.CursorsBitmaps(c,
4780 &guiApp.systemCursors[c].hotSpotX,&guiApp.systemCursors[c].hotSpotY, &guiApp.systemCursors[c].paletteShades);
4781 if(guiApp.systemCursors[c].bitmapName)
4783 guiApp.systemCursors[c].bitmap = eBitmap_LoadT(guiApp.systemCursors[c].bitmapName, null,
4784 guiApp.systemCursors[c].paletteShades ? null : guiApp.desktop.display.displaySystem);
4785 if(guiApp.systemCursors[c].bitmap)
4786 guiApp.systemCursors[c].bitmap.paletteShades = guiApp.systemCursors[c].paletteShades;
4791 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
4793 cursor.bitmap = eBitmap_LoadT(cursor.bitmapName, null,
4794 cursor.paletteShades ? null : guiApp.desktop.display.displaySystem);
4796 cursor.bitmap.paletteShades = cursor.paletteShades;
4800 guiApp.cursorUpdate = true;
4803 ConsequentialMouseMove(false);
4809 // Load Window Graphic Resources
4812 if(usedFont == setFont || usedFont == window.systemFont)
4813 RemoveResource(usedFont);
4816 RemoveResource(setFont); // TESTING setFont instead of usedFont);
4819 RemoveResource(systemFont);
4822 RemoveResource(captionFont);
4824 for(ptr = resources.first; ptr; ptr = ptr.next)
4826 ptr.loaded = display.displaySystem.LoadResource(ptr.resource);
4829 AddResource(setFont);
4831 AddResource(systemFont);
4833 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
4840 //if(master && master.font)
4841 if(parent && parent.font)
4845 faceName = parent.font.faceName,
4846 size = parent.font.size,
4847 bold = parent.font.bold,
4848 italic = parent.font.italic,
4849 underline = parent.font.underline
4851 //font = parent.font;
4852 watch(parent) { font { } };
4855 font = guiApp.currentSkin.SystemFont();
4862 captionFont = guiApp.currentSkin.CaptionFont();
4863 AddResource(captionFont);
4865 if(OnLoadGraphics())
4871 //SetScrollLineStep(sbStep.x, sbStep.y);
4873 if(this != guiApp.desktop)
4877 normalAnchor = anchor;
4878 normalSizeAnchor = sizeAnchor;
4881 // Break the anchors for moveable/resizable windows
4883 if(style.fixed && style.isDocument)
4885 ComputeAnchors(ax, ay, aw, ah, &x, &y, &w, &h);
4897 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
4898 stateSizeAnchor = SizeAnchor {};
4903 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
4908 left = (iconID % maxIcons) * MINIMIZED_WIDTH,
4909 bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24)
4912 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
4916 stateAnchor = normalAnchor;
4917 stateSizeAnchor = normalSizeAnchor;
4920 position = Point { };
4921 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
4932 if(Position(x, y, w, h, true, false, true, true, true, true))
4934 if((this != guiApp.desktop || guiApp.fullScreenMode) && rootWindow == this)
4937 guiApp.interfaceDriver.SetRootWindowState(this, normal, true);
4954 success = result = true;
4957 if(!creation && result)
4959 // Load menu bar first because sys buttons are on it...
4962 if(!menuBar.LoadGraphics(false, resetAnchors))
4968 for(child = children.first; child; child = child.next)
4970 if(child.created && child != menuBar && !child.LoadGraphics(false, resetAnchors))
4977 CreateSystemChildren();
4981 if(this == guiApp.desktop && !guiApp.fullScreenMode)
4984 guiApp.interfaceDriver.ActivateRootWindow(activeChild);
4989 //guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, caption);
4990 guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, class.name);
4993 // Do this here to avoid problems on Windows
4994 if(stateBackup == maximized)
4995 property::state = maximized;
4999 void UnloadGraphics(bool destroyWindows)
5003 // Free children's graphics
5004 for(child = children.first; child; child = child.next)
5005 child.UnloadGraphics(destroyWindows);
5008 display.Lock(false);
5011 if(guiApp.fullScreenMode && this == guiApp.desktop)
5016 for(c=0; c<SystemCursor::enumSize; c++)
5017 if(guiApp.systemCursors[c].bitmap)
5018 delete guiApp.systemCursors[c].bitmap;
5020 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5021 delete cursor.bitmap;
5023 guiApp.cursorBackground.Free();
5026 if(display && display.displaySystem)
5030 for(ptr = resources.first; ptr; ptr = ptr.next)
5034 display.displaySystem.UnloadResource(ptr.resource, ptr.loaded);
5039 // Free window graphics
5042 // Free skin graphics
5043 if(rootWindow == this)
5045 DisplaySystem displaySystem = display.displaySystem;
5048 display.driverData = null;
5049 display.displaySystem = null;
5053 if(displaySystem && !displaySystem.numDisplays && !is3D)
5054 delete displaySystem;
5063 if(guiApp.acquiredWindow && this == guiApp.acquiredWindow.rootWindow)
5064 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, false);
5066 if(this == guiApp.desktop || parent == guiApp.desktop)
5068 if((guiApp.fullScreenMode || this != guiApp.desktop) && rootWindow == this && windowHandle && destroyWindows)
5069 guiApp.interfaceDriver.DestroyRootWindow(this);
5073 // --- Window Hiding ---
5075 void SetVisibility(bool state)
5077 bool visible = (style.hidden || !created) ? false : state;
5078 if(visible != this.visible)
5082 this.visible = visible;
5083 for(child = children.first; child; child = child.next)
5084 child.SetVisibility(visible);
5086 ConsequentialMouseMove(false);
5090 // --- Windows and graphics initialization / termination ---
5092 bool DisplayModeChanged(void)
5094 bool result = false;
5095 if(!guiApp.fullScreenMode && !guiApp.modeSwitching/* && guiApp.desktop.active*/)
5097 guiApp.modeSwitching = true;
5098 UnloadGraphics(false);
5100 if(LoadGraphics(false, false))
5102 guiApp.modeSwitching = false;
5107 // --- Window updates system ---
5109 void UpdateDirty(Box updateBox)
5111 if(!manageDisplay) { OnRedraw(null);return; }
5114 if(display && (!guiApp.fullScreenMode || guiApp.desktop.active) && !guiApp.modeSwitching)
5117 if(display.flags.flipping)
5120 rootWindow.UpdateDisplay();
5123 UpdateBackDisplay(updateBox);
5125 if(guiApp.fullScreenMode)
5127 guiApp.cursorUpdate = true;
5128 guiApp.PreserveAndDrawCursor();
5130 if(guiApp.fullScreenMode)
5131 guiApp.RestoreCursorBackground();
5137 // This function is strictly called as a result of system window activation
5138 bool ExternalActivate(bool active, bool activateRoot, Window window, Window swap)
5141 Window interimMaster = null;
5142 Window interimWindow = guiApp.interimWindow;
5143 if(interimWindow && interimWindow.master)
5144 interimMaster = interimWindow.master.rootWindow;
5146 if(active && state == minimized)
5147 // SetState(normal, false, 0);
5148 SetState(lastState, false, 0);
5150 if(interimMaster && swap == interimMaster && interimMaster.IsSlaveOf(window))
5154 /* WTH is this doing here?
5155 while(swap && swap.activeChild)
5157 swap = swap.activeChild;
5160 // TESTING THIS BEFORE...
5161 if(interimWindow && this == interimMaster)
5165 // Window interimSwap = this;
5166 Window menuBar = this.menuBar;
5167 if(menuBar && interimWindow.master == menuBar)
5170 while(interimSwap && interimSwap.activeChild)
5171 interimSwap = interimSwap.activeChild;
5173 result = interimWindow.ActivateEx(false, false, false, activateRoot, null,
5174 (menuBar && interimWindow.master == menuBar) ? menuBar : interimSwap);
5176 result = /*interimWindow.*/ActivateEx(false, false, false, activateRoot, null, menuBar);
5177 //result = ActivateEx(true, true, false, activateRoot, window, null);
5182 // Testing & FindModal() here: broke reactivating when a modal dialog is up (didn't root activate dialog)
5183 result = ActivateEx(active, active, false, activateRoot /*&& FindModal()*/, window, swap);
5185 if(interimWindow == this && interimMaster && !active)
5187 while(interimMaster && interimMaster.interim && interimMaster.master)
5189 // printf("Going up one master %s\n", interimMaster._class.name);
5190 interimMaster = interimMaster.master.rootWindow;
5192 // printf("Unactivating interim master %s (%x)\n", interimMaster._class.name, interimMaster);
5193 interimMaster.ActivateEx(active, active, false, activateRoot, window, swap);
5199 bool DestroyEx(int returnCode)
5202 Timer timer, nextTimer;
5204 OldLink prevOrder = null;
5205 Window client = null;
5207 if(parent) stopwatching(parent, font);
5209 // if(window.modalSlave) return false;
5210 if(destroyed || !created)
5217 OldLink slave = master.slaves.FindVoid(this);
5218 master.slaves.Delete(slave);
5221 // TOFIX IMMEDIATELY: COMMENTED THIS OUT... causes problem second time creating file dialog
5227 this.returnCode = (DialogResult)returnCode;
5229 AcquireInput(false);
5234 master.hotKeys.Delete(hotKey);
5238 if(guiApp.prevWindow == this)
5240 guiApp.prevWindow = null;
5243 if(guiApp.caretOwner == this)
5245 guiApp.interfaceDriver.SetCaret(0,0,0);
5246 UpdateCaret(false, true);
5247 guiApp.caretEnabled = false;
5252 parent.childrenCycle.Remove(cycle);
5256 OldLink tmpPrev = order.prev;
5257 if(tmpPrev && !(((Window)tmpPrev.data).style.hidden) && !(((Window)tmpPrev.data).destroyed) && (((Window)tmpPrev.data).created))
5258 prevOrder = tmpPrev;
5261 client = tmpPrev ? tmpPrev.data : null;
5262 if(client == this) { client = null; break; }
5263 if(client && (client.style.hidden || client.destroyed || !client.created))
5264 tmpPrev = client.order.prev;
5268 prevOrder = tmpPrev;
5273 // If this window can be an active client, make sure the next window we activate can also be one
5274 if(!style.nonClient && style.isActiveClient)
5276 tmpPrev = prevOrder;
5279 client = tmpPrev ? tmpPrev.data : null;
5280 if(client == this) { client = null; break; }
5281 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
5282 tmpPrev = client.order.prev;
5286 prevOrder = tmpPrev;
5290 if(client && client.style.hidden) client = null;
5292 // parent.childrenOrder.Remove(order);
5295 // TESTING THIS HERE!
5299 // If no display, don't bother deactivating stuff (causes unneeded problems when trying
5300 // to create a window inside a rootwindow that's being destroyed)
5301 // DISABLED THIS BECAUSE OF CREATING WINDOW IN DESKTOP IN WINDOWED MODE
5303 if(master && !master.destroyed /*&&
5304 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5306 if(master.defaultControl == this)
5307 master.defaultControl = null;
5309 if(parent && !parent.destroyed /*&&
5310 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5312 if((parent.activeChild == this /*|| parent.activeClient == this */|| guiApp.interimWindow == this))
5314 if(order && prevOrder && prevOrder.data != this && active)
5316 //((Window)prevOrder.data).ActivateEx(true, false, false, false /*true*/, null);
5318 ((Window)prevOrder.data).ActivateEx(true, false, false, (rootWindow == this) ? true : false, null, null);
5319 if(parent.activeClient == this)
5321 parent.activeClient = null;
5322 parent.UpdateActiveDocument(null);
5327 if(guiApp.interimWindow == this)
5330 PropagateActive(false, null, &goOn, true);
5334 //if(window.parent.activeChild == window)
5335 parent.activeChild = null;
5336 if(!style.nonClient /*&& style.isActiveClient*/)
5338 Window previous = parent.activeClient;
5339 if(style.isActiveClient)
5340 parent.activeClient = null;
5341 parent.UpdateActiveDocument(previous);
5346 else if(parent.activeClient == this)
5348 parent.activeClient = client;
5349 parent.UpdateActiveDocument(this);
5353 if(guiApp.interimWindow == this)
5355 guiApp.interimWindow = null;
5356 if(guiApp.caretOwner)
5358 Window desktop = guiApp.desktop;
5359 if(desktop.activeChild && desktop.activeChild.menuBar && !desktop.activeChild.menuBar.focus)
5360 guiApp.caretOwner.UpdateCaret(false, false);
5365 if(style.modal && master && master.modalSlave == this)
5366 master.modalSlave = null;
5370 if(!guiApp.caretOwner && parent.caretSize)
5372 guiApp.caretOwner = parent;
5373 parent.UpdateCaret(false, false);
5374 parent.Update(null);
5377 if(style.isActiveClient && visible)
5379 if(state == minimized) parent.numIcons--;
5380 parent.numPositions--;
5382 // Why was this commented out?
5383 GetRidOfVirtualArea();
5389 dirtyArea.Free(null);
5390 dirtyBack.Free(null);
5391 scrollExtent.Free(null);
5393 /* ATTEMPTING TO MOVE THAT ABOVE
5402 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5403 for(;(child = window.children.first);)
5405 for(; child && (child.destroyed || !child.created); child = child.next);
5414 UnloadGraphics(true);
5417 delete previousActive;
5420 // statusBar = null;
5423 if(master && !master.destroyed)
5425 //master.NotifyDestroyed(this, this.returnCode);
5426 NotifyDestroyed(master, this, this.returnCode);
5429 for(timer = guiApp.windowTimers.first; timer; timer = nextTimer)
5431 nextTimer = timer.next;
5432 if(timer.window == this)
5434 // WHY WERE WE SETTING THIS TO NULL? NO MORE WINDOW WHEN RECREATING...
5435 // timer.window = null;
5441 if(this == guiApp.windowMoving)
5444 if(guiApp.windowCaptured == this)
5446 //guiApp.windowCaptured = null;
5448 if(rootWindow != this && rootWindow)
5449 rootWindow.ConsequentialMouseMove(false);
5457 //for(child = children.first; next = child ? child.next : null, child; child = next)
5458 for(;(child = children.first); )
5460 for(; child && (child.destroyed || !child.created); child = child.next);
5470 /* // MOVED THIS UP...
5473 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5474 for(;(child = window.children.first); )
5476 for(; child && (child.destroyed || !child.created); child = child.next);
5485 while((slave = slaves.first))
5487 for(; slave && (((Window)slave.data).destroyed || !((Window)slave.data).created); slave = slave.next);
5489 ((Window)slave.data).DestroyEx(0);
5494 if(guiApp.caretOwner == this)
5495 guiApp.caretOwner = null;
5497 sysButtons[0] = null;
5498 sysButtons[1] = null;
5499 sysButtons[2] = null;
5502 if(rootWindow != this)
5504 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
5507 box.left -= parent.clientStart.x;
5508 box.top -= parent.clientStart.y;
5509 box.right -= parent.clientStart.x;
5510 box.bottom -= parent.clientStart.y;
5512 if(parent) parent.Update(box);
5517 OldLink slave = master.slaves.FindVoid(this);
5518 master.slaves.Delete(slave);
5524 parent.children.Remove(this);
5529 //autoCreate = false;
5532 // SHOULD THIS BE HERE? FIXED CRASH WITH GOTO DIALOG
5533 if(((subclass(Window))_class).pureVTbl)
5535 if(_vTbl == _class._vTbl)
5537 _vTbl = ((subclass(Window))_class).pureVTbl;
5542 for(m = 0; m < _class.vTblSize; m++)
5544 if(_vTbl[m] == _class._vTbl[m])
5545 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5554 void SetStateEx(WindowState newState, bool activate)
5557 WindowState prevState = state;
5560 if(rootWindow == this && nativeDecorations)
5563 if(prevState != newState)
5564 lastState = prevState;
5565 if(style.isActiveClient && !style.hidden && prevState == minimized)
5568 // This block used to be at the end of the function... moved it for flicker problem in X
5569 // ------------------------------------------------------
5573 stateAnchor = normalAnchor;
5574 stateSizeAnchor = normalSizeAnchor;
5577 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5578 stateSizeAnchor = SizeAnchor {};
5582 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5585 byte * idBuffer = new0 byte[size];
5587 for(child = parent.children.first; child; child = child.next)
5589 if(child != this && child.state == minimized)
5591 if(child.iconID > size - 2)
5593 idBuffer = renew0 idBuffer byte[size*2];
5594 memset(idBuffer + size, 0, size);
5597 idBuffer[child.iconID] = (byte)bool::true;
5600 for(c = 0; c<size; c++)
5605 if(style.isActiveClient && !style.hidden)
5608 stateAnchor = Anchor { left = (iconID % maxIcons) * MINIMIZED_WIDTH, bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24) };
5609 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
5613 // TOCHECK: Why was this here?
5614 //position.x = (tx > 0) ? tx & 0xFFFFF : tx;
5615 //position.y = (ty > 0) ? ty & 0xFFFFF : ty;
5616 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5618 Position(x, y, w, h, true, true, true, true, false, true);
5620 if(!style.inactive && !style.interim && this == parent.activeClient)
5621 parent.UpdateActiveDocument(null);
5623 CreateSystemChildren();
5624 // ------------------------------------------------------
5627 int GetPositionID(Window forChild)
5631 byte * idBuffer = new0 byte[size];
5634 for(child = children.first; child; child = child.next)
5636 if(child.style.isActiveClient && !child.style.hidden && child != forChild)
5638 if(child.positionID > size - 2)
5640 idBuffer = renew0 idBuffer byte[size*2];
5641 memset(idBuffer + size, 0, size);
5644 idBuffer[child.positionID] = (byte)bool::true;
5647 for(c = 0; c<size; c++)
5654 // --- Window related graphics ---
5656 void SetPalette(ColorAlpha * newPalette, bool colorMatch)
5658 palette = newPalette;
5659 if(rootWindow.display)
5660 rootWindow.display.SetPalette(palette, colorMatch);
5663 public bool AcquireInput(bool acquired)
5666 if(acquiredInput != acquired)
5668 if(active || (!visible && creationActivation == activate))
5669 result = AcquireInputEx(acquired);
5674 acquiredInput = acquired ? result : !result;
5679 void ListChildren(ListBox listBox)
5683 for(child = children.first; child; child = child.next)
5685 if(child.cycle && !child.style.nonClient && child.style.isActiveClient)
5687 DataRow row = listBox.AddRow();
5688 row.tag = (int)child;
5689 child.FigureCaption(caption);
5690 row.SetData(null, caption);
5695 void UpdateVisual(Box extent)
5697 if(guiApp.driver != null)
5699 if(guiApp.fullScreenMode && guiApp.desktop.display)
5701 guiApp.desktop.mutex.Wait();
5702 guiApp.desktop.display.Lock(true);
5705 if(guiApp.desktop.active)
5707 if(guiApp.desktop.dirty || guiApp.cursorUpdate)
5709 if(guiApp.desktop.display.flags.flipping)
5710 guiApp.desktop.Update(null);
5711 guiApp.desktop.UpdateDisplay();
5712 guiApp.cursorUpdate = true;
5714 if(guiApp.cursorUpdate || guiApp.desktop.dirty)
5716 guiApp.PreserveAndDrawCursor();
5717 // guiApp.desktop.display.ShowScreen();
5718 guiApp.cursorUpdate = false;
5719 guiApp.desktop.dirty = false;
5720 guiApp.RestoreCursorBackground();
5724 guiApp.desktop.display.Unlock();
5725 guiApp.desktop.mutex.Release();
5729 Window rootWindow = this.rootWindow;
5730 rootWindow.mutex.Wait();
5735 guiApp.SignalEvent();
5738 guiApp.waitMutex.Wait();
5739 guiApp.interfaceDriver.Lock(rootWindow);
5740 if(!rootWindow.style.hidden && rootWindow.dirty)
5742 if(rootWindow.display)
5744 rootWindow.UpdateDisplay();
5745 //rootWindow.display.ShowScreen(null);
5747 rootWindow.dirty = false;
5749 guiApp.interfaceDriver.Unlock(rootWindow);
5750 guiApp.waitMutex.Release();
5753 rootWindow.mutex.Release();
5758 void UnlockDisplay(void)
5760 guiApp.interfaceDriver.Unlock(rootWindow);
5763 void LockDisplay(void)
5765 guiApp.interfaceDriver.Lock(rootWindow);
5768 Surface GetSurface(Box box)
5770 return Redraw((box == null) ? this.box : box);
5773 void SetMousePosition(int x, int y)
5775 guiApp.interfaceDriver.SetMousePosition(x + absPosition.x + clientStart.x, y + absPosition.y + clientStart.y);
5779 void IntegrationActivate(bool active)
5781 if(!guiApp.modeSwitching && !guiApp.fullScreenMode)
5783 isForegroundWindow = true;
5784 ActivateEx(active, active, false, false, null, null);
5785 isForegroundWindow = false;
5790 Window QueryCapture(void)
5792 return guiApp.windowCaptured;
5795 int GetDocumentID(void)
5799 byte * idBuffer = new0 byte[size];
5802 for(child = children.first; child; child = child.next)
5804 if(child.style.isDocument)
5806 if(child.documentID-1 > size - 2)
5808 idBuffer = renew0 idBuffer byte[size*2];
5809 memset(idBuffer + size, 0, size);
5812 idBuffer[child.documentID-1] = 1;
5815 for(c = 0; c<size; c++)
5823 void SetInitSize(Size size)
5826 sizeAnchor.size = size;
5827 normalSizeAnchor = sizeAnchor;
5829 // Break the anchors for moveable/resizable windows
5830 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
5832 stateAnchor = normalAnchor;
5833 stateSizeAnchor = normalSizeAnchor;
5835 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5836 Position(x,y, w, h, true, true, true, true, false, true);
5840 void MenuMoveOrSize(bool resize, bool setCursorPosition)
5842 if(this != guiApp.desktop && state != maximized && (resize ? (state != minimized && style.sizable) : (style.fixed || moveable)))
5844 guiApp.windowIsResizing = resize;
5845 guiApp.windowMoving = this;
5846 guiApp.windowMovingStart = guiApp.movingLast = absPosition;
5847 if(guiApp.windowIsResizing)
5849 guiApp.windowMovingStart.x += size.w - 1;
5850 guiApp.windowMovingStart.y += size.h - 1;
5852 guiApp.windowMovingBefore = scrolledPos;
5853 guiApp.windowResizingBefore = size;
5854 guiApp.windowMoving.UpdateDecorations();
5855 if(guiApp.windowIsResizing)
5856 guiApp.resizeEndX = guiApp.resizeEndY = true;
5858 if(setCursorPosition)
5859 guiApp.interfaceDriver.SetMousePosition(guiApp.windowMovingStart.x, guiApp.windowMovingStart.y);
5863 guiApp.interfaceDriver.GetMousePosition(&x, &y);
5864 guiApp.windowMovingStart.x += x - absPosition.x;
5865 guiApp.windowMovingStart.y += y - absPosition.y;
5868 if(guiApp.windowMoving)
5870 if(guiApp.windowMoving.style.nonClient)
5871 guiApp.windowMoving.parent.SetMouseRangeToWindow();
5873 guiApp.windowMoving.parent.SetMouseRangeToClient();
5878 if(this == rootWindow)
5879 guiApp.interfaceDriver.StartMoving(rootWindow, guiApp.windowMovingStart.x, guiApp.windowMovingStart.y, true);
5887 bool result = false;
5891 else if(guiApp && guiApp.driver != null)
5893 void * systemParent = null;
5894 OldLink slaveHolder;
5896 bool visible = !style.hidden;
5900 systemParent = parent;
5901 parent = guiApp.desktop;
5903 last = parent ? parent.children.last : null;
5905 if((parent && parent != guiApp.desktop && !parent.created) ||
5906 (master && master != guiApp.desktop && !master.created))
5910 property::parent = guiApp.desktop;
5911 if(!master) master = parent;
5913 if(style.modal && master.modalSlave)
5917 parent.children.Remove(this);
5920 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
5921 if(slaveHolder.data == this)
5923 master.slaves.Delete(slaveHolder);
5928 if(parent == guiApp.desktop && !mutex)
5931 if(style.isDocument)
5934 parent.numDocuments--;
5935 documentID = parent.GetDocumentID();
5938 if(!style.stayOnTop)
5939 for(; last && last.style.stayOnTop; last = last.prev);
5941 parent.children.Insert((last == this) ? null : last, this);
5942 //parent.children.Add(this);
5945 dispDriver = parent.dispDriver;
5948 master.modalSlave = this;
5950 box = Box { MAXINT, MAXINT, MININT, MININT }; //-MAXINT, -MAXINT };
5955 master.slaves.Add(slaveHolder = OldLink { data = this });
5960 master.hotKeys.Add(hotKey = HotKeySlot { key = setHotKey, window = this });
5962 if(style.isDefault && !master.defaultControl)
5963 master.defaultControl = this;
5965 stateAnchor = normalAnchor = anchor;
5966 stateSizeAnchor = normalSizeAnchor = sizeAnchor;
5968 // TOCHECK: Why is this here?
5969 //position.x = (ax > 0) ? ax & 0xFFFFF : ax;
5970 //position.y = (ay > 0) ? ay & 0xFFFFF : ay;
5972 this.visible = false;
5973 style.hidden = true;
5976 // autoCreate = true;
5984 if(parent == guiApp.desktop)
5985 Log("LoadGraphics %s\n", caption);
5987 if(LoadGraphics(true, false))
5995 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
6002 if(style.hasMenuBar /*&& menu*/)
6008 menu = menu, isMenuBar = true, anchor = Anchor { top = 23, left = 1, right = 1 },
6009 interim = false, inactive = true, nonClient = true, size.h = 24
6017 // Create the system buttons
6018 CreateSystemChildren();
6020 UpdateActiveDocument(null);
6022 if(style.isDocument)
6026 MenuItem item = menu.FindItem(MenuFileSave, 0);
6027 if(item) item.disabled = !modifiedDocument && fileName;
6032 if(parent == guiApp.desktop)
6033 Log("Preemptive SetState %s\n", caption);
6036 // Preemptive Set State to ensure proper anchoring
6037 SetStateEx(state, false);
6039 style.hidden = true;
6045 for(child = children.first; child; child = next)
6048 if(!child.created && (child.autoCreate || child.wasCreated))
6055 for(link = slaves.first; link; link = next)
6057 Window slave = link.data;
6059 if(!slave.created && (slave.autoCreate || slave.wasCreated))
6068 if(parent == guiApp.desktop)
6069 Log("Real SetState %s\n", caption);
6072 if(isActiveClient && visible)
6074 parent.numPositions--;
6075 if(state == minimized) parent.numIcons--;
6078 // Real set state & activate for proper display & activation
6079 property::visible = visible;
6080 // SetState(state & 0x00000003, true, 0);
6085 /*if(rootWindow == this)
6086 guiApp.interfaceDriver.ActivateRootWindow(this);
6088 if(creationActivation == activate)
6089 ActivateEx(true, false, true, true, null, null);
6090 else if(creationActivation == flash)
6095 rootWindow.ConsequentialMouseMove(false);
6106 guiApp.LogErrorCode(IERR_WINDOW_CREATION_FAILED, caption);
6112 // Testing this here... Otherwise a failed LoadGraphics stalls the application
6114 //style.hidden = true; // !visible;
6115 style.hidden = !visible;
6116 if(master.modalSlave == this)
6117 master.modalSlave = null;
6124 void WriteCaption(Surface surface, int x, int y)
6127 Interface::WriteKeyedTextDisabled(surface, x,y, caption, hotKey ? hotKey.key : 0, !isEnabled);
6130 void Update(Box region)
6136 rootWindow = this.rootWindow;
6138 // rootWindow.mutex.Wait();
6139 if(!destroyed && visible && display)
6144 // Testing this to avoid repetitve full update to take time...
6145 if(dirtyArea.count == 1)
6147 BoxItem item = (BoxItem)ACCESS_ITEM(dirtyArea, dirtyArea.first);
6148 if(item.box.left <= box.left &&
6149 item.box.top <= box.top &&
6150 item.box.right >= box.right &&
6151 item.box.bottom >= box.bottom)
6153 rootWindow.dirty = true;
6158 if(display.flags.flipping && !rootWindow.dirty)
6160 if(this == rootWindow)
6164 rootWindow.Update(null);
6169 rootWindow.dirty = true;
6174 realBox.left += clientStart.x;
6175 realBox.top += clientStart.y;
6176 realBox.right += clientStart.x;
6177 realBox.bottom += clientStart.y;
6183 if(realBox.right >= realBox.left &&
6184 realBox.bottom >= realBox.top)
6186 // if(!rootWindow.fullRender)
6187 dirtyArea.UnionBox(realBox, rootWindow.tempExtents[0]);
6189 for(child = children.first; child; child = child.next)
6194 box.left -= child.absPosition.x - absPosition.x;
6195 box.top -= child.absPosition.y - absPosition.y;
6196 box.right -= child.absPosition.x - absPosition.x;
6197 box.bottom -= child.absPosition.y - absPosition.y;
6198 if(box.right >= child.box.left && box.left <= child.box.right &&
6199 box.bottom >= child.box.top && box.top <= child.box.bottom)
6201 box.left -= child.clientStart.x;
6202 box.top -= child.clientStart.y;
6203 box.right -= child.clientStart.x;
6204 box.bottom -= child.clientStart.y;
6210 realBox.left += absPosition.x - rootWindow.absPosition.x;
6211 realBox.top += absPosition.y - rootWindow.absPosition.y;
6212 realBox.right += absPosition.x - rootWindow.absPosition.x;
6213 realBox.bottom += absPosition.y - rootWindow.absPosition.y;
6214 rootWindow.dirtyBack.UnionBox(realBox, rootWindow.tempExtents[0]);
6217 else if(this == guiApp.desktop)
6220 for(window = children.first; window; window = window.next)
6226 Box childBox = region;
6228 childBox.left -= window.absPosition.x - guiApp.desktop.absPosition.x;
6229 childBox.top -= window.absPosition.y - guiApp.desktop.absPosition.y;
6230 childBox.right -= window.absPosition.x - guiApp.desktop.absPosition.x;
6231 childBox.bottom -= window.absPosition.y - guiApp.desktop.absPosition.y;
6233 window.Update(childBox);
6236 window.Update(null);
6241 // rootWindow.mutex.Release();
6248 if(guiApp.windowCaptured != this)
6250 if(guiApp.windowCaptured)
6254 //Logf("Captured %s (%s)\n", caption, class.name);
6255 guiApp.interfaceDriver.SetMouseCapture(rootWindow);
6256 guiApp.windowCaptured = this;
6262 bool Destroy(int code)
6267 if(!CloseConfirmation(false)) return false;
6271 // TOCHECK: Should autoCreate be set to false here?
6274 // Is this needed here? DestroyEx should decref already...
6283 void Move(int x, int y, int w, int h)
6285 normalAnchor = Anchor { left = x, top = y };
6286 normalSizeAnchor = SizeAnchor { size = { w, h } };
6288 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6290 if(destroyed) return;
6292 stateAnchor = normalAnchor;
6293 stateSizeAnchor = normalSizeAnchor;
6295 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6296 Position(x,y, w, h, true, true, true, true, false, true);
6300 DialogResult Modal(void)
6306 // FIXES MEMORY LEAK IF Create() FAILED
6312 void SetScrollArea(int width, int height, bool snapToStep)
6314 bool resize = false;
6317 int stepX = sbStep.x, stepY = sbStep.y;
6318 // Needed to make snapped down position match the skin's check of client area
6319 // against realvirtual
6322 SNAPDOWN(stepX, textCellW);
6323 SNAPDOWN(stepY, textCellH);
6324 stepX = Max(stepX, textCellW);
6325 stepY = Max(stepY, textCellH);
6327 if(scrollFlags.snapX)
6328 SNAPUP(width, stepX);
6329 if(scrollFlags.snapY)
6330 SNAPUP(height, stepY);
6333 reqScrollArea.w = width;
6334 reqScrollArea.h = height;
6335 noAutoScrollArea = (width > 0 || height > 0);
6337 UpdateScrollBars(true, true);
6340 void SetScrollPosition(int x, int y)
6343 sbh.Action(setPosition, x, 0);
6347 int seen = clientSize.w, total = reqScrollArea.w;
6349 if(scrollFlags.snapX)
6350 SNAPDOWN(seen, sbStep.x);
6352 if(!total) total = seen;
6353 range = total - seen + 1;
6354 range = Max(range, 1);
6356 if(x >= range) x = range - 1;
6358 if(scrollFlags.snapX)
6359 SNAPUP(x, sbStep.x);
6362 OnHScroll(setPosition, x, 0);
6366 SNAPDOWN(x, textCellW);
6372 sbv.Action(setPosition, y, 0);
6376 int seen = clientSize.h, total = reqScrollArea.h;
6379 if(scrollFlags.snapY)
6380 SNAPDOWN(seen, sbStep.y);
6382 if(!total) total = seen;
6383 range = total - seen + 1;
6384 range = Max(range, 1);
6386 if(y >= range) y = range - 1;
6388 if(scrollFlags.snapY)
6389 SNAPUP(y, sbStep.y);
6392 OnVScroll(setPosition, y, 0);
6395 SNAPDOWN(y, textCellH);
6400 UpdateCaret(false, false);
6403 void SetScrollLineStep(int stepX, int stepY)
6409 SNAPDOWN(stepX, textCellW);
6410 SNAPDOWN(stepY, textCellH);
6411 stepX = Max(stepX, textCellW);
6412 stepY = Max(stepY, textCellH);
6415 sbh.lineStep = stepX;
6417 sbv.lineStep = stepY;
6420 void SetState(WindowState newState, bool activate, Modifiers mods)
6424 if(state == newState || OnStateChange(newState, mods))
6426 WindowState prevState = state;
6430 // This used to be at the end of the brackets... moved for X, testing...
6431 // This has the effect of activating the window through the system...
6432 if(rootWindow == this)
6433 guiApp.interfaceDriver.SetRootWindowState(this, newState, !style.hidden);
6435 SetStateEx(newState, activate);
6437 if(rootWindow == this && !rootWindow.nativeDecorations)
6439 int x = position.x, y = position.y;
6442 x -= guiApp.desktop.absPosition.x;
6443 y -= guiApp.desktop.absPosition.y;
6445 guiApp.interfaceDriver.PositionRootWindow(this, x, y, size.w, size.h, true, true);
6449 //state = prevState;
6451 if(state != maximized && style.hasMaximize)
6454 for(child = parent.children.first; child; child = child.next)
6456 if(child != this && child.state == maximized)
6457 child.SetStateEx(normal, false);
6461 if(!style.nonClient && (sbv || sbh) && this != parent.sbv && this != parent.sbh)
6462 parent.UpdateScrollBars(true, true);
6465 // Do we really need this stuff here?
6466 // Shouldn't the Activate stuff take care of it?
6467 if(parent.rootWindow == parent && style)
6470 parent.FigureCaption(caption);
6471 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
6472 parent.UpdateDecorations();
6476 rootWindow.ConsequentialMouseMove(false);
6483 BitmapResource GetIcon(SkinBitmap iconID)
6485 return guiApp.currentSkin.GetBitmap(iconID);
6488 void SetMouseRange(Box range)
6490 if(range || guiApp.fullScreenMode)
6495 clip.left = range.left + absPosition.x + clientStart.x;
6496 clip.top = range.top + absPosition.y + clientStart.y;
6497 clip.right = range.right + absPosition.x + clientStart.x;
6498 clip.bottom = range.bottom + absPosition.y + clientStart.y;
6502 clip.left = guiApp.desktop.box.left;
6503 clip.top = guiApp.desktop.box.top;
6504 clip.right = guiApp.desktop.box.right;
6505 clip.bottom = guiApp.desktop.box.bottom;
6507 guiApp.interfaceDriver.SetMouseRange(rootWindow, clip);
6510 guiApp.interfaceDriver.SetMouseRange(rootWindow, null);
6513 void SetMouseRangeToClient(void)
6515 if(guiApp.fullScreenMode || this != guiApp.desktop)
6517 Box box {0, 0, clientSize.w - 1, clientSize.h - 1 };
6518 box.Clip(clientArea);
6522 SetMouseRange(null);
6525 void SetMouseRangeToWindow(void)
6527 Box box { -clientStart.x, -clientStart.y, size.w-1, size.h-1 };
6528 if(this == guiApp.desktop)
6529 SetMouseRangeToClient();
6534 // x, y: Desktop Coordinates
6535 void ShowSysMenu(int x, int y)
6538 PopupMenu windowMenu { master = this, interim = true, position = { x + 1 - guiApp.desktop.position.x, y + 1 - guiApp.desktop.position.y }, menu = menu };
6541 menu, "Restore", r, NotifySelect = MenuWindowRestore,
6542 disabled = (!style.hasMaximize && !style.hasMinimize) || state == normal, bitmap = guiApp.currentSkin.GetBitmap(restore)
6546 menu, "Move", m, NotifySelect = MenuWindowMove,
6547 disabled = !style.fixed || state == maximized
6551 menu, "Size", s, NotifySelect = MenuWindowSize,
6552 disabled = !style.sizable || state != normal
6556 menu, "Minimize", n, NotifySelect = MenuWindowMinimize,
6557 disabled = !style.hasMinimize || state == minimized, bitmap = guiApp.currentSkin.GetBitmap(minimize)
6561 menu, "Maximize", KeyCode::x, NotifySelect = MenuWindowMaximize,
6562 disabled = !style.hasMaximize || state == maximized, bitmap = guiApp.currentSkin.GetBitmap(maximize)
6566 menu, "Stay On Top", t, NotifySelect = MenuWindowStayOnTop,
6567 disabled = !style.fixed, checkable = true, checked = style.stayOnTop
6569 MenuDivider { menu };
6572 menu, "Close", c, (parent == guiApp.desktop) ? altF4 : ( style.isActiveClient ? ctrlF4 : 0), NotifySelect = MenuWindowClose,
6573 bold = true, disabled = !style.hasClose, bitmap = guiApp.currentSkin.GetBitmap(close)
6575 windowMenu.Create();
6580 ActivateEx(true, true, true, true, null, null);
6583 void MakeActive(void)
6585 ActivateEx(true, false, true, false, null, null);
6588 void SoftActivate(void)
6590 if(guiApp.desktop.active)
6596 void Deactivate(void)
6598 ActivateEx(false, true, true, true, null, null);
6603 guiApp.interfaceDriver.FlashRootWindow(rootWindow);
6606 bool CycleChildren(bool backward, bool clientOnly, bool tabCycleOnly, bool cycleParents)
6608 bool result = false;
6609 if(activeChild && activeChild.cycle)
6611 Window modalWindow, child = activeChild;
6612 if(!clientOnly /*&& parent.tabCycle*/)
6614 Window next = child;
6617 if(next.cycle == (backward ? childrenCycle.first : childrenCycle.last))
6621 if(parent && parent.CycleChildren(backward, false, true, true))
6629 next = next.cycle.prev.data;
6631 next = next.cycle.next.data;
6632 if(!next.disabled && !next.inactive /*isRemote*/ && next.created && !next.nonClient && (!clientOnly || next.style.isActiveClient) && !next.style.hidden && next.FindModal() != activeChild)
6637 if(!clientOnly && child.cycle == (backward ? childrenCycle.first : childrenCycle.last) &&
6638 parent.tabCycle && parent.CycleChildren(backward, false, false))
6642 if(tabCycleOnly && !tabCycle) return false;
6649 child = child.cycle.prev.data;
6651 child = child.cycle.next.data;
6652 if(child == child.parent.activeChild)
6654 else if(!child.disabled && child.created && (!clientOnly || child.style.isActiveClient) && !child.style.hidden && child.FindModal() != activeChild)
6657 modalWindow = child.FindModal();
6660 // Scroll the window to include the active control
6661 if(sbh && !child.style.dontScrollHorz)
6663 if(child.scrolledPos.x < 0)
6664 sbh.Action(setPosition, scroll.x + child.scrolledPos.x, 0);
6665 else if(child.scrolledPos.x + child.size.w > clientSize.w)
6666 sbh.Action(setPosition, scroll.x + child.scrolledPos.x + child.size.w - clientSize.w, 0);
6668 if(sbv && !child.style.dontScrollVert)
6670 if(child.scrolledPos.y < 0)
6671 sbv.Action(setPosition, scroll.y + child.scrolledPos.y, 0);
6672 else if(child.scrolledPos.y + child.size.h > clientSize.h)
6673 sbv.Action(setPosition, scroll.y + child.scrolledPos.y + child.size.h - clientSize.h, 0);
6677 child = modalWindow ? modalWindow : child;
6678 child.ActivateEx(true, true, true, true, null, null);
6679 if(child.tabCycle && child.childrenCycle.first)
6680 child = ((OldLink)(backward ? child.childrenCycle.first : child.childrenCycle.last)).data;
6688 ConsequentialMouseMove(false);
6692 void AddResource(Resource resource)
6696 ResPtr ptr { resource = resource };
6700 // Load Graphics here if window is created already
6701 if(/*created && */display)
6703 display.Lock(false);
6704 ptr.loaded = display.displaySystem.LoadResource(resource);
6708 // Temporary hack to load font right away for listbox in dropbox ...
6709 else if(master && master.display)
6711 master.display.Lock(false);
6712 master.display.displaySystem.LoadResource(resource);
6713 master.display.Unlock();
6719 void RemoveResource(Resource resource)
6724 for(ptr = resources.first; ptr; ptr = ptr.next)
6726 if(ptr.resource == resource)
6732 // Unload Graphics here if window is created already
6733 if(/*created && */display)
6737 display.Lock(false);
6738 display.displaySystem.UnloadResource(resource, ptr.loaded);
6744 resources.Delete(ptr);
6749 void SetCaret(int x, int y, int size)
6756 if(active && !style.interim)
6758 if(visible || !guiApp.caretOwner)
6759 guiApp.caretOwner = size ? this : null;
6761 UpdateCaret(false, false);
6764 guiApp.interfaceDriver.SetCaret(0,0,0);
6765 UpdateCaret(false, true);
6766 guiApp.caretEnabled = false;
6769 else if(style.inactive && active)
6771 guiApp.interfaceDriver.SetCaret(0,0,0);
6772 UpdateCaret(false, true);
6773 guiApp.caretEnabled = false;
6778 void Scroll(int x, int y)
6780 bool opaque = !style.drawBehind || background.a;
6781 if(opaque && display && display.flags.scrolling)
6783 Box box = clientArea;
6784 box.left += clientStart.x;
6785 box.top += clientStart.y;
6786 box.right += clientStart.x;
6787 box.bottom += clientStart.y;
6789 //scrollExtent.Free(null);
6790 scrollExtent.AddBox(box);
6791 scrolledArea.x += x;
6792 scrolledArea.y += y;
6794 //scrollExtent.Free();
6795 //scrollExtent.AddBox(clientArea);
6796 //scrollExtent.Offset(clientStart.x, clientStart.y);
6797 //scrolledArea.x = x;
6798 //scrolledArea.y = y;
6804 rootWindow.dirty = true;
6807 void ReleaseCapture()
6809 if(guiApp && guiApp.windowCaptured && guiApp.windowCaptured == this)
6811 Window oldCaptured = guiApp.windowCaptured;
6812 guiApp.windowCaptured = null;
6813 guiApp.prevWindow = null;
6816 //guiApp.Log("Released Capture\n");
6818 guiApp.interfaceDriver.SetMouseCapture(null);
6820 //oldCaptured.OnMouseCaptureLost();
6823 oldCaptured.ConsequentialMouseMove(false);
6828 void SetText(char * format, ...)
6835 char caption[MAX_F_STRING];
6837 va_start(args, format);
6838 vsprintf(caption, format, args);
6841 this.caption = new char[strlen(caption)+1];
6843 strcpy(this.caption, caption);
6852 bool Grab(Bitmap bitmap, Box box, bool decorations)
6854 bool result = false;
6855 if(display || this == guiApp.desktop)
6857 Box clip = {MININT, MININT, MAXINT, MAXINT};
6863 clip.Clip(clientArea);
6865 clip.Clip(this.box);
6867 if(rootWindow != this)
6869 clip.left += absPosition.y;
6870 clip.top += absPosition.y;
6871 clip.right += absPosition.x;
6872 clip.bottom += absPosition.y;
6875 clip.left += decorations ? 0 : clientStart.x;
6876 clip.top += decorations ? 0 : clientStart.y;
6877 clip.right += decorations ? 0 : clientStart.x;
6878 clip.bottom += decorations ? 0 : clientStart.y;
6880 if(display && display.flags.flipping)
6882 rootWindow.Update(null);
6883 rootWindow.UpdateDisplay();
6890 result = window.display.displaySystem.driver.GrabScreen(null, bitmap, clip.left, clip.top,
6891 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6895 result = display.Grab(bitmap, clip.left, clip.top,
6896 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6898 if(bitmap.pixelFormat != pixelFormat888 && bitmap.pixelFormat != pixelFormat8)
6900 if(!bitmap.Convert(null, pixelFormat888, null))
6907 void GetMousePosition(int * x, int * y)
6909 int mouseX = 0, mouseY = 0;
6910 if(!guiApp.acquiredWindow && (guiApp.desktop.active || !guiApp.fullScreenMode))
6913 guiApp.interfaceDriver.GetMousePosition(&mouseX, &mouseY);
6914 if(this != guiApp.desktop)
6916 mouseX -= absPosition.x + clientStart.x;
6917 mouseY -= absPosition.y + clientStart.y;
6924 DialogResult DoModal()
6926 DialogResult returnCode = 0;
6927 int terminated = terminateX;
6930 while(!destroyed && guiApp.driver != null)
6932 if(terminateX != terminated)
6934 terminated = terminateX;
6935 guiApp.desktop.Destroy(0);
6936 if(guiApp.desktop.created)
6939 //printf("Resetting terminate X to 0\n");
6945 guiApp.UpdateDisplay();
6946 if(!guiApp.ProcessInput(false))
6949 returnCode = this.returnCode;
6962 return !destroyed && guiApp.driver != null && terminateX < 2;
6965 DialogResult DoModalEnd()
6967 DialogResult returnCode = this.returnCode;
6972 // --- Window manipulation ---
6973 /*bool GetDisabled()
6975 bool disabled = this.disabled;
6977 for(window = this; (window = window.master); )
6988 // --- Mouse Manipulation ---
6989 void GetNCMousePosition(int * x, int * y)
6991 GetMousePosition(x, y);
6992 if(x) *x += clientStart.x;
6993 if(y) *y += clientStart.y;
6996 // --- Carets manipulation ---
6997 void GetCaretPosition(Point caretPos)
6999 caretPos = this.caretPos;
7002 int GetCaretSize(void)
7007 bool ButtonCloseDialog(Button button, int x, int y, Modifiers mods)
7013 bool CloseConfirmation(bool parentClosing)
7026 if(!OnClose(parentClosing))
7029 // If you want to skip this, simply set modifiedDocument to false in OnClose
7030 if(result && (/*fileName || */style.isDocument) && modifiedDocument)
7032 DialogResult dialogRes;
7035 sprintf(message, "Save changes to %s?", fileName);
7037 sprintf(message, "Save changes to Untitled %d?", documentID);
7039 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption, contents = message }.Modal();
7041 if(dialogRes == yes)
7043 // TOFIX: Precomp error if brackets are taken out
7044 result = (DialogResult)MenuFileSave(null, 0) != cancel;
7046 else if(dialogRes == cancel)
7052 for(slave = slaves.first; slave; slave = slave.next)
7053 if(!((Window)slave.data).CloseConfirmation(true))
7055 // ((Window)slave.data).CloseConfirmation(true);
7063 for(child = children.first; child; child = child.next)
7064 if(child.master != this && !child.CloseConfirmation(true))
7074 // Static methods... move them somewhere else?
7075 void ::RestoreCaret()
7077 if(guiApp.caretOwner)
7078 guiApp.caretOwner.UpdateCaret(false, false);
7081 void ::FreeMouseRange()
7083 guiApp.interfaceDriver.SetMouseRange(null, null);
7087 bool MenuFileClose(MenuItem selection, Modifiers mods)
7089 Window document = activeChild;
7091 document.Destroy(0);
7095 bool MenuFileExit(MenuItem selection, Modifiers mods)
7101 bool MenuFileSave(MenuItem selection, Modifiers mods)
7105 fileMonitor.fileName = null;
7108 if(OnSaveFile(fileName))
7110 //if(OnFileModified != Window::OnFileModified)
7113 fileMonitor.fileName = fileName;
7119 MessageBox dialog { master = master, type = yesNoCancel, text = "Error writing file", contents = "Save as a different file?" };
7120 DialogResult answer = dialog.Modal();
7122 if(answer != yes) return (bool)answer;
7125 return MenuFileSaveAs(selection, mods);
7128 bool MenuFileSaveAs(MenuItem selection, Modifiers mods)
7130 DialogResult result = (DialogResult)bool::true;
7131 FileDialog fileDialog = saveDialog;
7134 fileDialog = FileDialog {};
7139 fileDialog.filePath = fileName;
7142 char filePath[MAX_FILENAME];
7143 sprintf(filePath, "Untitled %d", documentID);
7144 fileDialog.filePath = filePath;
7146 fileMonitor.fileName = null;
7148 fileDialog.type = save;
7149 fileDialog.text = "Save As";
7153 fileDialog.master = master.parent ? master : this;
7154 if(fileDialog.Modal() == ok)
7156 char * filePath = fileDialog.filePath;
7158 if(OnSaveFile(filePath))
7161 property::fileName = filePath;
7162 NotifySaved(master, this, filePath);
7167 MessageBox dialog { master = master.parent ? master : this, type = yesNoCancel, text = "Error writing file", contents = "Save as a different file?" };
7168 DialogResult answer = dialog.Modal();
7183 //if(OnFileModified != Window::OnFileModified && fileName)
7186 fileMonitor.fileName = fileName;
7190 return (bool)result; // Actually returning result from Yes/NoCancel message box
7193 bool MenuFileSaveAll(MenuItem selection, Modifiers mods)
7195 Window document = activeChild;
7197 for(document = children.first; document; document = next)
7199 next = document.next;
7200 if(document.style.isDocument || document.fileName)
7201 document.MenuFileSave(selection, mods);
7206 bool MenuWindowArrangeIcons(MenuItem selection, Modifiers mods)
7210 for(document = children.first; document; document = document.next)
7211 //if(document.style.isDocument && document.state == minimized)
7212 if(document.style.isActiveClient && document.state == minimized)
7213 document.SetState(minimized, false, mods);
7217 bool MenuWindowCascade(MenuItem selection, Modifiers mods)
7219 Window document = activeChild;
7222 Window firstDocument = null;
7224 OldLink cycle = document.cycle.prev;
7229 if(child.style.isActiveClient && !child.style.hidden)
7233 firstDocument = child;
7234 if(child.state == minimized)
7235 child.SetState(minimized, false, mods);
7238 child.positionID = id++;
7239 child.SetState(normal, false, mods);
7240 child.anchor.left.type = cascade;
7243 child.normalSizeAnchor = *&child.sizeAnchor;
7244 child.normalAnchor = child.anchor;
7246 // Break the anchors for moveable/resizable windows
7247 if(child.style.fixed)
7249 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7251 (*&child.normalAnchor).left = x;
7252 (*&child.normalAnchor).top = y;
7253 (*&child.normalAnchor).right.type = none;
7254 (*&child.normalAnchor).bottom.type = none;
7256 child.normalSizeAnchor.isClientW = false;
7257 child.normalSizeAnchor.isClientH = false;
7258 child.normalSizeAnchor.size.w = w;
7259 child.normalSizeAnchor.size.h = h;
7260 child.anchored = false;
7263 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7265 child.stateAnchor = child.normalAnchor;
7266 child.stateSizeAnchor = child.normalSizeAnchor;
7268 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7269 child.Position(x, y, w, h, true, true, true, true, false, false);
7274 last = children.last;
7275 if(!child.style.stayOnTop)
7276 for(; last && last.style.stayOnTop; last = last.prev);
7277 children.Move(child, last);
7278 childrenOrder.Move(child.order, childrenOrder.last);
7280 if(cycle == document.cycle) break;
7284 firstDocument.Activate();
7289 bool MenuWindowClose(MenuItem selection, Modifiers mods)
7296 // Close all closes all active clients, not all documents
7297 bool MenuWindowCloseAll(MenuItem selection, Modifiers mods)
7299 Window next, document;
7301 for(document = children.first; document; document = next)
7303 for(next = document.next; next && !(next.style.isActiveClient; next = next.next);
7304 if(document.style.isActiveClient)
7305 if(!document.Destroy(0) && !document.style.hidden)
7311 bool MenuWindowMaximize(MenuItem selection, Modifiers mods)
7313 if(style.hasMaximize && state != maximized)
7314 SetState(maximized, 0, 0);
7318 bool MenuWindowMinimize(MenuItem selection, Modifiers mods)
7320 if(style.hasMinimize && state != minimized)
7322 SetState(minimized, 0, 0);
7323 parent.CycleChildren(false, true, false, true);
7328 bool MenuWindowMove(MenuItem selection, Modifiers mods)
7330 MenuMoveOrSize(false, selection ? true : false);
7334 bool MenuWindowNext(MenuItem selection, Modifiers mods)
7336 CycleChildren(false, true, false, true);
7340 bool MenuWindowPrevious(MenuItem selection, Modifiers mods)
7342 CycleChildren(true, true, false, true);
7346 bool MenuWindowSize(MenuItem selection, Modifiers mods)
7348 MenuMoveOrSize(true, true);
7352 bool MenuWindowRestore(MenuItem selection, Modifiers mods)
7355 SetState(normal, 0, 0);
7359 bool MenuWindowSelectWindow(MenuItem selection, Modifiers mods)
7362 int id = selection.id;
7363 OldLink cycle = activeClient.cycle;
7365 //for(c = 0, cycle = activeChild.cycle; c<id; cycle = cycle.next, c++);
7368 Window sibling = cycle.data;
7369 if(sibling.style.isActiveClient)
7377 document = cycle.data;
7378 document.Activate();
7380 //if(activeChild.state == maximized)
7381 // document.SetState(maximized, false, mods);
7382 //else if(document.state == minimized)
7383 // document.SetState(normal, false, mods);
7387 bool MenuWindowStayOnTop(MenuItem selection, Modifiers mods)
7389 stayOnTop = !style.stayOnTop;
7393 bool MenuWindowTileHorz(MenuItem selection, Modifiers mods)
7395 Window document = activeChild;
7398 Window firstDocument = null;
7399 OldLink cycle = document.cycle;
7403 Window child = cycle.data;
7404 if(child.style.isActiveClient && !child.style.hidden)
7406 if(!firstDocument) firstDocument = child;
7407 if(child.state == minimized)
7408 child.SetState(minimized, false, mods);
7411 child.positionID = id++;
7412 child.SetState(normal, false, mods);
7413 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7415 child.anchor.left.type = hTiled;
7418 child.normalSizeAnchor = *&child.sizeAnchor;
7419 child.normalAnchor = child.anchor;
7421 // Break the anchors for moveable/resizable windows
7422 if(child.style.fixed)
7424 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7426 (*&child.normalAnchor).left = x;
7427 (*&child.normalAnchor).top = y;
7428 (*&child.normalAnchor).right.type = none;
7429 (*&child.normalAnchor).bottom.type = none;
7430 child.normalSizeAnchor.isClientW = false;
7431 child.normalSizeAnchor.isClientH = false;
7432 child.normalSizeAnchor.size.w = w;
7433 child.normalSizeAnchor.size.h = h;
7434 child.anchored = false;
7437 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7439 child.stateAnchor = child.normalAnchor;
7440 child.stateSizeAnchor = child.normalSizeAnchor;
7442 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7443 child.Position(x,y, w, h, true, true, true, true, false, true);
7448 if((cycle = cycle.next) == document.cycle) break;
7451 firstDocument.Activate();
7456 bool MenuWindowTileVert(MenuItem selection, Modifiers mods)
7458 Window document = activeChild;
7461 Window firstDocument = null;
7463 OldLink cycle = document.cycle;
7468 //if(child.style.isDocument)
7469 if(child.style.isActiveClient && !child.style.hidden)
7471 if(!firstDocument) firstDocument = child;
7472 if(child.state == minimized)
7473 child.SetState(minimized, false, mods);
7476 child.positionID = id++;
7477 child.SetState(normal, false, mods);
7478 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7480 child.anchor.left.type = vTiled;
7483 child.normalSizeAnchor = *&child.sizeAnchor;
7484 child.normalAnchor = child.anchor;
7486 // Break the anchors for moveable/resizable windows
7487 if(child.style.fixed)
7489 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7491 (*&child.normalAnchor).left = x;
7492 (*&child.normalAnchor).top = y;
7493 (*&child.normalAnchor).right.type = none;
7494 (*&child.normalAnchor).bottom.type = none;
7495 child.normalSizeAnchor.isClientW = false;
7496 child.normalSizeAnchor.isClientH = false;
7497 child.normalSizeAnchor.size.w = w;
7498 child.normalSizeAnchor.size.h = h;
7499 child.anchored = false;
7502 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7504 child.stateAnchor = child.normalAnchor;
7505 child.stateSizeAnchor = child.normalSizeAnchor;
7507 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7508 child.Position(x,y, w, h, true, true, true, true, false, true);
7513 if((cycle = cycle.next) == document.cycle) break;
7516 firstDocument.Activate();
7521 bool MenuWindowWindows(MenuItem selection, Modifiers mods)
7523 WindowList dialog { master = this };
7524 Window document = (Window)dialog.Modal();
7527 if(activeChild.state == maximized)
7528 document.SetState(maximized, false, mods);
7529 else if(document.state == minimized)
7530 document.SetState(normal, false, mods);
7531 document.Activate();
7537 virtual bool OnCreate(void);
7538 virtual void OnDestroy(void);
7539 virtual void OnDestroyed(void);
7540 virtual bool OnClose(bool parentClosing);
7541 virtual bool OnStateChange(WindowState state, Modifiers mods);
7542 virtual bool OnPostCreate(void);
7543 virtual bool OnMoving(int *x, int *y, int w, int h);
7544 virtual bool OnResizing(int *width, int *height);
7545 virtual void OnResize(int width, int height);
7546 virtual void OnPosition(int x, int y, int width, int height);
7547 virtual bool OnLoadGraphics(void);
7548 virtual void OnApplyGraphics(void);
7549 virtual void OnUnloadGraphics(void);
7550 virtual void OnRedraw(Surface surface);
7551 virtual bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct);
7552 virtual void OnActivateClient(Window client, Window previous);
7553 virtual bool OnKeyDown(Key key, unichar ch);
7554 virtual bool OnKeyUp(Key key, unichar ch);
7555 virtual bool OnKeyHit(Key key, unichar ch);
7556 virtual bool OnSysKeyDown(Key key, unichar ch);
7557 virtual bool OnSysKeyUp(Key key, unichar ch);
7558 virtual bool OnSysKeyHit(Key key, unichar ch);
7559 virtual bool OnMouseOver(int x, int y, Modifiers mods);
7560 virtual bool OnMouseLeave(Modifiers mods);
7561 virtual bool OnMouseMove(int x, int y, Modifiers mods);
7562 virtual bool OnLeftButtonDown(int x, int y, Modifiers mods);
7563 virtual bool OnLeftButtonUp(int x, int y, Modifiers mods);
7564 virtual bool OnLeftDoubleClick(int x, int y, Modifiers mods);
7565 virtual bool OnRightButtonDown(int x, int y, Modifiers mods);
7566 virtual bool OnRightButtonUp(int x, int y, Modifiers mods);
7567 virtual bool OnRightDoubleClick(int x, int y, Modifiers mods);
7568 virtual bool OnMiddleButtonDown(int x, int y, Modifiers mods);
7569 virtual bool OnMiddleButtonUp(int x, int y, Modifiers mods);
7570 virtual bool OnMiddleDoubleClick(int x, int y, Modifiers mods);
7571 virtual void OnMouseCaptureLost(void);
7572 virtual void OnHScroll(ScrollBarAction action, int position, Key key);
7573 virtual void OnVScroll(ScrollBarAction action, int position, Key key);
7574 virtual void OnDrawOverChildren(Surface surface);
7575 virtual bool OnFileModified(FileChange fileChange, char * param);
7576 virtual bool OnSaveFile(char * fileName);
7578 // Skins Virtual Functions
7579 virtual void GetDecorationsSize(MinMaxValue * w, MinMaxValue * h);
7580 virtual void SetWindowMinimum(MinMaxValue * mw, MinMaxValue * mh);
7581 virtual void SetWindowArea(int * x, int * y, MinMaxValue * w, MinMaxValue * h, MinMaxValue * cw, MinMaxValue * ch)
7586 virtual void ShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7587 virtual void PreShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7588 virtual bool IsMouseMoving(int x, int y, int w, int h);
7589 virtual bool IsMouseResizing(int x, int y, int w, int h, bool *resizeX, bool *resizeY, bool *resizeEndX, bool *resizeEndY);
7590 virtual void UpdateNonClient();
7591 virtual void SetBox(Box box);
7592 virtual bool IsInside(int x, int y)
7594 return box.IsPointInside({x, y});
7596 virtual bool IsOpaque()
7598 return (!style.drawBehind || background.a == 255);
7602 virtual bool Window::NotifyActivate(Window window, bool active, Window previous);
7603 virtual void Window::NotifyDestroyed(Window window, DialogResult result);
7604 virtual void Window::NotifySaved(Window window, char * filePath);
7609 property Window parent
7611 property_category "Layout"
7614 if(value || guiApp.desktop)
7617 Window oldParent = parent;
7618 Anchor anchor = this.anchor;
7620 if(value && value.IsDescendantOf(this)) return;
7621 if(value && value == this)
7623 if(!value) value = guiApp.desktop;
7625 if(value == oldParent) return;
7627 if(!master || (master == this.parent && master == guiApp.desktop))
7628 property::master = value;
7632 parent.children.Remove(this);
7636 box.left - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7637 box.top - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y,
7638 box.right - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7639 box.bottom - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y
7643 last = value.children.last;
7645 if(style.isDocument)
7648 parent.numDocuments--;
7649 documentID = value.GetDocumentID();
7652 if(style.isActiveClient && !style.hidden)
7654 if(parent && parent != guiApp.desktop && !(style.hidden))
7656 if(state == minimized) parent.numIcons--;
7657 parent.numPositions--;
7661 if(!style.stayOnTop)
7662 for(; last && last.style.stayOnTop; last = last.prev);
7664 value.children.Insert(last, this);
7666 // *** NEW HERE: ***
7668 parent.childrenCycle.Delete(cycle);
7670 parent.childrenOrder.Delete(order);
7678 int x = position.x, y = position.y, w = size.w, h = size.h;
7682 x += parent.absPosition.x - value.absPosition.x + parent.clientStart.x - value.clientStart.x;
7683 y += parent.absPosition.y - value.absPosition.y + parent.clientStart.y - value.clientStart.y;
7685 vpw = value.clientSize.w;
7686 vph = value.clientSize.h;
7692 else if(style.fixed)
7694 if(!style.dontScrollHorz && value.scrollArea.w) vpw = value.scrollArea.w;
7695 if(!style.dontScrollVert && value.scrollArea.h) vph = value.scrollArea.h;
7698 anchor = this.anchor;
7700 if(anchor.left.type == offset) anchor.left.distance = x;
7701 else if(anchor.left.type == relative) anchor.left.percent = (float)x / vpw;
7702 if(anchor.top.type == offset) anchor.top.distance = y;
7703 else if(anchor.top.type == relative) anchor.top.percent = (float)y / vph;
7704 if(anchor.right.type == offset) anchor.right.distance = vpw - (x + w);
7705 //else if(anchor.right.type == relative) anchor.right.percent = 1.0-(float) (vpw - (x + w)) / vpw;
7706 else if(anchor.right.type == relative) anchor.right.percent = (float) (vpw - (x + w)) / vpw;
7707 if(anchor.bottom.type == offset) anchor.bottom.distance = vph - (y + h);
7708 //else if(anchor.bottom.type == relative) anchor.bottom.percent = 1.0-(float) (vph - (y + h)) / vph;
7709 else if(anchor.bottom.type == relative) anchor.bottom.percent = (float) (vph - (y + h)) / vph;
7711 if(!anchor.left.type && !anchor.right.type)
7713 anchor.horz.distance = (x + w / 2) - (vpw / 2);
7714 //anchor.horz.type = anchor.horz.distance ? AnchorValueOffset : 0;
7716 else if(anchor.horz.type == middleRelative) anchor.horz.percent = (float) ((x + w / 2) - (vpw / 2)) / vpw;
7717 if(!anchor.top.type && !anchor.bottom.type)
7719 anchor.vert.distance = (y + h / 2) - (vph / 2);
7720 //anchor.vert.type = anchor.vert.distance ? AnchorValueOffset : 0;
7722 else if(anchor.vert.type == middleRelative) anchor.vert.percent = (float)((y + h / 2) - (vph / 2)) / vph;
7730 parent.childrenCycle.Insert(
7731 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
7732 cycle = OldLink { data = this });
7733 parent.childrenOrder.Insert(
7734 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
7735 order = OldLink { data = this });
7738 if(!style.hidden && style.isActiveClient)
7740 positionID = parent.GetPositionID(this);
7741 parent.numPositions++;
7742 if(state == minimized) parent.numIcons--;
7745 // *** FONT INHERITANCE ***
7746 if(!setFont && oldParent)
7747 stopwatching(oldParent, font);
7751 RemoveResource(systemFont);
7754 // TESTING WITH WATCHERS:
7755 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7756 // usedFont = setFont ? setFont : (systemFont);
7760 if(guiApp.currentSkin)
7762 systemFont = guiApp.currentSkin.SystemFont();
7765 usedFont = systemFont;
7766 AddResource(systemFont);
7774 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7783 if(value.rootWindow && value.rootWindow.display && rootWindow)
7785 bool reloadGraphics = (oldParent.rootWindow == oldParent && value.rootWindow) || (!value.rootWindow && rootWindow == this) ||
7786 (value.rootWindow.display && value.rootWindow.display.displaySystem != rootWindow.display.displaySystem);
7789 UnloadGraphics(false);
7792 LoadGraphics(false, false);
7795 if(value.rootWindow != rootWindow)
7796 DisplayModeChanged();
7800 scrolledPos.x = MININT; // Prevent parent update
7801 property::anchor = anchor;
7805 if(guiApp.currentSkin)
7806 guiApp.currentSkin.SetWindowMinimum(this, &skinMinSize.w, &skinMinSize.h);
7808 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
7809 Position(x, y, w, h, true, true, true, true, false, true);
7814 // else parent = value;
7817 get { return parent; }
7820 property Window master
7822 property_category "Behavior"
7825 //if(this == value) return;
7826 if(value && value.IsSlaveOf(this)) return;
7832 OldLink slaveHolder;
7833 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
7834 if(slaveHolder.data == this)
7836 master.slaves.Delete(slaveHolder);
7843 value.slaves.Add(OldLink { data = this });
7848 master.hotKeys.Remove(hotKey);
7849 value.hotKeys.Add(hotKey);
7852 if(master && master.defaultControl == this)
7853 master.defaultControl = null;
7855 if(style.isDefault && !value.defaultControl)
7856 value.defaultControl = this;
7862 get { return master ? master : parent; }
7865 property char * text
7867 property_category "Appearance"
7874 caption = new char[strlen(value)+1];
7876 strcpy(caption, value);
7881 get { return caption; }
7886 property_category "Behavior"
7895 master.hotKeys.Add(hotKey = HotKeySlot { });
7899 hotKey.window = this;
7904 master.hotKeys.Delete(hotKey);
7909 get { return hotKey ? hotKey.key : 0; }
7912 property Color background
7914 property_category "Appearance"
7917 background.color = value;
7922 if(this == rootWindow)
7923 guiApp.interfaceDriver.SetRootWindowColor(this);
7926 get { return background.color; }
7929 property Percentage opacity
7931 property_category "Appearance"
7934 background.a = (byte)Min(Max((int)(value * 255), 0), 255);
7935 drawBehind = background.a ? false : true;
7937 get { return background.a / 255.0f; }
7940 property Color foreground
7942 property_category "Appearance"
7950 get { return foreground; }
7953 property BorderStyle borderStyle
7955 property_category "Appearance"
7958 if(!((BorderBits)value).fixed)
7960 style.hasClose = false;
7961 style.hasMaximize = false;
7962 style.hasMinimize = false;
7964 style.borderBits = value;
7968 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
7970 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
7971 Position(x, y, w, h, true, true, true, true, false, true);
7972 CreateSystemChildren();
7975 get { return (BorderStyle)style.borderBits; }
7978 property Size minClientSize
7980 property_category "Layout"
7981 set { minSize = value; }
7982 get { value = minSize; }
7985 property Size maxClientSize
7987 property_category "Layout"
7988 set { maxSize = value; }
7989 get { value = maxSize; }
7992 property bool hasMaximize
7994 property_category "Window Style"
7997 style.hasMaximize = value;
7998 if(value) { style.fixed = true; style.contour = true; }
8002 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8004 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8005 Position(x, y, w, h, true, true, true, true, false, true);
8007 CreateSystemChildren();
8010 get { return style.hasMaximize; }
8013 property bool hasMinimize
8015 property_category "Window Style"
8018 style.hasMinimize = value;
8019 if(value) { style.fixed = true; style.contour = true; }
8023 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8025 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8026 Position(x, y, w, h, true, true, true, true, false, true);
8028 CreateSystemChildren();
8031 get { return style.hasMinimize; }
8034 property bool hasClose
8036 property_category "Window Style"
8039 style.hasClose = value;
8040 if(value) { style.fixed = true; style.contour = true; }
8044 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);
8047 CreateSystemChildren();
8050 get { return style.hasClose; }
8053 property bool nonClient
8055 property_category "Layout"
8058 style.nonClient = value;
8060 style.stayOnTop = true;
8062 get { return style.nonClient; }
8065 property bool inactive
8067 property_category "Behavior"
8072 // *** NEW HERE: ***
8076 parent.childrenCycle.Delete(cycle);
8078 parent.childrenOrder.Delete(order);
8085 active = false; // true;
8086 if(parent.activeChild == this)
8087 parent.activeChild = null;
8088 if(parent.activeClient == this)
8089 parent.activeClient = null;
8098 parent.childrenCycle.Insert(
8099 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8100 cycle = OldLink { data = this });
8102 parent.childrenOrder.Insert(
8103 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8104 order = OldLink { data = this });
8107 style.inactive = value;
8109 get { return style.inactive; }
8112 property bool clickThrough
8114 property_category "Behavior"
8115 set { style.clickThrough = value; }
8116 get { return style.clickThrough; }
8119 property bool isRemote
8121 property_category "Behavior"
8122 set { style.isRemote = value; }
8123 get { return style.isRemote; }
8126 property bool noCycle
8128 property_category "Behavior"
8129 set { style.noCycle = value; }
8130 get { return style.noCycle; }
8133 property bool isModal
8135 property_category "Behavior"
8136 set { style.modal = value; }
8137 get { return style.modal; }
8140 property bool interim
8142 property_category "Behavior"
8143 set { style.interim = value; }
8144 get { return style.interim; }
8147 property bool tabCycle
8149 property_category "Behavior"
8150 set { style.tabCycle = value; }
8151 get { return style.tabCycle; }
8154 property bool isDefault
8156 property_category "Behavior"
8164 /*for(sibling = parent.children.first; sibling; sibling = sibling.next)
8165 if(sibling != this && sibling.style.isDefault)
8166 sibling.style.isDefault = false;*/
8167 if(master.defaultControl)
8168 master.defaultControl.style.isDefault = false;
8169 master.defaultControl = this;
8171 else if(master.defaultControl == this)
8172 master.defaultControl = null;
8176 style.isDefault = value;
8178 Position(position.x, position.y, size.w, size.h, true, true, true,true,true, true);
8180 get { return style.isDefault; }
8183 property bool drawBehind
8185 property_category "Window Style"
8186 set { style.drawBehind = value; }
8187 get { return style.drawBehind; }
8190 property bool hasMenuBar
8192 property_category "Window Style"
8202 if(created && !menuBar)
8209 anchor = Anchor { top = 23, left = 1, right = 1 },
8211 inactive = true, nonClient = true
8216 else if(created && menuBar)
8221 style.hasMenuBar = value;
8223 get { return style.hasMenuBar; }
8226 property bool hasStatusBar
8228 property_category "Window Style"
8235 statusBar = StatusBar { this };
8243 style.hasStatusBar = value;
8245 get { return style.hasStatusBar; }
8247 property bool stayOnTop
8249 property_category "Window Style"
8254 if(created && !style.stayOnTop)
8256 if(rootWindow == this)
8257 guiApp.interfaceDriver.OrderRootWindow(this, true);
8258 else if(parent.children.last != this)
8260 parent.children.Move(this, parent.children.last);
8264 style.stayOnTop = true;
8268 if(created && style.stayOnTop)
8270 if(rootWindow == this)
8271 guiApp.interfaceDriver.OrderRootWindow(this, false);
8278 for(order = (this.order == parent.childrenOrder.first) ? null : this.order.prev;
8279 order && ((Window)order.data).style.stayOnTop;
8280 order = (order == parent.childrenOrder.first) ? null : order.prev);
8281 last = order ? order.data : null;
8285 for(last = parent.children.last;
8286 last && last.style.stayOnTop;
8290 parent.children.Move(this, last);
8294 style.stayOnTop = false;
8297 get { return style.stayOnTop; }
8302 property_category "Window Style"
8312 if(menuBar && !value)
8319 if(!menuBar && style.hasMenuBar && value)
8323 this, menu = value, isMenuBar = true,
8324 anchor = Anchor { left = 1, top = 23, right = 1 }, size.h = 24,
8325 inactive = true, nonClient = true
8329 UpdateActiveDocument(null);
8332 get { return menu; }
8335 property FontResource font
8337 property_category "Appearance"
8339 isset { return setFont ? true : false; }
8344 if(value && !setFont) { stopwatching(parent, font); }
8345 else if(!value && setFont)
8351 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8360 RemoveResource(setFont);
8365 RemoveResource(systemFont);
8372 AddResource(setFont);
8375 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
8378 systemFont = guiApp.currentSkin.SystemFont();
8380 usedFont = systemFont;
8381 AddResource(systemFont);
8389 get { return usedFont; }
8392 property SizeAnchor sizeAnchor
8394 property_category "Layout"
8397 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8398 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8399 sizeAnchor.isClientW != sizeAnchor.isClientH;
8406 normalSizeAnchor = sizeAnchor;
8408 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8410 stateAnchor = normalAnchor;
8411 stateSizeAnchor = normalSizeAnchor;
8413 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8414 Position(x,y, w, h, true, true, true, true, false, true);
8421 { sizeAnchor.isClientW ? clientSize.w : size.w, sizeAnchor.isClientH ? clientSize.h : size.h },
8422 sizeAnchor.isClientW,
8423 sizeAnchor.isClientH
8430 property_category "Layout"
8433 Anchor thisAnchor = anchor;
8434 SizeAnchor thisSizeAnchor = sizeAnchor;
8435 bool leftRight = (anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none);
8436 bool topBottom = (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none);
8437 bool isClient = !sizeAnchor.isClientW && !sizeAnchor.isClientH;
8438 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8439 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8440 !sizeAnchor.isClientW && !sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8446 sizeAnchor.isClientW = false;
8447 sizeAnchor.isClientH = false;
8448 sizeAnchor.size = value;
8450 normalSizeAnchor = sizeAnchor;
8452 if(state == normal /*|| state == Hidden*/) // Hidden is new here ...
8454 stateAnchor = normalAnchor;
8455 stateSizeAnchor = normalSizeAnchor;
8457 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8458 Position(x, y, w, h, true, true, true, true, false, true);
8461 get { value = size; }
8464 property Size clientSize
8466 property_category "Layout"
8469 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8470 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8471 sizeAnchor.isClientW && sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8476 sizeAnchor.isClientW = true;
8477 sizeAnchor.isClientH = true;
8478 sizeAnchor.size = value;
8480 normalSizeAnchor = sizeAnchor;
8482 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8484 stateAnchor = normalAnchor;
8485 stateSizeAnchor = normalSizeAnchor;
8487 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8488 Position(x,y, w, h, true, true, true, true, false, true);
8491 get { value = clientSize; }
8494 property Size initSize { get { value = sizeAnchor.size; } };
8496 property Anchor anchor
8498 property_category "Layout"
8499 isset { return (anchor.left.type != offset || anchor.top.type != offset || anchor.right.type || anchor.bottom.type); }
8505 if(anchor.left.type && anchor.right.type && (!value.left.type || !value.right.type))
8507 normalSizeAnchor.isClientW = sizeAnchor.isClientW = false;
8508 normalSizeAnchor.size.w = sizeAnchor.size.w = size.w;
8510 if(anchor.top.type && anchor.bottom.type && (!value.top.type || !value.bottom.type))
8512 normalSizeAnchor.isClientH = sizeAnchor.isClientH = false;
8513 normalSizeAnchor.size.h = sizeAnchor.size.h = size.h;
8517 if(anchor.right.type && (anchor.horz.type == middleRelative || !anchor.left.type))
8519 anchor.left.distance = 0;
8520 anchor.horz.type = 0;
8522 if(anchor.bottom.type && (anchor.vert.type == middleRelative || !anchor.top.type))
8524 anchor.top.distance = 0;
8525 anchor.vert.type = 0;
8534 normalAnchor = anchor;
8536 // Break the anchors for moveable/resizable windows
8537 /*if(style.fixed ) //&& value.left.type == cascade)
8539 ComputeAnchors(anchor, sizeAnchor, &x, &y, &w, &h);
8541 this.anchor = normalAnchor = Anchor { left = x, top = y };
8542 normalSizeAnchor = SizeAnchor { { w, h } };
8545 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8547 stateAnchor = normalAnchor;
8548 stateSizeAnchor = normalSizeAnchor;
8550 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8551 Position(x, y, w, h, true, true, true, true, false, true);
8560 get { value = this ? anchor : Anchor { }; }
8563 property Point position
8565 property_category "Layout"
8568 if(value == null) return;
8570 anchor.left = value.x;
8571 anchor.top = value.y;
8572 anchor.right.type = none;
8573 anchor.bottom.type = none;
8578 normalAnchor = anchor;
8580 // Break the anchors for moveable/resizable windows
8584 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8586 normalAnchor.left = x;
8587 normalAnchor.top = y;
8588 normalAnchor.right.type = none;
8589 normalAnchor.bottom.type = none;
8590 normalSizeAnchor.size.width = w;
8591 normalSizeAnchor.size.height = h;
8595 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8597 stateAnchor = normalAnchor;
8598 stateSizeAnchor = normalSizeAnchor;
8600 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8601 Position(x,y, w, h, true, true, true, true, false, true);
8605 get { value = position; }
8608 property bool disabled
8610 property_category "Behavior"
8613 if(this && disabled != value)
8620 get { return (bool)disabled; }
8623 property bool isEnabled
8628 for(parent = this; parent; parent = parent.parent)
8635 property WindowState state
8637 property_category "Behavior"
8638 set { SetState(value, false, 0); }
8639 get { return this ? state : 0; }
8642 property bool visible
8644 property_category "Behavior"
8647 if(this && !value && !style.hidden && parent)
8649 Window client = null;
8651 style.hidden = true;
8654 OldLink prevOrder = null;
8656 if(rootWindow == this)
8657 guiApp.interfaceDriver.SetRootWindowState(this, state, false);
8660 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
8663 box.left -= parent.clientStart.x;
8664 box.top -= parent.clientStart.y;
8665 box.right -= parent.clientStart.x;
8666 box.bottom -= parent.clientStart.y;
8670 if(style.modal && master && master.modalSlave == this)
8671 master.modalSlave = null;
8673 if(style.isActiveClient)
8675 parent.numPositions--;
8676 if(state == minimized) parent.numIcons--;
8681 OldLink tmpPrev = order.prev;
8682 client = tmpPrev ? tmpPrev.data : null;
8683 if(client && !client.style.hidden && !client.destroyed && client.created)
8684 prevOrder = tmpPrev;
8687 client = tmpPrev ? tmpPrev.data : null;
8688 if(client == this) { client = null; break; }
8689 if(client && ((client.style.hidden) || client.destroyed || !client.created))
8691 tmpPrev = client.order.prev;
8696 prevOrder = tmpPrev;
8701 // If this window can be an active client, make sure the next window we activate can also be one
8702 if(!style.nonClient && style.isActiveClient)
8704 tmpPrev = prevOrder;
8707 client = tmpPrev ? tmpPrev.data : null;
8708 if(client == this) { client = null; break; }
8709 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
8711 tmpPrev = client.order.prev;
8716 prevOrder = tmpPrev;
8720 if(client && client.style.hidden) client = null;
8724 if((parent.activeChild == this || guiApp.interimWindow == this) && true /*activate*/)
8726 if(order && prevOrder && prevOrder.data != this)
8727 ((Window)prevOrder.data).ActivateEx(true, false, false, true, null, null);
8729 ActivateEx(false, false, false, true, null, null);
8731 // TESTING THIS HERE FOR HIDING ACTIVE CLIENT
8732 if(parent.activeClient == this)
8734 parent.activeClient = null;
8735 parent.UpdateActiveDocument(null);
8738 else if(parent.activeClient == this)
8740 parent.activeClient = client;
8741 parent.UpdateActiveDocument(this);
8744 // *** Not doing this anymore ***
8747 parent.childrenCycle.Delete(cycle);
8749 parent.childrenOrder.Delete(order);
8754 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8759 else if(this && value && style.hidden)
8761 style.hidden = false;
8764 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8765 if(rootWindow == this)
8766 guiApp.interfaceDriver.SetRootWindowState(this, state, true);
8768 if(style.modal && master)
8769 master.modalSlave = this;
8771 if(style.isActiveClient)
8773 positionID = parent.GetPositionID(this);
8774 parent.numPositions++;
8775 if(state == minimized) parent.numIcons++;
8778 // *** NOT DOING THIS ANYMORE ***
8780 if(!(style.inactive))
8782 if(!(style.noCycle))
8784 cycle = parent.childrenCycle.AddAfter(
8785 (parent.activeChild && parent.activeChild.cycle) ?
8786 parent.activeChild.cycle.prev : null, sizeof(OldLink));
8789 order = parent.childrenOrder.AddAfter(
8790 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8797 if(true || !parent.activeChild)
8798 ActivateEx(true, false, true, true, null, null);
8800 if(creationActivation == activate)
8801 ActivateEx(true, false, true, true, null, null);
8802 else if(creationActivation == flash && !object)
8805 //SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8809 ConsequentialMouseMove(false);
8816 get { return (style.hidden || !setVisible) ? false : true; }
8819 property bool isDocument
8821 property_category "Document"
8822 set { style.isDocument = value; }
8823 get { return style.isDocument; }
8826 property bool mergeMenus
8828 property_category "Window Style"
8829 set { mergeMenus = value; }
8830 get { return (bool)mergeMenus; }
8833 property bool hasHorzScroll
8835 property_category "Window Style"
8840 if(!style.hasHorzScroll && created)
8842 CreateSystemChildren();
8843 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8846 else if(style.hasHorzScroll)
8850 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8852 style.hasHorzScroll = value;
8855 get { return style.hasHorzScroll; }
8858 property bool hasVertScroll
8860 property_category "Window Style"
8865 if(!style.hasVertScroll && created)
8867 style.hasVertScroll = true;
8868 CreateSystemChildren();
8869 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8872 else if(style.hasVertScroll)
8876 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8878 style.hasVertScroll = value;
8880 get { return style.hasVertScroll; }
8883 property bool dontHideScroll
8885 property_category "Behavior"
8888 scrollFlags.dontHide = value;
8891 //UpdateScrollBars(true, true);
8892 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
8896 // UpdateScrollBars(true, true);
8897 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
8900 get { return scrollFlags.dontHide; }
8903 property bool dontScrollVert
8905 property_category "Behavior"
8906 set { style.dontScrollVert = value; }
8907 get { return style.dontScrollVert; }
8909 property bool dontScrollHorz
8911 property_category "Behavior"
8912 set { style.dontScrollHorz = value; }
8913 get { return style.dontScrollHorz; }
8916 property bool snapVertScroll
8918 property_category "Behavior"
8921 scrollFlags.snapY = value;
8922 if(sbv) sbv.snap = value;
8924 get { return scrollFlags.snapY; }
8926 property bool snapHorzScroll
8928 property_category "Behavior"
8931 scrollFlags.snapX = value;
8932 if(sbh) sbh.snap = value;
8934 get { return scrollFlags.snapX; }
8937 property Point scroll
8939 property_category "Behavior"
8943 // TESTING THIS IMPLEMENTATION:
8944 SetScrollPosition(value.x, value.y);
8946 get { value = scroll; }
8949 property bool modifyVirtualArea
8951 property_category "Behavior"
8952 set { modifyVirtArea = value; }
8953 get { return (bool)modifyVirtArea; }
8956 property char * fileName
8958 property_category "Document"
8961 if(menu && ((!fileName && value) || (fileName && !value)))
8963 MenuItem item = menu.FindItem(MenuFileSave, 0);
8964 if(item) item.disabled = !modifiedDocument && value;
8969 if(value && value[0])
8970 fileName = CopyString(value);
8972 if(parent && this == parent.activeClient)
8973 parent.UpdateActiveDocument(null);
8977 // if(style.isDocument)
8979 fileMonitor.fileName = value;
8981 get { return fileName; }
8986 property_category "Data"
8991 property bool modifiedDocument
8993 property_category "Document"
8996 if(style.isDocument || fileName)
9000 MenuItem item = menu.FindItem(MenuFileSave, 0);
9001 if(item) item.disabled = !value && fileName;
9005 if(modifiedDocument != value)
9007 modifiedDocument = value;
9008 if(style.isDocument || fileName)
9012 get { return (bool)modifiedDocument; }
9015 property bool showInTaskBar
9017 property_category "Window Style"
9018 set { style.showInTaskBar = value; }
9019 get { return (style.showInTaskBar; }
9021 property FileDialog saveDialog { set { saveDialog = value; } };
9022 property bool isActiveClient
9024 property_category "Behavior"
9025 set { style.isActiveClient = value; }
9026 get { return style.isActiveClient; }
9029 property Cursor cursor
9031 property_category "Appearance"
9035 SelectMouseCursor();
9037 get { return cursor; }
9040 //#if !defined(ECERE_VANILLA)
9041 property char * name
9043 property_category "Design"
9046 return (this && object) ? object.name : null;
9051 activeDesigner.RenameObject(object, value);
9055 property char * displayDriver
9057 property_category "Behavior"
9060 dispDriver = GetDisplayDriver(value);
9061 //DisplayModeChanged();
9065 return dispDriver ? dispDriver.name : null;
9069 // RUNTIME PROPERTIES
9070 property bool autoCreate { set { autoCreate = value; } get { return (bool)autoCreate; } };
9071 property Size scrollArea
9073 property_category "Behavior"
9077 SetScrollArea(value.w, value.h, false);
9079 SetScrollArea(0,0, true);
9081 get { value = scrollArea; }
9084 return scrollArea.w > clientSize.w || scrollArea.h > clientSize.h;
9089 property_category "Layout"
9090 set { if(this) is3D = value; }
9091 get { return (bool)is3D; }
9094 // Runtime Only Properties (No Set, can display the displayable ones depending on the type?)
9096 // Will be merged with font later
9097 property Font fontObject { get { return usedFont ? usedFont.font : null; } };
9098 property Point clientStart { get { value = clientStart; } };
9099 property Point absPosition { get { value = absPosition; } };
9100 property Anchor normalAnchor { get {value = normalAnchor; } };
9101 // property Size normalSizeAnchor { get { value = normalSizeAnchor; } };
9102 property bool active { get { return (bool)active; } };
9103 property bool created { get { return (bool)created; } };
9104 property bool destroyed { get { return (bool)destroyed; } };
9105 property Window firstSlave { get { return slaves.first ? ((OldLink)slaves.first).data : null; } };
9106 property Window firstChild { get { return children.first; } };
9107 property Window lastChild { get { return children.last; } };
9108 property Window activeClient { get { return activeClient; } };
9109 property Window activeChild { get { return activeChild; } };
9110 property Display display { get { return display ? display : ((parent && parent.rootWindow) ? parent.rootWindow.display : null); } };
9111 property DisplaySystem displaySystem { get { return display ? display.displaySystem : null; } };
9112 property ScrollBar horzScroll { get { return sbh; } };
9113 property ScrollBar vertScroll { get { return sbv; } };
9114 property StatusBar statusBar { get { return statusBar; } };
9115 property Window rootWindow { get { return rootWindow; } };
9116 property bool closing { get { return (bool)closing; } set { closing = value; } };
9117 property int documentID { get { return documentID; } };
9118 property Window previous { get { return prev; } }
9119 property Window next { get { return next; } }
9120 property Window nextSlave { get { OldLink link = master.slaves.FindLink(this); return (link && link.next) ? link.next.data : null; } }
9121 property PopupMenu menuBar { get { return menuBar; } }
9122 property ScrollBar sbv { get { return sbv; } }
9123 property ScrollBar sbh { get { return sbh; } }
9124 property bool fullRender { set { fullRender = value; } get { return (bool)fullRender; } }
9125 property void * systemHandle { get { return windowHandle; } }
9126 property Button minimizeButton { get { return sysButtons[0]; } };
9127 property Button maximizeButton { get { return sysButtons[1]; } };
9128 property Button closeButton { get { return sysButtons[2]; } };
9129 property BitmapResource icon
9131 get { return icon; }
9137 guiApp.interfaceDriver.SetIcon(this, value);
9140 property bool moveable { get { return (bool)moveable; } set { moveable = value; } };
9141 property bool alphaBlend { get { return (bool)alphaBlend; } set { alphaBlend = value; } };
9142 property bool useSharedMemory { get { return (bool)useSharedMemory; } set { useSharedMemory = value; } };
9143 property CreationActivationOption creationActivation { get { return creationActivation; } set { creationActivation = value; } };
9144 property bool nativeDecorations { get { return (bool)nativeDecorations && rootWindow == this; } set { nativeDecorations = value; } };
9145 property bool manageDisplay { get { return (bool)manageDisplay; } set { manageDisplay = value; } };
9151 WindowBits style; // Window Style
9152 char * caption; // Name / Caption
9153 Window parent; // Parent window
9154 OldList children; // List of children in Z order
9155 Window activeChild; // Child window having focus
9156 Window activeClient;
9157 Window previousActive; // Child active prior to activating the default child
9158 Window master; // Window owning and receiving notifications concerning this window
9159 OldList slaves; // List of windows belonging to this window
9160 Display display; // Display this window is drawn into
9162 Point position; // Position in parent window client area
9163 Point absPosition; // Absolute position
9164 Point clientStart; // Client area position from (0,0) in this window
9166 Size clientSize; // Client area size
9167 Size scrollArea; // Virtual Scroll area size
9168 Size reqScrollArea; // Requested virtual area size
9169 Point scroll; // Virtual area scrolling position
9170 public ScrollBar sbh, sbv; // Scrollbar window handles
9171 Cursor cursor; // Mouse cursor used for this window
9174 StatusBar statusBar;
9175 Button sysButtons[3];
9177 Box clientArea; // Client Area box clipped to parent
9179 HotKeySlot hotKey; // HotKey for this window
9183 ScrollFlags scrollFlags;// Window Scrollbar Flags
9184 int id; // Control ID
9186 ColorAlpha background; // Background color used to draw the window area
9188 subclass(DisplayDriver) dispDriver; // Display driver name for this window
9189 OldList childrenCycle; // Cycling order
9190 OldLink cycle; // Element of parent's cycling order
9191 OldList childrenOrder; // Circular Z-Order
9192 OldLink order; // Element of parent's circular Z-Order
9193 Window modalSlave; // Slave window blocking this window's interaction
9195 Window rootWindow; // Topmost system managed window
9196 void * windowHandle; // System window handle
9198 DialogResult returnCode;// Return code for modal windows
9200 Point sbStep; // Scrollbar line scrolling steps
9203 SizeAnchor stateSizeAnchor;
9205 Anchor normalAnchor;
9206 SizeAnchor normalSizeAnchor;
9208 Size skinMinSize; // Minimal window size based on style
9209 Point scrolledPos; // Scrolled position
9210 Box box; // Window box clipped to parent
9211 Box * against; // What to clip the box to
9213 Extent dirtyArea { /*first = -1, last = -1, free = -1*/ }; // Area marked for update by Update
9214 Extent renderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered
9215 Extent overRenderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered over children
9216 Extent clipExtent { /*first = -1, last = -1, free = -1*/ }; // Temporary extent against which to clip render area
9217 Extent scrollExtent { /*first = -1, last = -1, free = -1*/ }; // Area to scroll
9218 Point scrolledArea; // Distance to scroll area by
9219 Extent dirtyBack { /*first = -1, last = -1, free = -1*/ }; // Only used by root window
9221 OldList hotKeys; // List of the hotkeys of all children
9222 Window defaultControl; // Default child control
9226 ColorAlpha * palette; // Color palette used for this window
9228 int caretSize; // Size of caret, non zero if a caret is present
9229 Point caretPos; // Caret position
9231 void * systemParent; // Parent System Window for embedded windows
9238 WindowState lastState;
9240 FileMonitor fileMonitor
9242 this, FileChange { modified = true };
9244 bool OnFileNotify(FileChange action, char * param)
9247 fileMonitor.StopMonitoring();
9248 if(OnFileModified(action, param))
9249 fileMonitor.StartMonitoring();
9254 FontResource setFont, systemFont;
9255 FontResource usedFont;
9256 FontResource captionFont;
9258 FileDialog saveDialog;
9260 SizeAnchor sizeAnchor;
9262 // FormDesigner data
9265 Extent * tempExtents; //[4];
9266 BitmapResource icon;
9268 CreationActivationOption creationActivation;
9271 bool active:1; // true if window and ancestors are active
9272 bool acquiredInput:1; // true if the window is processing state based input
9273 bool modifiedDocument:1;
9274 bool disabled:1; // true if window cannot interact
9275 bool isForegroundWindow:1;// true while a root window is being activated
9276 bool visible:1; // Visibility flag
9277 bool destroyed:1; // true if window is being destroyed
9278 bool anchored:1; // true if this window is repositioned when the parent resizes
9279 bool dirty:1; // Flag set to true if any descendant must be redrawn
9285 bool modifyVirtArea:1;
9286 bool noAutoScrollArea:1;
9289 bool setVisible:1; // FOR FORM DESIGNER
9295 bool useSharedMemory:1;
9298 bool nativeDecorations:1;
9299 bool manageDisplay:1;
9302 WindowController controller;
9303 public property WindowController controller { get { return controller; } set { delete controller; controller = value; if(controller) incref controller; } }
9306 public class CommonControl : Window
9308 // creationActivation = doNothing;
9311 public class Percentage : float
9313 char * OnGetString(char * string, float * fieldData, bool * needClass)
9317 sprintf(string, "%.2f", this);
9318 c = strlen(string)-1;
9321 if(string[c] != '0')
9322 last = Max(last, c);
9323 if(string[c] == '.')
9336 public void ApplySkin(Class c, char * name, void ** vTbl)
9338 char className[1024];
9343 subclass(Window) wc = (subclass(Window))c;
9344 subclass(Window) base = (subclass(Window))c.base;
9346 sprintf(className, "%sSkin_%s", name, c.name);
9347 wc.pureVTbl = c._vTbl;
9348 c._vTbl = new void *[c.vTblSize];
9349 memcpy(c._vTbl, wc.pureVTbl, c.vTblSize * sizeof(void *));
9350 sc = eSystem_FindClass(c.module.application, className);
9354 for(m = 0; m < c.base.vTblSize; m++)
9356 if(c._vTbl[m] == base.pureVTbl[m])
9357 c._vTbl[m] = vTbl[m];
9362 for(m = 0; m < c.vTblSize; m++)
9364 if(sc._vTbl[m] != wc.pureVTbl[m])
9365 c._vTbl[m] = sc._vTbl[m];
9369 for(d = c.derivatives.first; d; d = d.next)
9371 ApplySkin(d.data, name, c._vTbl);
9375 public void UnapplySkin(Class c)
9377 char className[1024];
9379 subclass(Window) wc = (subclass(Window))c;
9380 subclass(Window) base = (subclass(Window))c.base;
9383 if(wc.pureVTbl && c._vTbl != wc.pureVTbl)
9386 c._vTbl = wc.pureVTbl;
9390 for(d = c.derivatives.first; d; d = d.next)
9392 UnapplySkin(d.data);
9396 void CheckFontIntegrity(Window window)
9401 if(window.usedFont && window.usedFont.font == 0xecececec)
9403 FontResource uf = window.usedFont;
9404 char * className = window._class.name;
9405 char * text = window.text;
9408 for(c = window.firstChild; c; c = c.next)
9409 CheckFontIntegrity(c);
9413 public class ControllableWindow : Window
9415 /*WindowController controller;
9416 public property WindowController controller { get { return controller; } set { delete controller; controller = value; incref controller; } }
9417 ~ControllableWindow() { delete controller; }*/
9420 class WindowControllerInterface : ControllableWindow
9422 bool OnKeyDown(Key key, unichar ch)
9424 bool result = ((int(*)())(void *)controller.OnKeyDown)((void *)controller.controlled, (void *)controller, key, ch);
9426 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown](controller.window, key, ch);
9430 bool OnKeyUp(Key key, unichar ch)
9432 bool result = ((int(*)())(void *)controller.OnKeyUp)((void *)controller.controlled, (void *)controller, key, ch);
9434 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp](controller.window, key, ch);
9438 bool OnKeyHit(Key key, unichar ch)
9440 bool result = ((int(*)())(void *)controller.OnKeyHit)((void *)controller.controlled, (void *)controller, key, ch);
9442 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit](controller.window, key, ch);
9446 bool OnMouseMove(int x, int y, Modifiers mods)
9448 bool result = ((int(*)())(void *)controller.OnMouseMove)((void *)controller.controlled, (void *)controller, x, y, mods);
9450 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove](controller.window, x, y, mods);
9454 bool OnLeftButtonDown(int x, int y, Modifiers mods)
9456 bool result = ((int(*)())(void *)controller.OnLeftButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9458 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown](controller.window, x, y, mods);
9462 bool OnLeftButtonUp(int x, int y, Modifiers mods)
9464 bool result = ((int(*)())(void *)controller.OnLeftButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9466 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp](controller.window, x, y, mods);
9470 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
9472 bool result = ((int(*)())(void *)controller.OnLeftDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9474 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick](controller.window, x, y, mods);
9478 bool OnRightButtonDown(int x, int y, Modifiers mods)
9480 bool result = ((int(*)())(void *)controller.OnRightButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9482 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown](controller.window, x, y, mods);
9486 bool OnRightButtonUp(int x, int y, Modifiers mods)
9488 bool result = ((int(*)())(void *)controller.OnRightButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9490 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp](controller.window, x, y, mods);
9494 bool OnRightDoubleClick(int x, int y, Modifiers mods)
9496 bool result = ((int(*)())(void *)controller.OnRightDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9498 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick](controller.window, x, y, mods);
9502 bool OnMiddleButtonDown(int x, int y, Modifiers mods)
9504 bool result = ((int(*)())(void *)controller.OnMiddleButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9506 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown](controller.window, x, y, mods);
9510 bool OnMiddleButtonUp(int x, int y, Modifiers mods)
9512 bool result = ((int(*)())(void *)controller.OnMiddleButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9514 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp](controller.window, x, y, mods);
9518 bool OnMiddleDoubleClick(int x, int y, Modifiers mods)
9520 bool result = ((int(*)())(void *)controller.OnMiddleDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9522 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick](controller.window, x, y, mods);
9526 void OnResize(int width, int height)
9528 ((int(*)())(void *)controller.OnResize)((void *)controller.controlled, (void *)controller, width, height);
9529 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnResize](controller.window, width, height);
9532 void OnRedraw(Surface surface)
9534 ((int(*)())(void *)controller.OnRedraw)((void *)controller.controlled, (void *)controller, surface);
9535 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRedraw](controller.window, surface);
9540 bool result = ((int(*)())(void *)controller.OnCreate)((void *)controller.controlled, (void *)controller);
9542 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnCreate](controller.window);
9547 public class WindowController<class V>
9550 property Window window
9554 uint size = class(Window).vTblSize;
9557 windowVTbl = new void *[size];
9558 memcpy(windowVTbl, value._vTbl, size * sizeof(void *));
9559 if(value._vTbl == value._class._vTbl)
9561 value._vTbl = new void *[value._class.vTblSize];
9562 memcpy(value._vTbl + size, value._class._vTbl + size, (value._class.vTblSize - size) * sizeof(void *));
9566 for(c = 0; c < size; c++)
9568 void * function = class(WindowControllerInterface)._vTbl[c];
9569 if(function != DefaultFunction)
9570 value._vTbl[c] = function;
9572 value._vTbl[c] = windowVTbl[c];
9577 memcpy(value._vTbl, windowVTbl, class(Window).vTblSize * sizeof(void *));
9580 get { return window; }
9582 property V controlled
9584 set { controlled = value; }
9585 get { return controlled; }
9587 virtual bool V::OnKeyDown(WindowController controller, Key key, unichar ch);
9588 virtual bool V::OnKeyUp(WindowController controller, Key key, unichar ch);
9589 virtual bool V::OnKeyHit(WindowController controller, Key key, unichar ch);
9590 virtual bool V::OnMouseMove(WindowController controller, int x, int y, Modifiers mods);
9591 virtual bool V::OnLeftButtonDown(WindowController controller, int x, int y, Modifiers mods);
9592 virtual bool V::OnLeftButtonUp(WindowController controller, int x, int y, Modifiers mods);
9593 virtual bool V::OnLeftDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9594 virtual bool V::OnRightButtonDown(WindowController controller, int x, int y, Modifiers mods);
9595 virtual bool V::OnRightButtonUp(WindowController controller, int x, int y, Modifiers mods);
9596 virtual bool V::OnRightDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9597 virtual bool V::OnMiddleButtonDown(WindowController controller, int x, int y, Modifiers mods);
9598 virtual bool V::OnMiddleButtonUp(WindowController controller, int x, int y, Modifiers mods);
9599 virtual bool V::OnMiddleDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9600 virtual void V::OnResize(WindowController controller, int width, int height);
9601 virtual void V::OnRedraw(WindowController controller, Surface surface);
9602 virtual bool V::OnCreate(WindowController controller);
9605 int (** windowVTbl)();