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, thin:1; };
433 class WindowBits : BorderBits
435 BorderBits borderBits:6:0;
436 bool hidden:1, isActiveClient:1, hasHorzScroll:1, hasVertScroll:1, stayOnTop:1, modal: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, 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 thin = BorderBits { fixed = true, thin = true } | contour,
448 sizableThin = BorderBits { sizable = true } | thin,
449 deep = BorderBits { deep = true },
450 bevel = BorderBits { bevel = true },
451 sizableDeep = sizable|deep,
452 sizableBevel = sizable|bevel,
453 fixedDeep = fixed|deep,
454 fixedBevel = fixed|bevel,
455 deepContour = deep|contour
458 public enum CreationActivationOption
460 activate, flash, doNothing
463 public enum WindowState { normal, minimized, maximized };
465 private class ResPtr : struct
472 private class HotKeySlot : struct
474 HotKeySlot prev, next;
482 class_data char * icon;
484 class_default_property text;
485 // class_initialize GuiApplication::Initialize;
486 class_designer FormDesigner;
487 class_property char * icon
489 set { class_data(icon) = value; }
490 get { return class_data(icon); }
495 if(guiApp) guiApp.Initialize(true);
497 if(guiApp && guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
499 if(_vTbl == ((subclass(Window))_class).pureVTbl)
501 _vTbl = _class._vTbl;
503 else if(_vTbl != _class._vTbl)
506 for(m = 0; m < _class.vTblSize; m++)
508 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
509 _vTbl[m] = _class._vTbl[m];
514 //tempExtents[0] = { /*first = -1, last = -1, free = -1*/ };
515 //tempExtents[1] = { /*first = -1, last = -1, free = -1*/ };
516 //tempExtents[2] = { /*first = -1, last = -1, free = -1*/ };
517 //tempExtents[3] = { /*first = -1, last = -1, free = -1*/ };
521 // caption = CopyString(class.name);
523 children.offset = (byte*)&prev - (byte*)this;
524 childrenOrder.circ = true;
525 childrenCycle.circ = true;
527 maxSize = Size { MAXINT, MAXINT };
531 //style.isActiveClient = true;
534 modifyVirtArea = true;
535 manageDisplay = true;
537 // scrollFlags = ScrollFlags { snapX = true, snapY = true };
538 sbStep.x = sbStep.y = 8;
540 if(guiApp) // dynamic_cast<GuiApplication>(thisModule)
542 cursor = guiApp.GetCursor(arrow);
543 property::parent = guiApp.desktop;
554 stopwatching(parent, font);
558 // Prevent destructor from being called again...
564 /////////////////////////////////
567 OldLink slave = master.slaves.FindLink(this);
568 master.slaves.Delete(slave);
575 parent.childrenCycle.Remove(cycle);
577 parent.childrenOrder.Remove(order);
578 parent.children.Remove(this);
583 /////////////////////////////////
585 while(ptr = resources.first)
588 resources.Delete(ptr);
595 for(child = children.first; child; child = child.next)
597 // child.stopwatching(this, font);
599 eInstance_StopWatching(this, __ecereProp___ecereNameSpace__ecere__gui__Window_font, child);
600 // Don't want property here
601 *&child.parent = null;
604 while(slave = slaves.first)
606 // Don't want property here
607 *&((Window)slave.data).master = null;
608 slaves.Delete(slave);
611 // Because we do a decref in DestroyEx...
619 // Why was this commented?
620 //if(this != guiApp.desktop)
633 if(((subclass(Window))_class).pureVTbl)
635 if(_vTbl == _class._vTbl)
637 _vTbl = ((subclass(Window))_class).pureVTbl;
642 for(m = 0; m < _class.vTblSize; m++)
644 if(_vTbl[m] == _class._vTbl[m])
645 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
649 if(_vTbl == ((subclass(Window))_class).pureVTbl || _vTbl == _class._vTbl)
652 dirtyArea.Free(null);
653 renderArea.Free(null);
654 overRenderArea.Free(null);
655 clipExtent.Free(null);
656 scrollExtent.Free(null);
657 dirtyBack.Free(null);
661 tempExtents[0].Free(null);
662 tempExtents[1].Free(null);
663 tempExtents[2].Free(null);
664 tempExtents[3].Free(null);
669 //#if !defined(ECERE_VANILLA)
670 char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
672 if(this == activeDesigner)
676 char * name = property::name;
677 return name ? name : "";
682 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
683 bool OnGetDataFromString(char * string)
685 FormDesigner designer = (FormDesigner)activeDesigner.classDesigner;
688 if(!strcmp(string, "this") || !strcmp(string, designer.form.name))
689 this = designer.form;
690 else if(!strcmpi(string, "(Desktop)"))
691 this = activeDesigner;
693 return activeDesigner.FindObject(&this, string);
699 // --- Window updates system ---
701 // Setup a bitmap for Redrawing on client area of Window
702 Surface Redraw(Box box)
704 Surface surface = null;
706 Box clientArea = this.clientArea;
710 mox.left -= clientStart.x;
711 mox.top -= clientStart.y;
712 mox.right -= clientStart.x;
713 mox.bottom -= clientStart.y;
715 mox.Clip(clientArea);
716 // mox.ClipOffset(against, scrolledPos.x, scrolledPos.y);
718 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && mox.right >= mox.left && mox.bottom >= mox.top)
720 int x = absPosition.x + clientStart.x;
721 int y = absPosition.y + clientStart.y;
722 if(rootWindow.nativeDecorations)
724 x -= rootWindow.clientStart.x;
725 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
727 if(!guiApp.fullScreenMode || is3D)
729 x -= rootWindow.absPosition.x;
730 y -= rootWindow.absPosition.y;
734 x += rootWindow.parent.clientStart.x;
735 y += rootWindow.parent.clientStart.y;
737 mox.left += rootWindow.parent.clientStart.x;
738 mox.top += rootWindow.parent.clientStart.y;
739 mox.right += rootWindow.parent.clientStart.x;
740 mox.bottom += rootWindow.parent.clientStart.y;
745 surface = display.GetSurface(x, y, mox);
748 surface.width = clientSize.w;
749 surface.height = clientSize.h;
755 // Setup a bitmap for Redrawing on full Window
756 Surface RedrawFull(Box box)
758 Surface surface = null;
766 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && box.right >= box.left && box.bottom >= box.top)
768 int x = absPosition.x;
769 int y = absPosition.y;
770 if(rootWindow.nativeDecorations)
772 x -= rootWindow.clientStart.x;
773 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
775 if(!guiApp.fullScreenMode || is3D)
777 x -= rootWindow.absPosition.x;
778 y -= rootWindow.absPosition.y;
781 x += rootWindow.parent.clientStart.x;
782 y += rootWindow.parent.clientStart.y;
784 mox.left += rootWindow.parent.clientStart.x;
785 mox.top += rootWindow.parent.clientStart.y;
786 mox.right += rootWindow.parent.clientStart.x;
787 mox.bottom += rootWindow.parent.clientStart.y;
792 surface = display.GetSurface(x, y, mox);
795 surface.width = size.w;
796 surface.height = size.h;
802 void FigureCaption(char * caption)
806 strcpy(caption, this.caption);
807 if(style.isDocument || fileName)
809 if(caption[0]) strcat(caption, " - ");
811 strcat(caption, fileName);
815 sprintf(title, "Untitled %d", documentID);
816 strcat(caption, title);
819 strcat(caption, " *");
821 if(activeClient && menuBar &&
822 activeClient.state == maximized)
824 if(activeClient.caption)
826 if(caption[0]) strcat(caption, " - ");
827 strcat(caption, activeClient.caption);
829 if(activeClient.style.isDocument || activeClient.fileName)
831 if(caption[0]) strcat(caption, " - ");
832 strcat(caption, "[");
833 if(activeClient.fileName)
834 strcat(caption, activeClient.fileName);
838 sprintf(title, "Untitled %d", activeClient.documentID);
839 strcat(caption, title);
841 if(activeClient.modifiedDocument)
842 strcat(caption, " *");
843 strcat(caption, "]");
848 // Code for returning dirty from ScrollDisplay:
850 for(d = 0; d<scrollExtent.count; d++)
852 Box * box = &scrollExtent.boxes[d];
858 Min(box.right, box.left-scroll.x),box.bottom
860 dirtyArea.UnionBox(update);
866 Max(box.left, box.right-scroll.x), box.top,
867 box.right, box.bottom
869 dirtyArea.UnionBox(update);
877 box.right, Min(box.bottom, box.top-scroll.y),
879 dirtyArea.UnionBox(update);
885 box.left, Max(box.top, box.bottom-scroll.y),
886 box.right, box.bottom
888 dirtyArea.UnionBox(update);
893 void UpdateDecorations(void)
895 // TODO: *** TEMPORARY HACK ***
902 Update({ -clientStart.x, -clientStart.y, -clientStart.x + size.w-1, 0 });
904 Update({ -clientStart.x, clientSize.h, -clientStart.x + size.w-1, -clientStart.y + size.h-1 });
906 Update({ -clientStart.x,0, -1, clientSize.h-1 });
908 Update({ clientSize.w, 0, -clientStart.x + size.w-1, clientSize.h-1 });
911 // Returns w & h for Position
912 void ComputeAnchors(Anchor anchor, SizeAnchor sizeAnchor, int *ox, int *oy, int *ow, int *oh)
914 Window parent = this.parent ? this.parent : guiApp.desktop;
915 int vpw = parent ? parent.clientSize.w : 0;
916 int vph = parent ? parent.clientSize.h : 0;
917 int pw = parent ? parent.clientSize.w : 0;
918 int ph = parent ? parent.clientSize.h : 0;
919 int w = sizeAnchor.size.w, h = sizeAnchor.size.h;
920 int x = anchor.left.distance, y = anchor.top.distance;
922 MinMaxValue ew = 0, eh = 0;
924 float cascadeW, cascadeH;
926 int tilingW, tilingH, tilingSplit, tilingLastH;
927 int addX = 0, addY = 0;
929 if(parent && rootWindow == this && guiApp && guiApp.interfaceDriver)
931 Window masterWindow = this;
932 Box box { addX, addY, addX + vpw - 1, addY + vph - 1 };
935 if(master == guiApp.desktop)
936 masterWindow = guiApp.desktop.activeChild;
938 masterWindow = master.rootWindow;
939 if(!masterWindow) masterWindow = this;
941 guiApp.interfaceDriver.GetScreenArea(masterWindow, box);
942 if((anchor.left.type == offset && anchor.right.type == offset) || anchor.left.type == none)
945 pw = vpw = box.right - box.left + 1;
947 if((anchor.top.type == offset && anchor.bottom.type == offset) || anchor.top.type == none)
950 ph = vph = box.bottom - box.top + 1;
966 vpw = pw = parent.size.w;
967 vph = ph = parent.size.h;
969 else if(!style.fixed /*|| style.isDocument*/)
971 if(!style.dontScrollHorz && parent.scrollArea.w) vpw = parent.scrollArea.w;
972 if(!style.dontScrollVert && parent.scrollArea.h) vph = parent.scrollArea.h;
974 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
977 Desktop3D_FixSize(&pw, &ph);
978 Desktop3D_FixSize(&vpw, &vph);
981 if(pw < skinMinSize.w) pw = skinMinSize.w;
982 if(ph < skinMinSize.h) ph = skinMinSize.h;
983 if(vpw < skinMinSize.w) vpw = skinMinSize.w;
984 if(vph < skinMinSize.h) vph = skinMinSize.h;
986 // TODO: Must fix what we're snapping
991 SNAPUP(x, textCellW);
993 else if(anchor.right.type)
995 SNAPDOWN(x, textCellW);
1000 SNAPUP(y, textCellH);
1002 else if(anchor.bottom.type)
1004 SNAPDOWN(y, textCellH);
1008 // This is required to get proper initial decoration size using native decorations on Windows
1009 if(nativeDecorations && guiApp && guiApp.interfaceDriver && !visible)
1010 guiApp.interfaceDriver.PositionRootWindow(this, x, y, size.w, size.h, true, true);
1011 GetDecorationsSize(&ew, &eh);
1013 if(anchor.left.type >= cascade && (state == normal /*|| state == Hidden*/))
1015 if(parent.sbv && !parent.sbv.style.hidden)
1016 pw += guiApp.currentSkin.VerticalSBW();
1017 if(parent.sbh && !parent.sbh.style.hidden)
1018 ph += guiApp.currentSkin.HorizontalSBH();
1020 if(anchor.left.type == cascade)
1022 w = (int)(pw * 0.80);
1023 h = (int)(ph * 0.80);
1025 else if(anchor.left.type >= vTiled)
1030 numTiling = parent.numPositions - parent.numIcons;
1031 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1032 if(anchor.left.type == vTiled)
1034 tilingH = (int)sqrt(numTiling);
1035 tilingW = numTiling / tilingH;
1039 tilingW = (int)sqrt(numTiling);
1040 tilingH = numTiling / tilingW;
1043 leftOver = numTiling - tilingH * tilingW;
1046 tilingSplit = (tilingW - leftOver) * tilingH;
1047 tilingLastH = tilingH+1;
1050 tilingSplit = numTiling;
1052 if(positionID >= tilingSplit)
1054 x = pw * (tilingSplit / tilingH + (positionID - tilingSplit) / tilingLastH)/tilingW;
1055 y = ph * ((positionID - tilingSplit) % tilingLastH) / tilingLastH;
1056 x2 = pw * (tilingSplit/tilingH + (positionID - tilingSplit) / tilingLastH + 1)/tilingW;
1057 y2 = ph * (((positionID - tilingSplit) % tilingLastH) + 1) / tilingLastH;
1061 x = pw * (positionID / tilingH) / tilingW;
1062 y = ph * (positionID % tilingH) / tilingH;
1063 x2 = pw * (positionID / tilingH + 1) / tilingW;
1064 y2 = ph * ((positionID % tilingH) + 1) / tilingH;
1068 SNAPDOWN(x, textCellW);
1069 SNAPDOWN(y, textCellH);
1070 SNAPDOWN(x2, textCellW);
1071 SNAPDOWN(y2, textCellH);
1079 if(sizeAnchor.isClientW) w += ew;
1080 if(sizeAnchor.isClientH) h += eh;
1082 if(anchor.left.type == offset)
1083 x = anchor.left.distance;
1084 else if(anchor.left.type == relative)
1085 x = (anchor.left.percent < 0) ? ((int)(vpw * anchor.left.percent - 0.5)) : (int)(vpw * anchor.left.percent + 0.5);
1086 else if(anchor.right.type == relative)
1087 // ex = (anchor.right.percent < 0) ? ((int)(vpw * anchor.right.percent + 0)) : ((int)(vpw * anchor.right.percent + 0));
1088 ex = (anchor.right.percent < 0) ? ((int)(vpw * (1.0-anchor.right.percent) + 0)) : ((int)(vpw * (1.0-anchor.right.percent) + 0));
1089 else if(anchor.right.type == offset)
1090 ex = vpw - anchor.right.distance;
1092 if(anchor.top.type == offset)
1093 y = anchor.top.distance;
1094 else if(anchor.top.type == relative)
1095 y = (anchor.top.percent < 0) ? ((int)(vph * anchor.top.percent - 0.5)) : ((int)(vph * anchor.top.percent + 0.5));
1096 else if(anchor.bottom.type == relative)
1097 //ey = (anchor.bottom.percent < 0) ? ((int)(vph * anchor.bottom.percent + 0)) : ((int)(vph * anchor.bottom.percent + 0));
1098 ey = (anchor.bottom.percent < 0) ? ((int)(vph * (1.0-anchor.bottom.percent) + 0)) : ((int)(vph * (1.0-anchor.bottom.percent) + 0));
1099 else if(anchor.bottom.type == offset)
1100 ey = vph - anchor.bottom.distance;
1102 if(anchor.left.type && anchor.right.type)
1104 switch(anchor.right.type)
1107 ex = pw * (1.0f-anchor.right.percent);
1108 w = Max((int)(ex + 0.5) - x, 0);
1111 ex = vpw - anchor.right.distance;
1112 w = Max((int)(ex + 0.5) - x, 0);
1116 if(anchor.top.type && anchor.bottom.type)
1118 switch(anchor.bottom.type)
1121 ey = ph * (1.0f-anchor.bottom.percent);
1122 h = Max((int)(ey + 0.5) - y, 0);
1125 ey = vph - anchor.bottom.distance;
1126 h = Max((int)(ey + 0.5) - y, 0);
1135 if(state == normal /*|| state == Hidden*/)
1137 bool addSbV = false, addSbH = false;
1139 if(sizeAnchor.isClientW || (anchor.left.type && anchor.right.type)) w = Max(w, 1); else w = Max(w, 0);
1140 if(sizeAnchor.isClientH || (anchor.top.type && anchor.bottom.type)) h = Max(h, 1); else h = Max(h, 0);
1142 w = Max(w, minSize.w);
1143 h = Max(h, minSize.h);
1144 w = Min(w, maxSize.w);
1145 h = Min(h, maxSize.h);
1147 if((sizeAnchor.isClientW || !w || (anchor.left.type && anchor.right.type)) && reqScrollArea.h > h /*&& w*/ && sbv)
1149 if(w) w -= guiApp.currentSkin.VerticalSBW();
1152 if((sizeAnchor.isClientH || !h || (anchor.top.type && anchor.bottom.type)) && reqScrollArea.w > w /*&& h*/ && sbh)
1154 if(h) h -= guiApp.currentSkin.HorizontalSBH();
1158 if(!OnResizing(&w, &h))
1164 if((addSbV)) // || reqScrollArea.h > h) && sbv)
1165 w += guiApp.currentSkin.VerticalSBW();
1166 if((addSbH)) // || reqScrollArea.w > w) && sbh)
1167 h += guiApp.currentSkin.HorizontalSBH();
1169 w = Max(w, skinMinSize.w);
1170 h = Max(h, skinMinSize.h);
1183 SNAPDOWN(w, textCellW);
1184 SNAPDOWN(h, textCellH);
1187 if(anchor.left.type == cascade && (state == normal /*|| state == Hidden*/))
1189 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1192 (pw - w) / CASCADE_SPACE,
1193 (ph - h) / CASCADE_SPACE);
1199 cascW = (pw - w) / (numCascade-1);
1200 cascH = (ph - h) / (numCascade-1);
1201 SNAPDOWN(cascW, textCellW);
1202 SNAPDOWN(cascH, textCellH);
1203 cascadeW = (float)cascW;
1204 cascadeH = (float)cascH;
1208 numCascade = Max(numCascade, 2);
1209 cascadeW = (float)(pw - w) / (numCascade-1);
1210 cascadeH = (float)(ph - h) / (numCascade-1);
1213 x = (int)((positionID % numCascade) * cascadeW);
1214 y = (int)((positionID % numCascade) * cascadeH);
1216 else if(anchor.left.type < vTiled)
1218 if(!anchor.left.type || anchor.horz.type == middleRelative)
1220 if(!anchor.right.type)
1222 if(anchor.horz.type == middleRelative)
1223 x = (int)(vpw * (0.5 + anchor.horz.percent) - w / 2);
1225 x = vpw / 2 + anchor.horz.distance - w / 2;
1231 // case A_EDGE: x = x - w; break;
1233 if(!anchor.top.type || anchor.vert.type == middleRelative)
1235 if(!anchor.bottom.type)
1237 if(anchor.vert.type == middleRelative)
1238 y = (int)(vph * (0.5 + anchor.vert.percent) - h / 2);
1240 y = vph / 2 + anchor.vert.distance - h / 2;
1246 // case A_EDGE: y = y - h; break;
1249 if((state == normal /*|| state == Hidden*/) && !OnMoving(&x, &y, w, h))
1257 SNAPDOWN(x, textCellW);
1258 SNAPDOWN(y, textCellH);
1270 if(anchored && style.fixed && style.isActiveClient)
1275 void UpdateCaret(bool forceUpdate, bool erase)
1277 static Window lastWindow = null;
1278 static int caretX, caretY, caretSize;
1280 if(guiApp && guiApp.caretOwner == this)
1282 int x = caretPos.x - scroll.x;
1283 int y = caretPos.y - scroll.y;
1285 if((erase || this.caretSize) &&
1286 x >= clientArea.left && x <= clientArea.right &&
1287 y >= clientArea.top && y <= clientArea.bottom)
1291 guiApp.interfaceDriver.SetCaret(
1292 x + absPosition.x + clientStart.x,
1293 y + absPosition.y + clientStart.y, this.caretSize);
1294 guiApp.caretEnabled = true;
1296 if(erase || lastWindow != this || caretX != x || caretY != y || caretSize != this.caretSize || forceUpdate)
1300 if(lastWindow != this)
1302 updateBox.left = x + 1;
1304 updateBox.right = x + 2;
1305 updateBox.bottom = y + this.caretSize - 1;
1309 updateBox.left = Min(x + 1, caretX + 1);
1310 updateBox.top = Min(y, caretY);
1311 updateBox.right = Max(x + 2, caretX + 2);
1312 updateBox.bottom = Max(y + this.caretSize - 1, caretY + caretSize - 1);
1315 guiApp.caretOwner.Update(updateBox);
1322 caretSize = this.caretSize;
1328 guiApp.interfaceDriver.SetCaret(0,0,0);
1329 guiApp.caretEnabled = false;
1335 void SetPosition(int x, int y, int w, int h, bool modifyArea, bool modifyThisArea, bool modifyClientArea)
1340 scrolledPos.x = position.x = x;
1341 scrolledPos.y = position.y = y;
1343 clientSize.w = size.w = w;
1344 clientSize.h = size.h = h;
1346 if(parent && !style.nonClient)
1348 //if(!style.fixed || style.isDocument)
1350 if(!style.dontScrollHorz) scrolledPos.x -= parent.scroll.x;
1351 if(!style.dontScrollVert) scrolledPos.y -= parent.scroll.y;
1355 clientStart.x = clientStart.y = 0;
1357 SetWindowArea(&clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1359 //if(!activeClient || activeClient.state != maximized)
1360 if(!noAutoScrollArea)
1362 // Check if scroll area must be modified
1363 if(guiApp && !guiApp.modeSwitching && (sbv || sbh))
1365 bool foundChild = false;
1367 int cw = clientSize.w;// + ((!sbv || sbv.range > 1) ? guiApp.currentSkin.VerticalSBW() : 0);
1368 int ch = clientSize.h;// + ((!sbh || sbh.rangw > 1) ? guiApp.currentSkin.HorizontalSBH() : 0);
1369 for(child = children.first; child; child = child.next)
1371 if(child.modifyVirtArea && !child.style.hidden && child.created && /*!child.anchored &&*/
1372 !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1374 if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == offset)
1375 w = Max(w, child.position.x + child.size.w);
1376 else if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == none)
1377 w = Max(w, Max(child.position.x, 0) + child.size.w);
1378 if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == offset)
1379 h = Max(h, child.position.y + child.size.h);
1380 else if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == none)
1381 h = Max(h, Max(child.position.y, 0) + child.size.h);
1386 if(foundChild && (w > cw || h > ch))
1388 //if((w > reqScrollArea.w) || (h > reqScrollArea.w))
1390 int stepX = sbStep.x, stepY = sbStep.y;
1391 // Needed to make snapped down position match the skin's check of client area
1392 // against realvirtual
1395 SNAPDOWN(stepX, textCellW);
1396 SNAPDOWN(stepY, textCellH);
1397 stepX = Max(stepX, textCellW);
1398 stepY = Max(stepY, textCellH);
1400 if(scrollFlags.snapX)
1402 if(scrollFlags.snapY)
1405 reqScrollArea.w = w;
1406 reqScrollArea.h = h;
1409 else if(reqScrollArea.w || reqScrollArea.h)
1411 reqScrollArea.w = 0;
1412 reqScrollArea.h = 0;
1413 SetScrollPosition(0,0);
1418 // Automatic MDI Client Scrolling Area Adjustment
1419 if(parent && !parent.noAutoScrollArea)
1421 if(modifyArea && modifyVirtArea /*&& !anchored*/ && (parent.sbv || parent.sbh) &&
1422 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient)
1424 Window parent = this.parent;
1425 int w = parent.reqScrollArea.w;
1426 int h = parent.reqScrollArea.h;
1428 if(stateAnchor.right.type == none && stateAnchor.left.type == offset)
1429 w = Max(w, position.x + size.w);
1430 else if(stateAnchor.right.type == none && stateAnchor.left.type == none)
1431 w = Max(w, Max(position.x, 0) + size.w);
1432 if(stateAnchor.bottom.type == none && stateAnchor.top.type == offset)
1433 h = Max(h, position.y + size.h);
1434 else if(stateAnchor.bottom.type == none && stateAnchor.top.type == none)
1435 h = Max(h, Max(position.y, 0) + size.h);
1437 if((w > parent.clientSize.w && w > parent.reqScrollArea.w) ||
1438 (h > parent.clientSize.h && h > parent.reqScrollArea.h))
1440 /*bool resize = false;
1441 int stepX = parent.sbStep.x, stepY = parent.sbStep.y;
1442 // Needed to make snapped down position match the skin's check of client area
1443 // against realvirtual
1446 SNAPDOWN(stepX, textCellW);
1447 SNAPDOWN(stepY, textCellH);
1448 stepX = Max(stepX, textCellW);
1449 stepY = Max(stepY, textCellH);
1451 if(parent.scrollFlags.snapX)
1453 if(parent.scrollFlags.snapY)
1455 if(parent.reqScrollArea.w != w || parent.reqScrollArea.h != h)
1457 parent.reqScrollArea.w = w;
1458 parent.reqScrollArea.h = h;*/
1460 // parent.UpdateScrollBars(true, true);
1461 parent.Position(parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1462 false, true, true, true, false, false);
1467 GetRidOfVirtualArea();
1471 UpdateScrollBars(modifyThisArea, false);
1472 else if(guiApp.currentSkin)
1475 &clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1477 if(sbv && (scrollFlags.dontHide || sbv.range > 1))
1478 clientSize.w -= guiApp.currentSkin.VerticalSBW();
1479 if(sbh && (scrollFlags.dontHide || sbh.range > 1))
1480 clientSize.h -= guiApp.currentSkin.HorizontalSBH();
1483 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1484 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1486 absPosition = scrolledPos;
1487 if(guiApp && guiApp.driver != null && guiApp.interfaceDriver)
1488 guiApp.interfaceDriver.OffsetWindow(this, &absPosition.x, &absPosition.y);
1490 if(this != guiApp.desktop && parent)
1492 absPosition.x += parent.absPosition.x;
1493 absPosition.y += parent.absPosition.y;
1494 if(!style.nonClient && this != guiApp.desktop)
1496 absPosition.x += parent.clientStart.x;
1497 absPosition.y += parent.clientStart.y;
1501 box = Box { 0, 0, size.w - 1, size.h - 1 };
1506 // Clip against parent's client area
1507 box.ClipOffset(against, scrolledPos.x, scrolledPos.y);
1509 // Compute client area in this window coordinate system
1510 clientArea.left = 0;
1512 clientArea.right = clientSize.w - 1;
1513 clientArea.bottom = clientSize.h - 1;
1515 // Clip against parent's client area
1517 clientArea.ClipOffset(against, scrolledPos.x + clientStart.x, scrolledPos.y + clientStart.y);
1521 //absPosition.x -= parent.clientStart.x;
1522 //absPosition.y -= parent.clientStart.y;
1525 // Adjust all children
1526 for(child = children.first; child; child = child.next)
1527 child.SetPosition(child.position.x, child.position.y, child.size.w, child.size.h, false, true, true);
1529 UpdateCaret(false, false);
1532 void GetRidOfVirtualArea(void)
1534 if(parent && !parent.destroyed && style.fixed &&
1535 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient &&
1536 parent.reqScrollArea.w && parent.reqScrollArea.h)
1538 if(!parent.noAutoScrollArea)
1542 for(child = children.first; child; child = child.next)
1544 if(child.modifyVirtArea && !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1546 if(child.position.x + child.size.w > parent.clientSize.w + ((!parent.sbv || parent.sbv.style.hidden) ? 0 : guiApp.currentSkin.VerticalSBW()) ||
1547 child.position.y + child.size.h > parent.clientSize.h + ((!parent.sbh || parent.sbh.style.hidden) ? 0 : guiApp.currentSkin.HorizontalSBH()))
1556 Window parent = this.parent;
1558 parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1559 false, true, true, true, false, false);
1561 parent.SetScrollArea(0,0,true);
1562 parent.SetScrollPosition(0,0);
1568 public void ExternalPosition(int x, int y, int w, int h)
1570 Position(x, y, w, h, false, true, true, true, false, false);
1573 // (w, h): Full window size
1574 bool Position(int x, int y, int w, int h, bool force, bool processAnchors, bool modifyArea, bool updateScrollBars, bool thisOnly, bool changeRootWindow)
1576 bool result = false;
1577 int oldCW = clientSize.w, oldCH = clientSize.h;
1578 bool clientResized, windowResized, windowMoved;
1580 bool realResized = size.w != w || size.h != h;
1582 // TOCHECK: This wasn't in ecere.dll
1583 //if(!parent) return true;
1584 if(destroyed) return false;
1586 windowMoved = position.x != x || position.y != y || force;
1588 // windowResized = realResized || force;
1589 windowResized = size.w != w || size.h != h || force;
1591 if(rootWindow != this && display && !display.flags.flipping && scrolledPos.x != MININT)
1597 scrolledPos.x - parent.clientStart.x + this.box.left, scrolledPos.y - parent.clientStart.y + this.box.top,
1598 scrolledPos.x - parent.clientStart.x + this.box.right,
1599 scrolledPos.y - parent.clientStart.y + this.box.bottom
1605 Box box { scrolledPos.x + this.box.left, scrolledPos.y + this.box.top, scrolledPos.x + this.box.right, scrolledPos.y + this.box.bottom};
1610 SetPosition(x, y, w, h, true, modifyArea, updateScrollBars);
1612 clientResized = oldCW != clientSize.w || oldCH != clientSize.h || force;
1614 if(display && rootWindow != this)
1617 if(guiApp && guiApp.windowMoving)
1619 if(guiApp.windowMoving.style.nonClient)
1620 guiApp.windowMoving.parent.SetMouseRangeToWindow();
1622 guiApp.windowMoving.parent.SetMouseRangeToClient();
1634 // Process Anchored Children
1638 for(child = children.first; child; child = child.next)
1641 ((child.stateAnchor.left.type != offset ||
1642 child.stateAnchor.top.type != offset ||
1643 child.stateAnchor.right.type != none ||
1644 child.stateAnchor.bottom.type != none) ||
1645 child.state == maximized || child.state == minimized))
1647 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor,
1649 // child.Position(x, y, w, h, false, true, true, true, false);
1650 // This must be true cuz otherwise we're gonna miss everything since we SetPosition recursively already
1651 child.Position(x, y, w, h, true, true, true, true, false, true /*false*/);
1657 // Is this gonna cause other problems? Commented out for the FileDialog end bevel bug
1658 //if(updateScrollBars)
1660 OnResize(clientSize.w, clientSize.h);
1662 if((clientResized || windowMoved) && created)
1663 OnPosition(position.x, position.y, clientSize.w, clientSize.h);
1665 if(guiApp.interimWindow && guiApp.interimWindow.master.rootWindow == this)
1667 Window master = guiApp.interimWindow.master;
1668 master.OnPosition(master.position.x, master.position.y, master.clientSize.w, master.clientSize.h);
1671 if(rootWindow == this && !is3D)
1675 x -= guiApp.desktop.absPosition.x;
1676 y -= guiApp.desktop.absPosition.y;
1678 //guiApp.Log("Position %s\n", caption);
1679 if(windowResized || windowMoved)
1680 if(display && !display.flags.memBackBuffer && changeRootWindow)
1681 guiApp.interfaceDriver.PositionRootWindow(this, x, y, w, h, windowMoved, windowResized); //realResized);
1683 if(!guiApp.fullScreenMode && this != guiApp.desktop && (windowResized || windowMoved))
1684 for(child = parent.children.first; child && child != this; child = child.next)
1685 if(child.rootWindow)
1686 guiApp.interfaceDriver.UpdateRootWindow(child.rootWindow);
1690 if(windowMoved || windowResized)
1692 display.Lock(true /*false*/);
1695 display.Position(absPosition.x, absPosition.y);
1696 //display.Position(absPosition.x + clientStart.x, absPosition.y + clientStart.y);
1699 // result = realResized ? display.Resize(size.w, size.h) : true;
1700 if(nativeDecorations)
1702 int w = clientSize.w, h = clientSize.h;
1703 if(hasMenuBar) h += skinMenuHeight;
1704 if(hasStatusBar) h += statusBarHeight;
1705 if(sbv && sbv.visible) w += sbv.size.w;
1706 if(sbh && sbh.visible) h += sbh.size.h;
1707 result = manageDisplay ? display.Resize(w, h) : true;
1710 result = manageDisplay ? display.Resize(size.w, size.h) : true;
1714 else if(clientResized)
1716 // --- Major Slow Down / Fix OpenGL Resizing Main Window Lag
1719 if(!guiApp.fullScreenMode && !guiApp.modeSwitching && this == rootWindow)
1723 if(windowMoved || windowResized)
1728 if(guiApp.driver && changeRootWindow)
1730 if(windowResized || windowMoved)
1731 if(!display || display.flags.memBackBuffer)
1732 guiApp.interfaceDriver.PositionRootWindow(this,
1733 x, y, w, h, windowMoved, windowResized);
1734 guiApp.interfaceDriver.UpdateRootWindow(this);
1736 for(child = children.first; child; child = child.next)
1738 if(child.is3D && child.created)
1740 // Copy Display Content
1741 child.display.displaySystem = display.displaySystem;
1742 child.display.window = display.window;
1743 child.display.current = display.current;
1744 child.display.width = display.width;
1745 child.display.height = display.height;
1746 child.display.driverData = display.driverData;
1747 child.display.mutex = null;
1758 void UpdateScrollBars(bool flag, bool fullThing)
1761 bool resizeH = false, resizeV = false;
1762 bool scrolled = false;
1763 rvw = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.w;
1764 rvh = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.h;
1766 if(destroyed) return;
1767 if(guiApp.currentSkin)
1769 MinMaxValue cw = 0, ch = 0;
1770 bool sbvVisible, sbhVisible;
1772 int positionH, positionV;
1774 // First get client area with no respect to scroll bars
1779 &clientStart.x, &clientStart.y, &size.w, &size.h, &cw, &ch);
1781 if(scrollFlags.dontHide)
1784 cw -= guiApp.currentSkin.VerticalSBW();
1786 ch -= guiApp.currentSkin.HorizontalSBH();
1788 // Update the scrollbar visibility
1794 sbh.disabled = rangeH <= 1;
1795 if(sbh.style.hidden)
1805 sbv.disabled = rangeV <= 1;
1806 if(sbv.style.hidden)
1814 // Then start off with horizontal scrollbar range
1817 positionH = sbh.thumbPosition;
1822 ch -= guiApp.currentSkin.HorizontalSBH();
1825 // Do the same for vertical scrollbar
1828 positionV = sbv.thumbPosition;
1834 cw -= guiApp.currentSkin.VerticalSBW();
1835 // Maybe we need to set the range on the horizontal scrollbar again
1840 sbh.Action(setRange, positionH, 0);
1841 if(rangeH <= 1 && sbh.range > 1)
1843 ch -= guiApp.currentSkin.HorizontalSBH();
1847 sbv.Action(setRange, positionV, 0);
1854 // Update the scrollbar visibility
1855 if(!scrollFlags.dontHide)
1857 if(sbh && ((rangeH <= 1 && !sbh.style.hidden) || (rangeH > 1 && sbh.style.hidden)))
1861 if(sbv && ((rangeV <= 1 && !sbv.style.hidden) || (rangeV > 1 && sbv.style.hidden)))
1868 if(guiApp.currentSkin)
1875 sbhVisible = sbh.style.hidden ? true : false;
1877 sbvVisible = sbv.style.hidden ? true : false;
1879 // Do our resize here
1880 if(flag && (resizeH || resizeV) && fullThing)
1882 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, false);
1887 OnResize(clientSize.w, clientSize.h);
1893 sbh.visible = sbhVisible;
1895 sbv.visible = sbvVisible;
1897 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1898 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1901 sbh.pageStep = clientSize.w;
1903 sbv.pageStep = clientSize.h;
1905 // Notify doesn't handle setRange anymore... process it here
1908 int positionH = sbh.thumbPosition;
1909 if(scroll.x != positionH)
1911 OnHScroll(setRange, positionH, 0);
1915 SNAPDOWN(positionH, textCellW);
1916 scroll.x = positionH;
1922 int seen = clientSize.w, total = reqScrollArea.w;
1925 if(scrollFlags.snapX)
1926 SNAPDOWN(seen, sbStep.x);
1928 if(!total) total = seen;
1929 range = total - seen + 1;
1931 range = Max(range, 1);
1933 if(x >= range) x = range - 1;
1935 if(scrollFlags.snapX)
1936 SNAPUP(x, sbStep.x);
1940 OnHScroll(setRange, x, 0);
1945 SNAPDOWN(x, textCellW);
1951 int positionV = sbv.thumbPosition;
1952 if(scroll.y != positionV)
1954 OnVScroll(setRange, positionV, 0);
1958 SNAPDOWN(positionV, textCellH);
1959 scroll.y = positionV;
1965 int seen = clientSize.h, total = reqScrollArea.h;
1968 if(scrollFlags.snapY)
1969 SNAPDOWN(seen, sbStep.y);
1971 if(!total) total = seen;
1972 range = total - seen + 1;
1973 range = Max(range, 1);
1975 if(y >= range) y = range - 1;
1977 if(scrollFlags.snapY)
1978 SNAPUP(y, sbStep.y);
1982 OnVScroll(setRange, y, 0);
1987 SNAPDOWN(y, textCellH);
1993 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
1996 for(child = children.first; child; child = child.next)
1998 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2001 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2002 child.Position(x, y, w, h, false, true, false, true, false, false);
2009 // Process Scrollbars
2011 if(sbh) // && !sbh.style.hidden
2013 sbh.Move(clientStart.x, clientStart.y + clientSize.h, clientSize.w,0);
2014 // Need to set the range again (should improve...) since the scrollbars didn't have
2015 // the right size when UpdateScrollArea set the range on it
2018 sbh.seen = clientSize.w;
2022 if(sbv) // && !sbv.state.hidden
2024 sbv.Move(clientStart.x + clientSize.w, clientStart.y, 0, clientSize.h);
2025 // Need to set the range again (should improve...) since the scrollbars didn't have
2026 // the right size when UpdateScrollArea set the range on it
2029 sbv.seen = clientSize.h;
2034 // TESTING THIS LOWER
2035 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2038 for(child = children.first; child; child = child.next)
2040 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2043 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2044 child.Position(x, y, w, h, false, true, false, true, false, false);
2050 bool MaximizeButtonClicked(Button button, int x, int y, Modifiers mods)
2052 SetState(maximized, false, mods);
2056 bool RestoreButtonClicked(Button button, int x, int y, Modifiers mods)
2058 SetState(normal, false, mods);
2062 bool MinimizeButtonClicked(Button button, int x, int y, Modifiers mods)
2064 SetState(minimized, false, mods);
2065 parent.CycleChildren(false, true, false, true);
2069 void ScrollBarNotification(ScrollBar control, ScrollBarAction action, int position, Key keyFlags)
2072 // Scroll bar notifications
2073 if(action != setRange)
2075 bool changed = false;
2079 if(scroll.x != position)
2081 OnHScroll(action, position, keyFlags);
2086 SNAPDOWN(position, textCellW);
2088 scroll.x = position;
2092 if(scroll.y != position)
2094 OnVScroll(action, position, keyFlags);
2099 SNAPDOWN(position, textCellH);
2101 scroll.y = position;
2105 bool childMove = false;
2106 for(child = children.first; child; child = child.next)
2108 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2111 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2112 child.Position(x, y, w, h, false, true, false, true, false, false);
2116 // Testing this patch out to solve MDI workspace redraw bugs
2117 // We were already supposed to be updating parent's affected area in Position() but it doesn't seem to be working
2118 // Scroll offsets to blame?
2122 UpdateCaret(false, false);
2126 // Testing this patch out to solve MDI workspace redraw bugs
2127 for(child = children.first; child; child = child.next)
2129 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2138 void CreateSystemChildren(void)
2140 Window parent = this;
2141 bool scrollBarChanged = false;
2142 bool hasClose = false, hasMaxMin = false;
2143 Point scroll = this.scroll;
2145 if(state == maximized && this.parent.menuBar)
2147 if(this.parent.activeClient == this)
2148 parent = this.parent.menuBar;
2155 if(style.hasClose) hasClose = true;
2156 if(style.hasMaximize || style.hasMinimize)
2163 if(sysButtons[2] && (!hasClose || sysButtons[2].parent != parent))
2165 sysButtons[2].Destroy(0);
2166 sysButtons[2] = null;
2168 if(sysButtons[1] && (!hasMaxMin || sysButtons[1].parent != parent))
2170 sysButtons[1].Destroy(0);
2171 sysButtons[1] = null;
2173 if(sysButtons[0] && (!hasMaxMin || sysButtons[0].parent != parent))
2175 sysButtons[0].Destroy(0);
2176 sysButtons[0] = null;
2179 if(hasClose && parent)
2186 parent, master = this,
2187 inactive = true, nonClient = true, visible = false;
2189 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
2195 if(this.parent == guiApp.desktop)
2196 sysButtons[2].hotKey = altF4;
2197 else if(style.isActiveClient)
2198 sysButtons[2].hotKey = ctrlF4;
2199 sysButtons[2].Create();
2202 sysButtons[2].symbol = 'X';
2203 sysButtons[2].disabled = !style.hasClose;
2206 if(hasMaxMin && parent)
2210 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2211 if(state == maximized)
2214 method = RestoreButtonClicked;
2220 method = MaximizeButtonClicked;
2228 parent, master = this,
2229 hotKey = altEnter, inactive = true, nonClient = true, visible = false
2231 sysButtons[1].Create();
2233 sysButtons[1].NotifyClicked = method;
2235 sysButtons[1].symbol = symbol;
2236 sysButtons[1].disabled = !style.hasMaximize;
2239 if(hasMaxMin && parent)
2243 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2244 if (state == minimized)
2247 method = RestoreButtonClicked;
2253 method = MinimizeButtonClicked;
2261 parent, master = this,
2262 hotKey = altM, inactive = true, nonClient = true, visible = false
2264 sysButtons[0].Create();
2266 sysButtons[0].NotifyClicked = method;
2268 sysButtons[0].symbol = symbol;
2269 sysButtons[0].disabled = !style.hasMinimize;
2272 // Create the scrollbars
2273 if(style.hasHorzScroll && !sbh)
2279 direction = horizontal,
2283 snap = scrollFlags.snapX,
2284 NotifyScrolling = ScrollBarNotification
2287 scrollBarChanged = true;
2289 else if(sbh && !style.hasHorzScroll)
2295 if(style.hasVertScroll && !sbv)
2301 direction = vertical,
2305 snap = scrollFlags.snapY,
2306 NotifyScrolling = ScrollBarNotification
2309 scrollBarChanged = true;
2311 else if(sbv && !style.hasVertScroll)
2316 if(scrollBarChanged)
2318 SetScrollLineStep(sbStep.x, sbStep.y);
2319 UpdateScrollBars(true, true);
2323 if(scrollBarChanged)
2325 if(sbh) sbh.thumbPosition = scroll.x;
2326 if(sbv) sbv.thumbPosition = scroll.y;
2330 void UpdateCaption(void)
2332 if(rootWindow == this)
2335 FigureCaption(caption);
2336 guiApp.interfaceDriver.SetRootWindowCaption(this, caption);
2338 UpdateDecorations();
2341 if(parent.rootWindow == parent && parent.activeClient == this) // Added this last check
2344 parent.FigureCaption(caption);
2345 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
2347 parent.UpdateDecorations();
2351 void UpdateActiveDocument(Window previous)
2353 Window activeClient = this.activeClient;
2354 Window activeChild = this.activeChild;
2361 activeClient.CreateSystemChildren();
2363 previous.CreateSystemChildren();
2374 if(activeClient && activeClient.menu && activeClient.state != minimized)
2378 //activeClient.menu.Clean(activeClient);
2379 menu.Merge(activeClient.menu, true, activeClient);
2383 if(activeChild && activeChild != activeClient && activeChild.menu && activeChild.state != minimized)
2386 menu.Merge(activeChild.menu, true, activeChild);
2389 // Build window list
2392 Menu windowMenu = menu.FindMenu("Window");
2397 for(id = 0, cycle = activeClient.cycle; cycle && id<10;)
2400 Window document = cycle.data;
2401 if(!document.style.nonClient && document.style.isActiveClient && document.visible)
2403 char name[2048], caption[2048];
2404 document.FigureCaption(caption);
2405 sprintf(name, "%d %s", id+1, caption);
2406 windowMenu.AddDynamic(MenuItem
2408 copyText = true, text = name, hotKey = Key { k1 + id }, id = id++,
2409 NotifySelect = MenuWindowSelectWindow
2413 if(activeClient.cycle == cycle) break;
2418 if((!previous && activeClient) || !activeClient)
2424 item = menu.FindItem(MenuWindowCloseAll, 0);
2425 if(item) item.disabled = false;
2426 item = menu.FindItem(MenuWindowNext, 0);
2427 if(item) item.disabled = false;
2428 item = menu.FindItem(MenuWindowPrevious, 0);
2429 if(item) item.disabled = false;
2430 item = menu.FindItem(MenuWindowCascade, 0);
2431 if(item) item.disabled = false;
2432 item = menu.FindItem(MenuWindowTileHorz, 0);
2433 if(item) item.disabled = false;
2434 item = menu.FindItem(MenuWindowTileVert, 0);
2435 if(item) item.disabled = false;
2436 item = menu.FindItem(MenuWindowArrangeIcons, 0);
2437 if(item) item.disabled = false;
2438 item = menu.FindItem(MenuWindowWindows, 0);
2439 if(item) item.disabled = false;
2442 item = menu.FindItem(MenuFileClose, 0);
2443 if(item) item.disabled = !activeClient || !activeClient.style.hasClose;
2444 item = menu.FindItem(MenuFileSaveAll, 0);
2445 if(item) item.disabled = numDocuments < 1;
2447 // This is called again for a child window change, with same active client
2448 OnActivateClient(activeClient, previous);
2451 void _ShowDecorations(Box box, bool post)
2453 if(rootWindow == this && nativeDecorations) return;
2454 if(visible && this != guiApp.desktop)
2456 Surface surface = RedrawFull(box);
2460 FigureCaption(caption);
2463 ShowDecorations(captionFont.font,
2466 active, //parent.activeClient == this
2467 guiApp.windowMoving == this);
2469 PreShowDecorations(captionFont.font,
2472 active, //parent.activeClient == this
2473 guiApp.windowMoving == this);
2480 void UpdateExtent(Box refresh)
2482 Surface surface = null;
2484 if(!manageDisplay) { OnRedraw(null);return; }
2485 _ShowDecorations(refresh, false);
2487 surface = Redraw(refresh);
2488 // Opaque background: just fill before EW_REDRAW (clear?)
2491 surface.SetBackground(background);
2492 surface.SetForeground(foreground);
2493 surface.DrawingChar(' ');
2494 if(this == rootWindow)
2496 if(style.drawBehind || background.a)
2497 surface.Clear(colorBuffer);
2499 else if(background.a)
2503 background.color = { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2504 surface.SetForeground((background.color.r > 128 || background.color.g > 128) ? black : white);
2507 if(display.flags.alpha && background.a < 255 && background)
2509 surface.Area(0,0,clientSize.w, clientSize.h);
2510 /*if(style.clearDepthBuffer)
2511 surface.Clear(depthBuffer);*/
2513 else if(/*style.clearDepthBuffer || */background.a)
2515 // surface.Clear((style.clearDepthBuffer ? depthBuffer : 0) | (background.a ? colorBuffer : 0));
2516 surface.Clear(colorBuffer);
2521 surface.TextFont(usedFont.font);
2522 surface.TextOpacity(false);
2526 // Draw the caret ...
2527 if(!disabled && this == guiApp.caretOwner && guiApp.caretEnabled /*&& !guiApp.interimWindow*/ && !guiApp.currentSkin.textMode)
2529 // surface.SetBackground(0xFFFFFF - background.color);
2530 surface.SetBackground(~background.color);
2532 caretPos.x - scroll.x + 1, caretPos.y - scroll.y,
2533 caretPos.x - scroll.x + 2, caretPos.y - scroll.y + caretSize - 1);
2539 void DrawOverChildren(Box refresh)
2541 Surface surface = Redraw(refresh);
2545 surface.DrawingChar(' ');
2546 surface.SetBackground(background);
2547 surface.SetForeground(foreground);
2549 surface.TextFont(usedFont.font);
2550 surface.TextOpacity(false);
2552 OnDrawOverChildren(surface);
2557 _ShowDecorations(refresh, true);
2560 void ComputeClipExtents(void)
2563 Extent clipExtent { /*first = -1, last = -1, free = -1*/ };
2565 clipExtent.Copy(this.clipExtent);
2567 for(child = children.last; child; child = child.prev)
2569 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2571 bool opaque = child.IsOpaque(); // TODO: acess background directly
2572 int dx = child.absPosition.x - absPosition.x, dy = child.absPosition.y - absPosition.y;
2574 child.clipExtent.Copy(clipExtent);
2575 child.clipExtent.Offset(-dx, -dy);
2576 child.clipExtent.IntersectBox(child.box);
2578 child.ComputeClipExtents();
2580 if(opaque && !child.style.nonClient)
2582 // Adjust the box for the parent:
2583 Box box { child.box.left + dx, child.box.top + dy, child.box.right + dx, child.box.bottom + dy };
2584 clipExtent.ExcludeBox(box, rootWindow.tempExtents[0]);
2589 // ??? Only do this for overlapped window or if parent has with clip children flag
2591 // Do this if window has clip children flag on (default false?)
2592 // this.clipExtent = clipExtent;
2594 clipExtent.Free(null);
2597 void ComputeRenderAreaNonOpaque(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2599 bool opaque = IsOpaque();
2601 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2602 if(rootWindow.nativeDecorations)
2604 offsetX -= rootWindow.clientStart.x;
2605 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2609 for(child = children.last; child; child = child.prev)
2611 ColorAlpha background = *(ColorAlpha *)&child.background;
2612 bool opaque = child.IsOpaque();
2613 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2617 // Adjust renderArea to the root window level
2618 Extent * renderArea = &rootWindow.tempExtents[1];
2620 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2621 if(child.rootWindow.nativeDecorations)
2623 offsetX -= child.rootWindow.clientStart.x;
2624 offsetY -= child.rootWindow.clientStart.y - (child.rootWindow.hasMenuBar ? skinMenuHeight : 0);
2628 Extent childRenderArea;
2630 if(backBufferUpdate != null)
2632 childRenderArea.Copy(backBufferUpdate);
2633 childRenderArea.Offset(-offsetX, -offsetY);
2636 childRenderArea.Copy(child.dirtyArea);
2638 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2639 renderArea.Copy(dirtyExtent);
2640 renderArea.Offset(-offsetX, -offsetY);
2641 childRenderArea.Union(renderArea);
2644 // Intersect with the clip extent
2645 childRenderArea.Intersection(child.clipExtent);
2648 renderArea->Copy(child.dirtyArea /*childRenderArea*/);
2649 renderArea->Offset(offsetX, offsetY);
2650 dirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2651 // overDirtyExtent.Union(renderArea);
2652 renderArea->Empty();
2653 // childRenderArea.Free();
2655 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2660 for(child = children.last; child; child = child.prev)
2662 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2664 child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2669 void ComputeRenderArea(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2671 bool opaque = IsOpaque();
2672 Extent * dirtyExtentWindow = &rootWindow.tempExtents[1];
2674 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2675 if(rootWindow.nativeDecorations)
2677 offsetX -= rootWindow.clientStart.x;
2678 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2682 for(child = children.last; child; child = child.prev)
2684 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2686 ColorAlpha background = *(ColorAlpha *)&child.background;
2687 bool opaque = child.IsOpaque();
2688 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2692 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2693 // Adjust renderArea to the root window level
2695 renderArea.Copy(child.dirtyArea);
2696 renderArea.Offset(offsetX, offsetY);
2697 dirtyExtent.Union(renderArea);
2698 overDirtyExtent.Union(renderArea);
2704 for(child = children.last; child; child = child.prev)
2706 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2708 child.ComputeRenderArea(dirtyExtent, overDirtyExtent, backBufferUpdate);
2712 if(backBufferUpdate != null)
2714 renderArea.Copy(backBufferUpdate);
2715 renderArea.Offset(-offsetX, -offsetY);
2717 overRenderArea.Copy(backBufferUpdate);
2718 overRenderArea.Offset(-offsetX, -offsetY);
2724 renderArea.Copy(dirtyArea);
2726 overRenderArea.Copy(dirtyArea);
2729 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2730 dirtyExtentWindow->Copy(dirtyExtent);
2731 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2732 renderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2733 dirtyExtentWindow->Empty();
2735 // Intersect with the clip extent
2736 renderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2739 if(renderArea.count > 10)
2742 printf("\nToo many extents (%d):\n", renderArea.count);
2744 //extent.UnionBox({ 112, 6, 304, 7 }, rootWindow.tempExtents[0]);
2745 //extent.UnionBox({ 112, 8, 304, 17 }, rootWindow.tempExtents[0]);
2750 for(c = 0; c<10; c++)
2753 FASTLIST_LOOP(renderArea, extentBox)
2755 extent.UnionBox(extentBox.box, rootWindow.tempExtents[0]);
2757 renderArea.Copy(extent);
2759 FASTLIST_LOOP(renderArea, extentBox)
2762 printf("(%d, %d) - (%d, %d)\n",
2763 extentBox.box.left, extentBox.box.top,
2764 extentBox.box.right, extentBox.box.bottom);
2768 printf("\nNow %d\n", renderArea.count);
2774 // WHY WAS THIS COMMENTED ??
2776 // Add extent forced by DrawOverChildren to the dirty area, adjusting dirty extent to the window
2777 dirtyExtentWindow->Copy(overDirtyExtent);
2778 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2779 overRenderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2780 dirtyExtentWindow->Empty();
2782 // Intersect with the clip extent
2783 overRenderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2789 if(scrollExtent.count)
2791 // Subtract render extent from scrolling extent
2792 scrollExtent.Exclusion(renderArea, rootWindow.tempExtents[0]);
2794 if(backBufferUpdate == null)
2796 Extent * dirty = &rootWindow.tempExtents[3];
2799 // Intersect scrolling extent with clip extent
2800 scrollExtent.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2802 // offset this scroll to be at the root window level
2803 scrollExtent.Offset(offsetX, offsetY);
2804 // Add area that was scrolled to the dirty extents of the back buffer
2805 rootWindow.dirtyBack.Union(scrollExtent, rootWindow.tempExtents[0]);
2809 // Will need scrolledArea.x & scrolledArea.y to support multiple scrolls
2810 FASTLIST_LOOP(scrollExtent, scrollBox)
2811 display.Scroll(scrollBox.box, scrolledArea.x, scrolledArea.y, dirty);
2816 scrollExtent.Empty();
2818 // Add the exposed extent to the window render area
2819 dirty->Offset(-offsetX, -offsetY);
2820 renderArea.Union(dirty, rootWindow.tempExtents[0]);
2825 // Subtract the window's box from the transparency forced extent
2826 dirtyExtent.ExcludeBox({box.left + offsetX, box.top + offsetY, box.right + offsetX, box.bottom + offsetY }, rootWindow.tempExtents[0]);
2832 renderArea.Copy(this.renderArea);
2833 renderArea.Offset(offsetX, offsetY);
2834 dirtyExtent.Union(renderArea);
2840 Extent renderArea { };
2842 renderArea.Copy(overRenderArea);
2843 renderArea.Offset(offsetX, offsetY);
2844 overDirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2849 if(backBufferUpdate != null)
2851 // Remove render area from dirty area
2852 dirtyArea.Exclusion(renderArea, rootWindow.tempExtents[0]);
2854 dirtyArea.Exclusion(overRenderArea, rootWindow.tempExtents[0]);
2861 // Remove the window render area from the dirty extents of the back buffer
2862 rootWindow.dirtyBack.Exclusion(renderArea);
2866 void Render(Extent updateExtent)
2870 Window rootWindow = this.rootWindow;
2871 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2872 if(rootWindow.nativeDecorations)
2874 offsetX -= rootWindow.clientStart.x;
2875 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2878 if(rootWindow.fullRender)
2887 background = Color { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2888 foreground = (background.color.r > 128 || background.color.g > 128) ? black : white;
2893 /*if(renderArea.count)
2894 printf("\n\nRendering %s (%x):\n------------------------------------------\n", _class.name, this);*/
2897 FASTLIST_LOOP(renderArea, extentBox)
2899 Box box = extentBox.box;
2902 /*printf("(%d, %d) - (%d, %d)\n",
2903 extentBox.box.left, extentBox.box.top,
2904 extentBox.box.right, extentBox.box.bottom);*/
2909 box.left += offsetX;
2911 box.right += offsetX;
2912 box.bottom += offsetY;
2914 if(updateExtent != null)
2915 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
2919 for(child = children.first; child; child = child.next)
2920 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && !child.nonClient)
2921 child.Render(updateExtent);
2923 if(rootWindow.fullRender)
2924 DrawOverChildren(box);
2927 // TO DO: There's an issue about draw over children...
2928 // TO DO: Don't wanna go through this if method isn't used
2929 FASTLIST_LOOP(/*renderArea */overRenderArea, extentBox)
2931 Box box = extentBox.box;
2933 DrawOverChildren(box);
2935 box.left += offsetX;
2937 box.right += offsetX;
2938 box.bottom += offsetY;
2940 if(updateExtent != null)
2941 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
2944 for(child = children.first; child; child = child.next)
2945 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && child.nonClient)
2946 child.Render(updateExtent);
2949 overRenderArea.Empty();
2952 public void UpdateDisplay(void)
2954 if(!manageDisplay) { OnRedraw(null);return; }
2955 if(rootWindow && this != rootWindow)
2956 rootWindow.UpdateDisplay();
2959 Extent dirtyExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be forced due to transparency
2960 Extent overExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that forced for DrawOverChildren
2963 dirtyExtent.Clear();
2966 clipExtent.AddBox(box);
2968 display.StartUpdate();
2970 if(!rootWindow.fullRender)
2972 ComputeClipExtents();
2973 ComputeRenderAreaNonOpaque(dirtyExtent, overExtent, null);
2974 ComputeRenderArea(dirtyExtent, overExtent, null);
2977 clipExtent.Free(null);
2979 dirtyExtent.Free(null);
2980 overExtent.Free(null);
2982 if(display.flags.flipping)
2985 display.Update(null);
2989 Extent updateExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be updated
2990 updateExtent.Clear();
2992 Render(updateExtent);
2994 updateExtent.UnionBox(this.box, tempExtents[0]);
2997 //printf("\n\nUpdate:\n------------------------------------------\n");
3000 FASTLIST_LOOP(updateExtent, extentBox)
3003 /*printf("Updating (%d, %d) - (%d, %d)\n",
3004 extentBox.box.left, extentBox.box.top,
3005 extentBox.box.right, extentBox.box.bottom);*/
3008 display.Update(extentBox.box);
3011 updateExtent.Free(null);
3014 display.EndUpdate();
3022 void UpdateBackDisplay(Box box)
3028 Extent intersection { /*first = -1, last = -1, free = -1*/ };
3030 //printf("UpdateBackDisplay going through!\n");
3031 display.StartUpdate();
3035 intersection.Copy(dirtyBack);
3036 intersection.IntersectBox(box);
3038 dirtyExtent.Clear();
3041 clipExtent.AddBox(box);
3043 if(!rootWindow.fullRender)
3045 ComputeClipExtents();
3046 ComputeRenderArea(dirtyExtent, overExtent, intersection);
3049 clipExtent.Free(null);
3051 intersection.Free(null);
3052 dirtyExtent.Free(null);
3053 overExtent.Free(null);
3058 if(display.flags.flipping)
3059 display.Update(null);
3062 rootWindow.display.Update(box);
3065 display.EndUpdate();
3069 dirtyBack.ExcludeBox(box, rootWindow.tempExtents[0]);
3070 if(dirtyBack.count > MAX_DIRTY_BACK)
3072 BoxItem extentBox, next;
3073 BoxItem first = (BoxItem)ACCESS_ITEM(dirtyBack, dirtyBack.first);
3074 FASTLIST_LOOPN(dirtyBack, extentBox, next)
3076 if(extentBox != first)
3078 if(extentBox.box.left < first.box.left)
3079 first.box.left = extentBox.box.left;
3080 if(extentBox.box.top < first.box.top)
3081 first.box.top = extentBox.box.top;
3082 if(extentBox.box.right > first.box.right)
3083 first.box.right = extentBox.box.right;
3084 if(extentBox.box.bottom > first.box.bottom)
3085 first.box.bottom = extentBox.box.bottom;
3086 dirtyBack.Delete(extentBox);
3095 // --- Window positioning ---
3096 // --- Window identification ---
3098 // Returns window at position "Position"
3099 Window GetAtPosition(int x, int y, bool clickThru, bool acceptDisabled, Window last)
3101 Window child, result = null;
3103 box.left += absPosition.x;
3104 box.right += absPosition.x;
3105 box.top += absPosition.y;
3106 box.bottom += absPosition.y;
3108 if(!destroyed && visible && (acceptDisabled || !disabled))
3110 int lx = x - absPosition.x;
3111 int ly = y - absPosition.y;
3112 if(IsInside(lx, ly))
3113 // if(box.IsPointInside(Point{x, y}))
3115 if(!clickThru || !style.clickThrough) result = (this == last) ? null : this;
3116 // If the window is disabled, stop looking in children (for acceptDisabled mode)
3119 for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
3121 if(child != statusBar && child.rootWindow == rootWindow)
3123 Window childResult = child.GetAtPosition(x, y, clickThru, acceptDisabled, last);
3130 for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
3132 if(child != statusBar && child.rootWindow == rootWindow)
3134 Window childResult = child.GetAtPosition(x, y, false, acceptDisabled, last);
3146 Window FindModal(void)
3148 Window modalWindow = this, check;
3149 Window check2 = null;
3150 for(check = this; check.master; check = check.master)
3152 if(check.master.modalSlave && check.master.modalSlave.created && check != check.master.modalSlave)
3154 modalWindow = check.master.modalSlave;
3155 check = modalWindow;
3157 // TESTING THIS FOR DROPBOX...
3158 if(!rootWindow || !rootWindow.style.interim)
3160 for(check2 = check; check2.activeChild; check2 = check2.activeChild)
3162 if(check2.modalSlave && check2.modalSlave.created)
3164 modalWindow = check2.modalSlave;
3172 if(modalWindow == this)
3174 for(check = this; check.activeChild; check = check.activeChild)
3176 if(check.modalSlave)
3178 modalWindow = check.modalSlave;
3184 for(; modalWindow.modalSlave && modalWindow.modalSlave.created; modalWindow = modalWindow.modalSlave);
3185 return (modalWindow == this || this == guiApp.interimWindow || IsDescendantOf(modalWindow)) ? null : modalWindow;
3188 void StopMoving(void)
3190 if(this == guiApp.windowMoving)
3192 guiApp.windowMoving = null;
3193 UpdateDecorations();
3194 SetMouseRange(null);
3197 if(rootWindow.active)
3198 guiApp.interfaceDriver.StopMoving(rootWindow);
3201 guiApp.resizeX = guiApp.resizeY = guiApp.resizeEndX = guiApp.resizeEndY = false;
3202 guiApp.windowIsResizing = false;
3206 void SelectMouseCursor(void)
3211 Window cursorWindow = null;
3212 bool rx, ry, rex, rey;
3214 guiApp.desktop.GetMousePosition(&x, &y);
3215 mouseWindow = rootWindow ? rootWindow.GetAtPosition(x,y, true, false, null) : null;
3217 if((guiApp.windowMoving && !guiApp.windowIsResizing) || guiApp.windowScrolling)
3218 guiApp.SetCurrentCursor(guiApp.systemCursors[moving]);
3219 else if(mouseWindow)
3221 modalWindow = mouseWindow.FindModal();
3222 x -= mouseWindow.absPosition.x;
3223 y -= mouseWindow.absPosition.y;
3224 if(guiApp.windowIsResizing)
3226 rex = guiApp.resizeEndX;
3227 rey = guiApp.resizeEndY;
3228 rx = guiApp.resizeX;
3229 ry = guiApp.resizeY;
3230 if((rex && rey) || (rx && ry))
3231 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
3232 else if((rex && ry) || (rx && rey))
3233 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
3234 else if((ry || rey) && (!rx && !rex))
3235 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
3236 else if((rx || rex) && (!ry && !rey))
3237 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
3239 else if(!modalWindow && !guiApp.windowCaptured &&
3240 mouseWindow.IsMouseResizing(x, y, mouseWindow.size.w, mouseWindow.size.h,
3241 &rx, &ry, &rex, &rey))
3243 if((rex && rey) || (rx && ry))
3244 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
3245 else if((rex && ry) || (rx && rey))
3246 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
3247 else if((ry || rey) && (!rx && !rex))
3248 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
3249 else if((rx || rex) && (!ry && !rey))
3250 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
3252 else if(!guiApp.windowCaptured && !modalWindow && !guiApp.interimWindow)
3254 if(!mouseWindow.clientArea.IsPointInside({x - mouseWindow.clientStart.x, y - mouseWindow.clientStart.y}))
3255 cursorWindow = mouseWindow.parent;
3257 cursorWindow = mouseWindow;
3259 else if(!guiApp.interimWindow)
3260 cursorWindow = guiApp.windowCaptured;
3263 for(; !cursorWindow.cursor && !cursorWindow.style.nonClient; cursorWindow = cursorWindow.parent);
3264 guiApp.SetCurrentCursor(cursorWindow.cursor ? cursorWindow.cursor : guiApp.systemCursors[arrow]);
3266 else if(modalWindow)
3268 guiApp.SetCurrentCursor(guiApp.systemCursors[arrow]);
3270 else if(guiApp.interimWindow)
3272 if(guiApp.interimWindow.cursor)
3273 guiApp.SetCurrentCursor(guiApp.interimWindow.cursor);
3275 guiApp.SetCurrentCursor(mouseWindow.cursor ? mouseWindow.cursor : guiApp.systemCursors[arrow]);
3280 // --- State based input ---
3281 bool AcquireInputEx(bool state)
3286 guiApp.interfaceDriver.GetMousePosition(&guiApp.acquiredMouseX, &guiApp.acquiredMouseY);
3287 guiApp.interfaceDriver.SetMousePosition(clientSize.w/2 + absPosition.x, clientSize.h/2 + absPosition.y);
3289 result = guiApp.interfaceDriver.AcquireInput(rootWindow, state);
3291 guiApp.acquiredWindow = state ? this : null;
3294 SetMouseRangeToClient();
3295 guiApp.interfaceDriver.SetMouseCursor((SystemCursor)-1);
3300 SelectMouseCursor();
3302 if(!state) guiApp.interfaceDriver.SetMousePosition(guiApp.acquiredMouseX, guiApp.acquiredMouseY);
3306 // --- Window activation ---
3307 bool PropagateActive(bool active, Window previous, bool * goOnWithActivation, bool direct)
3310 if(!parent || !parent.style.inactive)
3312 Window parent = this.parent;
3315 if(rootWindow == this)
3316 Log(active ? "active\n" : "inactive\n");
3319 // Testing this here...
3320 if(!parent || parent == guiApp.desktop || parent.active)
3322 this.active = active;
3325 // TESTING THIS HERE
3326 UpdateDecorations();
3327 if(result = OnActivate(active, previous, goOnWithActivation, direct) && *goOnWithActivation && master)
3328 result = NotifyActivate(master, this, active, previous);
3331 this.active = !active;
3336 if(!parent || parent == guiApp.desktop || parent.active)
3338 this.active = active;
3340 AcquireInputEx(active);
3345 if(guiApp.caretOwner)
3349 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 1,
3350 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + 1,
3351 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 2,
3352 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + guiApp.caretOwner.caretSize - 1
3354 guiApp.caretOwner.Update(extent);
3357 if(visible || !guiApp.caretOwner)
3358 guiApp.caretOwner = this;
3359 UpdateCaret(false, false);
3365 this.active = false;
3367 AcquireInputEx(active);
3369 if(!active && guiApp.caretOwner == this)
3371 UpdateCaret(false, true);
3372 guiApp.caretOwner = null;
3373 guiApp.interfaceDriver.SetCaret(0,0,0);
3374 guiApp.caretEnabled = false;
3379 if(!active && parent && parent.activeChild && parent.activeChild != this)
3380 if(!parent.activeChild.PropagateActive(false, previous, goOnWithActivation, true) || !*goOnWithActivation)
3386 if(!active && menuBar)
3389 menuBar.OnActivate(false, null, &goOn, true);
3390 menuBar.NotifyActivate(menuBar.master, menuBar, false, null);
3394 if(!activeChild.PropagateActive(active, previous, goOnWithActivation, false) || !*goOnWithActivation)
3403 void ConsequentialMouseMove(bool kbMoving)
3407 if(kbMoving || !guiApp.windowMoving)
3411 if(rootWindow == guiApp.desktop || rootWindow.parent == guiApp.desktop)
3413 guiApp.interfaceDriver.GetMousePosition(&x, &y);
3415 if(guiApp.windowMoving || rootWindow.GetAtPosition(x, y, true, false, null))
3416 rootWindow.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove, x, y, &mods, true, false);
3422 bool IsDescendantOf(Window ancestor)
3425 for(window = this; window && window != ancestor; window = window.parent);
3426 return window == ancestor;
3429 bool IsSlaveOf(Window master)
3432 for(window = this; window && window != master; window = window.master);
3433 return window == master;
3436 bool ActivateEx(bool active, bool activateParent, bool moveInactive, bool activateRoot, Window external, Window externalSwap)
3440 if(this && !destroyed /*&& state != Hidden*/)
3442 Window swap = externalSwap;
3450 if(activateParent &&
3451 (parent.activeChild != this ||
3452 (guiApp.interimWindow && !IsDescendantOf(guiApp.interimWindow))) &&
3453 active && style.modal &&
3454 parent != master && master)
3455 master.ActivateEx(true, true, false, activateRoot, external, externalSwap);
3461 bool real = parent.activeChild != this;
3463 // TEST THIS: New activateParent check here!!! CAUSED MENUS NOT GOING AWAY
3464 if(/*activateParent && */guiApp.interimWindow &&
3465 !IsDescendantOf(guiApp.interimWindow) &&
3466 !IsSlaveOf(guiApp.interimWindow))
3468 Window interimWindow = guiApp.interimWindow;
3469 while(interimWindow && interimWindow != this)
3471 Window master = interimWindow.master;
3473 guiApp.interimWindow = null;
3474 if(guiApp.caretOwner)
3475 guiApp.caretOwner.UpdateCaret(false, false);
3477 incref interimWindow;
3478 if(!interimWindow.PropagateActive(false, this, &goOn, true))
3483 delete interimWindow;
3484 interimWindow = (master && master.style.interim) ? master : null;
3489 guiApp.interimWindow = this;
3490 /*guiApp.interfaceDriver.SetCaret(0,0,0);
3491 guiApp.caretEnabled = false;*/
3492 UpdateCaret(false, true);
3497 bool acquireInput = false;
3499 parent.activeChild &&
3500 parent.activeChild.state == maximized &&
3501 parent != guiApp.desktop;
3503 if(!style.inactive) // (!style.isRemote || parent.active || parent.style.hidden))
3508 swap = parent.activeChild;
3509 if(swap && swap.destroyed) swap = null;
3510 if(swap && swap != this)
3513 if(!swap.PropagateActive(false, this, &goOn, true))
3514 swap = parent.activeChild;
3525 if(!parent || parent.activeChild != this || style.interim)
3528 result = PropagateActive(true, swap, &goOn, true);
3529 if(!result && !goOn)
3534 acquireInput = true;
3538 if(style.hasMaximize && parent != guiApp.desktop)
3541 SetState(maximized, false, 0);
3542 else if(state != maximized)
3545 for(child = parent.children.first; child; child = child.next)
3547 if(this != child && child.state == maximized)
3548 child.SetState(normal, false, 0);
3555 if(!style.inactive && !style.interim /*&& (!style.isRemote || parent.active || parent.style.hidden)*/)
3557 Window previous = parent.activeClient;
3558 parent.activeChild = this;
3559 if(!style.nonClient /*&& style.isActiveClient*/)
3561 if(style.isActiveClient && !style.hidden)
3562 parent.activeClient = this;
3563 parent.UpdateActiveDocument(previous);
3568 //if(!style.isRemote)
3570 if(rootWindow != this)
3572 if(activateParent && parent && !parent.active /*parent != parent.parent.activeChild*/)
3573 parent.ActivateEx(true, true, moveInactive, activateRoot, external, externalSwap);
3575 else if(!guiApp.fullScreenMode)
3577 Window modalRoot = FindModal();
3578 if(!modalRoot) modalRoot = this;
3579 if(!modalRoot.isForegroundWindow)
3581 modalRoot.isForegroundWindow = true;
3582 // To check : Why is parent null?
3583 if(activateRoot && modalRoot.parent && !modalRoot.parent.display && external != modalRoot)
3585 guiApp.interfaceDriver.ActivateRootWindow(modalRoot);
3587 modalRoot.isForegroundWindow = false;
3592 if(result && real && (!style.inactive || moveInactive) && parent)
3594 Window last = parent.children.last;
3596 if(!style.stayOnTop)
3597 for(; last && last.style.stayOnTop; last = last.prev);
3599 parent.children.Move(this, last);
3601 // Definitely don't want that: why not?
3605 parent.childrenOrder.Move(order, parent.childrenOrder.last);
3611 if(!parent || style.interim || (parent.activeChild == this && !style.inactive))
3618 parent.activeChild = null;
3619 if(!style.nonClient /*&& style.isActiveClient*/)
3621 Window previous = parent.activeClient;
3622 if(style.isActiveClient)
3623 parent.activeClient = null;
3624 parent.UpdateActiveDocument(previous);
3628 if(this == guiApp.interimWindow)
3630 guiApp.interimWindow = null;
3631 if(guiApp.caretOwner)
3632 guiApp.caretOwner.UpdateCaret(false, false);
3634 if(!PropagateActive(false, externalSwap, &goOn, true) || !goOn)
3641 if(!active || !swap)
3642 UpdateDecorations();
3644 swap.UpdateDecorations();
3646 if(active && rootWindow != this)
3647 ConsequentialMouseMove(false);
3654 // --- Input Messages ---
3655 void ::UpdateMouseMove(int mouseX, int mouseY, bool consequential)
3657 static bool reEntrancy = false;
3658 if(reEntrancy) return;
3662 guiApp.cursorUpdate = true;
3663 if(guiApp.windowScrolling && !consequential)
3665 guiApp.windowScrolling.SetScrollPosition(
3666 (guiApp.windowScrolling.sbh) ?
3667 (guiApp.windowScrollingBefore.x - mouseX + guiApp.windowScrollingStart.x) : 0,
3668 (guiApp.windowScrolling.sbv) ?
3669 (guiApp.windowScrollingBefore.y - mouseY + guiApp.windowScrollingStart.y) : 0);
3671 if(guiApp.windowMoving)
3673 if(mouseX != guiApp.movingLast.x || mouseY != guiApp.movingLast.y)
3675 Window window = guiApp.windowMoving;
3677 int w = window.size.w;
3678 int h = window.size.h;
3683 rx = mouseX - guiApp.windowMovingStart.x;
3684 ry = mouseY - guiApp.windowMovingStart.y;
3687 window.GetDecorationsSize(&ew, &eh);
3689 if(guiApp.windowIsResizing)
3691 x = window.scrolledPos.x;
3692 y = window.scrolledPos.y;
3696 aw = Max(guiApp.windowResizingBefore.w - rx,window.skinMinSize.w);
3697 rx = guiApp.windowResizingBefore.w - aw;
3698 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3699 w = guiApp.windowResizingBefore.w - rx;
3703 ah = Max(guiApp.windowResizingBefore.h - ry,window.skinMinSize.h);
3704 ry = guiApp.windowResizingBefore.h - ah;
3705 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3706 ry = Max(ry, -guiApp.windowMovingBefore.y);
3707 h = guiApp.windowResizingBefore.h - ry;
3709 if(guiApp.resizeEndX)
3711 w = guiApp.windowResizingBefore.w + rx;
3714 if(guiApp.resizeEndY) h = guiApp.windowResizingBefore.h + ry;
3722 w = Max(w, window.minSize.w);
3723 h = Max(h, window.minSize.h);
3724 w = Min(w, window.maxSize.w);
3725 h = Min(h, window.maxSize.h);
3727 if(!window.OnResizing(&w, &h))
3729 w = window.clientSize.w;
3730 h = window.clientSize.h;
3733 w = Max(w, window.skinMinSize.w);
3734 h = Max(h, window.skinMinSize.h);
3741 SNAPDOWN(w, textCellW);
3742 SNAPDOWN(h, textCellH);
3747 aw = Max(w,window.skinMinSize.w);
3748 rx = guiApp.windowResizingBefore.w - aw;
3749 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3750 w = guiApp.windowResizingBefore.w - rx;
3754 ah = Max(h,window.skinMinSize.h);
3755 ry = guiApp.windowResizingBefore.h - ah;
3756 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3757 ry = Max(ry, -guiApp.windowMovingBefore.y);
3758 h = guiApp.windowResizingBefore.h - ry;
3763 if(!guiApp.windowIsResizing || guiApp.resizeX)
3764 x = guiApp.windowMovingBefore.x + rx;
3765 if(!guiApp.windowIsResizing || guiApp.resizeY)
3766 y = guiApp.windowMovingBefore.y + ry;
3768 if(!guiApp.windowIsResizing)
3771 if(window.parent == guiApp.desktop && guiApp.virtualScreen.w)
3773 x = Min(x, (guiApp.virtualScreen.w + guiApp.virtualScreenPos.x) -1);
3774 y = Min(y, (guiApp.virtualScreen.h + guiApp.virtualScreenPos.y) -1);
3775 x = Max(x,-(w-1) + guiApp.virtualScreenPos.x);
3776 y = Max(y,-(h-1) + guiApp.virtualScreenPos.y);
3780 x = Min(x, (window.parent.reqScrollArea.w ? window.parent.reqScrollArea.w : window.parent.clientSize.w) -1);
3781 y = Min(y, (window.parent.reqScrollArea.h ? window.parent.reqScrollArea.h : window.parent.clientSize.h) -1);
3787 if(!guiApp.windowIsResizing || (guiApp.resizeX || guiApp.resizeY))
3789 if(!window.OnMoving(&x, &y, w, h))
3791 x = window.scrolledPos.x;
3792 y = window.scrolledPos.y;
3798 SNAPDOWN(x, textCellW);
3799 SNAPDOWN(y, textCellH);
3802 if(!window.style.nonClient)
3804 if(!window.style.fixed /*|| window.style.isDocument*/)
3806 if(!window.style.dontScrollHorz)
3807 x += window.parent.scroll.x;
3808 if(!window.style.dontScrollVert)
3809 y += window.parent.scroll.y;
3813 // Break the anchors for moveable/resizable windows
3814 // Will probably cause problem with IDE windows... Will probably need a way to specify if anchors should break
3815 if(window.style.fixed)
3817 if(window.state == normal)
3819 window.normalAnchor = Anchor { left = x, top = y };
3820 window.normalSizeAnchor = SizeAnchor { { w, h } };
3821 window.anchored = false;
3825 window.stateAnchor = Anchor { left = x, top = y };
3826 window.stateSizeAnchor = SizeAnchor { { w, h } };
3828 window.Position(x, y, w, h, false, true, guiApp.windowIsResizing, guiApp.windowIsResizing, false, true);
3829 // TOCHECK: Investigate why the following only redraws the scrollbars
3830 //window.Position(x, y, w, h, false, true, true, true, false, true);
3832 guiApp.movingLast.x = mouseX;
3833 guiApp.movingLast.y = mouseY;
3839 public bool MouseMessage(uint method, int x, int y, Modifiers * mods, bool consequential, bool activate)
3842 bool wasMoving = guiApp.windowMoving ? true : false;
3843 bool wasScrolling = guiApp.windowScrolling ? true : false;
3845 while(result && w != this)
3847 Window msgWindow = GetAtPosition(x,y, false, true, w);
3848 Window trueWindow = GetAtPosition(x,y, false, false, w);
3849 bool windowDragged = false;
3854 window = (w && !w.disabled) ? w : null;
3856 if(trueWindow) incref trueWindow;
3858 if(consequential) mods->isSideEffect = true;
3860 UpdateMouseMove(x, y, consequential);
3862 if(guiApp.windowCaptured && (guiApp.windowCaptured.rootWindow == this))
3864 if(!guiApp.windowCaptured.isEnabled)
3865 guiApp.windowCaptured.ReleaseCapture();
3867 window = guiApp.windowCaptured;
3870 if(trueWindow && activate &&
3871 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
3872 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
3873 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
3874 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
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)))
3944 // Let the OnLeftButtonDown do the activating instead
3945 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
3953 incref activateWindow;
3954 if(!activateWindow.ActivateEx(true, true, false, true, null, null))
3956 delete activateWindow;
3960 if(activateWindow._refCount == 1)
3962 delete activateWindow;
3966 delete activateWindow;
3968 mods->isActivate = true;
3972 if(!modalWindow && window && !window.destroyed)
3974 if(!guiApp.windowCaptured || windowDragged)
3976 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown)
3978 bool moving = ((window.state != maximized &&
3979 window.IsMouseMoving(
3980 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
3981 || (guiApp.windowMoving && !guiApp.windowIsResizing);
3983 if(!moving && window.IsMouseResizing(
3984 x - window.absPosition.x,
3985 y - window.absPosition.y,
3986 window.size.w, window.size.h,
3987 &guiApp.resizeX, &guiApp.resizeY, &guiApp.resizeEndX, &guiApp.resizeEndY))
3989 guiApp.windowIsResizing = true;
3990 guiApp.windowResizingBefore.w = window.size.w;
3991 guiApp.windowResizingBefore.h = window.size.h;
3993 if(guiApp.windowIsResizing || windowDragged || moving)
3996 guiApp.windowMoving = window;
3997 guiApp.windowMovingStart.x = guiApp.movingLast.x = x;
3998 guiApp.windowMovingStart.y = guiApp.movingLast.y = y;
3999 guiApp.windowMovingBefore.x = window.position.x;//s;
4000 guiApp.windowMovingBefore.y = window.position.y;//s;
4001 if(guiApp.windowMoving == guiApp.windowMoving.rootWindow)
4002 guiApp.interfaceDriver.StartMoving(guiApp.windowMoving.rootWindow, 0,0,false);
4005 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown)
4007 if(window.style.fixed &&
4009 window.IsMouseMoving(
4010 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4012 window.ShowSysMenu(x, y);
4016 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown)
4018 if(window.sbv || window.sbh)
4021 guiApp.windowScrolling = window;
4022 guiApp.windowScrollingStart.x = x;
4023 guiApp.windowScrollingStart.y = y;
4024 guiApp.windowScrollingBefore.x = window.scroll.x;
4025 guiApp.windowScrollingBefore.y = window.scroll.y;
4028 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4030 if(window.style.hasMaximize &&
4031 window.IsMouseMoving(
4032 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h))
4035 (window.state == maximized) ? normal : maximized, false, *mods);
4043 if(guiApp.windowMoving)
4045 if(guiApp.windowMoving.parent)
4047 if(guiApp.windowMoving.style.nonClient)
4048 guiApp.windowMoving.parent.SetMouseRangeToWindow();
4050 guiApp.windowMoving.parent.SetMouseRangeToClient();
4054 window.UpdateDecorations();
4057 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp)
4059 // Log("\n*** LEFT BUTTON UP ***\n");
4060 if(guiApp.windowMoving)
4061 guiApp.windowMoving.StopMoving();
4063 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp)
4065 if(guiApp.windowScrolling)
4067 Window windowScrolling = guiApp.windowScrolling;
4068 guiApp.windowScrolling = null;
4069 windowScrolling.ReleaseCapture();
4073 if(!result || (window && window.destroyed)) window = null;
4075 if(window && window.FindModal())
4078 if(trueWindow && trueWindow.FindModal())
4086 msgWindow = GetAtPosition(x,y, true, false);
4088 msgWindow.SelectMouseCursor();
4091 if(guiApp.windowCaptured || trueWindow)
4093 Window prevWindow = guiApp.prevWindow;
4094 if(guiApp.prevWindow && trueWindow != guiApp.prevWindow)
4096 guiApp.prevWindow.mouseInside = false;
4097 guiApp.prevWindow = null;
4099 // Eventually fix this not to include captured?
4100 if(!prevWindow.OnMouseLeave(*mods))
4103 if(result && trueWindow && !trueWindow.destroyed/* && trueWindow == window*/)
4105 Box box = trueWindow.box;
4106 box.left += trueWindow.absPosition.x;
4107 box.right += trueWindow.absPosition.x;
4108 box.top += trueWindow.absPosition.y;
4109 box.bottom += trueWindow.absPosition.y;
4111 if(box.IsPointInside({x, y}) && trueWindow != /*guiApp.*/prevWindow /*!trueWindow.mouseInside*/)
4113 int overX = x - (trueWindow.absPosition.x + trueWindow.clientStart.x);
4114 int overY = y - (trueWindow.absPosition.y + trueWindow.clientStart.y);
4116 overX = Max(Min(overX, 32767),-32768);
4117 overY = Max(Min(overY, 32767),-32768);
4119 trueWindow.mouseInside = true;
4120 if(!trueWindow.OnMouseOver(overX, overY, *mods))
4124 if(trueWindow && trueWindow._refCount > 1 && !trueWindow.destroyed)
4125 guiApp.prevWindow = trueWindow;
4127 guiApp.prevWindow = null;
4129 SelectMouseCursor();
4131 if(window && !guiApp.windowMoving && !wasMoving && !wasScrolling)
4133 int clientX = x - (window.absPosition.x + window.clientStart.x);
4134 int clientY = y - (window.absPosition.y + window.clientStart.y);
4136 bool (* MouseMethod)(Window instance, int x, int y, Modifiers mods);
4138 clientX = Max(Min(clientX, 32767),-32768);
4139 clientY = Max(Min(clientY, 32767),-32768);
4141 MouseMethod = (void *)window._vTbl[method];
4143 if(MouseMethod /*&& !consequential*/ && !window.disabled)
4146 if(!MouseMethod(window, clientX, clientY, *mods))
4153 if(result && w && w.clickThrough && w.parent)
4158 if(!result || !w || !w.clickThrough)
4165 // --- Mouse cursor management ---
4167 bool KeyMessage(uint method, Key key, unichar character)
4172 if(guiApp.interimWindow)
4173 this = guiApp.interimWindow;
4176 if((SmartKey)key != alt && (SmartKey)key != Key::control && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && parent && this != parent.menuBar)
4180 if(!style.inactive || rootWindow != this)
4182 bool (*KeyMethod)(Window window, Key key, unichar ch) = (void *)_vTbl[method];
4183 Window modalWindow = FindModal();
4184 Window interimMaster = master ? master.rootWindow : null;
4188 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4189 status = OnSysKeyDown(key, character);
4190 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4191 status = OnSysKeyHit(key, character);
4192 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4193 status = OnSysKeyUp(key, character);
4200 // Process Key Message for Internal UI Keyboard actions
4201 if(status && !destroyed && menuBar && state != minimized)
4204 if((SmartKey)key != alt)
4205 menuBar.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4208 SmartKey sk = (SmartKey) key;
4209 if((character && !key.alt && !key.ctrl) || sk == left || sk == right || sk == up || sk == down || sk == home || sk == end || sk == escape || sk == alt)
4211 status = menuBar.KeyMessage(method, key, character);
4216 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4217 menuBar.OnKeyHit(escape, 0);
4219 if(!menuBar.focus && guiApp.caretOwner)
4220 guiApp.caretOwner.UpdateCaret(true, false);
4223 if(!destroyed && status)
4225 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4229 case left: case up: case right: case down:
4230 if(guiApp.windowMoving == this)
4233 int w = guiApp.windowMoving.size.w;
4234 int h = guiApp.windowMoving.size.h;
4235 int x = guiApp.windowMoving.scrolledPos.x;
4236 int y = guiApp.windowMoving.scrolledPos.y;
4240 if(key == down || key == up)
4241 step = Max(step, textCellH);
4243 step = Max(step, textCellW);
4246 if(guiApp.windowIsResizing)
4250 case left: w-=step; break;
4251 case right: w+=step; break;
4252 case up: h-=step; break;
4253 case down: h+=step; break;
4260 case left: x-=step; break;
4261 case right: x+=step; break;
4262 case up: y-=step; break;
4263 case down: y+=step; break;
4267 if(guiApp.resizeX) x += w - guiApp.windowMoving.size.w;
4268 if(guiApp.resizeY) y += h - guiApp.windowMoving.size.h;
4270 if(!guiApp.windowIsResizing || guiApp.resizeX)
4271 x = (x - guiApp.windowMovingBefore.x) + guiApp.windowMovingStart.x;
4273 x = (w - guiApp.windowResizingBefore.w) + guiApp.windowMovingStart.x;
4275 if(!guiApp.windowIsResizing || guiApp.resizeY)
4276 y = (y - guiApp.windowMovingBefore.y) + guiApp.windowMovingStart.y;
4278 y = (h - guiApp.windowResizingBefore.h) + guiApp.windowMovingStart.y;
4280 guiApp.interfaceDriver.SetMousePosition(x, y);
4281 ConsequentialMouseMove(true);
4289 if(guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4291 guiApp.windowMoving.StopMoving();
4292 ConsequentialMouseMove(false);
4300 ShowSysMenu(absPosition.x, absPosition.y);
4308 if(!destroyed && status && state != minimized)
4310 // Process all the way down the children
4311 if(activeChild && !activeChild.disabled)
4313 status = activeChild.KeyMessage(method, key, character);
4315 if(status && activeClient && activeChild != activeClient && !activeClient.disabled && (key.alt || key.ctrl) &&
4316 key.code != left && key.code != right && key.code != up && key.code != down)
4318 status = activeClient.KeyMessage(method, key, character);
4322 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4324 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && !defaultControl.disabled && state != minimized)
4325 // && defaultControl != activeChild)
4327 delete previousActive;
4328 previousActive = activeChild;
4329 if(previousActive) incref previousActive;
4331 ConsequentialMouseMove(false);
4332 if((defaultControl.active ||
4333 defaultControl.ActivateEx(true, true, false, true, null, null)) && !defaultControl.disabled)
4334 defaultControl.KeyMessage(method, defaultKey, character);
4340 if(!destroyed && status && (!modalWindow || this == guiApp.desktop))
4342 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4349 ShowSysMenu(absPosition.x, absPosition.y);
4356 if(this != guiApp.desktop)
4358 if(!guiApp.windowMoving && !guiApp.windowCaptured)
4360 if(state != maximized && (key.shift ? style.sizeable : style.fixed))
4362 MenuMoveOrSize(key.shift, true);
4366 else if(guiApp.windowMoving)
4368 guiApp.windowMoving.StopMoving();
4369 ConsequentialMouseMove(false);
4377 if(!destroyed && status && state != minimized)
4379 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4383 case tab: case shiftTab:
4385 Window cycleParent = this;
4386 if(this == guiApp.interimWindow && !master.style.interim && !cycleParent.style.tabCycle)
4387 cycleParent = master.parent;
4389 if(!guiApp.windowCaptured && cycleParent.style.tabCycle)
4391 if(cycleParent.CycleChildren(!key.shift, false, false, true))
4393 Window child = cycleParent.activeChild;
4395 // Scroll the window to include the active control
4397 if(cycleParent.sbh && !child.style.dontScrollHorz)
4399 if(child.scrolledPos.x < 0)
4400 cycleParent.sbh.Action(Position,
4401 cycleParent.scroll.x + child.scrolledPos.x, 0);
4402 else if(child.scrolledPos.x + child.size.w > cycleParent.clientSize.w)
4403 cycleParent.sbh.Action(Position,
4404 cycleParent.scroll.x + child.scrolledPos.x + child.size.w - cycleParent.clientSize.w, 0);
4406 if(cycleParent.sbv && !child.style.dontScrollVert)
4408 if(child.scrolledPos.y < 0)
4409 cycleParent.sbv.Action(Position,
4410 cycleParent.scroll.y + child.scrolledPos.y, 0);
4411 else if(child.scrolledPos.y + child.size.w > window.clientSize.h)
4412 cycleParent.sbv.Action(Position,
4413 cycleParent.scroll.y + child.scrolledPos.y+child.size.h - cycleParent.clientSize.h, 0);
4416 cycleParent.ConsequentialMouseMove(false);
4422 case f6: case shiftF6:
4423 if(!guiApp.windowMoving /*!guiApp.windowCaptured*/)
4425 // NOT NEEDED... guiApp.windowMoving.ReleaseCapture();
4426 if(parent == guiApp.desktop)
4427 if(guiApp.desktop.CycleChildren(key.shift, true, false, true))
4432 if(style.tabCycle ||
4433 CycleChildren(key.shift, true, false, true))
4441 // mIRC Style Window Shortcuts
4442 case alt1: case alt2: case alt3: case alt4: case alt5:
4443 case alt6: case alt7: case alt8: case alt9: case alt0:
4448 for(document = children.first; document; document = document.next)
4450 if(document.style.isDocument && document.documentID - 1 == key.code - k1)
4452 if(document == activeChild)
4454 if(document.state == minimized)
4455 document.SetState(normal, false, key);
4458 document.SetState(minimized, false, key);
4459 CycleChildren(false, true, false);
4464 if(activeChild.state == maximized && document.style.hasMaximize)
4465 document.SetState(maximized, false, key);
4466 else if(document.state == minimized)
4467 document.SetState(normal, false, key);
4468 document.Activate();
4483 if(!destroyed && status)
4485 if(state == minimized)
4490 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4492 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && previousActive)
4494 if(defaultControl.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, key, character))
4495 previousActive.ActivateEx(true, false, false, true, null, null);
4496 delete previousActive;
4502 if(!destroyed && status)
4504 status = ProcessHotKeys(method, key, character);
4506 if(!destroyed && status && !modalWindow && state != minimized)
4509 status = KeyMethod(this, key, character);
4510 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4511 status = OnKeyHit(key, character);
4512 if(!destroyed && status && (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit))
4514 bool result = false;
4517 case ctrlUp: case ctrlDown:
4518 if(sbv && !guiApp.windowScrolling)
4519 result = sbv.Action((key == ctrlUp) ? up : down, 0, key);
4521 case wheelUp: case wheelDown:
4522 if(sbv && !guiApp.windowScrolling)
4524 result = sbv.Action((key == wheelUp) ? wheelUp : wheelDown, 0, key);
4525 // Do we want to do a consequential move regardless of result in this case?
4526 ConsequentialMouseMove(false);
4529 case ctrlPageUp: case ctrlPageDown:
4530 if(sbh && !guiApp.windowScrolling)
4531 result = sbh.Action((key == ctrlPageUp) ? up : down, 0, key);
4536 ConsequentialMouseMove(false);
4541 if(status && !destroyed && menuBar && state != minimized)
4542 status = menuBar.KeyMessage(method, key, character);
4544 if(style.interim && /*destroyed && */status && interimMaster)
4546 // Testing this... for Ctrl-O to open dialog when autocompletion listbox is popped...
4547 status = interimMaster.KeyMessage(method, key, character);
4554 bool ProcessHotKeys(uint method, Key key, unichar character)
4559 for(hotKey = hotKeys.first; hotKey; hotKey = hotKey.next)
4560 if((hotKey.key == key || (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp && hotKey.key.code == key.code)) &&
4561 !hotKey.window.disabled && (hotKey.window.style.nonClient || state != minimized))
4563 Window hotKeyWindow = hotKey.window;
4564 Window parent = hotKeyWindow.parent;
4565 Window prevActiveWindow = activeChild;
4567 // Don't process non-visible buttons, but make an exception for the Alt-F4 with Native Decorations turned on
4568 if(hotKeyWindow.style.hidden && (!hotKeyWindow.style.nonClient || !parent || !parent.nativeDecorations || (hotKeyWindow != parent.sysButtons[2] && hotKeyWindow != parent.sysButtons[1] )))
4571 if(prevActiveWindow) incref prevActiveWindow;
4572 incref hotKeyWindow;
4573 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && !hotKeyWindow.style.nonClient)
4574 if(!hotKeyWindow.ActivateEx(true, true, false, true, null, null))
4577 delete hotKeyWindow;
4578 delete prevActiveWindow;
4582 if(hotKeyWindow.style.nonClient && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4583 method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
4584 if(!hotKeyWindow.KeyMessage(method, Key::hotKey, character))
4586 // ********* WORKING ON THIS ***********
4587 if(prevActiveWindow && !guiApp.interimWindow)
4588 prevActiveWindow.ActivateEx(true, false, false, false, null, null);
4591 else if(hotKeyWindow.style.inactive)
4592 status = hotKeyWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, Key::hotKey, character);
4594 delete prevActiveWindow;
4595 delete hotKeyWindow;
4596 // For Key Ups, don't set status to false... (e.g.: Releasing Enter vs AltEnter hot key)
4597 if(method != __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4601 if(status && tabCycle)
4604 for(child = children.first; child; child = child.next)
4606 if(child.tabCycle && !child.ProcessHotKeys(method, key, character))
4617 // --- Windows and graphics initialization / termination ---
4618 bool SetupRoot(void)
4622 // Setup relationship with outside world (bb root || !bb)
4623 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || this == guiApp.desktop ||
4624 (!formDesigner && displayDriver && displayDriver != parent.displayDriver))
4628 tempExtents = new0 Extent[4];
4633 /*if(guiApp.fullScreenMode)
4634 rootWindow = guiApp.desktop;
4636 //rootWindow = parent.created ? parent.rootWindow : null;
4637 rootWindow = parent.rootWindow;
4640 against = &parent.box;
4642 against = &parent.clientArea;
4645 for(child = children.first; child; child = child.next)
4648 return (rootWindow && (rootWindow == this || rootWindow.created)) ? true : false;
4651 bool Setup(bool positionChildren)
4653 bool result = false;
4656 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || (guiApp.fullScreenMode && (this == guiApp.desktop || (!formDesigner && displayDriver && displayDriver != parent.displayDriver))))
4658 subclass(DisplayDriver) dDriver = (dispDriver && !formDesigner) ? dispDriver : GetDisplayDriver(guiApp.defaultDisplayDriver);
4659 DisplaySystem displaySystem = dDriver ? dDriver.displaySystem : null;
4661 windowHandle = dDriver.printer ? null : guiApp.interfaceDriver.CreateRootWindow(this);
4663 // This was here, is it really needed?
4664 //guiApp.interfaceDriver.ActivateRootWindow(this);
4668 displaySystem = DisplaySystem {};
4669 if(!displaySystem.Create(dDriver.name, guiApp.fullScreenMode ? windowHandle : windowHandle /*null*/, guiApp.fullScreenMode))
4671 delete displaySystem;
4676 display = Display { alphaBlend = alphaBlend, useSharedMemory = useSharedMemory, windowDriverData = windowData };
4677 if(display.Create(displaySystem, windowHandle))
4684 guiApp.interfaceDriver.SetIcon(this, icon);
4686 else if(this != guiApp.desktop)
4688 display = rootWindow ? rootWindow.display : null;
4694 if(guiApp.acquiredWindow && rootWindow == guiApp.acquiredWindow.rootWindow)
4695 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, true);
4697 for(child = children.first; child; child = child.next)
4699 if(child.created && !child.Setup(false))
4705 bool SetupDisplay(void)
4707 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
4708 if(is3D) return Window3D_SetupDisplay(this); else
4715 class_data void ** pureVTbl;
4717 bool LoadGraphics(bool creation, bool resetAnchors)
4719 bool result = false;
4720 bool success = false;
4722 WindowState stateBackup = state;
4725 if(!rootWindow.created)
4729 if(((subclass(Window))_class).pureVTbl)
4731 if(_vTbl == _class._vTbl)
4733 _vTbl = ((subclass(Window))_class).pureVTbl;
4738 for(m = 0; m < _class.vTblSize; m++)
4740 if(_vTbl[m] == _class._vTbl[m])
4741 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
4745 if(guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
4747 if(_vTbl == ((subclass(Window))_class).pureVTbl)
4749 _vTbl = _class._vTbl;
4754 for(m = 0; m < _class.vTblSize; m++)
4756 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
4757 _vTbl[m] = _class._vTbl[m];
4762 if(guiApp.fullScreenMode || this != guiApp.desktop)
4764 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
4770 display.Lock(false);
4771 if(rootWindow == this)
4773 // Set Color Palette
4774 display.SetPalette(palette, true);
4778 if(guiApp.fullScreenMode && this == guiApp.desktop)
4783 for(c=0; c<SystemCursor::enumSize; c++)
4784 if(!guiApp.systemCursors[c].bitmap)
4786 guiApp.systemCursors[c].bitmapName = guiApp.currentSkin.CursorsBitmaps(c,
4787 &guiApp.systemCursors[c].hotSpotX,&guiApp.systemCursors[c].hotSpotY, &guiApp.systemCursors[c].paletteShades);
4788 if(guiApp.systemCursors[c].bitmapName)
4790 guiApp.systemCursors[c].bitmap = eBitmap_LoadT(guiApp.systemCursors[c].bitmapName, null,
4791 guiApp.systemCursors[c].paletteShades ? null : guiApp.desktop.display.displaySystem);
4792 if(guiApp.systemCursors[c].bitmap)
4793 guiApp.systemCursors[c].bitmap.paletteShades = guiApp.systemCursors[c].paletteShades;
4798 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
4800 cursor.bitmap = eBitmap_LoadT(cursor.bitmapName, null,
4801 cursor.paletteShades ? null : guiApp.desktop.display.displaySystem);
4803 cursor.bitmap.paletteShades = cursor.paletteShades;
4807 guiApp.cursorUpdate = true;
4810 ConsequentialMouseMove(false);
4816 // Load Window Graphic Resources
4819 if(usedFont == setFont || usedFont == window.systemFont)
4820 RemoveResource(usedFont);
4823 RemoveResource(setFont); // TESTING setFont instead of usedFont);
4826 RemoveResource(systemFont);
4829 RemoveResource(captionFont);
4831 for(ptr = resources.first; ptr; ptr = ptr.next)
4833 ptr.loaded = display.displaySystem.LoadResource(ptr.resource);
4836 AddResource(setFont);
4838 AddResource(systemFont);
4840 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
4847 //if(master && master.font)
4848 if(parent && parent.font)
4852 faceName = parent.font.faceName,
4853 size = parent.font.size,
4854 bold = parent.font.bold,
4855 italic = parent.font.italic,
4856 underline = parent.font.underline
4858 //font = parent.font;
4859 watch(parent) { font { } };
4862 font = guiApp.currentSkin.SystemFont();
4869 captionFont = guiApp.currentSkin.CaptionFont();
4870 AddResource(captionFont);
4872 if(OnLoadGraphics())
4878 //SetScrollLineStep(sbStep.x, sbStep.y);
4880 if(this != guiApp.desktop)
4884 normalAnchor = anchor;
4885 normalSizeAnchor = sizeAnchor;
4888 // Break the anchors for moveable/resizable windows
4890 if(style.fixed && style.isDocument)
4892 ComputeAnchors(ax, ay, aw, ah, &x, &y, &w, &h);
4904 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
4905 stateSizeAnchor = SizeAnchor {};
4910 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
4915 left = (iconID % maxIcons) * MINIMIZED_WIDTH,
4916 bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24)
4919 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
4923 stateAnchor = normalAnchor;
4924 stateSizeAnchor = normalSizeAnchor;
4927 position = Point { };
4928 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
4939 if(Position(x, y, w, h, true, false, true, true, true, true))
4941 if((this != guiApp.desktop || guiApp.fullScreenMode) && rootWindow == this)
4944 guiApp.interfaceDriver.SetRootWindowState(this, normal, true);
4961 success = result = true;
4964 if(!creation && result)
4966 // Load menu bar first because sys buttons are on it...
4969 if(!menuBar.LoadGraphics(false, resetAnchors))
4975 for(child = children.first; child; child = child.next)
4977 if(child.created && child != menuBar && !child.LoadGraphics(false, resetAnchors))
4984 CreateSystemChildren();
4988 if(this == guiApp.desktop && !guiApp.fullScreenMode)
4991 guiApp.interfaceDriver.ActivateRootWindow(activeChild);
4996 //guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, caption);
4997 guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, class.name);
5000 // Do this here to avoid problems on Windows
5001 if(stateBackup == maximized)
5002 property::state = maximized;
5006 void UnloadGraphics(bool destroyWindows)
5010 // Free children's graphics
5011 for(child = children.first; child; child = child.next)
5012 child.UnloadGraphics(destroyWindows);
5015 display.Lock(false);
5018 if(guiApp.fullScreenMode && this == guiApp.desktop)
5023 for(c=0; c<SystemCursor::enumSize; c++)
5024 if(guiApp.systemCursors[c].bitmap)
5025 delete guiApp.systemCursors[c].bitmap;
5027 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5028 delete cursor.bitmap;
5030 guiApp.cursorBackground.Free();
5033 if(display && display.displaySystem)
5037 for(ptr = resources.first; ptr; ptr = ptr.next)
5041 display.displaySystem.UnloadResource(ptr.resource, ptr.loaded);
5046 // Free window graphics
5049 // Free skin graphics
5050 if(rootWindow == this)
5052 DisplaySystem displaySystem = display.displaySystem;
5055 display.driverData = null;
5056 display.displaySystem = null;
5060 if(displaySystem && !displaySystem.numDisplays && !is3D)
5061 delete displaySystem;
5070 if(guiApp.acquiredWindow && this == guiApp.acquiredWindow.rootWindow)
5071 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, false);
5073 if(this == guiApp.desktop || parent == guiApp.desktop)
5075 if((guiApp.fullScreenMode || this != guiApp.desktop) && rootWindow == this && windowHandle && destroyWindows)
5076 guiApp.interfaceDriver.DestroyRootWindow(this);
5080 // --- Window Hiding ---
5082 void SetVisibility(bool state)
5084 bool visible = (style.hidden || !created) ? false : state;
5085 if(visible != this.visible)
5089 this.visible = visible;
5090 for(child = children.first; child; child = child.next)
5091 child.SetVisibility(visible);
5093 ConsequentialMouseMove(false);
5097 // --- Windows and graphics initialization / termination ---
5099 bool DisplayModeChanged(void)
5101 bool result = false;
5102 if(!guiApp.fullScreenMode && !guiApp.modeSwitching/* && guiApp.desktop.active*/)
5104 guiApp.modeSwitching = true;
5105 UnloadGraphics(false);
5107 if(LoadGraphics(false, false))
5109 guiApp.modeSwitching = false;
5114 // --- Window updates system ---
5116 void UpdateDirty(Box updateBox)
5118 if(!manageDisplay) { OnRedraw(null);return; }
5121 if(display && (!guiApp.fullScreenMode || guiApp.desktop.active) && !guiApp.modeSwitching)
5124 if(display.flags.flipping)
5127 rootWindow.UpdateDisplay();
5130 UpdateBackDisplay(updateBox);
5132 if(guiApp.fullScreenMode)
5134 guiApp.cursorUpdate = true;
5135 guiApp.PreserveAndDrawCursor();
5137 if(guiApp.fullScreenMode)
5138 guiApp.RestoreCursorBackground();
5144 // This function is strictly called as a result of system window activation
5145 bool ExternalActivate(bool active, bool activateRoot, Window window, Window swap)
5148 Window interimMaster = null;
5149 Window interimWindow = guiApp.interimWindow;
5150 if(interimWindow && interimWindow.master)
5151 interimMaster = interimWindow.master.rootWindow;
5153 if(active && state == minimized) // && (!window.nativeDecorations || window.rootWindow != window)
5154 // SetState(normal, false, 0);
5155 SetState(lastState, false, 0);
5157 if(interimMaster && swap == interimMaster && interimMaster.IsSlaveOf(window))
5161 /* WTH is this doing here?
5162 while(swap && swap.activeChild)
5164 swap = swap.activeChild;
5167 // TESTING THIS BEFORE...
5168 if(interimWindow && this == interimMaster)
5172 // Window interimSwap = this;
5173 Window menuBar = this.menuBar;
5174 if(menuBar && interimWindow.master == menuBar)
5177 while(interimSwap && interimSwap.activeChild)
5178 interimSwap = interimSwap.activeChild;
5180 result = interimWindow.ActivateEx(false, false, false, activateRoot, null,
5181 (menuBar && interimWindow.master == menuBar) ? menuBar : interimSwap);
5183 result = /*interimWindow.*/ActivateEx(false, false, false, activateRoot, null, menuBar);
5184 //result = ActivateEx(true, true, false, activateRoot, window, null);
5189 // Testing & FindModal() here: broke reactivating when a modal dialog is up (didn't root activate dialog)
5190 result = ActivateEx(active, active, false, activateRoot /*&& FindModal()*/, window, swap);
5192 if(interimWindow == this && interimMaster && !active)
5194 while(interimMaster && interimMaster.interim && interimMaster.master)
5196 // printf("Going up one master %s\n", interimMaster._class.name);
5197 interimMaster = interimMaster.master.rootWindow;
5199 // printf("Unactivating interim master %s (%x)\n", interimMaster._class.name, interimMaster);
5200 interimMaster.ActivateEx(active, active, false, activateRoot, window, swap);
5206 bool DestroyEx(int returnCode)
5209 Timer timer, nextTimer;
5211 OldLink prevOrder = null;
5212 Window client = null;
5214 if(parent) stopwatching(parent, font);
5216 // if(window.modalSlave) return false;
5217 if(destroyed || !created)
5224 OldLink slave = master.slaves.FindLink(this);
5225 master.slaves.Delete(slave);
5228 // TOFIX IMMEDIATELY: COMMENTED THIS OUT... causes problem second time creating file dialog
5234 this.returnCode = (DialogResult)returnCode;
5236 AcquireInput(false);
5241 master.hotKeys.Delete(hotKey);
5245 if(guiApp.prevWindow == this)
5247 guiApp.prevWindow = null;
5250 if(guiApp.caretOwner == this)
5252 guiApp.interfaceDriver.SetCaret(0,0,0);
5253 UpdateCaret(false, true);
5254 guiApp.caretEnabled = false;
5259 parent.childrenCycle.Remove(cycle);
5263 OldLink tmpPrev = order.prev;
5264 if(tmpPrev && !(((Window)tmpPrev.data).style.hidden) && !(((Window)tmpPrev.data).destroyed) && (((Window)tmpPrev.data).created))
5265 prevOrder = tmpPrev;
5268 client = tmpPrev ? tmpPrev.data : null;
5269 if(client == this) { client = null; break; }
5270 if(client && (client.style.hidden || client.destroyed || !client.created))
5271 tmpPrev = client.order.prev;
5275 prevOrder = tmpPrev;
5280 // If this window can be an active client, make sure the next window we activate can also be one
5281 if(!style.nonClient && style.isActiveClient)
5283 tmpPrev = prevOrder;
5286 client = tmpPrev ? tmpPrev.data : null;
5287 if(client == this) { client = null; break; }
5288 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
5289 tmpPrev = client.order.prev;
5293 prevOrder = tmpPrev;
5297 if(client && client.style.hidden) client = null;
5299 // parent.childrenOrder.Remove(order);
5302 if(parent && style.isActiveClient && visible)
5304 if(state == minimized) parent.numIcons--;
5305 parent.numPositions--;
5308 // TESTING THIS HERE!
5312 // If no display, don't bother deactivating stuff (causes unneeded problems when trying
5313 // to create a window inside a rootwindow that's being destroyed)
5314 // DISABLED THIS BECAUSE OF CREATING WINDOW IN DESKTOP IN WINDOWED MODE
5316 if(master && !master.destroyed /*&&
5317 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5319 if(master.defaultControl == this)
5320 master.defaultControl = null;
5322 if(parent && !parent.destroyed /*&&
5323 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5325 if((parent.activeChild == this /*|| parent.activeClient == this */|| guiApp.interimWindow == this))
5327 if(order && prevOrder && prevOrder.data != this && active)
5329 //((Window)prevOrder.data).ActivateEx(true, false, false, false /*true*/, null);
5331 ((Window)prevOrder.data).ActivateEx(true, false, false, (rootWindow == this) ? true : false, null, null);
5332 if(parent.activeClient == this)
5334 parent.activeClient = null;
5335 parent.UpdateActiveDocument(null);
5340 if(guiApp.interimWindow == this)
5343 PropagateActive(false, null, &goOn, true);
5347 //if(window.parent.activeChild == window)
5348 parent.activeChild = null;
5349 if(!style.nonClient /*&& style.isActiveClient*/)
5351 Window previous = parent.activeClient;
5352 if(style.isActiveClient)
5353 parent.activeClient = null;
5354 parent.UpdateActiveDocument(previous);
5359 else if(parent.activeClient == this)
5361 parent.activeClient = client;
5362 parent.UpdateActiveDocument(this);
5366 if(guiApp.interimWindow == this)
5368 guiApp.interimWindow = null;
5369 if(guiApp.caretOwner)
5371 Window desktop = guiApp.desktop;
5372 if(desktop.activeChild && desktop.activeChild.menuBar && !desktop.activeChild.menuBar.focus)
5373 guiApp.caretOwner.UpdateCaret(false, false);
5378 if(style.modal && master && master.modalSlave == this)
5379 master.modalSlave = null;
5383 if(!guiApp.caretOwner && parent.caretSize)
5385 guiApp.caretOwner = parent;
5386 parent.UpdateCaret(false, false);
5387 parent.Update(null);
5390 // Why was this commented out?
5391 GetRidOfVirtualArea();
5397 dirtyArea.Free(null);
5398 dirtyBack.Free(null);
5399 scrollExtent.Free(null);
5401 /* ATTEMPTING TO MOVE THAT ABOVE
5410 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5411 for(;(child = window.children.first);)
5413 for(; child && (child.destroyed || !child.created); child = child.next);
5422 UnloadGraphics(true);
5425 delete previousActive;
5428 // statusBar = null;
5431 if(master && !master.destroyed)
5433 //master.NotifyDestroyed(this, this.returnCode);
5434 NotifyDestroyed(master, this, this.returnCode);
5437 for(timer = guiApp.windowTimers.first; timer; timer = nextTimer)
5439 nextTimer = timer.next;
5440 if(timer.window == this)
5442 // WHY WERE WE SETTING THIS TO NULL? NO MORE WINDOW WHEN RECREATING...
5443 // timer.window = null;
5449 if(this == guiApp.windowMoving)
5452 if(guiApp.windowCaptured == this)
5454 //guiApp.windowCaptured = null;
5456 if(rootWindow != this && rootWindow)
5457 rootWindow.ConsequentialMouseMove(false);
5465 //for(child = children.first; next = child ? child.next : null, child; child = next)
5466 for(;(child = children.first); )
5468 for(; child && (child.destroyed || !child.created); child = child.next);
5478 /* // MOVED THIS UP...
5481 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5482 for(;(child = window.children.first); )
5484 for(; child && (child.destroyed || !child.created); child = child.next);
5493 while((slave = slaves.first))
5495 for(; slave && (((Window)slave.data).destroyed || !((Window)slave.data).created); slave = slave.next);
5497 ((Window)slave.data).DestroyEx(0);
5502 if(guiApp.caretOwner == this)
5503 guiApp.caretOwner = null;
5505 sysButtons[0] = null;
5506 sysButtons[1] = null;
5507 sysButtons[2] = null;
5510 if(rootWindow != this)
5512 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
5515 box.left -= parent.clientStart.x;
5516 box.top -= parent.clientStart.y;
5517 box.right -= parent.clientStart.x;
5518 box.bottom -= parent.clientStart.y;
5520 if(parent) parent.Update(box);
5525 OldLink slave = master.slaves.FindVoid(this);
5526 master.slaves.Delete(slave);
5532 parent.children.Remove(this);
5537 //autoCreate = false;
5540 // SHOULD THIS BE HERE? FIXED CRASH WITH GOTO DIALOG
5541 if(((subclass(Window))_class).pureVTbl)
5543 if(_vTbl == _class._vTbl)
5545 _vTbl = ((subclass(Window))_class).pureVTbl;
5550 for(m = 0; m < _class.vTblSize; m++)
5552 if(_vTbl[m] == _class._vTbl[m])
5553 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5562 void SetStateEx(WindowState newState, bool activate)
5565 WindowState prevState = state;
5569 if(prevState != newState)
5570 lastState = prevState;
5572 if(rootWindow != this || !nativeDecorations)
5574 if(style.isActiveClient && !style.hidden && prevState == minimized)
5577 // This block used to be at the end of the function... moved it for flicker problem in X
5578 // ------------------------------------------------------
5582 stateAnchor = normalAnchor;
5583 stateSizeAnchor = normalSizeAnchor;
5586 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5587 stateSizeAnchor = SizeAnchor {};
5591 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5594 byte * idBuffer = new0 byte[size];
5596 for(child = parent.children.first; child; child = child.next)
5598 if(child != this && child.state == minimized)
5600 if(child.iconID > size - 2)
5602 idBuffer = renew0 idBuffer byte[size*2];
5603 memset(idBuffer + size, 0, size);
5606 idBuffer[child.iconID] = (byte)bool::true;
5609 for(c = 0; c<size; c++)
5614 if(style.isActiveClient && !style.hidden)
5617 stateAnchor = Anchor { left = (iconID % maxIcons) * MINIMIZED_WIDTH, bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24) };
5618 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
5622 // TOCHECK: Why was this here?
5623 //position.x = (tx > 0) ? tx & 0xFFFFF : tx;
5624 //position.y = (ty > 0) ? ty & 0xFFFFF : ty;
5625 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5627 Position(x, y, w, h, true, true, true, true, false, true);
5629 if(!style.inactive && !style.interim && this == parent.activeClient)
5630 parent.UpdateActiveDocument(null);
5633 CreateSystemChildren();
5634 // ------------------------------------------------------
5637 int GetPositionID(Window forChild)
5641 byte * idBuffer = new0 byte[size];
5644 for(child = children.first; child; child = child.next)
5646 if(child.style.isActiveClient && !child.style.hidden && child != forChild)
5648 if(child.positionID > size - 2)
5650 idBuffer = renew0 idBuffer byte[size*2];
5651 memset(idBuffer + size, 0, size);
5654 idBuffer[child.positionID] = (byte)bool::true;
5657 for(c = 0; c<size; c++)
5664 // --- Window related graphics ---
5666 void SetPalette(ColorAlpha * newPalette, bool colorMatch)
5668 palette = newPalette;
5669 if(rootWindow.display)
5670 rootWindow.display.SetPalette(palette, colorMatch);
5673 public bool AcquireInput(bool acquired)
5676 if(acquiredInput != acquired)
5678 if(active || (!visible && creationActivation == activate))
5679 result = AcquireInputEx(acquired);
5684 acquiredInput = acquired ? result : !result;
5689 void ListChildren(ListBox listBox)
5693 for(child = children.first; child; child = child.next)
5695 if(child.cycle && !child.style.nonClient && child.style.isActiveClient && child.visible)
5697 DataRow row = listBox.AddRow();
5698 row.tag = (int)child;
5699 child.FigureCaption(caption);
5700 row.SetData(null, caption);
5705 void UpdateVisual(Box extent)
5707 if(guiApp.driver != null)
5709 if(guiApp.fullScreenMode && guiApp.desktop.display)
5711 guiApp.desktop.mutex.Wait();
5712 guiApp.desktop.display.Lock(true);
5715 if(guiApp.desktop.active)
5717 if(guiApp.desktop.dirty || guiApp.cursorUpdate)
5719 if(guiApp.desktop.display.flags.flipping)
5720 guiApp.desktop.Update(null);
5721 guiApp.desktop.UpdateDisplay();
5722 guiApp.cursorUpdate = true;
5724 if(guiApp.cursorUpdate || guiApp.desktop.dirty)
5726 guiApp.PreserveAndDrawCursor();
5727 // guiApp.desktop.display.ShowScreen();
5728 guiApp.cursorUpdate = false;
5729 guiApp.desktop.dirty = false;
5730 guiApp.RestoreCursorBackground();
5734 guiApp.desktop.display.Unlock();
5735 guiApp.desktop.mutex.Release();
5739 Window rootWindow = this.rootWindow;
5740 rootWindow.mutex.Wait();
5745 guiApp.SignalEvent();
5748 guiApp.waitMutex.Wait();
5749 guiApp.interfaceDriver.Lock(rootWindow);
5750 if(!rootWindow.style.hidden && rootWindow.dirty)
5752 if(rootWindow.display)
5754 rootWindow.UpdateDisplay();
5755 //rootWindow.display.ShowScreen(null);
5757 rootWindow.dirty = false;
5759 guiApp.interfaceDriver.Unlock(rootWindow);
5760 guiApp.waitMutex.Release();
5763 rootWindow.mutex.Release();
5768 void UnlockDisplay(void)
5770 guiApp.interfaceDriver.Unlock(rootWindow);
5773 void LockDisplay(void)
5775 guiApp.interfaceDriver.Lock(rootWindow);
5778 Surface GetSurface(Box box)
5780 return Redraw((box == null) ? this.box : box);
5783 void SetMousePosition(int x, int y)
5785 guiApp.interfaceDriver.SetMousePosition(x + absPosition.x + clientStart.x, y + absPosition.y + clientStart.y);
5789 void IntegrationActivate(bool active)
5791 if(!guiApp.modeSwitching && !guiApp.fullScreenMode)
5793 isForegroundWindow = true;
5794 ActivateEx(active, active, false, false, null, null);
5795 isForegroundWindow = false;
5800 Window QueryCapture(void)
5802 return guiApp.windowCaptured;
5805 int GetDocumentID(void)
5809 byte * idBuffer = new0 byte[size];
5812 for(child = children.first; child; child = child.next)
5814 if(child.style.isDocument)
5816 if(child.documentID-1 > size - 2)
5818 idBuffer = renew0 idBuffer byte[size*2];
5819 memset(idBuffer + size, 0, size);
5822 idBuffer[child.documentID-1] = 1;
5825 for(c = 0; c<size; c++)
5833 void SetInitSize(Size size)
5836 sizeAnchor.size = size;
5837 normalSizeAnchor = sizeAnchor;
5839 // Break the anchors for moveable/resizable windows
5840 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
5842 stateAnchor = normalAnchor;
5843 stateSizeAnchor = normalSizeAnchor;
5845 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5846 Position(x,y, w, h, true, true, true, true, false, true);
5850 void MenuMoveOrSize(bool resize, bool setCursorPosition)
5852 if(this != guiApp.desktop && state != maximized && (resize ? (state != minimized && style.sizable) : (style.fixed || moveable)))
5854 guiApp.windowIsResizing = resize;
5855 guiApp.windowMoving = this;
5856 guiApp.windowMovingStart = guiApp.movingLast = absPosition;
5857 if(guiApp.windowIsResizing)
5859 guiApp.windowMovingStart.x += size.w - 1;
5860 guiApp.windowMovingStart.y += size.h - 1;
5862 guiApp.windowMovingBefore = scrolledPos;
5863 guiApp.windowResizingBefore = size;
5864 guiApp.windowMoving.UpdateDecorations();
5865 if(guiApp.windowIsResizing)
5866 guiApp.resizeEndX = guiApp.resizeEndY = true;
5868 if(setCursorPosition)
5869 guiApp.interfaceDriver.SetMousePosition(guiApp.windowMovingStart.x, guiApp.windowMovingStart.y);
5873 guiApp.interfaceDriver.GetMousePosition(&x, &y);
5874 guiApp.windowMovingStart.x += x - absPosition.x;
5875 guiApp.windowMovingStart.y += y - absPosition.y;
5878 if(guiApp.windowMoving)
5880 if(guiApp.windowMoving.style.nonClient)
5881 guiApp.windowMoving.parent.SetMouseRangeToWindow();
5883 guiApp.windowMoving.parent.SetMouseRangeToClient();
5888 if(this == rootWindow)
5889 guiApp.interfaceDriver.StartMoving(rootWindow, guiApp.windowMovingStart.x, guiApp.windowMovingStart.y, true);
5897 bool result = false;
5901 else if(guiApp && guiApp.driver != null)
5903 void * systemParent = null;
5904 OldLink slaveHolder;
5906 bool visible = !style.hidden;
5910 systemParent = parent;
5911 parent = guiApp.desktop;
5913 last = parent ? parent.children.last : null;
5915 if((parent && parent != guiApp.desktop && !parent.created) ||
5916 (master && master != guiApp.desktop && !master.created))
5920 property::parent = guiApp.desktop;
5921 if(!master) master = parent;
5923 if(style.modal && master.modalSlave)
5924 property::master = master.modalSlave;
5928 parent.children.Remove(this);
5931 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
5932 if(slaveHolder.data == this)
5934 master.slaves.Delete(slaveHolder);
5939 if(parent == guiApp.desktop && !mutex)
5942 if(style.isDocument)
5945 parent.numDocuments--;
5946 documentID = parent.GetDocumentID();
5949 if(!style.stayOnTop)
5950 for(; last && last.style.stayOnTop; last = last.prev);
5952 parent.children.Insert((last == this) ? null : last, this);
5953 //parent.children.Add(this);
5956 dispDriver = parent.dispDriver;
5959 master.modalSlave = this;
5961 box = Box { MAXINT, MAXINT, MININT, MININT }; //-MAXINT, -MAXINT };
5966 master.slaves.Add(slaveHolder = OldLink { data = this });
5971 master.hotKeys.Add(hotKey = HotKeySlot { key = setHotKey, window = this });
5973 if(style.isDefault && !master.defaultControl)
5974 master.defaultControl = this;
5976 stateAnchor = normalAnchor = anchor;
5977 stateSizeAnchor = normalSizeAnchor = sizeAnchor;
5979 // TOCHECK: Why is this here?
5980 //position.x = (ax > 0) ? ax & 0xFFFFF : ax;
5981 //position.y = (ay > 0) ? ay & 0xFFFFF : ay;
5983 this.visible = false;
5984 style.hidden = true;
5987 // autoCreate = true;
5995 if(parent == guiApp.desktop)
5996 Log("LoadGraphics %s\n", caption);
5998 if(LoadGraphics(true, false))
6006 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
6013 if(style.hasMenuBar /*&& menu*/)
6019 menu = menu, isMenuBar = true, anchor = Anchor { top = 23, left = 1, right = 1 },
6020 interim = false, inactive = true, nonClient = true, size.h = 24
6028 // Create the system buttons
6029 CreateSystemChildren();
6031 UpdateActiveDocument(null);
6033 if(style.isDocument)
6037 MenuItem item = menu.FindItem(MenuFileSave, 0);
6038 if(item) item.disabled = !modifiedDocument && fileName;
6043 if(parent == guiApp.desktop)
6044 Log("Preemptive SetState %s\n", caption);
6047 // Preemptive Set State to ensure proper anchoring
6048 SetStateEx(state, false);
6050 style.hidden = true;
6056 for(child = children.first; child; child = next)
6059 if(!child.created && (child.autoCreate || child.wasCreated))
6066 for(link = slaves.first; link; link = next)
6068 Window slave = link.data;
6070 if(!slave.created && (slave.autoCreate || slave.wasCreated))
6079 if(parent == guiApp.desktop)
6080 Log("Real SetState %s\n", caption);
6083 if(isActiveClient && visible)
6085 parent.numPositions--;
6086 if(state == minimized) parent.numIcons--;
6089 // Real set state & activate for proper display & activation
6090 property::visible = visible;
6091 // SetState(state & 0x00000003, true, 0);
6096 /*if(rootWindow == this)
6097 guiApp.interfaceDriver.ActivateRootWindow(this);
6099 if(creationActivation == activate)
6100 ActivateEx(true, false, true, true, null, null);
6101 else if(creationActivation == flash)
6106 rootWindow.ConsequentialMouseMove(false);
6117 guiApp.LogErrorCode(IERR_WINDOW_CREATION_FAILED, caption);
6123 // Testing this here... Otherwise a failed LoadGraphics stalls the application
6125 //style.hidden = true; // !visible;
6126 style.hidden = !visible;
6127 if(master.modalSlave == this)
6128 master.modalSlave = null;
6135 void WriteCaption(Surface surface, int x, int y)
6138 Interface::WriteKeyedTextDisabled(surface, x,y, caption, hotKey ? hotKey.key : 0, !isEnabled);
6141 void Update(Box region)
6147 rootWindow = this.rootWindow;
6149 // rootWindow.mutex.Wait();
6150 if(!destroyed && visible && display)
6155 // Testing this to avoid repetitve full update to take time...
6156 if(dirtyArea.count == 1)
6158 BoxItem item = (BoxItem)ACCESS_ITEM(dirtyArea, dirtyArea.first);
6159 if(item.box.left <= box.left &&
6160 item.box.top <= box.top &&
6161 item.box.right >= box.right &&
6162 item.box.bottom >= box.bottom)
6164 rootWindow.dirty = true;
6169 if(display.flags.flipping && !rootWindow.dirty)
6171 if(this == rootWindow)
6175 rootWindow.Update(null);
6180 rootWindow.dirty = true;
6185 realBox.left += clientStart.x;
6186 realBox.top += clientStart.y;
6187 realBox.right += clientStart.x;
6188 realBox.bottom += clientStart.y;
6194 if(realBox.right >= realBox.left &&
6195 realBox.bottom >= realBox.top)
6197 // if(!rootWindow.fullRender)
6198 dirtyArea.UnionBox(realBox, rootWindow.tempExtents[0]);
6200 for(child = children.first; child; child = child.next)
6205 box.left -= child.absPosition.x - absPosition.x;
6206 box.top -= child.absPosition.y - absPosition.y;
6207 box.right -= child.absPosition.x - absPosition.x;
6208 box.bottom -= child.absPosition.y - absPosition.y;
6209 if(box.right >= child.box.left && box.left <= child.box.right &&
6210 box.bottom >= child.box.top && box.top <= child.box.bottom)
6212 box.left -= child.clientStart.x;
6213 box.top -= child.clientStart.y;
6214 box.right -= child.clientStart.x;
6215 box.bottom -= child.clientStart.y;
6221 realBox.left += absPosition.x - rootWindow.absPosition.x;
6222 realBox.top += absPosition.y - rootWindow.absPosition.y;
6223 realBox.right += absPosition.x - rootWindow.absPosition.x;
6224 realBox.bottom += absPosition.y - rootWindow.absPosition.y;
6225 rootWindow.dirtyBack.UnionBox(realBox, rootWindow.tempExtents[0]);
6228 else if(this == guiApp.desktop)
6231 for(window = children.first; window; window = window.next)
6237 Box childBox = region;
6239 childBox.left -= window.absPosition.x - guiApp.desktop.absPosition.x;
6240 childBox.top -= window.absPosition.y - guiApp.desktop.absPosition.y;
6241 childBox.right -= window.absPosition.x - guiApp.desktop.absPosition.x;
6242 childBox.bottom -= window.absPosition.y - guiApp.desktop.absPosition.y;
6244 window.Update(childBox);
6247 window.Update(null);
6252 // rootWindow.mutex.Release();
6259 if(guiApp.windowCaptured != this)
6261 if(guiApp.windowCaptured)
6265 //Logf("Captured %s (%s)\n", caption, class.name);
6266 guiApp.interfaceDriver.SetMouseCapture(rootWindow);
6267 guiApp.windowCaptured = this;
6273 bool Destroy(int code)
6278 if(!CloseConfirmation(false)) return false;
6282 // TOCHECK: Should autoCreate be set to false here?
6285 // Is this needed here? DestroyEx should decref already...
6294 void Move(int x, int y, int w, int h)
6296 normalAnchor = Anchor { left = x, top = y };
6297 normalSizeAnchor = SizeAnchor { size = { w, h } };
6299 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6301 if(destroyed) return;
6303 stateAnchor = normalAnchor;
6304 stateSizeAnchor = normalSizeAnchor;
6306 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6307 Position(x,y, w, h, true, true, true, true, false, true);
6311 DialogResult Modal(void)
6317 // FIXES MEMORY LEAK IF Create() FAILED
6323 void SetScrollArea(int width, int height, bool snapToStep)
6325 bool resize = false;
6328 int stepX = sbStep.x, stepY = sbStep.y;
6329 // Needed to make snapped down position match the skin's check of client area
6330 // against realvirtual
6333 SNAPDOWN(stepX, textCellW);
6334 SNAPDOWN(stepY, textCellH);
6335 stepX = Max(stepX, textCellW);
6336 stepY = Max(stepY, textCellH);
6338 if(scrollFlags.snapX)
6339 SNAPUP(width, stepX);
6340 if(scrollFlags.snapY)
6341 SNAPUP(height, stepY);
6344 reqScrollArea.w = width;
6345 reqScrollArea.h = height;
6346 noAutoScrollArea = (width > 0 || height > 0);
6348 UpdateScrollBars(true, true);
6351 void SetScrollPosition(int x, int y)
6354 sbh.Action(setPosition, x, 0);
6358 int seen = clientSize.w, total = reqScrollArea.w;
6360 if(scrollFlags.snapX)
6361 SNAPDOWN(seen, sbStep.x);
6363 if(!total) total = seen;
6364 range = total - seen + 1;
6365 range = Max(range, 1);
6367 if(x >= range) x = range - 1;
6369 if(scrollFlags.snapX)
6370 SNAPUP(x, sbStep.x);
6373 OnHScroll(setPosition, x, 0);
6377 SNAPDOWN(x, textCellW);
6383 sbv.Action(setPosition, y, 0);
6387 int seen = clientSize.h, total = reqScrollArea.h;
6390 if(scrollFlags.snapY)
6391 SNAPDOWN(seen, sbStep.y);
6393 if(!total) total = seen;
6394 range = total - seen + 1;
6395 range = Max(range, 1);
6397 if(y >= range) y = range - 1;
6399 if(scrollFlags.snapY)
6400 SNAPUP(y, sbStep.y);
6403 OnVScroll(setPosition, y, 0);
6406 SNAPDOWN(y, textCellH);
6411 UpdateCaret(false, false);
6414 void SetScrollLineStep(int stepX, int stepY)
6420 SNAPDOWN(stepX, textCellW);
6421 SNAPDOWN(stepY, textCellH);
6422 stepX = Max(stepX, textCellW);
6423 stepY = Max(stepY, textCellH);
6426 sbh.lineStep = stepX;
6428 sbv.lineStep = stepY;
6431 void SetState(WindowState newState, bool activate, Modifiers mods)
6435 if(state == newState || OnStateChange(newState, mods))
6437 WindowState prevState = state;
6441 // This used to be at the end of the brackets... moved for X, testing...
6442 // This has the effect of activating the window through the system...
6443 if(rootWindow == this)
6444 guiApp.interfaceDriver.SetRootWindowState(this, newState, !style.hidden);
6446 SetStateEx(newState, activate);
6448 if(rootWindow == this && !rootWindow.nativeDecorations)
6450 int x = position.x, y = position.y;
6453 x -= guiApp.desktop.absPosition.x;
6454 y -= guiApp.desktop.absPosition.y;
6456 guiApp.interfaceDriver.PositionRootWindow(this, x, y, size.w, size.h, true, true);
6460 //state = prevState;
6462 if(state != maximized && style.hasMaximize)
6465 for(child = parent.children.first; child; child = child.next)
6467 if(child != this && child.state == maximized)
6468 child.SetStateEx(normal, false);
6472 if(!style.nonClient && (sbv || sbh) && this != parent.sbv && this != parent.sbh)
6473 parent.UpdateScrollBars(true, true);
6476 // Do we really need this stuff here?
6477 // Shouldn't the Activate stuff take care of it?
6478 if(parent.rootWindow == parent && style)
6481 parent.FigureCaption(caption);
6482 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
6483 parent.UpdateDecorations();
6487 rootWindow.ConsequentialMouseMove(false);
6494 BitmapResource GetIcon(SkinBitmap iconID)
6496 return guiApp.currentSkin.GetBitmap(iconID);
6499 void SetMouseRange(Box range)
6501 if(range || guiApp.fullScreenMode)
6506 clip.left = range.left + absPosition.x + clientStart.x;
6507 clip.top = range.top + absPosition.y + clientStart.y;
6508 clip.right = range.right + absPosition.x + clientStart.x;
6509 clip.bottom = range.bottom + absPosition.y + clientStart.y;
6513 clip.left = guiApp.desktop.box.left;
6514 clip.top = guiApp.desktop.box.top;
6515 clip.right = guiApp.desktop.box.right;
6516 clip.bottom = guiApp.desktop.box.bottom;
6518 guiApp.interfaceDriver.SetMouseRange(rootWindow, clip);
6521 guiApp.interfaceDriver.SetMouseRange(rootWindow, null);
6524 void SetMouseRangeToClient(void)
6526 if(guiApp.fullScreenMode || this != guiApp.desktop)
6528 Box box {0, 0, clientSize.w - 1, clientSize.h - 1 };
6529 box.Clip(clientArea);
6533 SetMouseRange(null);
6536 void SetMouseRangeToWindow(void)
6538 Box box { -clientStart.x, -clientStart.y, size.w-1, size.h-1 };
6539 if(this == guiApp.desktop)
6540 SetMouseRangeToClient();
6545 // x, y: Desktop Coordinates
6546 void ShowSysMenu(int x, int y)
6549 PopupMenu windowMenu { master = this, interim = true, position = { x + 1 - guiApp.desktop.position.x, y + 1 - guiApp.desktop.position.y }, menu = menu };
6552 menu, "Restore", r, NotifySelect = MenuWindowRestore,
6553 disabled = (!style.hasMaximize && !style.hasMinimize) || state == normal, bitmap = guiApp.currentSkin.GetBitmap(restore)
6557 menu, "Move", m, NotifySelect = MenuWindowMove,
6558 disabled = !style.fixed || state == maximized
6562 menu, "Size", s, NotifySelect = MenuWindowSize,
6563 disabled = !style.sizable || state != normal
6567 menu, "Minimize", n, NotifySelect = MenuWindowMinimize,
6568 disabled = !style.hasMinimize || state == minimized, bitmap = guiApp.currentSkin.GetBitmap(minimize)
6572 menu, "Maximize", KeyCode::x, NotifySelect = MenuWindowMaximize,
6573 disabled = !style.hasMaximize || state == maximized, bitmap = guiApp.currentSkin.GetBitmap(maximize)
6577 menu, "Stay On Top", t, NotifySelect = MenuWindowStayOnTop,
6578 disabled = !style.fixed, checkable = true, checked = style.stayOnTop
6580 MenuDivider { menu };
6583 menu, "Close", c, (parent == guiApp.desktop) ? altF4 : ( style.isActiveClient ? ctrlF4 : 0), NotifySelect = MenuWindowClose,
6584 bold = true, disabled = !style.hasClose, bitmap = guiApp.currentSkin.GetBitmap(close)
6586 windowMenu.Create();
6591 ActivateEx(true, true, true, true, null, null);
6594 void MakeActive(void)
6596 ActivateEx(true, false, true, false, null, null);
6599 void SoftActivate(void)
6601 if(guiApp.desktop.active)
6607 void Deactivate(void)
6609 ActivateEx(false, true, true, true, null, null);
6614 guiApp.interfaceDriver.FlashRootWindow(rootWindow);
6617 bool CycleChildren(bool backward, bool clientOnly, bool tabCycleOnly, bool cycleParents)
6619 bool result = false;
6620 if(activeChild && activeChild.cycle)
6622 Window modalWindow, child = activeChild;
6623 if(!clientOnly /*&& parent.tabCycle*/)
6625 Window next = child;
6628 if(next.cycle == (backward ? childrenCycle.first : childrenCycle.last))
6632 if(parent && parent.CycleChildren(backward, false, true, true))
6640 next = next.cycle.prev.data;
6642 next = next.cycle.next.data;
6643 if(!next.disabled && !next.inactive /*isRemote*/ && next.created && !next.nonClient && (!clientOnly || next.style.isActiveClient) && !next.style.hidden && next.FindModal() != activeChild)
6648 if(!clientOnly && child.cycle == (backward ? childrenCycle.first : childrenCycle.last) &&
6649 parent.tabCycle && parent.CycleChildren(backward, false, false))
6653 if(tabCycleOnly && !tabCycle) return false;
6660 child = child.cycle.prev.data;
6662 child = child.cycle.next.data;
6663 if(child == child.parent.activeChild)
6665 else if(!child.disabled && child.created && (!clientOnly || child.style.isActiveClient) && !child.style.hidden && child.FindModal() != activeChild)
6668 modalWindow = child.FindModal();
6671 // Scroll the window to include the active control
6672 if(sbh && !child.style.dontScrollHorz)
6674 if(child.scrolledPos.x < 0)
6675 sbh.Action(setPosition, scroll.x + child.scrolledPos.x, 0);
6676 else if(child.scrolledPos.x + child.size.w > clientSize.w)
6677 sbh.Action(setPosition, scroll.x + child.scrolledPos.x + child.size.w - clientSize.w, 0);
6679 if(sbv && !child.style.dontScrollVert)
6681 if(child.scrolledPos.y < 0)
6682 sbv.Action(setPosition, scroll.y + child.scrolledPos.y, 0);
6683 else if(child.scrolledPos.y + child.size.h > clientSize.h)
6684 sbv.Action(setPosition, scroll.y + child.scrolledPos.y + child.size.h - clientSize.h, 0);
6688 child = modalWindow ? modalWindow : child;
6689 child.ActivateEx(true, true, true, true, null, null);
6690 if(child.tabCycle && child.childrenCycle.first)
6691 child = ((OldLink)(backward ? child.childrenCycle.first : child.childrenCycle.last)).data;
6699 ConsequentialMouseMove(false);
6703 void AddResource(Resource resource)
6707 ResPtr ptr { resource = resource };
6711 // Load Graphics here if window is created already
6712 if(/*created && */display)
6714 display.Lock(false);
6715 ptr.loaded = display.displaySystem.LoadResource(resource);
6719 // Temporary hack to load font right away for listbox in dropbox ...
6720 else if(master && master.display)
6722 master.display.Lock(false);
6723 master.display.displaySystem.LoadResource(resource);
6724 master.display.Unlock();
6730 void RemoveResource(Resource resource)
6735 for(ptr = resources.first; ptr; ptr = ptr.next)
6737 if(ptr.resource == resource)
6743 // Unload Graphics here if window is created already
6744 if(/*created && */display)
6748 display.Lock(false);
6749 display.displaySystem.UnloadResource(resource, ptr.loaded);
6755 resources.Delete(ptr);
6760 void SetCaret(int x, int y, int size)
6767 if(active && !style.interim)
6769 if(visible || !guiApp.caretOwner)
6770 guiApp.caretOwner = size ? this : null;
6772 UpdateCaret(false, false);
6775 guiApp.interfaceDriver.SetCaret(0,0,0);
6776 UpdateCaret(false, true);
6777 guiApp.caretEnabled = false;
6780 else if(style.inactive && active)
6782 guiApp.interfaceDriver.SetCaret(0,0,0);
6783 UpdateCaret(false, true);
6784 guiApp.caretEnabled = false;
6789 void Scroll(int x, int y)
6791 bool opaque = !style.drawBehind || background.a;
6792 if(opaque && display && display.flags.scrolling)
6794 Box box = clientArea;
6795 box.left += clientStart.x;
6796 box.top += clientStart.y;
6797 box.right += clientStart.x;
6798 box.bottom += clientStart.y;
6800 //scrollExtent.Free(null);
6801 scrollExtent.AddBox(box);
6802 scrolledArea.x += x;
6803 scrolledArea.y += y;
6805 //scrollExtent.Free();
6806 //scrollExtent.AddBox(clientArea);
6807 //scrollExtent.Offset(clientStart.x, clientStart.y);
6808 //scrolledArea.x = x;
6809 //scrolledArea.y = y;
6815 rootWindow.dirty = true;
6818 void ReleaseCapture()
6820 if(guiApp && guiApp.windowCaptured && guiApp.windowCaptured == this)
6822 Window oldCaptured = guiApp.windowCaptured;
6823 guiApp.windowCaptured = null;
6824 guiApp.prevWindow = null;
6827 //guiApp.Log("Released Capture\n");
6829 guiApp.interfaceDriver.SetMouseCapture(null);
6831 //oldCaptured.OnMouseCaptureLost();
6834 oldCaptured.ConsequentialMouseMove(false);
6839 void SetText(char * format, ...)
6846 char caption[MAX_F_STRING];
6848 va_start(args, format);
6849 vsprintf(caption, format, args);
6852 this.caption = new char[strlen(caption)+1];
6854 strcpy(this.caption, caption);
6863 bool Grab(Bitmap bitmap, Box box, bool decorations)
6865 bool result = false;
6866 if(display || this == guiApp.desktop)
6868 Box clip = {MININT, MININT, MAXINT, MAXINT};
6874 clip.Clip(clientArea);
6876 clip.Clip(this.box);
6878 if(rootWindow != this)
6880 clip.left += absPosition.y;
6881 clip.top += absPosition.y;
6882 clip.right += absPosition.x;
6883 clip.bottom += absPosition.y;
6886 clip.left += decorations ? 0 : clientStart.x;
6887 clip.top += decorations ? 0 : clientStart.y;
6888 clip.right += decorations ? 0 : clientStart.x;
6889 clip.bottom += decorations ? 0 : clientStart.y;
6891 if(display && display.flags.flipping)
6893 rootWindow.Update(null);
6894 rootWindow.UpdateDisplay();
6901 result = window.display.displaySystem.driver.GrabScreen(null, bitmap, clip.left, clip.top,
6902 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6906 result = display.Grab(bitmap, clip.left, clip.top,
6907 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6909 if(bitmap.pixelFormat != pixelFormat888 && bitmap.pixelFormat != pixelFormat8)
6911 if(!bitmap.Convert(null, pixelFormat888, null))
6918 void GetMousePosition(int * x, int * y)
6920 int mouseX = 0, mouseY = 0;
6921 if(!guiApp.acquiredWindow && (guiApp.desktop.active || !guiApp.fullScreenMode))
6924 guiApp.interfaceDriver.GetMousePosition(&mouseX, &mouseY);
6925 if(this != guiApp.desktop)
6927 mouseX -= absPosition.x + clientStart.x;
6928 mouseY -= absPosition.y + clientStart.y;
6935 DialogResult DoModal()
6937 DialogResult returnCode = 0;
6938 int terminated = terminateX;
6941 while(!destroyed && guiApp.driver != null)
6943 if(terminateX != terminated)
6945 terminated = terminateX;
6946 guiApp.desktop.Destroy(0);
6947 if(guiApp.desktop.created)
6950 //printf("Resetting terminate X to 0\n");
6956 guiApp.UpdateDisplay();
6957 if(!guiApp.ProcessInput(false))
6960 returnCode = this.returnCode;
6973 return !destroyed && guiApp.driver != null && terminateX < 2;
6976 DialogResult DoModalEnd()
6978 DialogResult returnCode = this.returnCode;
6983 // --- Window manipulation ---
6984 /*bool GetDisabled()
6986 bool disabled = this.disabled;
6988 for(window = this; (window = window.master); )
6999 // --- Mouse Manipulation ---
7000 void GetNCMousePosition(int * x, int * y)
7002 GetMousePosition(x, y);
7003 if(x) *x += clientStart.x;
7004 if(y) *y += clientStart.y;
7007 // --- Carets manipulation ---
7008 void GetCaretPosition(Point caretPos)
7010 caretPos = this.caretPos;
7013 int GetCaretSize(void)
7018 bool ButtonCloseDialog(Button button, int x, int y, Modifiers mods)
7024 bool CloseConfirmation(bool parentClosing)
7037 if(!OnClose(parentClosing))
7040 // If you want to skip this, simply set modifiedDocument to false in OnClose
7041 if(result && (/*fileName || */style.isDocument) && modifiedDocument)
7043 DialogResult dialogRes;
7046 sprintf(message, "Save changes to %s?", fileName);
7048 sprintf(message, "Save changes to Untitled %d?", documentID);
7050 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption, contents = message }.Modal();
7052 if(dialogRes == yes)
7054 // TOFIX: Precomp error if brackets are taken out
7055 result = (DialogResult)MenuFileSave(null, 0) != cancel;
7057 else if(dialogRes == cancel)
7063 for(slave = slaves.first; slave; slave = slave.next)
7064 if(!((Window)slave.data).CloseConfirmation(true))
7066 // ((Window)slave.data).CloseConfirmation(true);
7074 for(child = children.first; child; child = child.next)
7075 if(child.master != this && !child.CloseConfirmation(true))
7085 // Static methods... move them somewhere else?
7086 void ::RestoreCaret()
7088 if(guiApp.caretOwner)
7089 guiApp.caretOwner.UpdateCaret(false, false);
7092 void ::FreeMouseRange()
7094 guiApp.interfaceDriver.SetMouseRange(null, null);
7098 bool MenuFileClose(MenuItem selection, Modifiers mods)
7100 Window document = activeChild;
7102 document.Destroy(0);
7106 bool MenuFileExit(MenuItem selection, Modifiers mods)
7112 bool MenuFileSave(MenuItem selection, Modifiers mods)
7116 fileMonitor.fileName = null;
7119 if(OnSaveFile(fileName))
7121 //if(OnFileModified != Window::OnFileModified)
7124 fileMonitor.fileName = fileName;
7130 MessageBox dialog { master = master, type = yesNoCancel, text = "Error writing file", contents = "Save as a different file?" };
7131 DialogResult answer = dialog.Modal();
7133 if(answer != yes) return (bool)answer;
7136 return MenuFileSaveAs(selection, mods);
7139 bool MenuFileSaveAs(MenuItem selection, Modifiers mods)
7141 DialogResult result = (DialogResult)bool::true;
7142 FileDialog fileDialog = saveDialog;
7145 fileDialog = FileDialog {};
7150 fileDialog.filePath = fileName;
7153 char filePath[MAX_FILENAME];
7154 sprintf(filePath, "Untitled %d", documentID);
7155 fileDialog.filePath = filePath;
7157 fileMonitor.fileName = null;
7159 fileDialog.type = save;
7160 fileDialog.text = "Save As";
7164 fileDialog.master = master.parent ? master : this;
7165 if(fileDialog.Modal() == ok)
7167 char * filePath = fileDialog.filePath;
7169 if(OnSaveFile(filePath))
7172 property::fileName = filePath;
7173 NotifySaved(master, this, filePath);
7178 MessageBox dialog { master = master.parent ? master : this, type = yesNoCancel, text = "Error writing file", contents = "Save as a different file?" };
7179 DialogResult answer = dialog.Modal();
7194 //if(OnFileModified != Window::OnFileModified && fileName)
7197 fileMonitor.fileName = fileName;
7201 return (bool)result; // Actually returning result from Yes/NoCancel message box
7204 bool MenuFileSaveAll(MenuItem selection, Modifiers mods)
7206 Window document = activeChild;
7208 for(document = children.first; document; document = next)
7210 next = document.next;
7211 if(document.style.isDocument || document.fileName)
7212 document.MenuFileSave(selection, mods);
7217 bool MenuWindowArrangeIcons(MenuItem selection, Modifiers mods)
7221 for(document = children.first; document; document = document.next)
7222 //if(document.style.isDocument && document.state == minimized)
7223 if(document.style.isActiveClient && document.state == minimized)
7224 document.SetState(minimized, false, mods);
7228 bool MenuWindowCascade(MenuItem selection, Modifiers mods)
7230 Window document = activeChild;
7233 Window firstDocument = null;
7235 OldLink cycle = document.cycle.prev;
7240 if(child.style.isActiveClient && !child.style.hidden)
7244 firstDocument = child;
7245 if(child.state == minimized)
7246 child.SetState(minimized, false, mods);
7249 child.positionID = id++;
7250 child.SetState(normal, false, mods);
7251 child.anchor.left.type = cascade;
7254 child.normalSizeAnchor = *&child.sizeAnchor;
7255 child.normalAnchor = child.anchor;
7257 // Break the anchors for moveable/resizable windows
7258 if(child.style.fixed)
7260 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7262 (*&child.normalAnchor).left = x;
7263 (*&child.normalAnchor).top = y;
7264 (*&child.normalAnchor).right.type = none;
7265 (*&child.normalAnchor).bottom.type = none;
7267 child.normalSizeAnchor.isClientW = false;
7268 child.normalSizeAnchor.isClientH = false;
7269 child.normalSizeAnchor.size.w = w;
7270 child.normalSizeAnchor.size.h = h;
7271 child.anchored = false;
7274 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7276 child.stateAnchor = child.normalAnchor;
7277 child.stateSizeAnchor = child.normalSizeAnchor;
7279 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7280 child.Position(x, y, w, h, true, true, true, true, false, false);
7285 last = children.last;
7286 if(!child.style.stayOnTop)
7287 for(; last && last.style.stayOnTop; last = last.prev);
7288 children.Move(child, last);
7289 childrenOrder.Move(child.order, childrenOrder.last);
7291 if(cycle == document.cycle) break;
7295 firstDocument.Activate();
7300 bool MenuWindowClose(MenuItem selection, Modifiers mods)
7307 // Close all closes all active clients, not all documents
7308 bool MenuWindowCloseAll(MenuItem selection, Modifiers mods)
7310 Window next, document;
7312 for(document = children.first; document; document = next)
7314 for(next = document.next; next && !(next.style.isActiveClient; next = next.next);
7315 if(document.style.isActiveClient)
7316 if(!document.Destroy(0) && !document.style.hidden)
7322 bool MenuWindowMaximize(MenuItem selection, Modifiers mods)
7324 if(style.hasMaximize && state != maximized)
7325 SetState(maximized, 0, 0);
7329 bool MenuWindowMinimize(MenuItem selection, Modifiers mods)
7331 if(style.hasMinimize && state != minimized)
7333 SetState(minimized, 0, 0);
7334 parent.CycleChildren(false, true, false, true);
7339 bool MenuWindowMove(MenuItem selection, Modifiers mods)
7341 MenuMoveOrSize(false, selection ? true : false);
7345 bool MenuWindowNext(MenuItem selection, Modifiers mods)
7347 CycleChildren(false, true, false, true);
7351 bool MenuWindowPrevious(MenuItem selection, Modifiers mods)
7353 CycleChildren(true, true, false, true);
7357 bool MenuWindowSize(MenuItem selection, Modifiers mods)
7359 MenuMoveOrSize(true, true);
7363 bool MenuWindowRestore(MenuItem selection, Modifiers mods)
7366 SetState(normal, 0, 0);
7370 bool MenuWindowSelectWindow(MenuItem selection, Modifiers mods)
7373 int id = selection.id;
7374 OldLink cycle = activeClient.cycle;
7376 //for(c = 0, cycle = activeChild.cycle; c<id; cycle = cycle.next, c++);
7379 Window sibling = cycle.data;
7380 if(sibling.style.isActiveClient)
7388 document = cycle.data;
7389 document.Activate();
7391 //if(activeChild.state == maximized)
7392 // document.SetState(maximized, false, mods);
7393 //else if(document.state == minimized)
7394 // document.SetState(normal, false, mods);
7398 bool MenuWindowStayOnTop(MenuItem selection, Modifiers mods)
7400 stayOnTop = !style.stayOnTop;
7404 bool MenuWindowTileHorz(MenuItem selection, Modifiers mods)
7406 Window document = activeChild;
7409 Window firstDocument = null;
7410 OldLink cycle = document.cycle;
7414 Window child = cycle.data;
7415 if(child.style.isActiveClient && !child.style.hidden)
7417 if(!firstDocument) firstDocument = child;
7418 if(child.state == minimized)
7419 child.SetState(minimized, false, mods);
7422 child.positionID = id++;
7423 child.SetState(normal, false, mods);
7424 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7426 child.anchor.left.type = hTiled;
7429 child.normalSizeAnchor = *&child.sizeAnchor;
7430 child.normalAnchor = child.anchor;
7432 // Break the anchors for moveable/resizable windows
7433 if(child.style.fixed)
7435 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7437 (*&child.normalAnchor).left = x;
7438 (*&child.normalAnchor).top = y;
7439 (*&child.normalAnchor).right.type = none;
7440 (*&child.normalAnchor).bottom.type = none;
7441 child.normalSizeAnchor.isClientW = false;
7442 child.normalSizeAnchor.isClientH = false;
7443 child.normalSizeAnchor.size.w = w;
7444 child.normalSizeAnchor.size.h = h;
7445 child.anchored = false;
7448 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7450 child.stateAnchor = child.normalAnchor;
7451 child.stateSizeAnchor = child.normalSizeAnchor;
7453 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7454 child.Position(x,y, w, h, true, true, true, true, false, true);
7459 if((cycle = cycle.next) == document.cycle) break;
7462 firstDocument.Activate();
7467 bool MenuWindowTileVert(MenuItem selection, Modifiers mods)
7469 Window document = activeChild;
7472 Window firstDocument = null;
7474 OldLink cycle = document.cycle;
7479 //if(child.style.isDocument)
7480 if(child.style.isActiveClient && !child.style.hidden)
7482 if(!firstDocument) firstDocument = child;
7483 if(child.state == minimized)
7484 child.SetState(minimized, false, mods);
7487 child.positionID = id++;
7488 child.SetState(normal, false, mods);
7489 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7491 child.anchor.left.type = vTiled;
7494 child.normalSizeAnchor = *&child.sizeAnchor;
7495 child.normalAnchor = child.anchor;
7497 // Break the anchors for moveable/resizable windows
7498 if(child.style.fixed)
7500 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7502 (*&child.normalAnchor).left = x;
7503 (*&child.normalAnchor).top = y;
7504 (*&child.normalAnchor).right.type = none;
7505 (*&child.normalAnchor).bottom.type = none;
7506 child.normalSizeAnchor.isClientW = false;
7507 child.normalSizeAnchor.isClientH = false;
7508 child.normalSizeAnchor.size.w = w;
7509 child.normalSizeAnchor.size.h = h;
7510 child.anchored = false;
7513 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7515 child.stateAnchor = child.normalAnchor;
7516 child.stateSizeAnchor = child.normalSizeAnchor;
7518 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7519 child.Position(x,y, w, h, true, true, true, true, false, true);
7524 if((cycle = cycle.next) == document.cycle) break;
7527 firstDocument.Activate();
7532 bool MenuWindowWindows(MenuItem selection, Modifiers mods)
7534 WindowList dialog { master = this };
7535 Window document = (Window)dialog.Modal();
7538 if(activeChild.state == maximized)
7539 document.SetState(maximized, false, mods);
7540 else if(document.state == minimized)
7541 document.SetState(normal, false, mods);
7542 document.Activate();
7548 virtual bool OnCreate(void);
7549 virtual void OnDestroy(void);
7550 virtual void OnDestroyed(void);
7551 virtual bool OnClose(bool parentClosing);
7552 virtual bool OnStateChange(WindowState state, Modifiers mods);
7553 virtual bool OnPostCreate(void);
7554 virtual bool OnMoving(int *x, int *y, int w, int h);
7555 virtual bool OnResizing(int *width, int *height);
7556 virtual void OnResize(int width, int height);
7557 virtual void OnPosition(int x, int y, int width, int height);
7558 virtual bool OnLoadGraphics(void);
7559 virtual void OnApplyGraphics(void);
7560 virtual void OnUnloadGraphics(void);
7561 virtual void OnRedraw(Surface surface);
7562 virtual bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct);
7563 virtual void OnActivateClient(Window client, Window previous);
7564 virtual bool OnKeyDown(Key key, unichar ch);
7565 virtual bool OnKeyUp(Key key, unichar ch);
7566 virtual bool OnKeyHit(Key key, unichar ch);
7567 virtual bool OnSysKeyDown(Key key, unichar ch);
7568 virtual bool OnSysKeyUp(Key key, unichar ch);
7569 virtual bool OnSysKeyHit(Key key, unichar ch);
7570 virtual bool OnMouseOver(int x, int y, Modifiers mods);
7571 virtual bool OnMouseLeave(Modifiers mods);
7572 virtual bool OnMouseMove(int x, int y, Modifiers mods);
7573 virtual bool OnLeftButtonDown(int x, int y, Modifiers mods);
7574 virtual bool OnLeftButtonUp(int x, int y, Modifiers mods);
7575 virtual bool OnLeftDoubleClick(int x, int y, Modifiers mods);
7576 virtual bool OnRightButtonDown(int x, int y, Modifiers mods);
7577 virtual bool OnRightButtonUp(int x, int y, Modifiers mods);
7578 virtual bool OnRightDoubleClick(int x, int y, Modifiers mods);
7579 virtual bool OnMiddleButtonDown(int x, int y, Modifiers mods);
7580 virtual bool OnMiddleButtonUp(int x, int y, Modifiers mods);
7581 virtual bool OnMiddleDoubleClick(int x, int y, Modifiers mods);
7582 virtual void OnMouseCaptureLost(void);
7583 virtual void OnHScroll(ScrollBarAction action, int position, Key key);
7584 virtual void OnVScroll(ScrollBarAction action, int position, Key key);
7585 virtual void OnDrawOverChildren(Surface surface);
7586 virtual bool OnFileModified(FileChange fileChange, char * param);
7587 virtual bool OnSaveFile(char * fileName);
7589 // Skins Virtual Functions
7590 virtual void GetDecorationsSize(MinMaxValue * w, MinMaxValue * h);
7591 virtual void SetWindowMinimum(MinMaxValue * mw, MinMaxValue * mh);
7592 virtual void SetWindowArea(int * x, int * y, MinMaxValue * w, MinMaxValue * h, MinMaxValue * cw, MinMaxValue * ch)
7597 virtual void ShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7598 virtual void PreShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7599 virtual bool IsMouseMoving(int x, int y, int w, int h);
7600 virtual bool IsMouseResizing(int x, int y, int w, int h, bool *resizeX, bool *resizeY, bool *resizeEndX, bool *resizeEndY);
7601 virtual void UpdateNonClient();
7602 virtual void SetBox(Box box);
7603 virtual bool IsInside(int x, int y)
7605 return box.IsPointInside({x, y});
7607 virtual bool IsOpaque()
7609 return (!style.drawBehind || background.a == 255);
7613 virtual bool Window::NotifyActivate(Window window, bool active, Window previous);
7614 virtual void Window::NotifyDestroyed(Window window, DialogResult result);
7615 virtual void Window::NotifySaved(Window window, char * filePath);
7620 property Window parent
7622 property_category "Layout"
7625 if(value || guiApp.desktop)
7628 Window oldParent = parent;
7629 Anchor anchor = this.anchor;
7631 if(value && value.IsDescendantOf(this)) return;
7632 if(value && value == this)
7634 if(!value) value = guiApp.desktop;
7636 if(value == oldParent) return;
7638 if(!master || (master == this.parent && master == guiApp.desktop))
7639 property::master = value;
7643 parent.children.Remove(this);
7647 box.left - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7648 box.top - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y,
7649 box.right - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7650 box.bottom - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y
7654 last = value.children.last;
7656 if(style.isDocument)
7659 parent.numDocuments--;
7660 documentID = value.GetDocumentID();
7663 if(style.isActiveClient && !style.hidden)
7665 if(parent && parent != guiApp.desktop && !(style.hidden))
7667 if(state == minimized) parent.numIcons--;
7668 parent.numPositions--;
7672 if(!style.stayOnTop)
7673 for(; last && last.style.stayOnTop; last = last.prev);
7675 value.children.Insert(last, this);
7677 // *** NEW HERE: ***
7679 parent.childrenCycle.Delete(cycle);
7681 parent.childrenOrder.Delete(order);
7689 int x = position.x, y = position.y, w = size.w, h = size.h;
7693 x += parent.absPosition.x - value.absPosition.x + parent.clientStart.x - value.clientStart.x;
7694 y += parent.absPosition.y - value.absPosition.y + parent.clientStart.y - value.clientStart.y;
7696 vpw = value.clientSize.w;
7697 vph = value.clientSize.h;
7703 else if(style.fixed)
7705 if(!style.dontScrollHorz && value.scrollArea.w) vpw = value.scrollArea.w;
7706 if(!style.dontScrollVert && value.scrollArea.h) vph = value.scrollArea.h;
7709 anchor = this.anchor;
7711 if(anchor.left.type == offset) anchor.left.distance = x;
7712 else if(anchor.left.type == relative) anchor.left.percent = (float)x / vpw;
7713 if(anchor.top.type == offset) anchor.top.distance = y;
7714 else if(anchor.top.type == relative) anchor.top.percent = (float)y / vph;
7715 if(anchor.right.type == offset) anchor.right.distance = vpw - (x + w);
7716 //else if(anchor.right.type == relative) anchor.right.percent = 1.0-(float) (vpw - (x + w)) / vpw;
7717 else if(anchor.right.type == relative) anchor.right.percent = (float) (vpw - (x + w)) / vpw;
7718 if(anchor.bottom.type == offset) anchor.bottom.distance = vph - (y + h);
7719 //else if(anchor.bottom.type == relative) anchor.bottom.percent = 1.0-(float) (vph - (y + h)) / vph;
7720 else if(anchor.bottom.type == relative) anchor.bottom.percent = (float) (vph - (y + h)) / vph;
7722 if(!anchor.left.type && !anchor.right.type)
7724 anchor.horz.distance = (x + w / 2) - (vpw / 2);
7725 //anchor.horz.type = anchor.horz.distance ? AnchorValueOffset : 0;
7727 else if(anchor.horz.type == middleRelative) anchor.horz.percent = (float) ((x + w / 2) - (vpw / 2)) / vpw;
7728 if(!anchor.top.type && !anchor.bottom.type)
7730 anchor.vert.distance = (y + h / 2) - (vph / 2);
7731 //anchor.vert.type = anchor.vert.distance ? AnchorValueOffset : 0;
7733 else if(anchor.vert.type == middleRelative) anchor.vert.percent = (float)((y + h / 2) - (vph / 2)) / vph;
7741 parent.childrenCycle.Insert(
7742 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
7743 cycle = OldLink { data = this });
7744 parent.childrenOrder.Insert(
7745 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
7746 order = OldLink { data = this });
7749 if(!style.hidden && style.isActiveClient)
7751 positionID = parent.GetPositionID(this);
7752 parent.numPositions++;
7753 if(state == minimized) parent.numIcons--;
7756 // *** FONT INHERITANCE ***
7757 if(!setFont && oldParent)
7758 stopwatching(oldParent, font);
7762 RemoveResource(systemFont);
7765 // TESTING WITH WATCHERS:
7766 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7767 // usedFont = setFont ? setFont : (systemFont);
7771 if(guiApp.currentSkin)
7773 systemFont = guiApp.currentSkin.SystemFont();
7776 usedFont = systemFont;
7777 AddResource(systemFont);
7785 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7794 if(value.rootWindow && value.rootWindow.display && rootWindow)
7796 bool reloadGraphics = (oldParent.rootWindow == oldParent && value.rootWindow) || (!value.rootWindow && rootWindow == this) ||
7797 (value.rootWindow.display && value.rootWindow.display.displaySystem != rootWindow.display.displaySystem);
7800 UnloadGraphics(false);
7803 LoadGraphics(false, false);
7806 if(value.rootWindow != rootWindow)
7807 DisplayModeChanged();
7811 scrolledPos.x = MININT; // Prevent parent update
7812 property::anchor = anchor;
7816 if(guiApp.currentSkin)
7817 guiApp.currentSkin.SetWindowMinimum(this, &skinMinSize.w, &skinMinSize.h);
7819 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
7820 Position(x, y, w, h, true, true, true, true, false, true);
7825 // else parent = value;
7828 get { return parent; }
7831 property Window master
7833 property_category "Behavior"
7836 //if(this == value) return;
7837 if(value && value.IsSlaveOf(this)) return;
7843 OldLink slaveHolder;
7844 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
7845 if(slaveHolder.data == this)
7847 master.slaves.Delete(slaveHolder);
7854 value.slaves.Add(OldLink { data = this });
7859 master.hotKeys.Remove(hotKey);
7860 value.hotKeys.Add(hotKey);
7863 if(master && master.defaultControl == this)
7864 master.defaultControl = null;
7866 if(style.isDefault && !value.defaultControl)
7867 value.defaultControl = this;
7873 get { return master ? master : parent; }
7876 property char * text
7878 property_category "Appearance"
7885 caption = new char[strlen(value)+1];
7887 strcpy(caption, value);
7892 get { return caption; }
7897 property_category "Behavior"
7906 master.hotKeys.Add(hotKey = HotKeySlot { });
7910 hotKey.window = this;
7915 master.hotKeys.Delete(hotKey);
7920 get { return hotKey ? hotKey.key : 0; }
7923 property Color background
7925 property_category "Appearance"
7928 background.color = value;
7933 if(this == rootWindow)
7934 guiApp.interfaceDriver.SetRootWindowColor(this);
7937 get { return background.color; }
7940 property Percentage opacity
7942 property_category "Appearance"
7945 background.a = (byte)Min(Max((int)(value * 255), 0), 255);
7946 drawBehind = background.a ? false : true;
7948 get { return background.a / 255.0f; }
7951 property Color foreground
7953 property_category "Appearance"
7961 get { return foreground; }
7964 property BorderStyle borderStyle
7966 property_category "Appearance"
7969 if(!((BorderBits)value).fixed)
7971 style.hasClose = false;
7972 style.hasMaximize = false;
7973 style.hasMinimize = false;
7975 style.borderBits = value;
7979 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
7981 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
7982 Position(x, y, w, h, true, true, true, true, false, true);
7983 CreateSystemChildren();
7986 get { return (BorderStyle)style.borderBits; }
7989 property Size minClientSize
7991 property_category "Layout"
7992 set { minSize = value; }
7993 get { value = minSize; }
7996 property Size maxClientSize
7998 property_category "Layout"
7999 set { maxSize = value; }
8000 get { value = maxSize; }
8003 property bool hasMaximize
8005 property_category "Window Style"
8008 style.hasMaximize = value;
8009 if(value) { style.fixed = true; style.contour = true; }
8013 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8015 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8016 Position(x, y, w, h, true, true, true, true, false, true);
8018 CreateSystemChildren();
8021 get { return style.hasMaximize; }
8024 property bool hasMinimize
8026 property_category "Window Style"
8029 style.hasMinimize = value;
8030 if(value) { style.fixed = true; style.contour = true; }
8034 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8036 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8037 Position(x, y, w, h, true, true, true, true, false, true);
8039 CreateSystemChildren();
8042 get { return style.hasMinimize; }
8045 property bool hasClose
8047 property_category "Window Style"
8050 style.hasClose = value;
8051 if(value) { style.fixed = true; style.contour = true; }
8055 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8056 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8057 Position(x, y, w, h, true, true, true, true, false, true);
8058 CreateSystemChildren();
8061 get { return style.hasClose; }
8064 property bool nonClient
8066 property_category "Layout"
8069 style.nonClient = value;
8071 style.stayOnTop = true;
8073 get { return style.nonClient; }
8076 property bool inactive
8078 property_category "Behavior"
8083 // *** NEW HERE: ***
8087 parent.childrenCycle.Delete(cycle);
8089 parent.childrenOrder.Delete(order);
8096 active = false; // true;
8097 if(parent.activeChild == this)
8098 parent.activeChild = null;
8099 if(parent.activeClient == this)
8100 parent.activeClient = null;
8109 parent.childrenCycle.Insert(
8110 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8111 cycle = OldLink { data = this });
8113 parent.childrenOrder.Insert(
8114 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8115 order = OldLink { data = this });
8118 style.inactive = value;
8120 get { return style.inactive; }
8123 property bool clickThrough
8125 property_category "Behavior"
8126 set { style.clickThrough = value; }
8127 get { return style.clickThrough; }
8130 property bool isRemote
8132 property_category "Behavior"
8133 set { style.isRemote = value; }
8134 get { return style.isRemote; }
8137 property bool noCycle
8139 property_category "Behavior"
8140 set { style.noCycle = value; }
8141 get { return style.noCycle; }
8144 property bool isModal
8146 property_category "Behavior"
8147 set { style.modal = value; }
8148 get { return style.modal; }
8151 property bool interim
8153 property_category "Behavior"
8154 set { style.interim = value; }
8155 get { return style.interim; }
8158 property bool tabCycle
8160 property_category "Behavior"
8161 set { style.tabCycle = value; }
8162 get { return style.tabCycle; }
8165 property bool isDefault
8167 property_category "Behavior"
8175 /*for(sibling = parent.children.first; sibling; sibling = sibling.next)
8176 if(sibling != this && sibling.style.isDefault)
8177 sibling.style.isDefault = false;*/
8178 if(master.defaultControl)
8179 master.defaultControl.style.isDefault = false;
8180 master.defaultControl = this;
8182 else if(master.defaultControl == this)
8183 master.defaultControl = null;
8187 style.isDefault = value;
8189 Position(position.x, position.y, size.w, size.h, true, true, true,true,true, true);
8191 get { return style.isDefault; }
8194 property bool drawBehind
8196 property_category "Window Style"
8197 set { style.drawBehind = value; }
8198 get { return style.drawBehind; }
8201 property bool hasMenuBar
8203 property_category "Window Style"
8213 if(created && !menuBar)
8220 anchor = Anchor { top = 23, left = 1, right = 1 },
8222 inactive = true, nonClient = true
8227 else if(created && menuBar)
8232 style.hasMenuBar = value;
8234 get { return style.hasMenuBar; }
8237 property bool hasStatusBar
8239 property_category "Window Style"
8246 statusBar = StatusBar { this };
8254 style.hasStatusBar = value;
8256 get { return style.hasStatusBar; }
8258 property bool stayOnTop
8260 property_category "Window Style"
8265 if(created && !style.stayOnTop)
8267 if(rootWindow == this)
8268 guiApp.interfaceDriver.OrderRootWindow(this, true);
8269 else if(parent.children.last != this)
8271 parent.children.Move(this, parent.children.last);
8275 style.stayOnTop = true;
8279 if(created && style.stayOnTop)
8281 if(rootWindow == this)
8282 guiApp.interfaceDriver.OrderRootWindow(this, false);
8289 for(order = (this.order == parent.childrenOrder.first) ? null : this.order.prev;
8290 order && ((Window)order.data).style.stayOnTop;
8291 order = (order == parent.childrenOrder.first) ? null : order.prev);
8292 last = order ? order.data : null;
8296 for(last = parent.children.last;
8297 last && last.style.stayOnTop;
8301 parent.children.Move(this, last);
8305 style.stayOnTop = false;
8308 get { return style.stayOnTop; }
8313 property_category "Window Style"
8323 if(menuBar && !value)
8330 if(!menuBar && style.hasMenuBar && value)
8334 this, menu = value, isMenuBar = true,
8335 anchor = Anchor { left = 1, top = 23, right = 1 }, size.h = 24,
8336 inactive = true, nonClient = true
8340 UpdateActiveDocument(null);
8343 get { return menu; }
8346 property FontResource font
8348 property_category "Appearance"
8350 isset { return setFont ? true : false; }
8355 if(value && !setFont) { stopwatching(parent, font); }
8356 else if(!value && setFont)
8362 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8371 RemoveResource(setFont);
8376 RemoveResource(systemFont);
8383 AddResource(setFont);
8386 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
8389 systemFont = guiApp.currentSkin.SystemFont();
8391 usedFont = systemFont;
8392 AddResource(systemFont);
8400 get { return usedFont; }
8403 property SizeAnchor sizeAnchor
8405 property_category "Layout"
8408 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8409 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8410 sizeAnchor.isClientW != sizeAnchor.isClientH;
8417 normalSizeAnchor = sizeAnchor;
8419 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8421 stateAnchor = normalAnchor;
8422 stateSizeAnchor = normalSizeAnchor;
8424 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8425 Position(x,y, w, h, true, true, true, true, false, true);
8432 { sizeAnchor.isClientW ? clientSize.w : size.w, sizeAnchor.isClientH ? clientSize.h : size.h },
8433 sizeAnchor.isClientW,
8434 sizeAnchor.isClientH
8441 property_category "Layout"
8444 Anchor thisAnchor = anchor;
8445 SizeAnchor thisSizeAnchor = sizeAnchor;
8446 bool leftRight = (anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none);
8447 bool topBottom = (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none);
8448 bool isClient = !sizeAnchor.isClientW && !sizeAnchor.isClientH;
8449 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8450 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8451 !sizeAnchor.isClientW && !sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8457 sizeAnchor.isClientW = false;
8458 sizeAnchor.isClientH = false;
8459 sizeAnchor.size = value;
8461 normalSizeAnchor = sizeAnchor;
8463 if(state == normal /*|| state == Hidden*/) // Hidden is new here ...
8465 stateAnchor = normalAnchor;
8466 stateSizeAnchor = normalSizeAnchor;
8468 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8469 Position(x, y, w, h, true, true, true, true, false, true);
8472 get { value = size; }
8475 property Size clientSize
8477 property_category "Layout"
8480 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8481 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8482 sizeAnchor.isClientW && sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8487 sizeAnchor.isClientW = true;
8488 sizeAnchor.isClientH = true;
8489 sizeAnchor.size = value;
8491 normalSizeAnchor = sizeAnchor;
8493 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8495 stateAnchor = normalAnchor;
8496 stateSizeAnchor = normalSizeAnchor;
8498 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8499 Position(x,y, w, h, true, true, true, true, false, true);
8502 get { value = clientSize; }
8505 property Size initSize { get { value = sizeAnchor.size; } };
8507 property Anchor anchor
8509 property_category "Layout"
8510 isset { return (anchor.left.type != offset || anchor.top.type != offset || anchor.right.type || anchor.bottom.type); }
8516 if(anchor.left.type && anchor.right.type && (!value.left.type || !value.right.type))
8518 normalSizeAnchor.isClientW = sizeAnchor.isClientW = false;
8519 normalSizeAnchor.size.w = sizeAnchor.size.w = size.w;
8521 if(anchor.top.type && anchor.bottom.type && (!value.top.type || !value.bottom.type))
8523 normalSizeAnchor.isClientH = sizeAnchor.isClientH = false;
8524 normalSizeAnchor.size.h = sizeAnchor.size.h = size.h;
8528 if(anchor.right.type && (anchor.horz.type == middleRelative || !anchor.left.type))
8530 anchor.left.distance = 0;
8531 anchor.horz.type = 0;
8533 if(anchor.bottom.type && (anchor.vert.type == middleRelative || !anchor.top.type))
8535 anchor.top.distance = 0;
8536 anchor.vert.type = 0;
8545 normalAnchor = anchor;
8547 // Break the anchors for moveable/resizable windows
8548 /*if(style.fixed ) //&& value.left.type == cascade)
8550 ComputeAnchors(anchor, sizeAnchor, &x, &y, &w, &h);
8552 this.anchor = normalAnchor = Anchor { left = x, top = y };
8553 normalSizeAnchor = SizeAnchor { { w, h } };
8556 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8558 stateAnchor = normalAnchor;
8559 stateSizeAnchor = normalSizeAnchor;
8561 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8562 Position(x, y, w, h, true, true, true, true, false, true);
8571 get { value = this ? anchor : Anchor { }; }
8574 property Point position
8576 property_category "Layout"
8579 if(value == null) return;
8581 anchor.left = value.x;
8582 anchor.top = value.y;
8583 anchor.right.type = none;
8584 anchor.bottom.type = none;
8589 normalAnchor = anchor;
8591 // Break the anchors for moveable/resizable windows
8595 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8597 normalAnchor.left = x;
8598 normalAnchor.top = y;
8599 normalAnchor.right.type = none;
8600 normalAnchor.bottom.type = none;
8601 normalSizeAnchor.size.width = w;
8602 normalSizeAnchor.size.height = h;
8606 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8608 stateAnchor = normalAnchor;
8609 stateSizeAnchor = normalSizeAnchor;
8611 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8612 Position(x,y, w, h, true, true, true, true, false, true);
8616 get { value = position; }
8619 property bool disabled
8621 property_category "Behavior"
8624 if(this && disabled != value)
8631 get { return (bool)disabled; }
8634 property bool isEnabled
8639 for(parent = this; parent; parent = parent.parent)
8646 property WindowState state
8648 property_category "Behavior"
8649 set { SetState(value, false, 0); }
8650 get { return this ? state : 0; }
8653 property bool visible
8655 property_category "Behavior"
8658 if(this && !value && !style.hidden && parent)
8660 bool wasActiveChild = parent.activeChild == this;
8661 Window client = null;
8663 style.hidden = true;
8664 if(style.isActiveClient)
8666 parent.numPositions--;
8667 if(state == minimized) parent.numIcons--;
8672 OldLink prevOrder = null;
8674 if(rootWindow == this)
8675 guiApp.interfaceDriver.SetRootWindowState(this, state, false);
8678 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
8681 box.left -= parent.clientStart.x;
8682 box.top -= parent.clientStart.y;
8683 box.right -= parent.clientStart.x;
8684 box.bottom -= parent.clientStart.y;
8688 if(style.modal && master && master.modalSlave == this)
8689 master.modalSlave = null;
8693 OldLink tmpPrev = order.prev;
8694 client = tmpPrev ? tmpPrev.data : null;
8695 if(client && !client.style.hidden && !client.destroyed && client.created)
8696 prevOrder = tmpPrev;
8699 client = tmpPrev ? tmpPrev.data : null;
8700 if(client == this) { client = null; break; }
8701 if(client && ((client.style.hidden) || client.destroyed || !client.created))
8703 tmpPrev = client.order.prev;
8708 prevOrder = tmpPrev;
8713 // If this window can be an active client, make sure the next window we activate can also be one
8714 if(!style.nonClient && style.isActiveClient)
8716 tmpPrev = prevOrder;
8719 client = tmpPrev ? tmpPrev.data : null;
8720 if(client == this) { client = null; break; }
8721 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
8723 tmpPrev = client.order.prev;
8728 prevOrder = tmpPrev;
8732 if(client && client.style.hidden) client = null;
8736 if((wasActiveChild /*parent.activeChild == this*/ || guiApp.interimWindow == this) && true /*activate*/)
8738 if(order && prevOrder && prevOrder.data != this)
8739 ((Window)prevOrder.data).ActivateEx(true, false, false, true, null, null);
8741 ActivateEx(false, false, false, true, null, null);
8743 // TESTING THIS HERE FOR HIDING ACTIVE CLIENT
8744 if(parent.activeClient == this)
8746 parent.activeClient = null;
8747 parent.UpdateActiveDocument(null);
8750 else if(parent.activeClient == this)
8752 parent.activeClient = client;
8753 parent.UpdateActiveDocument(this);
8756 // *** Not doing this anymore ***
8759 parent.childrenCycle.Delete(cycle);
8761 parent.childrenOrder.Delete(order);
8766 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8771 else if(this && value && style.hidden)
8773 style.hidden = false;
8776 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8777 if(rootWindow == this)
8778 guiApp.interfaceDriver.SetRootWindowState(this, state, true);
8780 if(style.modal && master)
8781 master.modalSlave = this;
8783 if(style.isActiveClient)
8785 positionID = parent.GetPositionID(this);
8786 parent.numPositions++;
8787 if(state == minimized) parent.numIcons++;
8790 // *** NOT DOING THIS ANYMORE ***
8792 if(!(style.inactive))
8794 if(!(style.noCycle))
8796 cycle = parent.childrenCycle.AddAfter(
8797 (parent.activeChild && parent.activeChild.cycle) ?
8798 parent.activeChild.cycle.prev : null, sizeof(OldLink));
8801 order = parent.childrenOrder.AddAfter(
8802 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8809 if(true || !parent.activeChild)
8810 ActivateEx(true, false, true, true, null, null);
8812 if(creationActivation == activate)
8813 ActivateEx(true, false, true, true, null, null);
8814 else if(creationActivation == flash && !object)
8817 //SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8821 ConsequentialMouseMove(false);
8827 style.hidden = !value;
8830 get { return (style.hidden || !setVisible) ? false : true; }
8833 property bool isDocument
8835 property_category "Document"
8836 set { style.isDocument = value; }
8837 get { return style.isDocument; }
8840 property bool mergeMenus
8842 property_category "Window Style"
8843 set { mergeMenus = value; }
8844 get { return (bool)mergeMenus; }
8847 property bool hasHorzScroll
8849 property_category "Window Style"
8854 if(!style.hasHorzScroll && created)
8856 CreateSystemChildren();
8857 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8860 else if(style.hasHorzScroll)
8864 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8866 style.hasHorzScroll = value;
8869 get { return style.hasHorzScroll; }
8872 property bool hasVertScroll
8874 property_category "Window Style"
8879 if(!style.hasVertScroll && created)
8881 style.hasVertScroll = true;
8882 CreateSystemChildren();
8883 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8886 else if(style.hasVertScroll)
8890 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8892 style.hasVertScroll = value;
8894 get { return style.hasVertScroll; }
8897 property bool dontHideScroll
8899 property_category "Behavior"
8902 scrollFlags.dontHide = value;
8905 //UpdateScrollBars(true, true);
8906 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
8910 // UpdateScrollBars(true, true);
8911 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
8914 get { return scrollFlags.dontHide; }
8917 property bool dontScrollVert
8919 property_category "Behavior"
8920 set { style.dontScrollVert = value; }
8921 get { return style.dontScrollVert; }
8923 property bool dontScrollHorz
8925 property_category "Behavior"
8926 set { style.dontScrollHorz = value; }
8927 get { return style.dontScrollHorz; }
8930 property bool snapVertScroll
8932 property_category "Behavior"
8935 scrollFlags.snapY = value;
8936 if(sbv) sbv.snap = value;
8938 get { return scrollFlags.snapY; }
8940 property bool snapHorzScroll
8942 property_category "Behavior"
8945 scrollFlags.snapX = value;
8946 if(sbh) sbh.snap = value;
8948 get { return scrollFlags.snapX; }
8951 property Point scroll
8953 property_category "Behavior"
8957 // TESTING THIS IMPLEMENTATION:
8958 SetScrollPosition(value.x, value.y);
8960 get { value = scroll; }
8963 property bool modifyVirtualArea
8965 property_category "Behavior"
8966 set { modifyVirtArea = value; }
8967 get { return (bool)modifyVirtArea; }
8970 property char * fileName
8972 property_category "Document"
8975 if(menu && ((!fileName && value) || (fileName && !value)))
8977 MenuItem item = menu.FindItem(MenuFileSave, 0);
8978 if(item) item.disabled = !modifiedDocument && value;
8983 if(value && value[0])
8984 fileName = CopyString(value);
8986 if(parent && this == parent.activeClient)
8987 parent.UpdateActiveDocument(null);
8991 // if(style.isDocument)
8993 fileMonitor.fileName = value;
8995 get { return fileName; }
9000 property_category "Data"
9005 property bool modifiedDocument
9007 property_category "Document"
9010 if(style.isDocument || fileName)
9014 MenuItem item = menu.FindItem(MenuFileSave, 0);
9015 if(item) item.disabled = !value && fileName;
9019 if(modifiedDocument != value)
9021 modifiedDocument = value;
9022 if(style.isDocument || fileName)
9026 get { return (bool)modifiedDocument; }
9029 property bool showInTaskBar
9031 property_category "Window Style"
9032 set { style.showInTaskBar = value; }
9033 get { return (style.showInTaskBar; }
9035 property FileDialog saveDialog { set { saveDialog = value; } };
9036 property bool isActiveClient
9038 property_category "Behavior"
9039 set { style.isActiveClient = value; }
9040 get { return style.isActiveClient; }
9043 property Cursor cursor
9045 property_category "Appearance"
9049 SelectMouseCursor();
9051 get { return cursor; }
9054 //#if !defined(ECERE_VANILLA)
9055 property char * name
9057 property_category "Design"
9060 return (this && object) ? object.name : null;
9065 activeDesigner.RenameObject(object, value);
9069 property char * displayDriver
9071 property_category "Behavior"
9074 dispDriver = GetDisplayDriver(value);
9075 //DisplayModeChanged();
9079 return dispDriver ? dispDriver.name : null;
9083 // RUNTIME PROPERTIES
9084 property bool autoCreate { set { autoCreate = value; } get { return (bool)autoCreate; } };
9085 property Size scrollArea
9087 property_category "Behavior"
9091 SetScrollArea(value.w, value.h, false);
9093 SetScrollArea(0,0, true);
9095 get { value = scrollArea; }
9098 return scrollArea.w > clientSize.w || scrollArea.h > clientSize.h;
9103 property_category "Layout"
9104 set { if(this) is3D = value; }
9105 get { return (bool)is3D; }
9108 // Runtime Only Properties (No Set, can display the displayable ones depending on the type?)
9110 // Will be merged with font later
9111 property Font fontObject { get { return usedFont ? usedFont.font : null; } };
9112 property Point clientStart { get { value = clientStart; } };
9113 property Point absPosition { get { value = absPosition; } };
9114 property Anchor normalAnchor { get {value = normalAnchor; } };
9115 // property Size normalSizeAnchor { get { value = normalSizeAnchor; } };
9116 property bool active { get { return (bool)active; } };
9117 property bool created { get { return (bool)created; } };
9118 property bool destroyed { get { return (bool)destroyed; } };
9119 property Window firstSlave { get { return slaves.first ? ((OldLink)slaves.first).data : null; } };
9120 property Window firstChild { get { return children.first; } };
9121 property Window lastChild { get { return children.last; } };
9122 property Window activeClient { get { return activeClient; } };
9123 property Window activeChild { get { return activeChild; } };
9124 property Display display { get { return display ? display : ((parent && parent.rootWindow) ? parent.rootWindow.display : null); } };
9125 property DisplaySystem displaySystem { get { return display ? display.displaySystem : null; } };
9126 property ScrollBar horzScroll { get { return sbh; } };
9127 property ScrollBar vertScroll { get { return sbv; } };
9128 property StatusBar statusBar { get { return statusBar; } };
9129 property Window rootWindow { get { return rootWindow; } };
9130 property bool closing { get { return (bool)closing; } set { closing = value; } };
9131 property int documentID { get { return documentID; } };
9132 property Window previous { get { return prev; } }
9133 property Window next { get { return next; } }
9134 property Window nextSlave { get { OldLink link = master ? master.slaves.FindLink(this) : null; return (link && link.next) ? link.next.data : null; } }
9135 property PopupMenu menuBar { get { return menuBar; } }
9136 property ScrollBar sbv { get { return sbv; } }
9137 property ScrollBar sbh { get { return sbh; } }
9138 property bool fullRender { set { fullRender = value; } get { return (bool)fullRender; } }
9139 property void * systemHandle { get { return windowHandle; } }
9140 property Button minimizeButton { get { return sysButtons[0]; } };
9141 property Button maximizeButton { get { return sysButtons[1]; } };
9142 property Button closeButton { get { return sysButtons[2]; } };
9143 property BitmapResource icon
9145 get { return icon; }
9149 if(icon) incref icon;
9151 guiApp.interfaceDriver.SetIcon(this, value);
9154 property bool moveable { get { return (bool)moveable; } set { moveable = value; } };
9155 property bool alphaBlend { get { return (bool)alphaBlend; } set { alphaBlend = value; } };
9156 property bool useSharedMemory { get { return (bool)useSharedMemory; } set { useSharedMemory = value; } };
9157 property CreationActivationOption creationActivation { get { return creationActivation; } set { creationActivation = value; } };
9158 property bool nativeDecorations { get { return (bool)nativeDecorations && (formDesigner || rootWindow == this); } set { nativeDecorations = value; } };
9159 property bool manageDisplay { get { return (bool)manageDisplay; } set { manageDisplay = value; } };
9165 WindowBits style; // Window Style
9166 char * caption; // Name / Caption
9167 Window parent; // Parent window
9168 OldList children; // List of children in Z order
9169 Window activeChild; // Child window having focus
9170 Window activeClient;
9171 Window previousActive; // Child active prior to activating the default child
9172 Window master; // Window owning and receiving notifications concerning this window
9173 OldList slaves; // List of windows belonging to this window
9174 Display display; // Display this window is drawn into
9176 Point position; // Position in parent window client area
9177 Point absPosition; // Absolute position
9178 Point clientStart; // Client area position from (0,0) in this window
9180 Size clientSize; // Client area size
9181 Size scrollArea; // Virtual Scroll area size
9182 Size reqScrollArea; // Requested virtual area size
9183 Point scroll; // Virtual area scrolling position
9184 public ScrollBar sbh, sbv; // Scrollbar window handles
9185 Cursor cursor; // Mouse cursor used for this window
9188 StatusBar statusBar;
9189 Button sysButtons[3];
9191 Box clientArea; // Client Area box clipped to parent
9193 HotKeySlot hotKey; // HotKey for this window
9197 ScrollFlags scrollFlags;// Window Scrollbar Flags
9198 int id; // Control ID
9200 ColorAlpha background; // Background color used to draw the window area
9202 subclass(DisplayDriver) dispDriver; // Display driver name for this window
9203 OldList childrenCycle; // Cycling order
9204 OldLink cycle; // Element of parent's cycling order
9205 OldList childrenOrder; // Circular Z-Order
9206 OldLink order; // Element of parent's circular Z-Order
9207 Window modalSlave; // Slave window blocking this window's interaction
9209 Window rootWindow; // Topmost system managed window
9210 void * windowHandle; // System window handle
9212 DialogResult returnCode;// Return code for modal windows
9214 Point sbStep; // Scrollbar line scrolling steps
9217 SizeAnchor stateSizeAnchor;
9219 Anchor normalAnchor;
9220 SizeAnchor normalSizeAnchor;
9222 Size skinMinSize; // Minimal window size based on style
9223 Point scrolledPos; // Scrolled position
9224 Box box; // Window box clipped to parent
9225 Box * against; // What to clip the box to
9227 Extent dirtyArea { /*first = -1, last = -1, free = -1*/ }; // Area marked for update by Update
9228 Extent renderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered
9229 Extent overRenderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered over children
9230 Extent clipExtent { /*first = -1, last = -1, free = -1*/ }; // Temporary extent against which to clip render area
9231 Extent scrollExtent { /*first = -1, last = -1, free = -1*/ }; // Area to scroll
9232 Point scrolledArea; // Distance to scroll area by
9233 Extent dirtyBack { /*first = -1, last = -1, free = -1*/ }; // Only used by root window
9235 OldList hotKeys; // List of the hotkeys of all children
9236 Window defaultControl; // Default child control
9240 ColorAlpha * palette; // Color palette used for this window
9242 int caretSize; // Size of caret, non zero if a caret is present
9243 Point caretPos; // Caret position
9245 void * systemParent; // Parent System Window for embedded windows
9252 WindowState lastState;
9254 FileMonitor fileMonitor
9256 this, FileChange { modified = true };
9258 bool OnFileNotify(FileChange action, char * param)
9261 fileMonitor.StopMonitoring();
9262 if(OnFileModified(action, param))
9263 fileMonitor.StartMonitoring();
9268 FontResource setFont, systemFont;
9269 FontResource usedFont;
9270 FontResource captionFont;
9272 FileDialog saveDialog;
9274 SizeAnchor sizeAnchor;
9276 // FormDesigner data
9279 Extent * tempExtents; //[4];
9280 BitmapResource icon;
9282 CreationActivationOption creationActivation;
9285 bool active:1; // true if window and ancestors are active
9286 bool acquiredInput:1; // true if the window is processing state based input
9287 bool modifiedDocument:1;
9288 bool disabled:1; // true if window cannot interact
9289 bool isForegroundWindow:1;// true while a root window is being activated
9290 bool visible:1; // Visibility flag
9291 bool destroyed:1; // true if window is being destroyed
9292 bool anchored:1; // true if this window is repositioned when the parent resizes
9293 bool dirty:1; // Flag set to true if any descendant must be redrawn
9299 bool modifyVirtArea:1;
9300 bool noAutoScrollArea:1;
9303 bool setVisible:1; // FOR FORM DESIGNER
9309 bool useSharedMemory:1;
9312 bool nativeDecorations:1;
9313 bool manageDisplay:1;
9314 bool formDesigner:1; // True if we this is running in the form editor
9317 WindowController controller;
9318 public property WindowController controller { get { return controller; } set { delete controller; controller = value; if(controller) incref controller; } }
9321 public class CommonControl : Window
9323 // creationActivation = doNothing;
9326 public class Percentage : float
9328 char * OnGetString(char * string, float * fieldData, bool * needClass)
9332 sprintf(string, "%.2f", this);
9333 c = strlen(string)-1;
9336 if(string[c] != '0')
9337 last = Max(last, c);
9338 if(string[c] == '.')
9351 public void ApplySkin(Class c, char * name, void ** vTbl)
9353 char className[1024];
9358 subclass(Window) wc = (subclass(Window))c;
9359 subclass(Window) base = (subclass(Window))c.base;
9361 sprintf(className, "%sSkin_%s", name, c.name);
9362 wc.pureVTbl = c._vTbl;
9363 c._vTbl = new void *[c.vTblSize];
9364 memcpy(c._vTbl, wc.pureVTbl, c.vTblSize * sizeof(void *));
9365 sc = eSystem_FindClass(c.module.application, className);
9369 for(m = 0; m < c.base.vTblSize; m++)
9371 if(c._vTbl[m] == base.pureVTbl[m])
9372 c._vTbl[m] = vTbl[m];
9377 for(m = 0; m < c.vTblSize; m++)
9379 if(sc._vTbl[m] != wc.pureVTbl[m])
9380 c._vTbl[m] = sc._vTbl[m];
9384 for(d = c.derivatives.first; d; d = d.next)
9386 ApplySkin(d.data, name, c._vTbl);
9390 public void UnapplySkin(Class c)
9392 char className[1024];
9394 subclass(Window) wc = (subclass(Window))c;
9395 subclass(Window) base = (subclass(Window))c.base;
9398 if(wc.pureVTbl && c._vTbl != wc.pureVTbl)
9401 c._vTbl = wc.pureVTbl;
9405 for(d = c.derivatives.first; d; d = d.next)
9407 UnapplySkin(d.data);
9411 void CheckFontIntegrity(Window window)
9416 if(window.usedFont && window.usedFont.font == 0xecececec)
9418 FontResource uf = window.usedFont;
9419 char * className = window._class.name;
9420 char * text = window.text;
9423 for(c = window.firstChild; c; c = c.next)
9424 CheckFontIntegrity(c);
9428 public class ControllableWindow : Window
9430 /*WindowController controller;
9431 public property WindowController controller { get { return controller; } set { delete controller; controller = value; incref controller; } }
9432 ~ControllableWindow() { delete controller; }*/
9435 class WindowControllerInterface : ControllableWindow
9437 bool OnKeyDown(Key key, unichar ch)
9439 bool result = ((int(*)())(void *)controller.OnKeyDown)((void *)controller.controlled, (void *)controller, key, ch);
9441 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown](controller.window, key, ch);
9445 bool OnKeyUp(Key key, unichar ch)
9447 bool result = ((int(*)())(void *)controller.OnKeyUp)((void *)controller.controlled, (void *)controller, key, ch);
9449 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp](controller.window, key, ch);
9453 bool OnKeyHit(Key key, unichar ch)
9455 bool result = ((int(*)())(void *)controller.OnKeyHit)((void *)controller.controlled, (void *)controller, key, ch);
9457 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit](controller.window, key, ch);
9461 bool OnMouseMove(int x, int y, Modifiers mods)
9463 bool result = ((int(*)())(void *)controller.OnMouseMove)((void *)controller.controlled, (void *)controller, x, y, mods);
9465 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove](controller.window, x, y, mods);
9469 bool OnLeftButtonDown(int x, int y, Modifiers mods)
9471 bool result = ((int(*)())(void *)controller.OnLeftButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9473 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown](controller.window, x, y, mods);
9477 bool OnLeftButtonUp(int x, int y, Modifiers mods)
9479 bool result = ((int(*)())(void *)controller.OnLeftButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9481 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp](controller.window, x, y, mods);
9485 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
9487 bool result = ((int(*)())(void *)controller.OnLeftDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9489 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick](controller.window, x, y, mods);
9493 bool OnRightButtonDown(int x, int y, Modifiers mods)
9495 bool result = ((int(*)())(void *)controller.OnRightButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9497 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown](controller.window, x, y, mods);
9501 bool OnRightButtonUp(int x, int y, Modifiers mods)
9503 bool result = ((int(*)())(void *)controller.OnRightButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9505 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp](controller.window, x, y, mods);
9509 bool OnRightDoubleClick(int x, int y, Modifiers mods)
9511 bool result = ((int(*)())(void *)controller.OnRightDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9513 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick](controller.window, x, y, mods);
9517 bool OnMiddleButtonDown(int x, int y, Modifiers mods)
9519 bool result = ((int(*)())(void *)controller.OnMiddleButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9521 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown](controller.window, x, y, mods);
9525 bool OnMiddleButtonUp(int x, int y, Modifiers mods)
9527 bool result = ((int(*)())(void *)controller.OnMiddleButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9529 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp](controller.window, x, y, mods);
9533 bool OnMiddleDoubleClick(int x, int y, Modifiers mods)
9535 bool result = ((int(*)())(void *)controller.OnMiddleDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9537 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick](controller.window, x, y, mods);
9541 void OnResize(int width, int height)
9543 ((int(*)())(void *)controller.OnResize)((void *)controller.controlled, (void *)controller, width, height);
9544 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnResize](controller.window, width, height);
9547 void OnRedraw(Surface surface)
9549 ((int(*)())(void *)controller.OnRedraw)((void *)controller.controlled, (void *)controller, surface);
9550 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRedraw](controller.window, surface);
9555 bool result = ((int(*)())(void *)controller.OnCreate)((void *)controller.controlled, (void *)controller);
9557 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnCreate](controller.window);
9562 public class WindowController<class V>
9565 property Window window
9569 uint size = class(Window).vTblSize;
9572 windowVTbl = new void *[size];
9573 memcpy(windowVTbl, value._vTbl, size * sizeof(void *));
9574 if(value._vTbl == value._class._vTbl)
9576 value._vTbl = new void *[value._class.vTblSize];
9577 memcpy(value._vTbl + size, value._class._vTbl + size, (value._class.vTblSize - size) * sizeof(void *));
9581 for(c = 0; c < size; c++)
9583 void * function = class(WindowControllerInterface)._vTbl[c];
9584 if(function != DefaultFunction)
9585 value._vTbl[c] = function;
9587 value._vTbl[c] = windowVTbl[c];
9592 memcpy(value._vTbl, windowVTbl, class(Window).vTblSize * sizeof(void *));
9595 get { return window; }
9597 property V controlled
9599 set { controlled = value; }
9600 get { return controlled; }
9602 virtual bool V::OnKeyDown(WindowController controller, Key key, unichar ch);
9603 virtual bool V::OnKeyUp(WindowController controller, Key key, unichar ch);
9604 virtual bool V::OnKeyHit(WindowController controller, Key key, unichar ch);
9605 virtual bool V::OnMouseMove(WindowController controller, int x, int y, Modifiers mods);
9606 virtual bool V::OnLeftButtonDown(WindowController controller, int x, int y, Modifiers mods);
9607 virtual bool V::OnLeftButtonUp(WindowController controller, int x, int y, Modifiers mods);
9608 virtual bool V::OnLeftDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9609 virtual bool V::OnRightButtonDown(WindowController controller, int x, int y, Modifiers mods);
9610 virtual bool V::OnRightButtonUp(WindowController controller, int x, int y, Modifiers mods);
9611 virtual bool V::OnRightDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9612 virtual bool V::OnMiddleButtonDown(WindowController controller, int x, int y, Modifiers mods);
9613 virtual bool V::OnMiddleButtonUp(WindowController controller, int x, int y, Modifiers mods);
9614 virtual bool V::OnMiddleDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9615 virtual void V::OnResize(WindowController controller, int width, int height);
9616 virtual void V::OnRedraw(WindowController controller, Surface surface);
9617 virtual bool V::OnCreate(WindowController controller);
9620 int (** windowVTbl)();