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();
1632 // Buttons bitmap resources crash if we do this while switching mode
1633 if(!guiApp || !guiApp.modeSwitching)
1636 // Process Anchored Children
1640 for(child = children.first; child; child = child.next)
1643 ((child.stateAnchor.left.type != offset ||
1644 child.stateAnchor.top.type != offset ||
1645 child.stateAnchor.right.type != none ||
1646 child.stateAnchor.bottom.type != none) ||
1647 child.state == maximized || child.state == minimized))
1649 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor,
1651 // child.Position(x, y, w, h, false, true, true, true, false);
1652 // This must be true cuz otherwise we're gonna miss everything since we SetPosition recursively already
1653 child.Position(x, y, w, h, true, true, true, true, false, true /*false*/);
1659 // Is this gonna cause other problems? Commented out for the FileDialog end bevel bug
1660 //if(updateScrollBars)
1662 OnResize(clientSize.w, clientSize.h);
1664 if((clientResized || windowMoved) && created)
1665 OnPosition(position.x, position.y, clientSize.w, clientSize.h);
1667 if(guiApp.interimWindow && guiApp.interimWindow.master.rootWindow == this)
1669 Window master = guiApp.interimWindow.master;
1670 master.OnPosition(master.position.x, master.position.y, master.clientSize.w, master.clientSize.h);
1673 if(rootWindow == this && !is3D)
1677 x -= guiApp.desktop.absPosition.x;
1678 y -= guiApp.desktop.absPosition.y;
1680 //guiApp.Log("Position %s\n", caption);
1681 if(windowResized || windowMoved)
1682 if(display && !display.flags.memBackBuffer && changeRootWindow)
1683 guiApp.interfaceDriver.PositionRootWindow(this, x, y, w, h, windowMoved, windowResized); //realResized);
1685 if(!guiApp.fullScreenMode && this != guiApp.desktop && (windowResized || windowMoved))
1686 for(child = parent.children.first; child && child != this; child = child.next)
1687 if(child.rootWindow)
1688 guiApp.interfaceDriver.UpdateRootWindow(child.rootWindow);
1692 if(windowMoved || windowResized)
1694 display.Lock(true /*false*/);
1697 display.Position(absPosition.x, absPosition.y);
1698 //display.Position(absPosition.x + clientStart.x, absPosition.y + clientStart.y);
1701 // result = realResized ? display.Resize(size.w, size.h) : true;
1702 if(nativeDecorations)
1704 int w = clientSize.w, h = clientSize.h;
1705 if(hasMenuBar) h += skinMenuHeight;
1706 if(hasStatusBar) h += statusBarHeight;
1707 if(sbv && sbv.visible) w += sbv.size.w;
1708 if(sbh && sbh.visible) h += sbh.size.h;
1709 result = manageDisplay ? display.Resize(w, h) : true;
1712 result = manageDisplay ? display.Resize(size.w, size.h) : true;
1716 else if(clientResized)
1718 // --- Major Slow Down / Fix OpenGL Resizing Main Window Lag
1721 if(!guiApp.fullScreenMode && !guiApp.modeSwitching && this == rootWindow)
1725 if(windowMoved || windowResized)
1730 if(guiApp.driver && changeRootWindow)
1732 if(windowResized || windowMoved)
1733 if(!display || display.flags.memBackBuffer)
1734 guiApp.interfaceDriver.PositionRootWindow(this,
1735 x, y, w, h, windowMoved, windowResized);
1736 guiApp.interfaceDriver.UpdateRootWindow(this);
1738 for(child = children.first; child; child = child.next)
1740 if(child.is3D && child.created)
1742 // Copy Display Content
1743 child.display.displaySystem = display.displaySystem;
1744 child.display.window = display.window;
1745 child.display.current = display.current;
1746 child.display.width = display.width;
1747 child.display.height = display.height;
1748 child.display.driverData = display.driverData;
1749 child.display.mutex = null;
1760 void UpdateScrollBars(bool flag, bool fullThing)
1763 bool resizeH = false, resizeV = false;
1764 bool scrolled = false;
1765 rvw = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.w;
1766 rvh = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.h;
1768 if(destroyed) return;
1769 if(guiApp.currentSkin)
1771 MinMaxValue cw = 0, ch = 0;
1772 bool sbvVisible, sbhVisible;
1774 int positionH, positionV;
1776 // First get client area with no respect to scroll bars
1781 &clientStart.x, &clientStart.y, &size.w, &size.h, &cw, &ch);
1783 if(scrollFlags.dontHide)
1786 cw -= guiApp.currentSkin.VerticalSBW();
1788 ch -= guiApp.currentSkin.HorizontalSBH();
1790 // Update the scrollbar visibility
1796 sbh.disabled = rangeH <= 1;
1797 if(sbh.style.hidden)
1807 sbv.disabled = rangeV <= 1;
1808 if(sbv.style.hidden)
1816 // Then start off with horizontal scrollbar range
1819 positionH = sbh.thumbPosition;
1824 ch -= guiApp.currentSkin.HorizontalSBH();
1827 // Do the same for vertical scrollbar
1830 positionV = sbv.thumbPosition;
1836 cw -= guiApp.currentSkin.VerticalSBW();
1837 // Maybe we need to set the range on the horizontal scrollbar again
1842 sbh.Action(setRange, positionH, 0);
1843 if(rangeH <= 1 && sbh.range > 1)
1845 ch -= guiApp.currentSkin.HorizontalSBH();
1849 sbv.Action(setRange, positionV, 0);
1856 // Update the scrollbar visibility
1857 if(!scrollFlags.dontHide)
1859 if(sbh && ((rangeH <= 1 && !sbh.style.hidden) || (rangeH > 1 && sbh.style.hidden)))
1863 if(sbv && ((rangeV <= 1 && !sbv.style.hidden) || (rangeV > 1 && sbv.style.hidden)))
1870 if(guiApp.currentSkin)
1877 sbhVisible = sbh.style.hidden ? true : false;
1879 sbvVisible = sbv.style.hidden ? true : false;
1881 // Do our resize here
1882 if(flag && (resizeH || resizeV) && fullThing)
1884 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, false);
1889 OnResize(clientSize.w, clientSize.h);
1895 sbh.visible = sbhVisible;
1897 sbv.visible = sbvVisible;
1899 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1900 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1903 sbh.pageStep = clientSize.w;
1905 sbv.pageStep = clientSize.h;
1907 // Notify doesn't handle setRange anymore... process it here
1910 int positionH = sbh.thumbPosition;
1911 if(scroll.x != positionH)
1913 OnHScroll(setRange, positionH, 0);
1917 SNAPDOWN(positionH, textCellW);
1918 scroll.x = positionH;
1924 int seen = clientSize.w, total = reqScrollArea.w;
1927 if(scrollFlags.snapX)
1928 SNAPDOWN(seen, sbStep.x);
1930 if(!total) total = seen;
1931 range = total - seen + 1;
1933 range = Max(range, 1);
1935 if(x >= range) x = range - 1;
1937 if(scrollFlags.snapX)
1938 SNAPUP(x, sbStep.x);
1942 OnHScroll(setRange, x, 0);
1947 SNAPDOWN(x, textCellW);
1953 int positionV = sbv.thumbPosition;
1954 if(scroll.y != positionV)
1956 OnVScroll(setRange, positionV, 0);
1960 SNAPDOWN(positionV, textCellH);
1961 scroll.y = positionV;
1967 int seen = clientSize.h, total = reqScrollArea.h;
1970 if(scrollFlags.snapY)
1971 SNAPDOWN(seen, sbStep.y);
1973 if(!total) total = seen;
1974 range = total - seen + 1;
1975 range = Max(range, 1);
1977 if(y >= range) y = range - 1;
1979 if(scrollFlags.snapY)
1980 SNAPUP(y, sbStep.y);
1984 OnVScroll(setRange, y, 0);
1989 SNAPDOWN(y, textCellH);
1995 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
1998 for(child = children.first; child; child = child.next)
2000 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2003 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2004 child.Position(x, y, w, h, false, true, false, true, false, false);
2011 // Process Scrollbars
2013 if(sbh) // && !sbh.style.hidden
2015 sbh.Move(clientStart.x, clientStart.y + clientSize.h, clientSize.w,0);
2016 // Need to set the range again (should improve...) since the scrollbars didn't have
2017 // the right size when UpdateScrollArea set the range on it
2020 sbh.seen = clientSize.w;
2024 if(sbv) // && !sbv.state.hidden
2026 sbv.Move(clientStart.x + clientSize.w, clientStart.y, 0, clientSize.h);
2027 // Need to set the range again (should improve...) since the scrollbars didn't have
2028 // the right size when UpdateScrollArea set the range on it
2031 sbv.seen = clientSize.h;
2036 // TESTING THIS LOWER
2037 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2040 for(child = children.first; child; child = child.next)
2042 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2045 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2046 child.Position(x, y, w, h, false, true, false, true, false, false);
2052 bool MaximizeButtonClicked(Button button, int x, int y, Modifiers mods)
2054 SetState(maximized, false, mods);
2058 bool RestoreButtonClicked(Button button, int x, int y, Modifiers mods)
2060 SetState(normal, false, mods);
2064 bool MinimizeButtonClicked(Button button, int x, int y, Modifiers mods)
2066 SetState(minimized, false, mods);
2067 parent.CycleChildren(false, true, false, true);
2071 void ScrollBarNotification(ScrollBar control, ScrollBarAction action, int position, Key keyFlags)
2074 // Scroll bar notifications
2075 if(action != setRange)
2077 bool changed = false;
2081 if(scroll.x != position)
2083 OnHScroll(action, position, keyFlags);
2088 SNAPDOWN(position, textCellW);
2090 scroll.x = position;
2094 if(scroll.y != position)
2096 OnVScroll(action, position, keyFlags);
2101 SNAPDOWN(position, textCellH);
2103 scroll.y = position;
2107 bool childMove = false;
2108 for(child = children.first; child; child = child.next)
2110 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2113 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2114 child.Position(x, y, w, h, false, true, false, true, false, false);
2118 // Testing this patch out to solve MDI workspace redraw bugs
2119 // We were already supposed to be updating parent's affected area in Position() but it doesn't seem to be working
2120 // Scroll offsets to blame?
2124 UpdateCaret(false, false);
2128 // Testing this patch out to solve MDI workspace redraw bugs
2129 for(child = children.first; child; child = child.next)
2131 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2140 void CreateSystemChildren(void)
2142 Window parent = this;
2143 bool scrollBarChanged = false;
2144 bool hasClose = false, hasMaxMin = false;
2145 Point scroll = this.scroll;
2147 if(state == maximized && this.parent.menuBar)
2149 if(this.parent.activeClient == this)
2150 parent = this.parent.menuBar;
2157 if(style.hasClose) hasClose = true;
2158 if(style.hasMaximize || style.hasMinimize)
2165 if(sysButtons[2] && (!hasClose || sysButtons[2].parent != parent))
2167 sysButtons[2].Destroy(0);
2168 sysButtons[2] = null;
2170 if(sysButtons[1] && (!hasMaxMin || sysButtons[1].parent != parent))
2172 sysButtons[1].Destroy(0);
2173 sysButtons[1] = null;
2175 if(sysButtons[0] && (!hasMaxMin || sysButtons[0].parent != parent))
2177 sysButtons[0].Destroy(0);
2178 sysButtons[0] = null;
2181 if(hasClose && parent)
2188 parent, master = this,
2189 inactive = true, nonClient = true, visible = false;
2191 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
2197 if(this.parent == guiApp.desktop)
2198 sysButtons[2].hotKey = altF4;
2199 else if(style.isActiveClient)
2200 sysButtons[2].hotKey = ctrlF4;
2201 sysButtons[2].Create();
2204 sysButtons[2].symbol = 'X';
2205 sysButtons[2].disabled = !style.hasClose;
2208 if(hasMaxMin && parent)
2212 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2213 if(state == maximized)
2216 method = RestoreButtonClicked;
2222 method = MaximizeButtonClicked;
2230 parent, master = this,
2231 hotKey = altEnter, inactive = true, nonClient = true, visible = false
2233 sysButtons[1].Create();
2235 sysButtons[1].NotifyClicked = method;
2237 sysButtons[1].symbol = symbol;
2238 sysButtons[1].disabled = !style.hasMaximize;
2241 if(hasMaxMin && parent)
2245 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2246 if (state == minimized)
2249 method = RestoreButtonClicked;
2255 method = MinimizeButtonClicked;
2263 parent, master = this,
2264 hotKey = altM, inactive = true, nonClient = true, visible = false
2266 sysButtons[0].Create();
2268 sysButtons[0].NotifyClicked = method;
2270 sysButtons[0].symbol = symbol;
2271 sysButtons[0].disabled = !style.hasMinimize;
2274 // Create the scrollbars
2275 if(style.hasHorzScroll && !sbh)
2281 direction = horizontal,
2285 snap = scrollFlags.snapX,
2286 NotifyScrolling = ScrollBarNotification
2289 scrollBarChanged = true;
2291 else if(sbh && !style.hasHorzScroll)
2297 if(style.hasVertScroll && !sbv)
2303 direction = vertical,
2307 snap = scrollFlags.snapY,
2308 NotifyScrolling = ScrollBarNotification
2311 scrollBarChanged = true;
2313 else if(sbv && !style.hasVertScroll)
2318 if(scrollBarChanged)
2320 SetScrollLineStep(sbStep.x, sbStep.y);
2321 UpdateScrollBars(true, true);
2325 if(scrollBarChanged)
2327 if(sbh) sbh.thumbPosition = scroll.x;
2328 if(sbv) sbv.thumbPosition = scroll.y;
2332 void UpdateCaption(void)
2334 if(rootWindow == this)
2337 FigureCaption(caption);
2338 guiApp.interfaceDriver.SetRootWindowCaption(this, caption);
2340 UpdateDecorations();
2343 if(parent.rootWindow == parent && parent.activeClient == this) // Added this last check
2346 parent.FigureCaption(caption);
2347 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
2349 parent.UpdateDecorations();
2353 void UpdateActiveDocument(Window previous)
2355 Window activeClient = this.activeClient;
2356 Window activeChild = this.activeChild;
2363 activeClient.CreateSystemChildren();
2365 previous.CreateSystemChildren();
2376 if(activeClient && activeClient.menu && activeClient.state != minimized)
2380 //activeClient.menu.Clean(activeClient);
2381 menu.Merge(activeClient.menu, true, activeClient);
2385 if(activeChild && activeChild != activeClient && activeChild.menu && activeChild.state != minimized)
2388 menu.Merge(activeChild.menu, true, activeChild);
2391 // Build window list
2394 Menu windowMenu = menu.FindMenu("Window");
2399 for(id = 0, cycle = activeClient.cycle; cycle && id<10;)
2402 Window document = cycle.data;
2403 if(!document.style.nonClient && document.style.isActiveClient && document.visible)
2405 char name[2048], caption[2048];
2406 document.FigureCaption(caption);
2407 sprintf(name, "%d %s", id+1, caption);
2408 windowMenu.AddDynamic(MenuItem
2410 copyText = true, text = name, hotKey = Key { k1 + id }, id = id++,
2411 NotifySelect = MenuWindowSelectWindow
2415 if(activeClient.cycle == cycle) break;
2420 if((!previous && activeClient) || !activeClient)
2426 item = menu.FindItem(MenuWindowCloseAll, 0);
2427 if(item) item.disabled = false;
2428 item = menu.FindItem(MenuWindowNext, 0);
2429 if(item) item.disabled = false;
2430 item = menu.FindItem(MenuWindowPrevious, 0);
2431 if(item) item.disabled = false;
2432 item = menu.FindItem(MenuWindowCascade, 0);
2433 if(item) item.disabled = false;
2434 item = menu.FindItem(MenuWindowTileHorz, 0);
2435 if(item) item.disabled = false;
2436 item = menu.FindItem(MenuWindowTileVert, 0);
2437 if(item) item.disabled = false;
2438 item = menu.FindItem(MenuWindowArrangeIcons, 0);
2439 if(item) item.disabled = false;
2440 item = menu.FindItem(MenuWindowWindows, 0);
2441 if(item) item.disabled = false;
2444 item = menu.FindItem(MenuFileClose, 0);
2445 if(item) item.disabled = !activeClient || !activeClient.style.hasClose;
2446 item = menu.FindItem(MenuFileSaveAll, 0);
2447 if(item) item.disabled = numDocuments < 1;
2449 // This is called again for a child window change, with same active client
2450 OnActivateClient(activeClient, previous);
2453 void _ShowDecorations(Box box, bool post)
2455 if(rootWindow == this && nativeDecorations) return;
2456 if(visible && this != guiApp.desktop)
2458 Surface surface = RedrawFull(box);
2462 FigureCaption(caption);
2465 ShowDecorations(captionFont.font,
2468 active, //parent.activeClient == this
2469 guiApp.windowMoving == this);
2471 PreShowDecorations(captionFont.font,
2474 active, //parent.activeClient == this
2475 guiApp.windowMoving == this);
2482 void UpdateExtent(Box refresh)
2484 Surface surface = null;
2486 if(!manageDisplay) { OnRedraw(null);return; }
2487 _ShowDecorations(refresh, false);
2489 surface = Redraw(refresh);
2490 // Opaque background: just fill before EW_REDRAW (clear?)
2493 surface.SetBackground(background);
2494 surface.SetForeground(foreground);
2495 surface.DrawingChar(' ');
2496 if(this == rootWindow)
2498 if(style.drawBehind || background.a)
2499 surface.Clear(colorBuffer);
2501 else if(background.a)
2505 background.color = { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2506 surface.SetForeground((background.color.r > 128 || background.color.g > 128) ? black : white);
2509 if(display.flags.alpha && background.a < 255 && background)
2511 surface.Area(0,0,clientSize.w, clientSize.h);
2512 /*if(style.clearDepthBuffer)
2513 surface.Clear(depthBuffer);*/
2515 else if(/*style.clearDepthBuffer || */background.a)
2517 // surface.Clear((style.clearDepthBuffer ? depthBuffer : 0) | (background.a ? colorBuffer : 0));
2518 surface.Clear(colorBuffer);
2523 surface.TextFont(usedFont.font);
2524 surface.TextOpacity(false);
2528 // Draw the caret ...
2529 if(!disabled && this == guiApp.caretOwner && guiApp.caretEnabled /*&& !guiApp.interimWindow*/ && !guiApp.currentSkin.textMode)
2531 // surface.SetBackground(0xFFFFFF - background.color);
2532 surface.SetBackground(~background.color);
2534 caretPos.x - scroll.x + 1, caretPos.y - scroll.y,
2535 caretPos.x - scroll.x + 2, caretPos.y - scroll.y + caretSize - 1);
2541 void DrawOverChildren(Box refresh)
2543 Surface surface = Redraw(refresh);
2547 surface.DrawingChar(' ');
2548 surface.SetBackground(background);
2549 surface.SetForeground(foreground);
2551 surface.TextFont(usedFont.font);
2552 surface.TextOpacity(false);
2554 OnDrawOverChildren(surface);
2559 _ShowDecorations(refresh, true);
2562 void ComputeClipExtents(void)
2565 Extent clipExtent { /*first = -1, last = -1, free = -1*/ };
2567 clipExtent.Copy(this.clipExtent);
2569 for(child = children.last; child; child = child.prev)
2571 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2573 bool opaque = child.IsOpaque(); // TODO: acess background directly
2574 int dx = child.absPosition.x - absPosition.x, dy = child.absPosition.y - absPosition.y;
2576 child.clipExtent.Copy(clipExtent);
2577 child.clipExtent.Offset(-dx, -dy);
2578 child.clipExtent.IntersectBox(child.box);
2580 child.ComputeClipExtents();
2582 if(opaque && !child.style.nonClient)
2584 // Adjust the box for the parent:
2585 Box box { child.box.left + dx, child.box.top + dy, child.box.right + dx, child.box.bottom + dy };
2586 clipExtent.ExcludeBox(box, rootWindow.tempExtents[0]);
2591 // ??? Only do this for overlapped window or if parent has with clip children flag
2593 // Do this if window has clip children flag on (default false?)
2594 // this.clipExtent = clipExtent;
2596 clipExtent.Free(null);
2599 void ComputeRenderAreaNonOpaque(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2601 bool opaque = IsOpaque();
2603 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2604 if(rootWindow.nativeDecorations)
2606 offsetX -= rootWindow.clientStart.x;
2607 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2611 for(child = children.last; child; child = child.prev)
2613 ColorAlpha background = *(ColorAlpha *)&child.background;
2614 bool opaque = child.IsOpaque();
2615 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2619 // Adjust renderArea to the root window level
2620 Extent * renderArea = &rootWindow.tempExtents[1];
2622 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2623 if(child.rootWindow.nativeDecorations)
2625 offsetX -= child.rootWindow.clientStart.x;
2626 offsetY -= child.rootWindow.clientStart.y - (child.rootWindow.hasMenuBar ? skinMenuHeight : 0);
2630 Extent childRenderArea;
2632 if(backBufferUpdate != null)
2634 childRenderArea.Copy(backBufferUpdate);
2635 childRenderArea.Offset(-offsetX, -offsetY);
2638 childRenderArea.Copy(child.dirtyArea);
2640 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2641 renderArea.Copy(dirtyExtent);
2642 renderArea.Offset(-offsetX, -offsetY);
2643 childRenderArea.Union(renderArea);
2646 // Intersect with the clip extent
2647 childRenderArea.Intersection(child.clipExtent);
2650 renderArea->Copy(child.dirtyArea /*childRenderArea*/);
2651 renderArea->Offset(offsetX, offsetY);
2652 dirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2653 // overDirtyExtent.Union(renderArea);
2654 renderArea->Empty();
2655 // childRenderArea.Free();
2657 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2662 for(child = children.last; child; child = child.prev)
2664 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2666 child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2671 void ComputeRenderArea(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2673 bool opaque = IsOpaque();
2674 Extent * dirtyExtentWindow = &rootWindow.tempExtents[1];
2676 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2677 if(rootWindow.nativeDecorations)
2679 offsetX -= rootWindow.clientStart.x;
2680 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2684 for(child = children.last; child; child = child.prev)
2686 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2688 ColorAlpha background = *(ColorAlpha *)&child.background;
2689 bool opaque = child.IsOpaque();
2690 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2694 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2695 // Adjust renderArea to the root window level
2697 renderArea.Copy(child.dirtyArea);
2698 renderArea.Offset(offsetX, offsetY);
2699 dirtyExtent.Union(renderArea);
2700 overDirtyExtent.Union(renderArea);
2706 for(child = children.last; child; child = child.prev)
2708 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2710 child.ComputeRenderArea(dirtyExtent, overDirtyExtent, backBufferUpdate);
2714 if(backBufferUpdate != null)
2716 renderArea.Copy(backBufferUpdate);
2717 renderArea.Offset(-offsetX, -offsetY);
2719 overRenderArea.Copy(backBufferUpdate);
2720 overRenderArea.Offset(-offsetX, -offsetY);
2726 renderArea.Copy(dirtyArea);
2728 overRenderArea.Copy(dirtyArea);
2731 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2732 dirtyExtentWindow->Copy(dirtyExtent);
2733 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2734 renderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2735 dirtyExtentWindow->Empty();
2737 // Intersect with the clip extent
2738 renderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2741 if(renderArea.count > 10)
2744 printf("\nToo many extents (%d):\n", renderArea.count);
2746 //extent.UnionBox({ 112, 6, 304, 7 }, rootWindow.tempExtents[0]);
2747 //extent.UnionBox({ 112, 8, 304, 17 }, rootWindow.tempExtents[0]);
2752 for(c = 0; c<10; c++)
2755 FASTLIST_LOOP(renderArea, extentBox)
2757 extent.UnionBox(extentBox.box, rootWindow.tempExtents[0]);
2759 renderArea.Copy(extent);
2761 FASTLIST_LOOP(renderArea, extentBox)
2764 printf("(%d, %d) - (%d, %d)\n",
2765 extentBox.box.left, extentBox.box.top,
2766 extentBox.box.right, extentBox.box.bottom);
2770 printf("\nNow %d\n", renderArea.count);
2776 // WHY WAS THIS COMMENTED ??
2778 // Add extent forced by DrawOverChildren to the dirty area, adjusting dirty extent to the window
2779 dirtyExtentWindow->Copy(overDirtyExtent);
2780 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2781 overRenderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2782 dirtyExtentWindow->Empty();
2784 // Intersect with the clip extent
2785 overRenderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2791 if(scrollExtent.count)
2793 // Subtract render extent from scrolling extent
2794 scrollExtent.Exclusion(renderArea, rootWindow.tempExtents[0]);
2796 if(backBufferUpdate == null)
2798 Extent * dirty = &rootWindow.tempExtents[3];
2801 // Intersect scrolling extent with clip extent
2802 scrollExtent.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2804 // offset this scroll to be at the root window level
2805 scrollExtent.Offset(offsetX, offsetY);
2806 // Add area that was scrolled to the dirty extents of the back buffer
2807 rootWindow.dirtyBack.Union(scrollExtent, rootWindow.tempExtents[0]);
2811 // Will need scrolledArea.x & scrolledArea.y to support multiple scrolls
2812 FASTLIST_LOOP(scrollExtent, scrollBox)
2813 display.Scroll(scrollBox.box, scrolledArea.x, scrolledArea.y, dirty);
2818 scrollExtent.Empty();
2820 // Add the exposed extent to the window render area
2821 dirty->Offset(-offsetX, -offsetY);
2822 renderArea.Union(dirty, rootWindow.tempExtents[0]);
2827 // Subtract the window's box from the transparency forced extent
2828 dirtyExtent.ExcludeBox({box.left + offsetX, box.top + offsetY, box.right + offsetX, box.bottom + offsetY }, rootWindow.tempExtents[0]);
2834 renderArea.Copy(this.renderArea);
2835 renderArea.Offset(offsetX, offsetY);
2836 dirtyExtent.Union(renderArea);
2842 Extent renderArea { };
2844 renderArea.Copy(overRenderArea);
2845 renderArea.Offset(offsetX, offsetY);
2846 overDirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2851 if(backBufferUpdate != null)
2853 // Remove render area from dirty area
2854 dirtyArea.Exclusion(renderArea, rootWindow.tempExtents[0]);
2856 dirtyArea.Exclusion(overRenderArea, rootWindow.tempExtents[0]);
2863 // Remove the window render area from the dirty extents of the back buffer
2864 rootWindow.dirtyBack.Exclusion(renderArea);
2868 void Render(Extent updateExtent)
2872 Window rootWindow = this.rootWindow;
2873 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2874 if(rootWindow.nativeDecorations)
2876 offsetX -= rootWindow.clientStart.x;
2877 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2880 if(rootWindow.fullRender)
2889 background = Color { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2890 foreground = (background.color.r > 128 || background.color.g > 128) ? black : white;
2895 /*if(renderArea.count)
2896 printf("\n\nRendering %s (%x):\n------------------------------------------\n", _class.name, this);*/
2899 FASTLIST_LOOP(renderArea, extentBox)
2901 Box box = extentBox.box;
2904 /*printf("(%d, %d) - (%d, %d)\n",
2905 extentBox.box.left, extentBox.box.top,
2906 extentBox.box.right, extentBox.box.bottom);*/
2911 box.left += offsetX;
2913 box.right += offsetX;
2914 box.bottom += offsetY;
2916 if(updateExtent != null)
2917 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
2921 for(child = children.first; child; child = child.next)
2922 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && !child.nonClient)
2923 child.Render(updateExtent);
2925 if(rootWindow.fullRender)
2926 DrawOverChildren(box);
2929 // TO DO: There's an issue about draw over children...
2930 // TO DO: Don't wanna go through this if method isn't used
2931 FASTLIST_LOOP(/*renderArea */overRenderArea, extentBox)
2933 Box box = extentBox.box;
2935 DrawOverChildren(box);
2937 box.left += offsetX;
2939 box.right += offsetX;
2940 box.bottom += offsetY;
2942 if(updateExtent != null)
2943 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
2946 for(child = children.first; child; child = child.next)
2947 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && child.nonClient)
2948 child.Render(updateExtent);
2951 overRenderArea.Empty();
2954 public void UpdateDisplay(void)
2956 if(!manageDisplay) { OnRedraw(null);return; }
2957 if(rootWindow && this != rootWindow)
2958 rootWindow.UpdateDisplay();
2961 Extent dirtyExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be forced due to transparency
2962 Extent overExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that forced for DrawOverChildren
2965 dirtyExtent.Clear();
2968 clipExtent.AddBox(box);
2970 display.StartUpdate();
2972 if(!rootWindow.fullRender)
2974 ComputeClipExtents();
2975 ComputeRenderAreaNonOpaque(dirtyExtent, overExtent, null);
2976 ComputeRenderArea(dirtyExtent, overExtent, null);
2979 clipExtent.Free(null);
2981 dirtyExtent.Free(null);
2982 overExtent.Free(null);
2984 if(display.flags.flipping)
2987 display.Update(null);
2991 Extent updateExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be updated
2992 updateExtent.Clear();
2994 Render(updateExtent);
2996 updateExtent.UnionBox(this.box, tempExtents[0]);
2999 //printf("\n\nUpdate:\n------------------------------------------\n");
3002 FASTLIST_LOOP(updateExtent, extentBox)
3005 /*printf("Updating (%d, %d) - (%d, %d)\n",
3006 extentBox.box.left, extentBox.box.top,
3007 extentBox.box.right, extentBox.box.bottom);*/
3010 display.Update(extentBox.box);
3013 updateExtent.Free(null);
3016 display.EndUpdate();
3024 void UpdateBackDisplay(Box box)
3030 Extent intersection { /*first = -1, last = -1, free = -1*/ };
3032 //printf("UpdateBackDisplay going through!\n");
3033 display.StartUpdate();
3037 intersection.Copy(dirtyBack);
3038 intersection.IntersectBox(box);
3040 dirtyExtent.Clear();
3043 clipExtent.AddBox(box);
3045 if(!rootWindow.fullRender)
3047 ComputeClipExtents();
3048 ComputeRenderArea(dirtyExtent, overExtent, intersection);
3051 clipExtent.Free(null);
3053 intersection.Free(null);
3054 dirtyExtent.Free(null);
3055 overExtent.Free(null);
3060 if(display.flags.flipping)
3061 display.Update(null);
3064 rootWindow.display.Update(box);
3067 display.EndUpdate();
3071 dirtyBack.ExcludeBox(box, rootWindow.tempExtents[0]);
3072 if(dirtyBack.count > MAX_DIRTY_BACK)
3074 BoxItem extentBox, next;
3075 BoxItem first = (BoxItem)ACCESS_ITEM(dirtyBack, dirtyBack.first);
3076 FASTLIST_LOOPN(dirtyBack, extentBox, next)
3078 if(extentBox != first)
3080 if(extentBox.box.left < first.box.left)
3081 first.box.left = extentBox.box.left;
3082 if(extentBox.box.top < first.box.top)
3083 first.box.top = extentBox.box.top;
3084 if(extentBox.box.right > first.box.right)
3085 first.box.right = extentBox.box.right;
3086 if(extentBox.box.bottom > first.box.bottom)
3087 first.box.bottom = extentBox.box.bottom;
3088 dirtyBack.Delete(extentBox);
3097 // --- Window positioning ---
3098 // --- Window identification ---
3100 // Returns window at position "Position"
3101 Window GetAtPosition(int x, int y, bool clickThru, bool acceptDisabled, Window last)
3103 Window child, result = null;
3105 box.left += absPosition.x;
3106 box.right += absPosition.x;
3107 box.top += absPosition.y;
3108 box.bottom += absPosition.y;
3110 if(!destroyed && visible && (acceptDisabled || !disabled))
3112 int lx = x - absPosition.x;
3113 int ly = y - absPosition.y;
3114 if(IsInside(lx, ly))
3115 // if(box.IsPointInside(Point{x, y}))
3117 if(!clickThru || !style.clickThrough) result = (this == last) ? null : this;
3118 // If the window is disabled, stop looking in children (for acceptDisabled mode)
3121 for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
3123 if(child != statusBar && child.rootWindow == rootWindow)
3125 Window childResult = child.GetAtPosition(x, y, clickThru, acceptDisabled, last);
3132 for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
3134 if(child != statusBar && child.rootWindow == rootWindow)
3136 Window childResult = child.GetAtPosition(x, y, false, acceptDisabled, last);
3148 Window FindModal(void)
3150 Window modalWindow = this, check;
3151 Window check2 = null;
3152 for(check = this; check.master; check = check.master)
3154 if(check.master.modalSlave && check.master.modalSlave.created && check != check.master.modalSlave)
3156 modalWindow = check.master.modalSlave;
3157 check = modalWindow;
3159 // TESTING THIS FOR DROPBOX...
3160 if(!rootWindow || !rootWindow.style.interim)
3162 for(check2 = check; check2.activeChild; check2 = check2.activeChild)
3164 if(check2.modalSlave && check2.modalSlave.created)
3166 modalWindow = check2.modalSlave;
3174 if(modalWindow == this)
3176 for(check = this; check.activeChild; check = check.activeChild)
3178 if(check.modalSlave)
3180 modalWindow = check.modalSlave;
3186 for(; modalWindow.modalSlave && modalWindow.modalSlave.created; modalWindow = modalWindow.modalSlave);
3187 return (modalWindow == this || this == guiApp.interimWindow || IsDescendantOf(modalWindow)) ? null : modalWindow;
3190 void StopMoving(void)
3192 if(this == guiApp.windowMoving)
3194 guiApp.windowMoving = null;
3195 UpdateDecorations();
3196 SetMouseRange(null);
3199 if(rootWindow.active)
3200 guiApp.interfaceDriver.StopMoving(rootWindow);
3203 guiApp.resizeX = guiApp.resizeY = guiApp.resizeEndX = guiApp.resizeEndY = false;
3204 guiApp.windowIsResizing = false;
3208 void SelectMouseCursor(void)
3213 Window cursorWindow = null;
3214 bool rx, ry, rex, rey;
3216 guiApp.desktop.GetMousePosition(&x, &y);
3217 mouseWindow = rootWindow ? rootWindow.GetAtPosition(x,y, true, false, null) : null;
3219 if((guiApp.windowMoving && !guiApp.windowIsResizing) || guiApp.windowScrolling)
3220 guiApp.SetCurrentCursor(guiApp.systemCursors[moving]);
3221 else if(mouseWindow)
3223 modalWindow = mouseWindow.FindModal();
3224 x -= mouseWindow.absPosition.x;
3225 y -= mouseWindow.absPosition.y;
3226 if(guiApp.windowIsResizing)
3228 rex = guiApp.resizeEndX;
3229 rey = guiApp.resizeEndY;
3230 rx = guiApp.resizeX;
3231 ry = guiApp.resizeY;
3232 if((rex && rey) || (rx && ry))
3233 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
3234 else if((rex && ry) || (rx && rey))
3235 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
3236 else if((ry || rey) && (!rx && !rex))
3237 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
3238 else if((rx || rex) && (!ry && !rey))
3239 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
3241 else if(!modalWindow && !guiApp.windowCaptured &&
3242 mouseWindow.IsMouseResizing(x, y, mouseWindow.size.w, mouseWindow.size.h,
3243 &rx, &ry, &rex, &rey))
3245 if((rex && rey) || (rx && ry))
3246 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
3247 else if((rex && ry) || (rx && rey))
3248 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
3249 else if((ry || rey) && (!rx && !rex))
3250 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
3251 else if((rx || rex) && (!ry && !rey))
3252 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
3254 else if(!guiApp.windowCaptured && !modalWindow && !guiApp.interimWindow)
3256 if(!mouseWindow.clientArea.IsPointInside({x - mouseWindow.clientStart.x, y - mouseWindow.clientStart.y}))
3257 cursorWindow = mouseWindow.parent;
3259 cursorWindow = mouseWindow;
3261 else if(!guiApp.interimWindow)
3262 cursorWindow = guiApp.windowCaptured;
3265 for(; !cursorWindow.cursor && !cursorWindow.style.nonClient; cursorWindow = cursorWindow.parent);
3266 guiApp.SetCurrentCursor(cursorWindow.cursor ? cursorWindow.cursor : guiApp.systemCursors[arrow]);
3268 else if(modalWindow)
3270 guiApp.SetCurrentCursor(guiApp.systemCursors[arrow]);
3272 else if(guiApp.interimWindow)
3274 if(guiApp.interimWindow.cursor)
3275 guiApp.SetCurrentCursor(guiApp.interimWindow.cursor);
3277 guiApp.SetCurrentCursor(mouseWindow.cursor ? mouseWindow.cursor : guiApp.systemCursors[arrow]);
3282 // --- State based input ---
3283 bool AcquireInputEx(bool state)
3288 guiApp.interfaceDriver.GetMousePosition(&guiApp.acquiredMouseX, &guiApp.acquiredMouseY);
3289 guiApp.interfaceDriver.SetMousePosition(clientSize.w/2 + absPosition.x, clientSize.h/2 + absPosition.y);
3291 result = guiApp.interfaceDriver.AcquireInput(rootWindow, state);
3293 guiApp.acquiredWindow = state ? this : null;
3296 SetMouseRangeToClient();
3297 guiApp.interfaceDriver.SetMouseCursor((SystemCursor)-1);
3302 SelectMouseCursor();
3304 if(!state) guiApp.interfaceDriver.SetMousePosition(guiApp.acquiredMouseX, guiApp.acquiredMouseY);
3308 // --- Window activation ---
3309 bool PropagateActive(bool active, Window previous, bool * goOnWithActivation, bool direct)
3312 if(!parent || !parent.style.inactive)
3314 Window parent = this.parent;
3317 if(rootWindow == this)
3318 Log(active ? "active\n" : "inactive\n");
3321 // Testing this here...
3322 if(!parent || parent == guiApp.desktop || parent.active)
3324 this.active = active;
3327 // TESTING THIS HERE
3328 UpdateDecorations();
3329 if(result = OnActivate(active, previous, goOnWithActivation, direct) && *goOnWithActivation && master)
3330 result = NotifyActivate(master, this, active, previous);
3333 this.active = !active;
3338 if(!parent || parent == guiApp.desktop || parent.active)
3340 this.active = active;
3342 AcquireInputEx(active);
3347 if(guiApp.caretOwner)
3351 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 1,
3352 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + 1,
3353 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 2,
3354 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + guiApp.caretOwner.caretSize - 1
3356 guiApp.caretOwner.Update(extent);
3359 if(visible || !guiApp.caretOwner)
3360 guiApp.caretOwner = this;
3361 UpdateCaret(false, false);
3367 this.active = false;
3369 AcquireInputEx(active);
3371 if(!active && guiApp.caretOwner == this)
3373 UpdateCaret(false, true);
3374 guiApp.caretOwner = null;
3375 guiApp.interfaceDriver.SetCaret(0,0,0);
3376 guiApp.caretEnabled = false;
3381 if(!active && parent && parent.activeChild && parent.activeChild != this)
3382 if(!parent.activeChild.PropagateActive(false, previous, goOnWithActivation, true) || !*goOnWithActivation)
3388 if(!active && menuBar)
3391 menuBar.OnActivate(false, null, &goOn, true);
3392 menuBar.NotifyActivate(menuBar.master, menuBar, false, null);
3396 if(!activeChild.PropagateActive(active, previous, goOnWithActivation, false) || !*goOnWithActivation)
3405 void ConsequentialMouseMove(bool kbMoving)
3409 if(kbMoving || !guiApp.windowMoving)
3413 if(rootWindow == guiApp.desktop || rootWindow.parent == guiApp.desktop)
3415 guiApp.interfaceDriver.GetMousePosition(&x, &y);
3417 if(guiApp.windowMoving || rootWindow.GetAtPosition(x, y, true, false, null))
3418 rootWindow.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove, x, y, &mods, true, false);
3424 bool IsDescendantOf(Window ancestor)
3427 for(window = this; window && window != ancestor; window = window.parent);
3428 return window == ancestor;
3431 bool IsSlaveOf(Window master)
3434 for(window = this; window && window != master; window = window.master);
3435 return window == master;
3438 bool ActivateEx(bool active, bool activateParent, bool moveInactive, bool activateRoot, Window external, Window externalSwap)
3442 if(this && !destroyed /*&& state != Hidden*/)
3444 Window swap = externalSwap;
3452 if(activateParent &&
3453 (parent.activeChild != this ||
3454 (guiApp.interimWindow && !IsDescendantOf(guiApp.interimWindow))) &&
3455 active && _isModal &&
3456 parent != master && master)
3457 master.ActivateEx(true, true, false, activateRoot, external, externalSwap);
3463 bool real = parent.activeChild != this;
3465 // TEST THIS: New activateParent check here!!! CAUSED MENUS NOT GOING AWAY
3466 if(/*activateParent && */guiApp.interimWindow &&
3467 !IsDescendantOf(guiApp.interimWindow) &&
3468 !IsSlaveOf(guiApp.interimWindow))
3470 Window interimWindow = guiApp.interimWindow;
3471 while(interimWindow && interimWindow != this)
3473 Window master = interimWindow.master;
3475 guiApp.interimWindow = null;
3476 if(guiApp.caretOwner)
3477 guiApp.caretOwner.UpdateCaret(false, false);
3479 incref interimWindow;
3480 if(!interimWindow.PropagateActive(false, this, &goOn, true))
3485 delete interimWindow;
3486 interimWindow = (master && master.style.interim) ? master : null;
3491 guiApp.interimWindow = this;
3492 /*guiApp.interfaceDriver.SetCaret(0,0,0);
3493 guiApp.caretEnabled = false;*/
3494 UpdateCaret(false, true);
3499 bool acquireInput = false;
3501 parent.activeChild &&
3502 parent.activeChild.state == maximized &&
3503 parent != guiApp.desktop;
3505 if(!style.inactive) // (!style.isRemote || parent.active || parent.style.hidden))
3510 swap = parent.activeChild;
3511 if(swap && swap.destroyed) swap = null;
3512 if(swap && swap != this)
3515 if(!swap.PropagateActive(false, this, &goOn, true))
3516 swap = parent.activeChild;
3527 if(!parent || parent.activeChild != this || style.interim)
3530 result = PropagateActive(true, swap, &goOn, true);
3531 if(!result && !goOn)
3536 acquireInput = true;
3540 if(style.hasMaximize && parent != guiApp.desktop)
3543 SetState(maximized, false, 0);
3544 else if(state != maximized)
3547 for(child = parent.children.first; child; child = child.next)
3549 if(this != child && child.state == maximized)
3550 child.SetState(normal, false, 0);
3557 if(!style.inactive && !style.interim /*&& (!style.isRemote || parent.active || parent.style.hidden)*/)
3559 Window previous = parent.activeClient;
3560 parent.activeChild = this;
3561 if(!style.nonClient /*&& style.isActiveClient*/)
3563 if(style.isActiveClient && !style.hidden)
3564 parent.activeClient = this;
3565 parent.UpdateActiveDocument(previous);
3570 //if(!style.isRemote)
3572 if(rootWindow != this)
3574 if(activateParent && parent && !parent.active /*parent != parent.parent.activeChild*/)
3575 parent.ActivateEx(true, true, moveInactive, activateRoot, external, externalSwap);
3577 else if(!guiApp.fullScreenMode)
3579 Window modalRoot = FindModal();
3580 if(!modalRoot) modalRoot = this;
3581 if(!modalRoot.isForegroundWindow)
3583 modalRoot.isForegroundWindow = true;
3584 // To check : Why is parent null?
3585 if(activateRoot && modalRoot.parent && !modalRoot.parent.display && external != modalRoot)
3587 guiApp.interfaceDriver.ActivateRootWindow(modalRoot);
3589 modalRoot.isForegroundWindow = false;
3594 if(result && real && (!style.inactive || moveInactive) && parent)
3596 Window last = parent.children.last;
3598 if(!style.stayOnTop)
3599 for(; last && last.style.stayOnTop; last = last.prev);
3601 parent.children.Move(this, last);
3603 // Definitely don't want that: why not?
3607 parent.childrenOrder.Move(order, parent.childrenOrder.last);
3613 if(!parent || style.interim || (parent.activeChild == this && !style.inactive))
3620 parent.activeChild = null;
3621 if(!style.nonClient /*&& style.isActiveClient*/)
3623 Window previous = parent.activeClient;
3624 if(style.isActiveClient)
3625 parent.activeClient = null;
3626 parent.UpdateActiveDocument(previous);
3630 if(this == guiApp.interimWindow)
3632 guiApp.interimWindow = null;
3633 if(guiApp.caretOwner)
3634 guiApp.caretOwner.UpdateCaret(false, false);
3636 if(!PropagateActive(false, externalSwap, &goOn, true) || !goOn)
3643 if(!active || !swap)
3644 UpdateDecorations();
3646 swap.UpdateDecorations();
3648 if(active && rootWindow != this)
3649 ConsequentialMouseMove(false);
3656 // --- Input Messages ---
3657 void ::UpdateMouseMove(int mouseX, int mouseY, bool consequential)
3659 static bool reEntrancy = false;
3660 if(reEntrancy) return;
3664 guiApp.cursorUpdate = true;
3665 if(guiApp.windowScrolling && !consequential)
3667 guiApp.windowScrolling.SetScrollPosition(
3668 (guiApp.windowScrolling.sbh) ?
3669 (guiApp.windowScrollingBefore.x - mouseX + guiApp.windowScrollingStart.x) : 0,
3670 (guiApp.windowScrolling.sbv) ?
3671 (guiApp.windowScrollingBefore.y - mouseY + guiApp.windowScrollingStart.y) : 0);
3673 if(guiApp.windowMoving)
3675 if(mouseX != guiApp.movingLast.x || mouseY != guiApp.movingLast.y)
3677 Window window = guiApp.windowMoving;
3679 int w = window.size.w;
3680 int h = window.size.h;
3685 rx = mouseX - guiApp.windowMovingStart.x;
3686 ry = mouseY - guiApp.windowMovingStart.y;
3689 window.GetDecorationsSize(&ew, &eh);
3691 if(guiApp.windowIsResizing)
3693 x = window.scrolledPos.x;
3694 y = window.scrolledPos.y;
3698 aw = Max(guiApp.windowResizingBefore.w - rx,window.skinMinSize.w);
3699 rx = guiApp.windowResizingBefore.w - aw;
3700 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3701 w = guiApp.windowResizingBefore.w - rx;
3705 ah = Max(guiApp.windowResizingBefore.h - ry,window.skinMinSize.h);
3706 ry = guiApp.windowResizingBefore.h - ah;
3707 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3708 ry = Max(ry, -guiApp.windowMovingBefore.y);
3709 h = guiApp.windowResizingBefore.h - ry;
3711 if(guiApp.resizeEndX)
3713 w = guiApp.windowResizingBefore.w + rx;
3716 if(guiApp.resizeEndY) h = guiApp.windowResizingBefore.h + ry;
3724 w = Max(w, window.minSize.w);
3725 h = Max(h, window.minSize.h);
3726 w = Min(w, window.maxSize.w);
3727 h = Min(h, window.maxSize.h);
3729 if(!window.OnResizing(&w, &h))
3731 w = window.clientSize.w;
3732 h = window.clientSize.h;
3735 w = Max(w, window.skinMinSize.w);
3736 h = Max(h, window.skinMinSize.h);
3743 SNAPDOWN(w, textCellW);
3744 SNAPDOWN(h, textCellH);
3749 aw = Max(w,window.skinMinSize.w);
3750 rx = guiApp.windowResizingBefore.w - aw;
3751 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3752 w = guiApp.windowResizingBefore.w - rx;
3756 ah = Max(h,window.skinMinSize.h);
3757 ry = guiApp.windowResizingBefore.h - ah;
3758 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3759 ry = Max(ry, -guiApp.windowMovingBefore.y);
3760 h = guiApp.windowResizingBefore.h - ry;
3765 if(!guiApp.windowIsResizing || guiApp.resizeX)
3766 x = guiApp.windowMovingBefore.x + rx;
3767 if(!guiApp.windowIsResizing || guiApp.resizeY)
3768 y = guiApp.windowMovingBefore.y + ry;
3770 if(!guiApp.windowIsResizing)
3773 if(window.parent == guiApp.desktop && guiApp.virtualScreen.w)
3775 x = Min(x, (guiApp.virtualScreen.w + guiApp.virtualScreenPos.x) -1);
3776 y = Min(y, (guiApp.virtualScreen.h + guiApp.virtualScreenPos.y) -1);
3777 x = Max(x,-(w-1) + guiApp.virtualScreenPos.x);
3778 y = Max(y,-(h-1) + guiApp.virtualScreenPos.y);
3782 x = Min(x, (window.parent.reqScrollArea.w ? window.parent.reqScrollArea.w : window.parent.clientSize.w) -1);
3783 y = Min(y, (window.parent.reqScrollArea.h ? window.parent.reqScrollArea.h : window.parent.clientSize.h) -1);
3789 if(!guiApp.windowIsResizing || (guiApp.resizeX || guiApp.resizeY))
3791 if(!window.OnMoving(&x, &y, w, h))
3793 x = window.scrolledPos.x;
3794 y = window.scrolledPos.y;
3800 SNAPDOWN(x, textCellW);
3801 SNAPDOWN(y, textCellH);
3804 if(!window.style.nonClient)
3806 if(!window.style.fixed /*|| window.style.isDocument*/)
3808 if(!window.style.dontScrollHorz)
3809 x += window.parent.scroll.x;
3810 if(!window.style.dontScrollVert)
3811 y += window.parent.scroll.y;
3815 // Break the anchors for moveable/resizable windows
3816 // Will probably cause problem with IDE windows... Will probably need a way to specify if anchors should break
3817 if(window.style.fixed)
3819 if(window.state == normal)
3821 window.normalAnchor = Anchor { left = x, top = y };
3822 window.normalSizeAnchor = SizeAnchor { { w, h } };
3823 window.anchored = false;
3827 window.stateAnchor = Anchor { left = x, top = y };
3828 window.stateSizeAnchor = SizeAnchor { { w, h } };
3830 window.Position(x, y, w, h, false, true, guiApp.windowIsResizing, guiApp.windowIsResizing, false, true);
3831 // TOCHECK: Investigate why the following only redraws the scrollbars
3832 //window.Position(x, y, w, h, false, true, true, true, false, true);
3834 guiApp.movingLast.x = mouseX;
3835 guiApp.movingLast.y = mouseY;
3841 public bool MouseMessage(uint method, int x, int y, Modifiers * mods, bool consequential, bool activate)
3844 bool wasMoving = guiApp.windowMoving ? true : false;
3845 bool wasScrolling = guiApp.windowScrolling ? true : false;
3847 while(result && w != this)
3849 Window msgWindow = GetAtPosition(x,y, false, true, w);
3850 Window trueWindow = GetAtPosition(x,y, false, false, w);
3851 bool windowDragged = false;
3856 window = (w && !w.disabled) ? w : null;
3858 if(trueWindow) incref trueWindow;
3860 if(consequential) mods->isSideEffect = true;
3862 UpdateMouseMove(x, y, consequential);
3864 if(guiApp.windowCaptured && (guiApp.windowCaptured.rootWindow == this))
3866 if(!guiApp.windowCaptured.isEnabled)
3867 guiApp.windowCaptured.ReleaseCapture();
3869 window = guiApp.windowCaptured;
3872 if(trueWindow && activate &&
3873 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
3874 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
3875 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
3876 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
3878 if(mods->alt && !mods->ctrl && !mods->shift)
3880 Window moved = trueWindow;
3881 for(moved = trueWindow; moved; moved = moved.parent)
3882 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
3887 windowDragged = true;
3889 // Cancel the ALT menu toggling...
3890 window.rootWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
3895 if(window && activate &&
3896 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
3897 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
3898 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
3899 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
3901 Window modalWindow = window.FindModal();
3903 /*if(mods->alt && !mods->shift && !mods->ctrl)
3905 Window moved = window;
3906 for(moved = window; moved; moved = moved.parent)
3907 if(method == OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
3912 windowDragged = true;
3914 // Cancel the ALT menu toggling...
3915 window.rootWindow.KeyMessage(OnKeyDown, 0, 0);
3921 Window activateWindow = modalWindow ? modalWindow : window;
3922 if(activateWindow && !activateWindow.isRemote)
3924 bool doActivation = true;
3925 //bool needToDoActivation = false;
3926 Window check = activateWindow;
3928 for(check = activateWindow; check && check != guiApp.desktop; check = check.parent)
3930 if(!check.style.inactive)
3932 //needToDoActivation = true;
3934 doActivation = false;
3939 if(!needToDoActivation)
3940 doActivation = false;
3943 if((doActivation && (activateWindow.parent != guiApp.desktop || guiApp.fullScreen)) ||
3944 (guiApp.interimWindow && !window.IsDescendantOf(guiApp.interimWindow)))
3946 // Let the OnLeftButtonDown do the activating instead
3947 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
3955 incref activateWindow;
3956 if(!activateWindow.ActivateEx(true, true, false, true, null, null))
3958 delete activateWindow;
3962 if(activateWindow._refCount == 1)
3964 delete activateWindow;
3968 delete activateWindow;
3970 mods->isActivate = true;
3974 if(!modalWindow && window && !window.destroyed)
3976 if(!guiApp.windowCaptured || windowDragged)
3978 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown)
3980 bool moving = ((window.state != maximized &&
3981 window.IsMouseMoving(
3982 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
3983 || (guiApp.windowMoving && !guiApp.windowIsResizing);
3985 if(!moving && window.IsMouseResizing(
3986 x - window.absPosition.x,
3987 y - window.absPosition.y,
3988 window.size.w, window.size.h,
3989 &guiApp.resizeX, &guiApp.resizeY, &guiApp.resizeEndX, &guiApp.resizeEndY))
3991 guiApp.windowIsResizing = true;
3992 guiApp.windowResizingBefore.w = window.size.w;
3993 guiApp.windowResizingBefore.h = window.size.h;
3995 if(guiApp.windowIsResizing || windowDragged || moving)
3998 guiApp.windowMoving = window;
3999 guiApp.windowMovingStart.x = guiApp.movingLast.x = x;
4000 guiApp.windowMovingStart.y = guiApp.movingLast.y = y;
4001 guiApp.windowMovingBefore.x = window.position.x;//s;
4002 guiApp.windowMovingBefore.y = window.position.y;//s;
4003 if(guiApp.windowMoving == guiApp.windowMoving.rootWindow)
4004 guiApp.interfaceDriver.StartMoving(guiApp.windowMoving.rootWindow, 0,0,false);
4007 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown)
4009 if(window.style.fixed &&
4011 window.IsMouseMoving(
4012 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4014 window.ShowSysMenu(x, y);
4018 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown)
4020 if(window.sbv || window.sbh)
4023 guiApp.windowScrolling = window;
4024 guiApp.windowScrollingStart.x = x;
4025 guiApp.windowScrollingStart.y = y;
4026 guiApp.windowScrollingBefore.x = window.scroll.x;
4027 guiApp.windowScrollingBefore.y = window.scroll.y;
4030 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4032 if(window.style.hasMaximize &&
4033 window.IsMouseMoving(
4034 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h))
4037 (window.state == maximized) ? normal : maximized, false, *mods);
4045 if(guiApp.windowMoving)
4047 if(guiApp.windowMoving.parent)
4049 if(guiApp.windowMoving.style.nonClient)
4050 guiApp.windowMoving.parent.SetMouseRangeToWindow();
4052 guiApp.windowMoving.parent.SetMouseRangeToClient();
4056 window.UpdateDecorations();
4059 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp)
4061 // Log("\n*** LEFT BUTTON UP ***\n");
4062 if(guiApp.windowMoving)
4063 guiApp.windowMoving.StopMoving();
4065 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp)
4067 if(guiApp.windowScrolling)
4069 Window windowScrolling = guiApp.windowScrolling;
4070 guiApp.windowScrolling = null;
4071 windowScrolling.ReleaseCapture();
4075 if(!result || (window && window.destroyed)) window = null;
4077 if(window && window.FindModal())
4080 if(trueWindow && trueWindow.FindModal())
4088 msgWindow = GetAtPosition(x,y, true, false);
4090 msgWindow.SelectMouseCursor();
4093 if(guiApp.windowCaptured || trueWindow)
4095 Window prevWindow = guiApp.prevWindow;
4096 if(guiApp.prevWindow && trueWindow != guiApp.prevWindow)
4098 guiApp.prevWindow.mouseInside = false;
4099 guiApp.prevWindow = null;
4101 // Eventually fix this not to include captured?
4102 if(!prevWindow.OnMouseLeave(*mods))
4105 if(result && trueWindow && !trueWindow.destroyed/* && trueWindow == window*/)
4107 Box box = trueWindow.box;
4108 box.left += trueWindow.absPosition.x;
4109 box.right += trueWindow.absPosition.x;
4110 box.top += trueWindow.absPosition.y;
4111 box.bottom += trueWindow.absPosition.y;
4113 if(box.IsPointInside({x, y}) && trueWindow != /*guiApp.*/prevWindow /*!trueWindow.mouseInside*/)
4115 int overX = x - (trueWindow.absPosition.x + trueWindow.clientStart.x);
4116 int overY = y - (trueWindow.absPosition.y + trueWindow.clientStart.y);
4118 overX = Max(Min(overX, 32767),-32768);
4119 overY = Max(Min(overY, 32767),-32768);
4121 trueWindow.mouseInside = true;
4122 if(!trueWindow.OnMouseOver(overX, overY, *mods))
4126 if(trueWindow && trueWindow._refCount > 1 && !trueWindow.destroyed)
4127 guiApp.prevWindow = trueWindow;
4129 guiApp.prevWindow = null;
4131 SelectMouseCursor();
4133 if(window && !guiApp.windowMoving && !wasMoving && !wasScrolling)
4135 int clientX = x - (window.absPosition.x + window.clientStart.x);
4136 int clientY = y - (window.absPosition.y + window.clientStart.y);
4138 bool (* MouseMethod)(Window instance, int x, int y, Modifiers mods);
4140 clientX = Max(Min(clientX, 32767),-32768);
4141 clientY = Max(Min(clientY, 32767),-32768);
4143 MouseMethod = (void *)window._vTbl[method];
4145 if(MouseMethod /*&& !consequential*/ && !window.disabled)
4148 if(!MouseMethod(window, clientX, clientY, *mods))
4155 if(result && w && w.clickThrough && w.parent)
4160 if(!result || !w || !w.clickThrough)
4167 // --- Mouse cursor management ---
4169 bool KeyMessage(uint method, Key key, unichar character)
4174 if(guiApp.interimWindow)
4175 this = guiApp.interimWindow;
4178 if((SmartKey)key != alt && (SmartKey)key != Key::control && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && parent && this != parent.menuBar)
4182 if(!style.inactive || rootWindow != this)
4184 bool (*KeyMethod)(Window window, Key key, unichar ch) = (void *)_vTbl[method];
4185 Window modalWindow = FindModal();
4186 Window interimMaster = master ? master.rootWindow : null;
4190 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4191 status = OnSysKeyDown(key, character);
4192 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4193 status = OnSysKeyHit(key, character);
4194 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4195 status = OnSysKeyUp(key, character);
4202 // Process Key Message for Internal UI Keyboard actions
4203 if(status && !destroyed && menuBar && state != minimized)
4206 if((SmartKey)key != alt)
4207 menuBar.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4210 SmartKey sk = (SmartKey) key;
4211 if((character && !key.alt && !key.ctrl) || sk == left || sk == right || sk == up || sk == down || sk == home || sk == end || sk == escape || sk == alt)
4213 status = menuBar.KeyMessage(method, key, character);
4218 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4219 menuBar.OnKeyHit(escape, 0);
4221 if(!menuBar.focus && guiApp.caretOwner)
4222 guiApp.caretOwner.UpdateCaret(true, false);
4225 if(!destroyed && status)
4227 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4231 case left: case up: case right: case down:
4232 if(guiApp.windowMoving == this)
4235 int w = guiApp.windowMoving.size.w;
4236 int h = guiApp.windowMoving.size.h;
4237 int x = guiApp.windowMoving.scrolledPos.x;
4238 int y = guiApp.windowMoving.scrolledPos.y;
4242 if(key == down || key == up)
4243 step = Max(step, textCellH);
4245 step = Max(step, textCellW);
4248 if(guiApp.windowIsResizing)
4252 case left: w-=step; break;
4253 case right: w+=step; break;
4254 case up: h-=step; break;
4255 case down: h+=step; break;
4262 case left: x-=step; break;
4263 case right: x+=step; break;
4264 case up: y-=step; break;
4265 case down: y+=step; break;
4269 if(guiApp.resizeX) x += w - guiApp.windowMoving.size.w;
4270 if(guiApp.resizeY) y += h - guiApp.windowMoving.size.h;
4272 if(!guiApp.windowIsResizing || guiApp.resizeX)
4273 x = (x - guiApp.windowMovingBefore.x) + guiApp.windowMovingStart.x;
4275 x = (w - guiApp.windowResizingBefore.w) + guiApp.windowMovingStart.x;
4277 if(!guiApp.windowIsResizing || guiApp.resizeY)
4278 y = (y - guiApp.windowMovingBefore.y) + guiApp.windowMovingStart.y;
4280 y = (h - guiApp.windowResizingBefore.h) + guiApp.windowMovingStart.y;
4282 guiApp.interfaceDriver.SetMousePosition(x, y);
4283 ConsequentialMouseMove(true);
4291 if(guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4293 guiApp.windowMoving.StopMoving();
4294 ConsequentialMouseMove(false);
4302 ShowSysMenu(absPosition.x, absPosition.y);
4310 if(!destroyed && status && state != minimized)
4312 // Process all the way down the children
4313 if(activeChild && !activeChild.disabled)
4315 status = activeChild.KeyMessage(method, key, character);
4317 if(status && activeClient && activeChild != activeClient && !activeClient.disabled && (key.alt || key.ctrl) &&
4318 key.code != left && key.code != right && key.code != up && key.code != down)
4320 status = activeClient.KeyMessage(method, key, character);
4324 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4326 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && !defaultControl.disabled && state != minimized)
4327 // && defaultControl != activeChild)
4329 delete previousActive;
4330 previousActive = activeChild;
4331 if(previousActive) incref previousActive;
4333 ConsequentialMouseMove(false);
4334 if((defaultControl.active ||
4335 defaultControl.ActivateEx(true, true, false, true, null, null)) && !defaultControl.disabled)
4336 defaultControl.KeyMessage(method, defaultKey, character);
4342 if(!destroyed && status && (!modalWindow || this == guiApp.desktop))
4344 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4351 ShowSysMenu(absPosition.x, absPosition.y);
4358 if(this != guiApp.desktop)
4360 if(!guiApp.windowMoving && !guiApp.windowCaptured)
4362 if(state != maximized && (key.shift ? style.sizeable : style.fixed))
4364 MenuMoveOrSize(key.shift, true);
4368 else if(guiApp.windowMoving)
4370 guiApp.windowMoving.StopMoving();
4371 ConsequentialMouseMove(false);
4379 if(!destroyed && status && state != minimized)
4381 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4385 case tab: case shiftTab:
4387 Window cycleParent = this;
4388 if(this == guiApp.interimWindow && !master.style.interim && !cycleParent.style.tabCycle)
4389 cycleParent = master.parent;
4391 if(!guiApp.windowCaptured && cycleParent.style.tabCycle)
4393 if(cycleParent.CycleChildren(!key.shift, false, false, true))
4395 Window child = cycleParent.activeChild;
4397 // Scroll the window to include the active control
4399 if(cycleParent.sbh && !child.style.dontScrollHorz)
4401 if(child.scrolledPos.x < 0)
4402 cycleParent.sbh.Action(Position,
4403 cycleParent.scroll.x + child.scrolledPos.x, 0);
4404 else if(child.scrolledPos.x + child.size.w > cycleParent.clientSize.w)
4405 cycleParent.sbh.Action(Position,
4406 cycleParent.scroll.x + child.scrolledPos.x + child.size.w - cycleParent.clientSize.w, 0);
4408 if(cycleParent.sbv && !child.style.dontScrollVert)
4410 if(child.scrolledPos.y < 0)
4411 cycleParent.sbv.Action(Position,
4412 cycleParent.scroll.y + child.scrolledPos.y, 0);
4413 else if(child.scrolledPos.y + child.size.w > window.clientSize.h)
4414 cycleParent.sbv.Action(Position,
4415 cycleParent.scroll.y + child.scrolledPos.y+child.size.h - cycleParent.clientSize.h, 0);
4418 cycleParent.ConsequentialMouseMove(false);
4424 case f6: case shiftF6:
4425 if(!guiApp.windowMoving /*!guiApp.windowCaptured*/)
4427 // NOT NEEDED... guiApp.windowMoving.ReleaseCapture();
4428 if(parent == guiApp.desktop)
4429 if(guiApp.desktop.CycleChildren(key.shift, true, false, true))
4434 if(style.tabCycle ||
4435 CycleChildren(key.shift, true, false, true))
4443 // mIRC Style Window Shortcuts
4444 case alt1: case alt2: case alt3: case alt4: case alt5:
4445 case alt6: case alt7: case alt8: case alt9: case alt0:
4450 for(document = children.first; document; document = document.next)
4452 if(document.style.isDocument && document.documentID - 1 == key.code - k1)
4454 if(document == activeChild)
4456 if(document.state == minimized)
4457 document.SetState(normal, false, key);
4460 document.SetState(minimized, false, key);
4461 CycleChildren(false, true, false);
4466 if(activeChild.state == maximized && document.style.hasMaximize)
4467 document.SetState(maximized, false, key);
4468 else if(document.state == minimized)
4469 document.SetState(normal, false, key);
4470 document.Activate();
4485 if(!destroyed && status)
4487 if(state == minimized)
4492 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4494 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && previousActive)
4496 if(defaultControl.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, key, character))
4497 previousActive.ActivateEx(true, false, false, true, null, null);
4498 delete previousActive;
4504 if(!destroyed && status)
4506 status = ProcessHotKeys(method, key, character);
4508 if(!destroyed && status && !modalWindow && state != minimized)
4511 status = KeyMethod(this, key, character);
4512 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4513 status = OnKeyHit(key, character);
4514 if(!destroyed && status && (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit))
4516 bool result = false;
4519 case ctrlUp: case ctrlDown:
4520 if(sbv && !guiApp.windowScrolling)
4521 result = sbv.Action((key == ctrlUp) ? up : down, 0, key);
4523 case wheelUp: case wheelDown:
4524 if(sbv && !guiApp.windowScrolling)
4526 result = sbv.Action((key == wheelUp) ? wheelUp : wheelDown, 0, key);
4527 // Do we want to do a consequential move regardless of result in this case?
4528 ConsequentialMouseMove(false);
4531 case ctrlPageUp: case ctrlPageDown:
4532 if(sbh && !guiApp.windowScrolling)
4533 result = sbh.Action((key == ctrlPageUp) ? up : down, 0, key);
4538 ConsequentialMouseMove(false);
4543 if(status && !destroyed && menuBar && state != minimized)
4544 status = menuBar.KeyMessage(method, key, character);
4546 if(style.interim && /*destroyed && */status && interimMaster)
4548 // Testing this... for Ctrl-O to open dialog when autocompletion listbox is popped...
4549 status = interimMaster.KeyMessage(method, key, character);
4556 bool ProcessHotKeys(uint method, Key key, unichar character)
4561 for(hotKey = hotKeys.first; hotKey; hotKey = hotKey.next)
4562 if((hotKey.key == key || (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp && hotKey.key.code == key.code)) &&
4563 !hotKey.window.disabled && (hotKey.window.style.nonClient || state != minimized))
4565 Window hotKeyWindow = hotKey.window;
4566 Window parent = hotKeyWindow.parent;
4567 Window prevActiveWindow = activeChild;
4569 // Don't process non-visible buttons, but make an exception for the Alt-F4 with Native Decorations turned on
4570 if(hotKeyWindow.style.hidden && (!hotKeyWindow.style.nonClient || !parent || !parent.nativeDecorations || (hotKeyWindow != parent.sysButtons[2] && hotKeyWindow != parent.sysButtons[1] )))
4573 if(prevActiveWindow) incref prevActiveWindow;
4574 incref hotKeyWindow;
4575 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && !hotKeyWindow.style.nonClient)
4576 if(!hotKeyWindow.ActivateEx(true, true, false, true, null, null))
4579 delete hotKeyWindow;
4580 delete prevActiveWindow;
4584 if(hotKeyWindow.style.nonClient && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4585 method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
4586 if(!hotKeyWindow.KeyMessage(method, Key::hotKey, character))
4588 // ********* WORKING ON THIS ***********
4589 if(prevActiveWindow && !guiApp.interimWindow)
4590 prevActiveWindow.ActivateEx(true, false, false, false, null, null);
4593 else if(hotKeyWindow.style.inactive)
4594 status = hotKeyWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, Key::hotKey, character);
4596 delete prevActiveWindow;
4597 delete hotKeyWindow;
4598 // For Key Ups, don't set status to false... (e.g.: Releasing Enter vs AltEnter hot key)
4599 if(method != __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4603 if(status && tabCycle)
4606 for(child = children.first; child; child = child.next)
4608 if(child.tabCycle && !child.ProcessHotKeys(method, key, character))
4619 // --- Windows and graphics initialization / termination ---
4620 bool SetupRoot(void)
4624 // Setup relationship with outside world (bb root || !bb)
4625 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || this == guiApp.desktop ||
4626 (_displayDriver && dispDriver != parent.dispDriver))
4630 tempExtents = new0 Extent[4];
4635 /*if(guiApp.fullScreenMode)
4636 rootWindow = guiApp.desktop;
4638 //rootWindow = parent.created ? parent.rootWindow : null;
4639 rootWindow = parent.rootWindow;
4642 against = &parent.box;
4644 against = &parent.clientArea;
4647 for(child = children.first; child; child = child.next)
4650 return (rootWindow && (rootWindow == this || rootWindow.created)) ? true : false;
4653 bool Setup(bool positionChildren)
4655 bool result = false;
4658 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || (guiApp.fullScreenMode && (this == guiApp.desktop || (_displayDriver && dispDriver != parent.dispDriver))))
4660 subclass(DisplayDriver) dDriver = (dispDriver && !formDesigner) ? dispDriver : GetDisplayDriver(guiApp.defaultDisplayDriver);
4661 DisplaySystem displaySystem = dDriver ? dDriver.displaySystem : null;
4663 windowHandle = dDriver.printer ? null : guiApp.interfaceDriver.CreateRootWindow(this);
4665 // This was here, is it really needed?
4666 //guiApp.interfaceDriver.ActivateRootWindow(this);
4670 displaySystem = DisplaySystem {};
4671 if(!displaySystem.Create(dDriver.name, guiApp.fullScreenMode ? windowHandle : windowHandle /*null*/, guiApp.fullScreenMode))
4673 delete displaySystem;
4678 display = Display { alphaBlend = alphaBlend, useSharedMemory = useSharedMemory, windowDriverData = windowData };
4679 if(display.Create(displaySystem, windowHandle))
4686 guiApp.interfaceDriver.SetIcon(this, icon);
4688 else if(this != guiApp.desktop)
4690 display = rootWindow ? rootWindow.display : null;
4696 if(guiApp.acquiredWindow && rootWindow == guiApp.acquiredWindow.rootWindow)
4697 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, true);
4699 for(child = children.first; child; child = child.next)
4701 if(child.created && !child.Setup(false))
4707 bool SetupDisplay(void)
4709 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
4710 if(is3D) return Window3D_SetupDisplay(this); else
4717 class_data void ** pureVTbl;
4719 bool LoadGraphics(bool creation, bool resetAnchors)
4721 bool result = false;
4722 bool success = false;
4724 WindowState stateBackup = state;
4727 if(!rootWindow.created)
4731 if(((subclass(Window))_class).pureVTbl)
4733 if(_vTbl == _class._vTbl)
4735 _vTbl = ((subclass(Window))_class).pureVTbl;
4740 for(m = 0; m < _class.vTblSize; m++)
4742 if(_vTbl[m] == _class._vTbl[m])
4743 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
4747 if(guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
4749 if(_vTbl == ((subclass(Window))_class).pureVTbl)
4751 _vTbl = _class._vTbl;
4756 for(m = 0; m < _class.vTblSize; m++)
4758 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
4759 _vTbl[m] = _class._vTbl[m];
4764 if(guiApp.fullScreenMode || this != guiApp.desktop)
4766 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
4772 display.Lock(false);
4773 if(rootWindow == this)
4775 // Set Color Palette
4776 display.SetPalette(palette, true);
4780 if(guiApp.fullScreenMode && this == guiApp.desktop)
4785 for(c=0; c<SystemCursor::enumSize; c++)
4786 if(!guiApp.systemCursors[c].bitmap)
4788 guiApp.systemCursors[c].bitmapName = guiApp.currentSkin.CursorsBitmaps(c,
4789 &guiApp.systemCursors[c].hotSpotX,&guiApp.systemCursors[c].hotSpotY, &guiApp.systemCursors[c].paletteShades);
4790 if(guiApp.systemCursors[c].bitmapName)
4792 guiApp.systemCursors[c].bitmap = eBitmap_LoadT(guiApp.systemCursors[c].bitmapName, null,
4793 guiApp.systemCursors[c].paletteShades ? null : guiApp.desktop.display.displaySystem);
4794 if(guiApp.systemCursors[c].bitmap)
4795 guiApp.systemCursors[c].bitmap.paletteShades = guiApp.systemCursors[c].paletteShades;
4800 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
4802 cursor.bitmap = eBitmap_LoadT(cursor.bitmapName, null,
4803 cursor.paletteShades ? null : guiApp.desktop.display.displaySystem);
4805 cursor.bitmap.paletteShades = cursor.paletteShades;
4809 guiApp.cursorUpdate = true;
4812 ConsequentialMouseMove(false);
4818 // Load Window Graphic Resources
4821 if(usedFont == setFont || usedFont == window.systemFont)
4822 RemoveResource(usedFont);
4825 RemoveResource(setFont); // TESTING setFont instead of usedFont);
4828 RemoveResource(systemFont);
4831 RemoveResource(captionFont);
4833 for(ptr = resources.first; ptr; ptr = ptr.next)
4835 ptr.loaded = display.displaySystem.LoadResource(ptr.resource);
4838 AddResource(setFont);
4840 AddResource(systemFont);
4842 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
4849 //if(master && master.font)
4850 if(parent && parent.font)
4854 faceName = parent.font.faceName,
4855 size = parent.font.size,
4856 bold = parent.font.bold,
4857 italic = parent.font.italic,
4858 underline = parent.font.underline
4860 //font = parent.font;
4861 watch(parent) { font { } };
4864 font = guiApp.currentSkin.SystemFont();
4871 captionFont = guiApp.currentSkin.CaptionFont();
4872 AddResource(captionFont);
4874 if(OnLoadGraphics())
4880 //SetScrollLineStep(sbStep.x, sbStep.y);
4882 if(this != guiApp.desktop)
4886 normalAnchor = anchor;
4887 normalSizeAnchor = sizeAnchor;
4890 // Break the anchors for moveable/resizable windows
4892 if(style.fixed && style.isDocument)
4894 ComputeAnchors(ax, ay, aw, ah, &x, &y, &w, &h);
4906 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
4907 stateSizeAnchor = SizeAnchor {};
4912 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
4917 left = (iconID % maxIcons) * MINIMIZED_WIDTH,
4918 bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24)
4921 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
4925 stateAnchor = normalAnchor;
4926 stateSizeAnchor = normalSizeAnchor;
4929 position = Point { };
4930 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
4941 if(Position(x, y, w, h, true, false, true, true, true, true))
4943 if((this != guiApp.desktop || guiApp.fullScreenMode) && rootWindow == this)
4946 guiApp.interfaceDriver.SetRootWindowState(this, normal, true);
4963 success = result = true;
4966 if(!creation && result)
4968 // Load menu bar first because sys buttons are on it...
4971 if(!menuBar.LoadGraphics(false, resetAnchors))
4977 for(child = children.first; child; child = child.next)
4979 if(child.created && child != menuBar && !child.LoadGraphics(false, resetAnchors))
4986 CreateSystemChildren();
4990 if(this == guiApp.desktop && !guiApp.fullScreenMode)
4993 guiApp.interfaceDriver.ActivateRootWindow(activeChild);
4998 //guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, caption);
4999 guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, class.name);
5002 // Do this here to avoid problems on Windows
5003 if(stateBackup == maximized)
5004 property::state = maximized;
5008 void UnloadGraphics(bool destroyWindows)
5012 // Free children's graphics
5013 for(child = children.first; child; child = child.next)
5014 child.UnloadGraphics(destroyWindows);
5017 display.Lock(false);
5020 if(guiApp.fullScreenMode && this == guiApp.desktop)
5025 for(c=0; c<SystemCursor::enumSize; c++)
5026 if(guiApp.systemCursors[c].bitmap)
5027 delete guiApp.systemCursors[c].bitmap;
5029 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5030 delete cursor.bitmap;
5032 guiApp.cursorBackground.Free();
5035 if(display && display.displaySystem)
5039 for(ptr = resources.first; ptr; ptr = ptr.next)
5043 display.displaySystem.UnloadResource(ptr.resource, ptr.loaded);
5048 // Free window graphics
5051 // Free skin graphics
5052 if(rootWindow == this)
5054 DisplaySystem displaySystem = display.displaySystem;
5057 display.driverData = null;
5058 display.displaySystem = null;
5062 if(displaySystem && !displaySystem.numDisplays && !is3D)
5063 delete displaySystem;
5072 if(guiApp.acquiredWindow && this == guiApp.acquiredWindow.rootWindow)
5073 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, false);
5075 if(this == guiApp.desktop || parent == guiApp.desktop)
5077 if((guiApp.fullScreenMode || this != guiApp.desktop) && rootWindow == this && windowHandle && destroyWindows)
5078 guiApp.interfaceDriver.DestroyRootWindow(this);
5082 // --- Window Hiding ---
5084 void SetVisibility(bool state)
5086 bool visible = (style.hidden || !created) ? false : state;
5087 if(visible != this.visible)
5091 this.visible = visible;
5092 for(child = children.first; child; child = child.next)
5093 child.SetVisibility(visible);
5095 ConsequentialMouseMove(false);
5099 // --- Windows and graphics initialization / termination ---
5101 bool DisplayModeChanged(void)
5103 bool result = false;
5104 if(!guiApp.fullScreenMode && !guiApp.modeSwitching/* && guiApp.desktop.active*/)
5106 guiApp.modeSwitching = true;
5107 UnloadGraphics(false);
5109 if(LoadGraphics(false, false))
5111 guiApp.modeSwitching = false;
5116 // --- Window updates system ---
5118 void UpdateDirty(Box updateBox)
5120 if(!manageDisplay) { OnRedraw(null);return; }
5123 if(display && (!guiApp.fullScreenMode || guiApp.desktop.active) && !guiApp.modeSwitching)
5126 if(display.flags.flipping)
5129 rootWindow.UpdateDisplay();
5132 UpdateBackDisplay(updateBox);
5134 if(guiApp.fullScreenMode)
5136 guiApp.cursorUpdate = true;
5137 guiApp.PreserveAndDrawCursor();
5139 if(guiApp.fullScreenMode)
5140 guiApp.RestoreCursorBackground();
5146 // This function is strictly called as a result of system window activation
5147 bool ExternalActivate(bool active, bool activateRoot, Window window, Window swap)
5150 Window interimMaster = null;
5151 Window interimWindow = guiApp.interimWindow;
5152 if(interimWindow && interimWindow.master)
5153 interimMaster = interimWindow.master.rootWindow;
5155 if(active && state == minimized) // && (!window.nativeDecorations || window.rootWindow != window)
5156 // SetState(normal, false, 0);
5157 SetState(lastState, false, 0);
5159 if(interimMaster && swap == interimMaster && interimMaster.IsSlaveOf(window))
5163 /* WTH is this doing here?
5164 while(swap && swap.activeChild)
5166 swap = swap.activeChild;
5169 // TESTING THIS BEFORE...
5170 if(interimWindow && this == interimMaster)
5174 // Window interimSwap = this;
5175 Window menuBar = this.menuBar;
5176 if(menuBar && interimWindow.master == menuBar)
5179 while(interimSwap && interimSwap.activeChild)
5180 interimSwap = interimSwap.activeChild;
5182 result = interimWindow.ActivateEx(false, false, false, activateRoot, null,
5183 (menuBar && interimWindow.master == menuBar) ? menuBar : interimSwap);
5185 result = /*interimWindow.*/ActivateEx(false, false, false, activateRoot, null, menuBar);
5186 //result = ActivateEx(true, true, false, activateRoot, window, null);
5191 // Testing & FindModal() here: broke reactivating when a modal dialog is up (didn't root activate dialog)
5192 result = ActivateEx(active, active, false, activateRoot /*&& FindModal()*/, window, swap);
5194 if(interimWindow == this && interimMaster && !active)
5196 while(interimMaster && interimMaster.interim && interimMaster.master)
5198 // printf("Going up one master %s\n", interimMaster._class.name);
5199 interimMaster = interimMaster.master.rootWindow;
5201 // printf("Unactivating interim master %s (%x)\n", interimMaster._class.name, interimMaster);
5202 interimMaster.ActivateEx(active, active, false, activateRoot, window, swap);
5208 bool DestroyEx(int returnCode)
5211 Timer timer, nextTimer;
5213 OldLink prevOrder = null;
5214 Window client = null;
5216 if(parent) stopwatching(parent, font);
5218 // if(window.modalSlave) return false;
5219 if(destroyed || !created)
5226 OldLink slave = master.slaves.FindLink(this);
5227 master.slaves.Delete(slave);
5230 // TOFIX IMMEDIATELY: COMMENTED THIS OUT... causes problem second time creating file dialog
5236 this.returnCode = (DialogResult)returnCode;
5238 AcquireInput(false);
5243 master.hotKeys.Delete(hotKey);
5247 if(guiApp.prevWindow == this)
5249 guiApp.prevWindow = null;
5252 if(guiApp.caretOwner == this)
5254 guiApp.interfaceDriver.SetCaret(0,0,0);
5255 UpdateCaret(false, true);
5256 guiApp.caretEnabled = false;
5261 parent.childrenCycle.Remove(cycle);
5265 OldLink tmpPrev = order.prev;
5266 if(tmpPrev && !(((Window)tmpPrev.data).style.hidden) && !(((Window)tmpPrev.data).destroyed) && (((Window)tmpPrev.data).created))
5267 prevOrder = tmpPrev;
5270 client = tmpPrev ? tmpPrev.data : null;
5271 if(client == this) { client = null; break; }
5272 if(client && (client.style.hidden || client.destroyed || !client.created))
5273 tmpPrev = client.order.prev;
5277 prevOrder = tmpPrev;
5282 // If this window can be an active client, make sure the next window we activate can also be one
5283 if(!style.nonClient && style.isActiveClient)
5285 tmpPrev = prevOrder;
5288 client = tmpPrev ? tmpPrev.data : null;
5289 if(client == this) { client = null; break; }
5290 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
5291 tmpPrev = client.order.prev;
5295 prevOrder = tmpPrev;
5299 if(client && client.style.hidden) client = null;
5301 // parent.childrenOrder.Remove(order);
5304 if(parent && style.isActiveClient && visible)
5306 if(state == minimized) parent.numIcons--;
5307 parent.numPositions--;
5310 // TESTING THIS HERE!
5314 // If no display, don't bother deactivating stuff (causes unneeded problems when trying
5315 // to create a window inside a rootwindow that's being destroyed)
5316 // DISABLED THIS BECAUSE OF CREATING WINDOW IN DESKTOP IN WINDOWED MODE
5318 if(master && !master.destroyed /*&&
5319 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5321 if(master.defaultControl == this)
5322 master.defaultControl = null;
5324 if(parent && !parent.destroyed /*&&
5325 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5327 if((parent.activeChild == this /*|| parent.activeClient == this */|| guiApp.interimWindow == this))
5329 if(order && prevOrder && prevOrder.data != this && active)
5331 //((Window)prevOrder.data).ActivateEx(true, false, false, false /*true*/, null);
5333 ((Window)prevOrder.data).ActivateEx(true, false, false, (rootWindow == this) ? true : false, null, null);
5334 if(parent.activeClient == this)
5336 parent.activeClient = null;
5337 parent.UpdateActiveDocument(null);
5342 if(guiApp.interimWindow == this)
5345 PropagateActive(false, null, &goOn, true);
5349 //if(window.parent.activeChild == window)
5350 parent.activeChild = null;
5351 if(!style.nonClient /*&& style.isActiveClient*/)
5353 Window previous = parent.activeClient;
5354 if(style.isActiveClient)
5355 parent.activeClient = null;
5356 parent.UpdateActiveDocument(previous);
5361 else if(parent.activeClient == this)
5363 parent.activeClient = client;
5364 parent.UpdateActiveDocument(this);
5368 if(guiApp.interimWindow == this)
5370 guiApp.interimWindow = null;
5371 if(guiApp.caretOwner)
5373 Window desktop = guiApp.desktop;
5374 if(desktop.activeChild && desktop.activeChild.menuBar && !desktop.activeChild.menuBar.focus)
5375 guiApp.caretOwner.UpdateCaret(false, false);
5380 if(_isModal && master && master.modalSlave == this)
5381 master.modalSlave = null;
5385 if(!guiApp.caretOwner && parent.caretSize)
5387 guiApp.caretOwner = parent;
5388 parent.UpdateCaret(false, false);
5389 parent.Update(null);
5392 // Why was this commented out?
5393 GetRidOfVirtualArea();
5399 dirtyArea.Free(null);
5400 dirtyBack.Free(null);
5401 scrollExtent.Free(null);
5403 /* ATTEMPTING TO MOVE THAT ABOVE
5412 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5413 for(;(child = window.children.first);)
5415 for(; child && (child.destroyed || !child.created); child = child.next);
5424 UnloadGraphics(true);
5427 delete previousActive;
5430 // statusBar = null;
5433 if(master && !master.destroyed)
5435 //master.NotifyDestroyed(this, this.returnCode);
5436 NotifyDestroyed(master, this, this.returnCode);
5439 for(timer = guiApp.windowTimers.first; timer; timer = nextTimer)
5441 nextTimer = timer.next;
5442 if(timer.window == this)
5444 // WHY WERE WE SETTING THIS TO NULL? NO MORE WINDOW WHEN RECREATING...
5445 // timer.window = null;
5451 if(this == guiApp.windowMoving)
5454 if(guiApp.windowCaptured == this)
5456 //guiApp.windowCaptured = null;
5458 if(rootWindow != this && rootWindow)
5459 rootWindow.ConsequentialMouseMove(false);
5467 //for(child = children.first; next = child ? child.next : null, child; child = next)
5468 for(;(child = children.first); )
5470 for(; child && (child.destroyed || !child.created); child = child.next);
5480 /* // MOVED THIS UP...
5483 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5484 for(;(child = window.children.first); )
5486 for(; child && (child.destroyed || !child.created); child = child.next);
5495 while((slave = slaves.first))
5497 for(; slave && (((Window)slave.data).destroyed || !((Window)slave.data).created); slave = slave.next);
5499 ((Window)slave.data).DestroyEx(0);
5504 if(guiApp.caretOwner == this)
5505 guiApp.caretOwner = null;
5507 sysButtons[0] = null;
5508 sysButtons[1] = null;
5509 sysButtons[2] = null;
5512 if(rootWindow != this)
5514 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
5517 box.left -= parent.clientStart.x;
5518 box.top -= parent.clientStart.y;
5519 box.right -= parent.clientStart.x;
5520 box.bottom -= parent.clientStart.y;
5522 if(parent) parent.Update(box);
5527 OldLink slave = master.slaves.FindVoid(this);
5528 master.slaves.Delete(slave);
5534 parent.children.Remove(this);
5539 //autoCreate = false;
5542 // SHOULD THIS BE HERE? FIXED CRASH WITH GOTO DIALOG
5543 if(((subclass(Window))_class).pureVTbl)
5545 if(_vTbl == _class._vTbl)
5547 _vTbl = ((subclass(Window))_class).pureVTbl;
5552 for(m = 0; m < _class.vTblSize; m++)
5554 if(_vTbl[m] == _class._vTbl[m])
5555 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5564 void SetStateEx(WindowState newState, bool activate)
5567 WindowState prevState = state;
5571 if(prevState != newState)
5572 lastState = prevState;
5574 if(rootWindow != this || !nativeDecorations)
5576 if(style.isActiveClient && !style.hidden && prevState == minimized)
5579 // This block used to be at the end of the function... moved it for flicker problem in X
5580 // ------------------------------------------------------
5584 stateAnchor = normalAnchor;
5585 stateSizeAnchor = normalSizeAnchor;
5588 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5589 stateSizeAnchor = SizeAnchor {};
5593 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5596 byte * idBuffer = new0 byte[size];
5598 for(child = parent.children.first; child; child = child.next)
5600 if(child != this && child.state == minimized)
5602 if(child.iconID > size - 2)
5604 idBuffer = renew0 idBuffer byte[size*2];
5605 memset(idBuffer + size, 0, size);
5608 idBuffer[child.iconID] = (byte)bool::true;
5611 for(c = 0; c<size; c++)
5616 if(style.isActiveClient && !style.hidden)
5619 stateAnchor = Anchor { left = (iconID % maxIcons) * MINIMIZED_WIDTH, bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24) };
5620 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
5624 // TOCHECK: Why was this here?
5625 //position.x = (tx > 0) ? tx & 0xFFFFF : tx;
5626 //position.y = (ty > 0) ? ty & 0xFFFFF : ty;
5627 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5629 Position(x, y, w, h, true, true, true, true, false, true);
5631 if(!style.inactive && !style.interim && this == parent.activeClient)
5632 parent.UpdateActiveDocument(null);
5635 CreateSystemChildren();
5636 // ------------------------------------------------------
5639 int GetPositionID(Window forChild)
5643 byte * idBuffer = new0 byte[size];
5646 for(child = children.first; child; child = child.next)
5648 if(child.style.isActiveClient && !child.style.hidden && child != forChild)
5650 if(child.positionID > size - 2)
5652 idBuffer = renew0 idBuffer byte[size*2];
5653 memset(idBuffer + size, 0, size);
5656 idBuffer[child.positionID] = (byte)bool::true;
5659 for(c = 0; c<size; c++)
5666 // --- Window related graphics ---
5668 void SetPalette(ColorAlpha * newPalette, bool colorMatch)
5670 palette = newPalette;
5671 if(rootWindow.display)
5672 rootWindow.display.SetPalette(palette, colorMatch);
5675 public bool AcquireInput(bool acquired)
5678 if(acquiredInput != acquired)
5680 if(active || (!visible && creationActivation == activate))
5681 result = AcquireInputEx(acquired);
5686 acquiredInput = acquired ? result : !result;
5691 void ListChildren(ListBox listBox)
5695 for(child = children.first; child; child = child.next)
5697 if(child.cycle && !child.style.nonClient && child.style.isActiveClient && child.visible)
5699 DataRow row = listBox.AddRow();
5700 row.tag = (int)child;
5701 child.FigureCaption(caption);
5702 row.SetData(null, caption);
5707 void UpdateVisual(Box extent)
5709 if(guiApp.driver != null)
5711 if(guiApp.fullScreenMode && guiApp.desktop.display)
5713 guiApp.desktop.mutex.Wait();
5714 guiApp.desktop.display.Lock(true);
5717 if(guiApp.desktop.active)
5719 if(guiApp.desktop.dirty || guiApp.cursorUpdate)
5721 if(guiApp.desktop.display.flags.flipping)
5722 guiApp.desktop.Update(null);
5723 guiApp.desktop.UpdateDisplay();
5724 guiApp.cursorUpdate = true;
5726 if(guiApp.cursorUpdate || guiApp.desktop.dirty)
5728 guiApp.PreserveAndDrawCursor();
5729 // guiApp.desktop.display.ShowScreen();
5730 guiApp.cursorUpdate = false;
5731 guiApp.desktop.dirty = false;
5732 guiApp.RestoreCursorBackground();
5736 guiApp.desktop.display.Unlock();
5737 guiApp.desktop.mutex.Release();
5741 Window rootWindow = this.rootWindow;
5742 rootWindow.mutex.Wait();
5747 guiApp.SignalEvent();
5750 guiApp.waitMutex.Wait();
5751 guiApp.interfaceDriver.Lock(rootWindow);
5752 if(!rootWindow.style.hidden && rootWindow.dirty)
5754 if(rootWindow.display)
5756 rootWindow.UpdateDisplay();
5757 //rootWindow.display.ShowScreen(null);
5759 rootWindow.dirty = false;
5761 guiApp.interfaceDriver.Unlock(rootWindow);
5762 guiApp.waitMutex.Release();
5765 rootWindow.mutex.Release();
5770 void UnlockDisplay(void)
5772 guiApp.interfaceDriver.Unlock(rootWindow);
5775 void LockDisplay(void)
5777 guiApp.interfaceDriver.Lock(rootWindow);
5780 Surface GetSurface(Box box)
5782 return Redraw((box == null) ? this.box : box);
5785 void SetMousePosition(int x, int y)
5787 guiApp.interfaceDriver.SetMousePosition(x + absPosition.x + clientStart.x, y + absPosition.y + clientStart.y);
5791 void IntegrationActivate(bool active)
5793 if(!guiApp.modeSwitching && !guiApp.fullScreenMode)
5795 isForegroundWindow = true;
5796 ActivateEx(active, active, false, false, null, null);
5797 isForegroundWindow = false;
5802 Window QueryCapture(void)
5804 return guiApp.windowCaptured;
5807 int GetDocumentID(void)
5811 byte * idBuffer = new0 byte[size];
5814 for(child = children.first; child; child = child.next)
5816 if(child.style.isDocument)
5818 if(child.documentID-1 > size - 2)
5820 idBuffer = renew0 idBuffer byte[size*2];
5821 memset(idBuffer + size, 0, size);
5824 idBuffer[child.documentID-1] = 1;
5827 for(c = 0; c<size; c++)
5835 void SetInitSize(Size size)
5838 sizeAnchor.size = size;
5839 normalSizeAnchor = sizeAnchor;
5841 // Break the anchors for moveable/resizable windows
5842 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
5844 stateAnchor = normalAnchor;
5845 stateSizeAnchor = normalSizeAnchor;
5847 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5848 Position(x,y, w, h, true, true, true, true, false, true);
5852 void MenuMoveOrSize(bool resize, bool setCursorPosition)
5854 if(this != guiApp.desktop && state != maximized && (resize ? (state != minimized && style.sizable) : (style.fixed || moveable)))
5856 guiApp.windowIsResizing = resize;
5857 guiApp.windowMoving = this;
5858 guiApp.windowMovingStart = guiApp.movingLast = absPosition;
5859 if(guiApp.windowIsResizing)
5861 guiApp.windowMovingStart.x += size.w - 1;
5862 guiApp.windowMovingStart.y += size.h - 1;
5864 guiApp.windowMovingBefore = scrolledPos;
5865 guiApp.windowResizingBefore = size;
5866 guiApp.windowMoving.UpdateDecorations();
5867 if(guiApp.windowIsResizing)
5868 guiApp.resizeEndX = guiApp.resizeEndY = true;
5870 if(setCursorPosition)
5871 guiApp.interfaceDriver.SetMousePosition(guiApp.windowMovingStart.x, guiApp.windowMovingStart.y);
5875 guiApp.interfaceDriver.GetMousePosition(&x, &y);
5876 guiApp.windowMovingStart.x += x - absPosition.x;
5877 guiApp.windowMovingStart.y += y - absPosition.y;
5880 if(guiApp.windowMoving)
5882 if(guiApp.windowMoving.style.nonClient)
5883 guiApp.windowMoving.parent.SetMouseRangeToWindow();
5885 guiApp.windowMoving.parent.SetMouseRangeToClient();
5890 if(this == rootWindow)
5891 guiApp.interfaceDriver.StartMoving(rootWindow, guiApp.windowMovingStart.x, guiApp.windowMovingStart.y, true);
5899 bool result = false;
5903 else if(guiApp && guiApp.driver != null)
5905 void * systemParent = null;
5906 OldLink slaveHolder;
5908 bool visible = !style.hidden;
5912 systemParent = parent;
5913 parent = guiApp.desktop;
5915 last = parent ? parent.children.last : null;
5917 if((parent && parent != guiApp.desktop && !parent.created) ||
5918 (master && master != guiApp.desktop && !master.created))
5922 property::parent = guiApp.desktop;
5923 if(!master) master = parent;
5925 if(_isModal && master.modalSlave)
5926 property::master = master.modalSlave;
5930 parent.children.Remove(this);
5933 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
5934 if(slaveHolder.data == this)
5936 master.slaves.Delete(slaveHolder);
5941 if(parent == guiApp.desktop && !mutex)
5944 if(style.isDocument)
5947 parent.numDocuments--;
5948 documentID = parent.GetDocumentID();
5951 if(!style.stayOnTop)
5952 for(; last && last.style.stayOnTop; last = last.prev);
5954 parent.children.Insert((last == this) ? null : last, this);
5955 //parent.children.Add(this);
5958 dispDriver = parent.dispDriver;
5961 master.modalSlave = this;
5963 box = Box { MAXINT, MAXINT, MININT, MININT }; //-MAXINT, -MAXINT };
5968 master.slaves.Add(slaveHolder = OldLink { data = this });
5973 master.hotKeys.Add(hotKey = HotKeySlot { key = setHotKey, window = this });
5975 if(style.isDefault && !master.defaultControl)
5976 master.defaultControl = this;
5978 stateAnchor = normalAnchor = anchor;
5979 stateSizeAnchor = normalSizeAnchor = sizeAnchor;
5981 // TOCHECK: Why is this here?
5982 //position.x = (ax > 0) ? ax & 0xFFFFF : ax;
5983 //position.y = (ay > 0) ? ay & 0xFFFFF : ay;
5985 this.visible = false;
5986 style.hidden = true;
5989 // autoCreate = true;
5997 if(parent == guiApp.desktop)
5998 Log("LoadGraphics %s\n", caption);
6000 if(LoadGraphics(true, false))
6008 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
6015 if(style.hasMenuBar /*&& menu*/)
6021 menu = menu, isMenuBar = true, anchor = Anchor { top = 23, left = 1, right = 1 },
6022 interim = false, inactive = true, nonClient = true, size.h = 24
6030 // Create the system buttons
6031 CreateSystemChildren();
6033 UpdateActiveDocument(null);
6035 if(style.isDocument)
6039 MenuItem item = menu.FindItem(MenuFileSave, 0);
6040 if(item) item.disabled = !modifiedDocument && fileName;
6045 if(parent == guiApp.desktop)
6046 Log("Preemptive SetState %s\n", caption);
6049 // Preemptive Set State to ensure proper anchoring
6050 SetStateEx(state, false);
6052 style.hidden = true;
6058 for(child = children.first; child; child = next)
6061 if(!child.created && (child.autoCreate || child.wasCreated))
6068 for(link = slaves.first; link; link = next)
6070 Window slave = link.data;
6072 if(!slave.created && (slave.autoCreate || slave.wasCreated))
6081 if(parent == guiApp.desktop)
6082 Log("Real SetState %s\n", caption);
6085 if(isActiveClient && visible)
6087 parent.numPositions--;
6088 if(state == minimized) parent.numIcons--;
6091 // Real set state & activate for proper display & activation
6092 property::visible = visible;
6093 // SetState(state & 0x00000003, true, 0);
6098 /*if(rootWindow == this)
6099 guiApp.interfaceDriver.ActivateRootWindow(this);
6101 if(creationActivation == activate)
6102 ActivateEx(true, false, true, true, null, null);
6103 else if(creationActivation == flash)
6108 rootWindow.ConsequentialMouseMove(false);
6119 guiApp.LogErrorCode(IERR_WINDOW_CREATION_FAILED, caption);
6125 // Testing this here... Otherwise a failed LoadGraphics stalls the application
6127 //style.hidden = true; // !visible;
6128 style.hidden = !visible;
6129 if(master.modalSlave == this)
6130 master.modalSlave = null;
6137 void WriteCaption(Surface surface, int x, int y)
6140 Interface::WriteKeyedTextDisabled(surface, x,y, caption, hotKey ? hotKey.key : 0, !isEnabled);
6143 void Update(Box region)
6149 rootWindow = this.rootWindow;
6151 // rootWindow.mutex.Wait();
6152 if(!destroyed && visible && display)
6157 // Testing this to avoid repetitve full update to take time...
6158 if(dirtyArea.count == 1)
6160 BoxItem item = (BoxItem)ACCESS_ITEM(dirtyArea, dirtyArea.first);
6161 if(item.box.left <= box.left &&
6162 item.box.top <= box.top &&
6163 item.box.right >= box.right &&
6164 item.box.bottom >= box.bottom)
6166 rootWindow.dirty = true;
6171 if(display.flags.flipping && !rootWindow.dirty)
6173 if(this == rootWindow)
6177 rootWindow.Update(null);
6182 rootWindow.dirty = true;
6187 realBox.left += clientStart.x;
6188 realBox.top += clientStart.y;
6189 realBox.right += clientStart.x;
6190 realBox.bottom += clientStart.y;
6196 if(realBox.right >= realBox.left &&
6197 realBox.bottom >= realBox.top)
6199 // if(!rootWindow.fullRender)
6200 dirtyArea.UnionBox(realBox, rootWindow.tempExtents[0]);
6202 for(child = children.first; child; child = child.next)
6207 box.left -= child.absPosition.x - absPosition.x;
6208 box.top -= child.absPosition.y - absPosition.y;
6209 box.right -= child.absPosition.x - absPosition.x;
6210 box.bottom -= child.absPosition.y - absPosition.y;
6211 if(box.right >= child.box.left && box.left <= child.box.right &&
6212 box.bottom >= child.box.top && box.top <= child.box.bottom)
6214 box.left -= child.clientStart.x;
6215 box.top -= child.clientStart.y;
6216 box.right -= child.clientStart.x;
6217 box.bottom -= child.clientStart.y;
6223 realBox.left += absPosition.x - rootWindow.absPosition.x;
6224 realBox.top += absPosition.y - rootWindow.absPosition.y;
6225 realBox.right += absPosition.x - rootWindow.absPosition.x;
6226 realBox.bottom += absPosition.y - rootWindow.absPosition.y;
6227 rootWindow.dirtyBack.UnionBox(realBox, rootWindow.tempExtents[0]);
6230 else if(this == guiApp.desktop)
6233 for(window = children.first; window; window = window.next)
6239 Box childBox = region;
6241 childBox.left -= window.absPosition.x - guiApp.desktop.absPosition.x;
6242 childBox.top -= window.absPosition.y - guiApp.desktop.absPosition.y;
6243 childBox.right -= window.absPosition.x - guiApp.desktop.absPosition.x;
6244 childBox.bottom -= window.absPosition.y - guiApp.desktop.absPosition.y;
6246 window.Update(childBox);
6249 window.Update(null);
6254 // rootWindow.mutex.Release();
6261 if(guiApp.windowCaptured != this)
6263 if(guiApp.windowCaptured)
6267 //Logf("Captured %s (%s)\n", caption, class.name);
6268 guiApp.interfaceDriver.SetMouseCapture(rootWindow);
6269 guiApp.windowCaptured = this;
6275 bool Destroy(int code)
6280 if(!CloseConfirmation(false)) return false;
6284 // TOCHECK: Should autoCreate be set to false here?
6287 // Is this needed here? DestroyEx should decref already...
6296 void Move(int x, int y, int w, int h)
6298 normalAnchor = Anchor { left = x, top = y };
6299 normalSizeAnchor = SizeAnchor { size = { w, h } };
6301 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6303 if(destroyed) return;
6305 stateAnchor = normalAnchor;
6306 stateSizeAnchor = normalSizeAnchor;
6308 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6309 Position(x,y, w, h, true, true, true, true, false, true);
6313 DialogResult Modal(void)
6319 // FIXES MEMORY LEAK IF Create() FAILED
6325 void SetScrollArea(int width, int height, bool snapToStep)
6327 bool resize = false;
6330 int stepX = sbStep.x, stepY = sbStep.y;
6331 // Needed to make snapped down position match the skin's check of client area
6332 // against realvirtual
6335 SNAPDOWN(stepX, textCellW);
6336 SNAPDOWN(stepY, textCellH);
6337 stepX = Max(stepX, textCellW);
6338 stepY = Max(stepY, textCellH);
6340 if(scrollFlags.snapX)
6341 SNAPUP(width, stepX);
6342 if(scrollFlags.snapY)
6343 SNAPUP(height, stepY);
6346 reqScrollArea.w = width;
6347 reqScrollArea.h = height;
6348 noAutoScrollArea = (width > 0 || height > 0);
6350 UpdateScrollBars(true, true);
6353 void SetScrollPosition(int x, int y)
6356 sbh.Action(setPosition, x, 0);
6360 int seen = clientSize.w, total = reqScrollArea.w;
6362 if(scrollFlags.snapX)
6363 SNAPDOWN(seen, sbStep.x);
6365 if(!total) total = seen;
6366 range = total - seen + 1;
6367 range = Max(range, 1);
6369 if(x >= range) x = range - 1;
6371 if(scrollFlags.snapX)
6372 SNAPUP(x, sbStep.x);
6375 OnHScroll(setPosition, x, 0);
6379 SNAPDOWN(x, textCellW);
6385 sbv.Action(setPosition, y, 0);
6389 int seen = clientSize.h, total = reqScrollArea.h;
6392 if(scrollFlags.snapY)
6393 SNAPDOWN(seen, sbStep.y);
6395 if(!total) total = seen;
6396 range = total - seen + 1;
6397 range = Max(range, 1);
6399 if(y >= range) y = range - 1;
6401 if(scrollFlags.snapY)
6402 SNAPUP(y, sbStep.y);
6405 OnVScroll(setPosition, y, 0);
6408 SNAPDOWN(y, textCellH);
6413 UpdateCaret(false, false);
6416 void SetScrollLineStep(int stepX, int stepY)
6422 SNAPDOWN(stepX, textCellW);
6423 SNAPDOWN(stepY, textCellH);
6424 stepX = Max(stepX, textCellW);
6425 stepY = Max(stepY, textCellH);
6428 sbh.lineStep = stepX;
6430 sbv.lineStep = stepY;
6433 void SetState(WindowState newState, bool activate, Modifiers mods)
6437 if(state == newState || OnStateChange(newState, mods))
6439 WindowState prevState = state;
6443 // This used to be at the end of the brackets... moved for X, testing...
6444 // This has the effect of activating the window through the system...
6445 if(rootWindow == this)
6446 guiApp.interfaceDriver.SetRootWindowState(this, newState, !style.hidden);
6448 SetStateEx(newState, activate);
6450 if(rootWindow == this && !rootWindow.nativeDecorations)
6452 int x = position.x, y = position.y;
6455 x -= guiApp.desktop.absPosition.x;
6456 y -= guiApp.desktop.absPosition.y;
6458 guiApp.interfaceDriver.PositionRootWindow(this, x, y, size.w, size.h, true, true);
6462 //state = prevState;
6464 if(state != maximized && style.hasMaximize)
6467 for(child = parent.children.first; child; child = child.next)
6469 if(child != this && child.state == maximized)
6470 child.SetStateEx(normal, false);
6474 if(!style.nonClient && (sbv || sbh) && this != parent.sbv && this != parent.sbh)
6475 parent.UpdateScrollBars(true, true);
6478 // Do we really need this stuff here?
6479 // Shouldn't the Activate stuff take care of it?
6480 if(parent.rootWindow == parent && style)
6483 parent.FigureCaption(caption);
6484 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
6485 parent.UpdateDecorations();
6489 rootWindow.ConsequentialMouseMove(false);
6496 BitmapResource GetIcon(SkinBitmap iconID)
6498 return guiApp.currentSkin.GetBitmap(iconID);
6501 void SetMouseRange(Box range)
6503 if(range || guiApp.fullScreenMode)
6508 clip.left = range.left + absPosition.x + clientStart.x;
6509 clip.top = range.top + absPosition.y + clientStart.y;
6510 clip.right = range.right + absPosition.x + clientStart.x;
6511 clip.bottom = range.bottom + absPosition.y + clientStart.y;
6515 clip.left = guiApp.desktop.box.left;
6516 clip.top = guiApp.desktop.box.top;
6517 clip.right = guiApp.desktop.box.right;
6518 clip.bottom = guiApp.desktop.box.bottom;
6520 guiApp.interfaceDriver.SetMouseRange(rootWindow, clip);
6523 guiApp.interfaceDriver.SetMouseRange(rootWindow, null);
6526 void SetMouseRangeToClient(void)
6528 if(guiApp.fullScreenMode || this != guiApp.desktop)
6530 Box box {0, 0, clientSize.w - 1, clientSize.h - 1 };
6531 box.Clip(clientArea);
6535 SetMouseRange(null);
6538 void SetMouseRangeToWindow(void)
6540 Box box { -clientStart.x, -clientStart.y, size.w-1, size.h-1 };
6541 if(this == guiApp.desktop)
6542 SetMouseRangeToClient();
6547 // x, y: Desktop Coordinates
6548 void ShowSysMenu(int x, int y)
6551 PopupMenu windowMenu { master = this, interim = true, position = { x + 1 - guiApp.desktop.position.x, y + 1 - guiApp.desktop.position.y }, menu = menu };
6554 menu, "Restore", r, NotifySelect = MenuWindowRestore,
6555 disabled = (!style.hasMaximize && !style.hasMinimize) || state == normal, bitmap = guiApp.currentSkin.GetBitmap(restore)
6559 menu, "Move", m, NotifySelect = MenuWindowMove,
6560 disabled = !style.fixed || state == maximized
6564 menu, "Size", s, NotifySelect = MenuWindowSize,
6565 disabled = !style.sizable || state != normal
6569 menu, "Minimize", n, NotifySelect = MenuWindowMinimize,
6570 disabled = !style.hasMinimize || state == minimized, bitmap = guiApp.currentSkin.GetBitmap(minimize)
6574 menu, "Maximize", KeyCode::x, NotifySelect = MenuWindowMaximize,
6575 disabled = !style.hasMaximize || state == maximized, bitmap = guiApp.currentSkin.GetBitmap(maximize)
6579 menu, "Stay On Top", t, NotifySelect = MenuWindowStayOnTop,
6580 disabled = !style.fixed, checkable = true, checked = style.stayOnTop
6582 MenuDivider { menu };
6585 menu, "Close", c, (parent == guiApp.desktop) ? altF4 : ( style.isActiveClient ? ctrlF4 : 0), NotifySelect = MenuWindowClose,
6586 bold = true, disabled = !style.hasClose, bitmap = guiApp.currentSkin.GetBitmap(close)
6588 windowMenu.Create();
6593 ActivateEx(true, true, true, true, null, null);
6596 void MakeActive(void)
6598 ActivateEx(true, false, true, false, null, null);
6601 void SoftActivate(void)
6603 if(guiApp.desktop.active)
6609 void Deactivate(void)
6611 ActivateEx(false, true, true, true, null, null);
6616 guiApp.interfaceDriver.FlashRootWindow(rootWindow);
6619 bool CycleChildren(bool backward, bool clientOnly, bool tabCycleOnly, bool cycleParents)
6621 bool result = false;
6622 if(activeChild && activeChild.cycle)
6624 Window modalWindow, child = activeChild;
6625 if(!clientOnly /*&& parent.tabCycle*/)
6627 Window next = child;
6630 if(next.cycle == (backward ? childrenCycle.first : childrenCycle.last))
6634 if(parent && parent.CycleChildren(backward, false, true, true))
6642 next = next.cycle.prev.data;
6644 next = next.cycle.next.data;
6645 if(!next.disabled && !next.inactive /*isRemote*/ && next.created && !next.nonClient && (!clientOnly || next.style.isActiveClient) && !next.style.hidden && next.FindModal() != activeChild)
6650 if(!clientOnly && child.cycle == (backward ? childrenCycle.first : childrenCycle.last) &&
6651 parent.tabCycle && parent.CycleChildren(backward, false, false))
6655 if(tabCycleOnly && !tabCycle) return false;
6662 child = child.cycle.prev.data;
6664 child = child.cycle.next.data;
6665 if(child == child.parent.activeChild)
6667 else if(!child.disabled && child.created && (!clientOnly || child.style.isActiveClient) && !child.style.hidden && child.FindModal() != activeChild)
6670 modalWindow = child.FindModal();
6673 // Scroll the window to include the active control
6674 if(sbh && !child.style.dontScrollHorz)
6676 if(child.scrolledPos.x < 0)
6677 sbh.Action(setPosition, scroll.x + child.scrolledPos.x, 0);
6678 else if(child.scrolledPos.x + child.size.w > clientSize.w)
6679 sbh.Action(setPosition, scroll.x + child.scrolledPos.x + child.size.w - clientSize.w, 0);
6681 if(sbv && !child.style.dontScrollVert)
6683 if(child.scrolledPos.y < 0)
6684 sbv.Action(setPosition, scroll.y + child.scrolledPos.y, 0);
6685 else if(child.scrolledPos.y + child.size.h > clientSize.h)
6686 sbv.Action(setPosition, scroll.y + child.scrolledPos.y + child.size.h - clientSize.h, 0);
6690 child = modalWindow ? modalWindow : child;
6691 child.ActivateEx(true, true, true, true, null, null);
6692 if(child.tabCycle && child.childrenCycle.first)
6693 child = ((OldLink)(backward ? child.childrenCycle.first : child.childrenCycle.last)).data;
6701 ConsequentialMouseMove(false);
6705 void AddResource(Resource resource)
6709 ResPtr ptr { resource = resource };
6713 // Load Graphics here if window is created already
6714 if(/*created && */display)
6716 display.Lock(false);
6717 ptr.loaded = display.displaySystem.LoadResource(resource);
6721 // Temporary hack to load font right away for listbox in dropbox ...
6722 else if(master && master.display)
6724 master.display.Lock(false);
6725 master.display.displaySystem.LoadResource(resource);
6726 master.display.Unlock();
6732 void RemoveResource(Resource resource)
6737 for(ptr = resources.first; ptr; ptr = ptr.next)
6739 if(ptr.resource == resource)
6745 // Unload Graphics here if window is created already
6746 if(/*created && */display)
6750 display.Lock(false);
6751 display.displaySystem.UnloadResource(resource, ptr.loaded);
6757 resources.Delete(ptr);
6762 void SetCaret(int x, int y, int size)
6769 if(active && !style.interim)
6771 if(visible || !guiApp.caretOwner)
6772 guiApp.caretOwner = size ? this : null;
6774 UpdateCaret(false, false);
6777 guiApp.interfaceDriver.SetCaret(0,0,0);
6778 UpdateCaret(false, true);
6779 guiApp.caretEnabled = false;
6782 else if(style.inactive && active)
6784 guiApp.interfaceDriver.SetCaret(0,0,0);
6785 UpdateCaret(false, true);
6786 guiApp.caretEnabled = false;
6791 void Scroll(int x, int y)
6793 bool opaque = !style.drawBehind || background.a;
6794 if(opaque && display && display.flags.scrolling)
6796 Box box = clientArea;
6797 box.left += clientStart.x;
6798 box.top += clientStart.y;
6799 box.right += clientStart.x;
6800 box.bottom += clientStart.y;
6802 //scrollExtent.Free(null);
6803 scrollExtent.AddBox(box);
6804 scrolledArea.x += x;
6805 scrolledArea.y += y;
6807 //scrollExtent.Free();
6808 //scrollExtent.AddBox(clientArea);
6809 //scrollExtent.Offset(clientStart.x, clientStart.y);
6810 //scrolledArea.x = x;
6811 //scrolledArea.y = y;
6817 rootWindow.dirty = true;
6820 void ReleaseCapture()
6822 if(guiApp && guiApp.windowCaptured && guiApp.windowCaptured == this)
6824 Window oldCaptured = guiApp.windowCaptured;
6825 guiApp.windowCaptured = null;
6826 guiApp.prevWindow = null;
6829 //guiApp.Log("Released Capture\n");
6831 guiApp.interfaceDriver.SetMouseCapture(null);
6833 //oldCaptured.OnMouseCaptureLost();
6836 oldCaptured.ConsequentialMouseMove(false);
6841 void SetText(char * format, ...)
6848 char caption[MAX_F_STRING];
6850 va_start(args, format);
6851 vsprintf(caption, format, args);
6854 this.caption = new char[strlen(caption)+1];
6856 strcpy(this.caption, caption);
6865 bool Grab(Bitmap bitmap, Box box, bool decorations)
6867 bool result = false;
6868 if(display || this == guiApp.desktop)
6870 Box clip = {MININT, MININT, MAXINT, MAXINT};
6876 clip.Clip(clientArea);
6878 clip.Clip(this.box);
6880 if(rootWindow != this)
6882 clip.left += absPosition.y;
6883 clip.top += absPosition.y;
6884 clip.right += absPosition.x;
6885 clip.bottom += absPosition.y;
6888 clip.left += decorations ? 0 : clientStart.x;
6889 clip.top += decorations ? 0 : clientStart.y;
6890 clip.right += decorations ? 0 : clientStart.x;
6891 clip.bottom += decorations ? 0 : clientStart.y;
6893 if(display && display.flags.flipping)
6895 rootWindow.Update(null);
6896 rootWindow.UpdateDisplay();
6903 result = window.display.displaySystem.driver.GrabScreen(null, bitmap, clip.left, clip.top,
6904 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6908 result = display.Grab(bitmap, clip.left, clip.top,
6909 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6911 if(bitmap.pixelFormat != pixelFormat888 && bitmap.pixelFormat != pixelFormat8)
6913 if(!bitmap.Convert(null, pixelFormat888, null))
6920 void GetMousePosition(int * x, int * y)
6922 int mouseX = 0, mouseY = 0;
6923 if(!guiApp.acquiredWindow && (guiApp.desktop.active || !guiApp.fullScreenMode))
6926 guiApp.interfaceDriver.GetMousePosition(&mouseX, &mouseY);
6927 if(this != guiApp.desktop)
6929 mouseX -= absPosition.x + clientStart.x;
6930 mouseY -= absPosition.y + clientStart.y;
6937 DialogResult DoModal()
6939 DialogResult returnCode = 0;
6940 int terminated = terminateX;
6943 while(!destroyed && guiApp.driver != null)
6945 if(terminateX != terminated)
6947 terminated = terminateX;
6948 guiApp.desktop.Destroy(0);
6949 if(guiApp.desktop.created)
6952 //printf("Resetting terminate X to 0\n");
6958 guiApp.UpdateDisplay();
6959 if(!guiApp.ProcessInput(false))
6962 returnCode = this.returnCode;
6975 return !destroyed && guiApp.driver != null && terminateX < 2;
6978 DialogResult DoModalEnd()
6980 DialogResult returnCode = this.returnCode;
6985 // --- Window manipulation ---
6986 /*bool GetDisabled()
6988 bool disabled = this.disabled;
6990 for(window = this; (window = window.master); )
7001 // --- Mouse Manipulation ---
7002 void GetNCMousePosition(int * x, int * y)
7004 GetMousePosition(x, y);
7005 if(x) *x += clientStart.x;
7006 if(y) *y += clientStart.y;
7009 // --- Carets manipulation ---
7010 void GetCaretPosition(Point caretPos)
7012 caretPos = this.caretPos;
7015 int GetCaretSize(void)
7020 bool ButtonCloseDialog(Button button, int x, int y, Modifiers mods)
7026 bool CloseConfirmation(bool parentClosing)
7039 if(!OnClose(parentClosing))
7042 // If you want to skip this, simply set modifiedDocument to false in OnClose
7043 if(result && (/*fileName || */style.isDocument) && modifiedDocument)
7045 DialogResult dialogRes;
7048 sprintf(message, "Save changes to %s?", fileName);
7050 sprintf(message, "Save changes to Untitled %d?", documentID);
7052 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption, contents = message }.Modal();
7054 if(dialogRes == yes)
7056 // TOFIX: Precomp error if brackets are taken out
7057 result = (DialogResult)MenuFileSave(null, 0) != cancel;
7059 else if(dialogRes == cancel)
7065 for(slave = slaves.first; slave; slave = slave.next)
7066 if(!((Window)slave.data).CloseConfirmation(true))
7068 // ((Window)slave.data).CloseConfirmation(true);
7076 for(child = children.first; child; child = child.next)
7077 if(child.master != this && !child.CloseConfirmation(true))
7087 // Static methods... move them somewhere else?
7088 void ::RestoreCaret()
7090 if(guiApp.caretOwner)
7091 guiApp.caretOwner.UpdateCaret(false, false);
7094 void ::FreeMouseRange()
7096 guiApp.interfaceDriver.SetMouseRange(null, null);
7100 bool MenuFileClose(MenuItem selection, Modifiers mods)
7102 Window document = activeChild;
7104 document.Destroy(0);
7108 bool MenuFileExit(MenuItem selection, Modifiers mods)
7114 bool MenuFileSave(MenuItem selection, Modifiers mods)
7118 fileMonitor.fileName = null;
7121 if(OnSaveFile(fileName))
7123 //if(OnFileModified != Window::OnFileModified)
7126 fileMonitor.fileName = fileName;
7132 MessageBox dialog { master = master, type = yesNoCancel, text = "Error writing file", contents = "Save as a different file?" };
7133 DialogResult answer = dialog.Modal();
7135 if(answer != yes) return (bool)answer;
7138 return MenuFileSaveAs(selection, mods);
7141 bool MenuFileSaveAs(MenuItem selection, Modifiers mods)
7143 DialogResult result = (DialogResult)bool::true;
7144 FileDialog fileDialog = saveDialog;
7147 fileDialog = FileDialog {};
7152 fileDialog.filePath = fileName;
7155 char filePath[MAX_FILENAME];
7156 sprintf(filePath, "Untitled %d", documentID);
7157 fileDialog.filePath = filePath;
7159 fileMonitor.fileName = null;
7161 fileDialog.type = save;
7162 fileDialog.text = "Save As";
7166 fileDialog.master = master.parent ? master : this;
7167 if(fileDialog.Modal() == ok)
7169 char * filePath = fileDialog.filePath;
7171 if(OnSaveFile(filePath))
7174 property::fileName = filePath;
7175 NotifySaved(master, this, filePath);
7180 MessageBox dialog { master = master.parent ? master : this, type = yesNoCancel, text = "Error writing file", contents = "Save as a different file?" };
7181 DialogResult answer = dialog.Modal();
7196 //if(OnFileModified != Window::OnFileModified && fileName)
7199 fileMonitor.fileName = fileName;
7203 return (bool)result; // Actually returning result from Yes/NoCancel message box
7206 bool MenuFileSaveAll(MenuItem selection, Modifiers mods)
7208 Window document = activeChild;
7210 for(document = children.first; document; document = next)
7212 next = document.next;
7213 if(document.style.isDocument || document.fileName)
7214 document.MenuFileSave(selection, mods);
7219 bool MenuWindowArrangeIcons(MenuItem selection, Modifiers mods)
7223 for(document = children.first; document; document = document.next)
7224 //if(document.style.isDocument && document.state == minimized)
7225 if(document.style.isActiveClient && document.state == minimized)
7226 document.SetState(minimized, false, mods);
7230 bool MenuWindowCascade(MenuItem selection, Modifiers mods)
7232 Window document = activeChild;
7235 Window firstDocument = null;
7237 OldLink cycle = document.cycle.prev;
7242 if(child.style.isActiveClient && !child.style.hidden)
7246 firstDocument = child;
7247 if(child.state == minimized)
7248 child.SetState(minimized, false, mods);
7251 child.positionID = id++;
7252 child.SetState(normal, false, mods);
7253 child.anchor.left.type = cascade;
7256 child.normalSizeAnchor = *&child.sizeAnchor;
7257 child.normalAnchor = child.anchor;
7259 // Break the anchors for moveable/resizable windows
7260 if(child.style.fixed)
7262 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7264 (*&child.normalAnchor).left = x;
7265 (*&child.normalAnchor).top = y;
7266 (*&child.normalAnchor).right.type = none;
7267 (*&child.normalAnchor).bottom.type = none;
7269 child.normalSizeAnchor.isClientW = false;
7270 child.normalSizeAnchor.isClientH = false;
7271 child.normalSizeAnchor.size.w = w;
7272 child.normalSizeAnchor.size.h = h;
7273 child.anchored = false;
7276 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7278 child.stateAnchor = child.normalAnchor;
7279 child.stateSizeAnchor = child.normalSizeAnchor;
7281 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7282 child.Position(x, y, w, h, true, true, true, true, false, false);
7287 last = children.last;
7288 if(!child.style.stayOnTop)
7289 for(; last && last.style.stayOnTop; last = last.prev);
7290 children.Move(child, last);
7291 childrenOrder.Move(child.order, childrenOrder.last);
7293 if(cycle == document.cycle) break;
7297 firstDocument.Activate();
7302 bool MenuWindowClose(MenuItem selection, Modifiers mods)
7309 // Close all closes all active clients, not all documents
7310 bool MenuWindowCloseAll(MenuItem selection, Modifiers mods)
7312 Window next, document;
7314 for(document = children.first; document; document = next)
7316 for(next = document.next; next && !(next.style.isActiveClient; next = next.next);
7317 if(document.style.isActiveClient)
7318 if(!document.Destroy(0) && !document.style.hidden)
7324 bool MenuWindowMaximize(MenuItem selection, Modifiers mods)
7326 if(style.hasMaximize && state != maximized)
7327 SetState(maximized, 0, 0);
7331 bool MenuWindowMinimize(MenuItem selection, Modifiers mods)
7333 if(style.hasMinimize && state != minimized)
7335 SetState(minimized, 0, 0);
7336 parent.CycleChildren(false, true, false, true);
7341 bool MenuWindowMove(MenuItem selection, Modifiers mods)
7343 MenuMoveOrSize(false, selection ? true : false);
7347 bool MenuWindowNext(MenuItem selection, Modifiers mods)
7349 CycleChildren(false, true, false, true);
7353 bool MenuWindowPrevious(MenuItem selection, Modifiers mods)
7355 CycleChildren(true, true, false, true);
7359 bool MenuWindowSize(MenuItem selection, Modifiers mods)
7361 MenuMoveOrSize(true, true);
7365 bool MenuWindowRestore(MenuItem selection, Modifiers mods)
7368 SetState(normal, 0, 0);
7372 bool MenuWindowSelectWindow(MenuItem selection, Modifiers mods)
7375 int id = selection.id;
7376 OldLink cycle = activeClient.cycle;
7378 //for(c = 0, cycle = activeChild.cycle; c<id; cycle = cycle.next, c++);
7381 Window sibling = cycle.data;
7382 if(sibling.style.isActiveClient)
7390 document = cycle.data;
7391 document.Activate();
7393 //if(activeChild.state == maximized)
7394 // document.SetState(maximized, false, mods);
7395 //else if(document.state == minimized)
7396 // document.SetState(normal, false, mods);
7400 bool MenuWindowStayOnTop(MenuItem selection, Modifiers mods)
7402 stayOnTop = !style.stayOnTop;
7406 bool MenuWindowTileHorz(MenuItem selection, Modifiers mods)
7408 Window document = activeChild;
7411 Window firstDocument = null;
7412 OldLink cycle = document.cycle;
7416 Window child = cycle.data;
7417 if(child.style.isActiveClient && !child.style.hidden)
7419 if(!firstDocument) firstDocument = child;
7420 if(child.state == minimized)
7421 child.SetState(minimized, false, mods);
7424 child.positionID = id++;
7425 child.SetState(normal, false, mods);
7426 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7428 child.anchor.left.type = hTiled;
7431 child.normalSizeAnchor = *&child.sizeAnchor;
7432 child.normalAnchor = child.anchor;
7434 // Break the anchors for moveable/resizable windows
7435 if(child.style.fixed)
7437 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7439 (*&child.normalAnchor).left = x;
7440 (*&child.normalAnchor).top = y;
7441 (*&child.normalAnchor).right.type = none;
7442 (*&child.normalAnchor).bottom.type = none;
7443 child.normalSizeAnchor.isClientW = false;
7444 child.normalSizeAnchor.isClientH = false;
7445 child.normalSizeAnchor.size.w = w;
7446 child.normalSizeAnchor.size.h = h;
7447 child.anchored = false;
7450 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7452 child.stateAnchor = child.normalAnchor;
7453 child.stateSizeAnchor = child.normalSizeAnchor;
7455 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7456 child.Position(x,y, w, h, true, true, true, true, false, true);
7461 if((cycle = cycle.next) == document.cycle) break;
7464 firstDocument.Activate();
7469 bool MenuWindowTileVert(MenuItem selection, Modifiers mods)
7471 Window document = activeChild;
7474 Window firstDocument = null;
7476 OldLink cycle = document.cycle;
7481 //if(child.style.isDocument)
7482 if(child.style.isActiveClient && !child.style.hidden)
7484 if(!firstDocument) firstDocument = child;
7485 if(child.state == minimized)
7486 child.SetState(minimized, false, mods);
7489 child.positionID = id++;
7490 child.SetState(normal, false, mods);
7491 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7493 child.anchor.left.type = vTiled;
7496 child.normalSizeAnchor = *&child.sizeAnchor;
7497 child.normalAnchor = child.anchor;
7499 // Break the anchors for moveable/resizable windows
7500 if(child.style.fixed)
7502 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7504 (*&child.normalAnchor).left = x;
7505 (*&child.normalAnchor).top = y;
7506 (*&child.normalAnchor).right.type = none;
7507 (*&child.normalAnchor).bottom.type = none;
7508 child.normalSizeAnchor.isClientW = false;
7509 child.normalSizeAnchor.isClientH = false;
7510 child.normalSizeAnchor.size.w = w;
7511 child.normalSizeAnchor.size.h = h;
7512 child.anchored = false;
7515 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7517 child.stateAnchor = child.normalAnchor;
7518 child.stateSizeAnchor = child.normalSizeAnchor;
7520 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7521 child.Position(x,y, w, h, true, true, true, true, false, true);
7526 if((cycle = cycle.next) == document.cycle) break;
7529 firstDocument.Activate();
7534 bool MenuWindowWindows(MenuItem selection, Modifiers mods)
7536 WindowList dialog { master = this };
7537 Window document = (Window)dialog.Modal();
7540 if(activeChild.state == maximized)
7541 document.SetState(maximized, false, mods);
7542 else if(document.state == minimized)
7543 document.SetState(normal, false, mods);
7544 document.Activate();
7550 virtual bool OnCreate(void);
7551 virtual void OnDestroy(void);
7552 virtual void OnDestroyed(void);
7553 virtual bool OnClose(bool parentClosing);
7554 virtual bool OnStateChange(WindowState state, Modifiers mods);
7555 virtual bool OnPostCreate(void);
7556 virtual bool OnMoving(int *x, int *y, int w, int h);
7557 virtual bool OnResizing(int *width, int *height);
7558 virtual void OnResize(int width, int height);
7559 virtual void OnPosition(int x, int y, int width, int height);
7560 virtual bool OnLoadGraphics(void);
7561 virtual void OnApplyGraphics(void);
7562 virtual void OnUnloadGraphics(void);
7563 virtual void OnRedraw(Surface surface);
7564 virtual bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct);
7565 virtual void OnActivateClient(Window client, Window previous);
7566 virtual bool OnKeyDown(Key key, unichar ch);
7567 virtual bool OnKeyUp(Key key, unichar ch);
7568 virtual bool OnKeyHit(Key key, unichar ch);
7569 virtual bool OnSysKeyDown(Key key, unichar ch);
7570 virtual bool OnSysKeyUp(Key key, unichar ch);
7571 virtual bool OnSysKeyHit(Key key, unichar ch);
7572 virtual bool OnMouseOver(int x, int y, Modifiers mods);
7573 virtual bool OnMouseLeave(Modifiers mods);
7574 virtual bool OnMouseMove(int x, int y, Modifiers mods);
7575 virtual bool OnLeftButtonDown(int x, int y, Modifiers mods);
7576 virtual bool OnLeftButtonUp(int x, int y, Modifiers mods);
7577 virtual bool OnLeftDoubleClick(int x, int y, Modifiers mods);
7578 virtual bool OnRightButtonDown(int x, int y, Modifiers mods);
7579 virtual bool OnRightButtonUp(int x, int y, Modifiers mods);
7580 virtual bool OnRightDoubleClick(int x, int y, Modifiers mods);
7581 virtual bool OnMiddleButtonDown(int x, int y, Modifiers mods);
7582 virtual bool OnMiddleButtonUp(int x, int y, Modifiers mods);
7583 virtual bool OnMiddleDoubleClick(int x, int y, Modifiers mods);
7584 virtual void OnMouseCaptureLost(void);
7585 virtual void OnHScroll(ScrollBarAction action, int position, Key key);
7586 virtual void OnVScroll(ScrollBarAction action, int position, Key key);
7587 virtual void OnDrawOverChildren(Surface surface);
7588 virtual bool OnFileModified(FileChange fileChange, char * param);
7589 virtual bool OnSaveFile(char * fileName);
7591 // Skins Virtual Functions
7592 virtual void GetDecorationsSize(MinMaxValue * w, MinMaxValue * h);
7593 virtual void SetWindowMinimum(MinMaxValue * mw, MinMaxValue * mh);
7594 virtual void SetWindowArea(int * x, int * y, MinMaxValue * w, MinMaxValue * h, MinMaxValue * cw, MinMaxValue * ch)
7599 virtual void ShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7600 virtual void PreShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7601 virtual bool IsMouseMoving(int x, int y, int w, int h);
7602 virtual bool IsMouseResizing(int x, int y, int w, int h, bool *resizeX, bool *resizeY, bool *resizeEndX, bool *resizeEndY);
7603 virtual void UpdateNonClient();
7604 virtual void SetBox(Box box);
7605 virtual bool IsInside(int x, int y)
7607 return box.IsPointInside({x, y});
7609 virtual bool IsOpaque()
7611 return (!style.drawBehind || background.a == 255);
7615 virtual bool Window::NotifyActivate(Window window, bool active, Window previous);
7616 virtual void Window::NotifyDestroyed(Window window, DialogResult result);
7617 virtual void Window::NotifySaved(Window window, char * filePath);
7622 property Window parent
7624 property_category "Layout"
7627 if(value || guiApp.desktop)
7630 Window oldParent = parent;
7631 Anchor anchor = this.anchor;
7633 if(value && value.IsDescendantOf(this)) return;
7634 if(value && value == this)
7636 if(!value) value = guiApp.desktop;
7638 if(value == oldParent) return;
7640 if(!master || (master == this.parent && master == guiApp.desktop))
7641 property::master = value;
7645 parent.children.Remove(this);
7649 box.left - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7650 box.top - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y,
7651 box.right - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7652 box.bottom - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y
7656 last = value.children.last;
7658 if(style.isDocument)
7661 parent.numDocuments--;
7662 documentID = value.GetDocumentID();
7665 if(style.isActiveClient && !style.hidden)
7667 if(parent && parent != guiApp.desktop && !(style.hidden))
7669 if(state == minimized) parent.numIcons--;
7670 parent.numPositions--;
7674 if(!style.stayOnTop)
7675 for(; last && last.style.stayOnTop; last = last.prev);
7677 value.children.Insert(last, this);
7679 // *** NEW HERE: ***
7681 parent.childrenCycle.Delete(cycle);
7683 parent.childrenOrder.Delete(order);
7691 int x = position.x, y = position.y, w = size.w, h = size.h;
7695 x += parent.absPosition.x - value.absPosition.x + parent.clientStart.x - value.clientStart.x;
7696 y += parent.absPosition.y - value.absPosition.y + parent.clientStart.y - value.clientStart.y;
7698 vpw = value.clientSize.w;
7699 vph = value.clientSize.h;
7705 else if(style.fixed)
7707 if(!style.dontScrollHorz && value.scrollArea.w) vpw = value.scrollArea.w;
7708 if(!style.dontScrollVert && value.scrollArea.h) vph = value.scrollArea.h;
7711 anchor = this.anchor;
7713 if(anchor.left.type == offset) anchor.left.distance = x;
7714 else if(anchor.left.type == relative) anchor.left.percent = (float)x / vpw;
7715 if(anchor.top.type == offset) anchor.top.distance = y;
7716 else if(anchor.top.type == relative) anchor.top.percent = (float)y / vph;
7717 if(anchor.right.type == offset) anchor.right.distance = vpw - (x + w);
7718 //else if(anchor.right.type == relative) anchor.right.percent = 1.0-(float) (vpw - (x + w)) / vpw;
7719 else if(anchor.right.type == relative) anchor.right.percent = (float) (vpw - (x + w)) / vpw;
7720 if(anchor.bottom.type == offset) anchor.bottom.distance = vph - (y + h);
7721 //else if(anchor.bottom.type == relative) anchor.bottom.percent = 1.0-(float) (vph - (y + h)) / vph;
7722 else if(anchor.bottom.type == relative) anchor.bottom.percent = (float) (vph - (y + h)) / vph;
7724 if(!anchor.left.type && !anchor.right.type)
7726 anchor.horz.distance = (x + w / 2) - (vpw / 2);
7727 //anchor.horz.type = anchor.horz.distance ? AnchorValueOffset : 0;
7729 else if(anchor.horz.type == middleRelative) anchor.horz.percent = (float) ((x + w / 2) - (vpw / 2)) / vpw;
7730 if(!anchor.top.type && !anchor.bottom.type)
7732 anchor.vert.distance = (y + h / 2) - (vph / 2);
7733 //anchor.vert.type = anchor.vert.distance ? AnchorValueOffset : 0;
7735 else if(anchor.vert.type == middleRelative) anchor.vert.percent = (float)((y + h / 2) - (vph / 2)) / vph;
7743 parent.childrenCycle.Insert(
7744 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
7745 cycle = OldLink { data = this });
7746 parent.childrenOrder.Insert(
7747 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
7748 order = OldLink { data = this });
7751 if(!style.hidden && style.isActiveClient)
7753 positionID = parent.GetPositionID(this);
7754 parent.numPositions++;
7755 if(state == minimized) parent.numIcons--;
7758 // *** FONT INHERITANCE ***
7759 if(!setFont && oldParent)
7760 stopwatching(oldParent, font);
7764 RemoveResource(systemFont);
7767 // TESTING WITH WATCHERS:
7768 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7769 // usedFont = setFont ? setFont : (systemFont);
7773 if(guiApp.currentSkin)
7775 systemFont = guiApp.currentSkin.SystemFont();
7778 usedFont = systemFont;
7779 AddResource(systemFont);
7787 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7796 if(value.rootWindow && value.rootWindow.display && rootWindow)
7798 bool reloadGraphics = (oldParent.rootWindow == oldParent && value.rootWindow) || (!value.rootWindow && rootWindow == this) ||
7799 (value.rootWindow.display && value.rootWindow.display.displaySystem != rootWindow.display.displaySystem);
7802 UnloadGraphics(false);
7805 LoadGraphics(false, false);
7808 if(value.rootWindow != rootWindow)
7809 DisplayModeChanged();
7813 scrolledPos.x = MININT; // Prevent parent update
7814 property::anchor = anchor;
7818 if(guiApp.currentSkin)
7819 guiApp.currentSkin.SetWindowMinimum(this, &skinMinSize.w, &skinMinSize.h);
7821 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
7822 Position(x, y, w, h, true, true, true, true, false, true);
7827 // else parent = value;
7830 get { return parent; }
7833 property Window master
7835 property_category "Behavior"
7838 //if(this == value) return;
7839 if(value && value.IsSlaveOf(this)) return;
7845 OldLink slaveHolder;
7846 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
7847 if(slaveHolder.data == this)
7849 master.slaves.Delete(slaveHolder);
7856 value.slaves.Add(OldLink { data = this });
7861 master.hotKeys.Remove(hotKey);
7862 value.hotKeys.Add(hotKey);
7865 if(master && master.defaultControl == this)
7866 master.defaultControl = null;
7868 if(style.isDefault && !value.defaultControl)
7869 value.defaultControl = this;
7875 get { return master ? master : parent; }
7878 property char * text
7880 property_category "Appearance"
7887 caption = new char[strlen(value)+1];
7889 strcpy(caption, value);
7894 get { return caption; }
7899 property_category "Behavior"
7908 master.hotKeys.Add(hotKey = HotKeySlot { });
7912 hotKey.window = this;
7917 master.hotKeys.Delete(hotKey);
7922 get { return hotKey ? hotKey.key : 0; }
7925 property Color background
7927 property_category "Appearance"
7930 background.color = value;
7935 if(this == rootWindow)
7936 guiApp.interfaceDriver.SetRootWindowColor(this);
7939 get { return background.color; }
7942 property Percentage opacity
7944 property_category "Appearance"
7947 background.a = (byte)Min(Max((int)(value * 255), 0), 255);
7948 drawBehind = background.a ? false : true;
7950 get { return background.a / 255.0f; }
7953 property Color foreground
7955 property_category "Appearance"
7963 get { return foreground; }
7966 property BorderStyle borderStyle
7968 property_category "Appearance"
7971 if(!((BorderBits)value).fixed)
7973 style.hasClose = false;
7974 style.hasMaximize = false;
7975 style.hasMinimize = false;
7977 style.borderBits = value;
7981 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
7983 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
7984 Position(x, y, w, h, true, true, true, true, false, true);
7985 CreateSystemChildren();
7988 get { return (BorderStyle)style.borderBits; }
7991 property Size minClientSize
7993 property_category "Layout"
7994 set { minSize = value; }
7995 get { value = minSize; }
7998 property Size maxClientSize
8000 property_category "Layout"
8001 set { maxSize = value; }
8002 get { value = maxSize; }
8005 property bool hasMaximize
8007 property_category "Window Style"
8010 style.hasMaximize = value;
8011 if(value) { style.fixed = true; style.contour = true; }
8015 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8017 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8018 Position(x, y, w, h, true, true, true, true, false, true);
8020 CreateSystemChildren();
8023 get { return style.hasMaximize; }
8026 property bool hasMinimize
8028 property_category "Window Style"
8031 style.hasMinimize = value;
8032 if(value) { style.fixed = true; style.contour = true; }
8036 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8038 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8039 Position(x, y, w, h, true, true, true, true, false, true);
8041 CreateSystemChildren();
8044 get { return style.hasMinimize; }
8047 property bool hasClose
8049 property_category "Window Style"
8052 style.hasClose = value;
8053 if(value) { style.fixed = true; style.contour = true; }
8057 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8058 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8059 Position(x, y, w, h, true, true, true, true, false, true);
8060 CreateSystemChildren();
8063 get { return style.hasClose; }
8066 property bool nonClient
8068 property_category "Layout"
8071 style.nonClient = value;
8073 style.stayOnTop = true;
8075 get { return style.nonClient; }
8078 property bool inactive
8080 property_category "Behavior"
8085 // *** NEW HERE: ***
8089 parent.childrenCycle.Delete(cycle);
8091 parent.childrenOrder.Delete(order);
8098 active = false; // true;
8099 if(parent.activeChild == this)
8100 parent.activeChild = null;
8101 if(parent.activeClient == this)
8102 parent.activeClient = null;
8111 parent.childrenCycle.Insert(
8112 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8113 cycle = OldLink { data = this });
8115 parent.childrenOrder.Insert(
8116 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8117 order = OldLink { data = this });
8120 style.inactive = value;
8122 get { return style.inactive; }
8125 property bool clickThrough
8127 property_category "Behavior"
8128 set { style.clickThrough = value; }
8129 get { return style.clickThrough; }
8132 property bool isRemote
8134 property_category "Behavior"
8135 set { style.isRemote = value; }
8136 get { return style.isRemote; }
8139 property bool noCycle
8141 property_category "Behavior"
8142 set { style.noCycle = value; }
8143 get { return style.noCycle; }
8146 property bool isModal
8148 property_category "Behavior"
8149 set { style.modal = value; }
8150 get { return style.modal; }
8153 property bool interim
8155 property_category "Behavior"
8156 set { style.interim = value; }
8157 get { return style.interim; }
8160 property bool tabCycle
8162 property_category "Behavior"
8163 set { style.tabCycle = value; }
8164 get { return style.tabCycle; }
8167 property bool isDefault
8169 property_category "Behavior"
8177 /*for(sibling = parent.children.first; sibling; sibling = sibling.next)
8178 if(sibling != this && sibling.style.isDefault)
8179 sibling.style.isDefault = false;*/
8180 if(master.defaultControl)
8181 master.defaultControl.style.isDefault = false;
8182 master.defaultControl = this;
8184 else if(master.defaultControl == this)
8185 master.defaultControl = null;
8189 style.isDefault = value;
8191 Position(position.x, position.y, size.w, size.h, true, true, true,true,true, true);
8193 get { return style.isDefault; }
8196 property bool drawBehind
8198 property_category "Window Style"
8199 set { style.drawBehind = value; }
8200 get { return style.drawBehind; }
8203 property bool hasMenuBar
8205 property_category "Window Style"
8215 if(created && !menuBar)
8222 anchor = Anchor { top = 23, left = 1, right = 1 },
8224 inactive = true, nonClient = true
8229 else if(created && menuBar)
8234 style.hasMenuBar = value;
8236 get { return style.hasMenuBar; }
8239 property bool hasStatusBar
8241 property_category "Window Style"
8248 statusBar = StatusBar { this };
8256 style.hasStatusBar = value;
8258 get { return style.hasStatusBar; }
8260 property bool stayOnTop
8262 property_category "Window Style"
8267 if(created && !style.stayOnTop)
8269 if(rootWindow == this)
8270 guiApp.interfaceDriver.OrderRootWindow(this, true);
8271 else if(parent.children.last != this)
8273 parent.children.Move(this, parent.children.last);
8277 style.stayOnTop = true;
8281 if(created && style.stayOnTop)
8283 if(rootWindow == this)
8284 guiApp.interfaceDriver.OrderRootWindow(this, false);
8291 for(order = (this.order == parent.childrenOrder.first) ? null : this.order.prev;
8292 order && ((Window)order.data).style.stayOnTop;
8293 order = (order == parent.childrenOrder.first) ? null : order.prev);
8294 last = order ? order.data : null;
8298 for(last = parent.children.last;
8299 last && last.style.stayOnTop;
8303 parent.children.Move(this, last);
8307 style.stayOnTop = false;
8310 get { return style.stayOnTop; }
8315 property_category "Window Style"
8325 if(menuBar && !value)
8332 if(!menuBar && style.hasMenuBar && value)
8336 this, menu = value, isMenuBar = true,
8337 anchor = Anchor { left = 1, top = 23, right = 1 }, size.h = 24,
8338 inactive = true, nonClient = true
8342 UpdateActiveDocument(null);
8345 get { return menu; }
8348 property FontResource font
8350 property_category "Appearance"
8352 isset { return setFont ? true : false; }
8357 if(value && !setFont) { stopwatching(parent, font); }
8358 else if(!value && setFont)
8364 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8373 RemoveResource(setFont);
8378 RemoveResource(systemFont);
8385 AddResource(setFont);
8388 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
8391 systemFont = guiApp.currentSkin.SystemFont();
8393 usedFont = systemFont;
8394 AddResource(systemFont);
8402 get { return usedFont; }
8405 property SizeAnchor sizeAnchor
8407 property_category "Layout"
8410 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8411 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8412 sizeAnchor.isClientW != sizeAnchor.isClientH;
8419 normalSizeAnchor = sizeAnchor;
8421 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8423 stateAnchor = normalAnchor;
8424 stateSizeAnchor = normalSizeAnchor;
8426 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8427 Position(x,y, w, h, true, true, true, true, false, true);
8434 { sizeAnchor.isClientW ? clientSize.w : size.w, sizeAnchor.isClientH ? clientSize.h : size.h },
8435 sizeAnchor.isClientW,
8436 sizeAnchor.isClientH
8443 property_category "Layout"
8446 Anchor thisAnchor = anchor;
8447 SizeAnchor thisSizeAnchor = sizeAnchor;
8448 bool leftRight = (anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none);
8449 bool topBottom = (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none);
8450 bool isClient = !sizeAnchor.isClientW && !sizeAnchor.isClientH;
8451 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8452 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8453 !sizeAnchor.isClientW && !sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8459 sizeAnchor.isClientW = false;
8460 sizeAnchor.isClientH = false;
8461 sizeAnchor.size = value;
8463 normalSizeAnchor = sizeAnchor;
8465 if(state == normal /*|| state == Hidden*/) // Hidden is new here ...
8467 stateAnchor = normalAnchor;
8468 stateSizeAnchor = normalSizeAnchor;
8470 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8471 Position(x, y, w, h, true, true, true, true, false, true);
8474 get { value = size; }
8477 property Size clientSize
8479 property_category "Layout"
8482 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8483 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8484 sizeAnchor.isClientW && sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8489 sizeAnchor.isClientW = true;
8490 sizeAnchor.isClientH = true;
8491 sizeAnchor.size = value;
8493 normalSizeAnchor = sizeAnchor;
8495 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8497 stateAnchor = normalAnchor;
8498 stateSizeAnchor = normalSizeAnchor;
8500 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8501 Position(x,y, w, h, true, true, true, true, false, true);
8504 get { value = clientSize; }
8507 property Size initSize { get { value = sizeAnchor.size; } };
8509 property Anchor anchor
8511 property_category "Layout"
8512 isset { return (anchor.left.type != offset || anchor.top.type != offset || anchor.right.type || anchor.bottom.type); }
8518 if(anchor.left.type && anchor.right.type && (!value.left.type || !value.right.type))
8520 normalSizeAnchor.isClientW = sizeAnchor.isClientW = false;
8521 normalSizeAnchor.size.w = sizeAnchor.size.w = size.w;
8523 if(anchor.top.type && anchor.bottom.type && (!value.top.type || !value.bottom.type))
8525 normalSizeAnchor.isClientH = sizeAnchor.isClientH = false;
8526 normalSizeAnchor.size.h = sizeAnchor.size.h = size.h;
8530 if(anchor.right.type && (anchor.horz.type == middleRelative || !anchor.left.type))
8532 anchor.left.distance = 0;
8533 anchor.horz.type = 0;
8535 if(anchor.bottom.type && (anchor.vert.type == middleRelative || !anchor.top.type))
8537 anchor.top.distance = 0;
8538 anchor.vert.type = 0;
8547 normalAnchor = anchor;
8549 // Break the anchors for moveable/resizable windows
8550 /*if(style.fixed ) //&& value.left.type == cascade)
8552 ComputeAnchors(anchor, sizeAnchor, &x, &y, &w, &h);
8554 this.anchor = normalAnchor = Anchor { left = x, top = y };
8555 normalSizeAnchor = SizeAnchor { { w, h } };
8558 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8560 stateAnchor = normalAnchor;
8561 stateSizeAnchor = normalSizeAnchor;
8563 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8564 Position(x, y, w, h, true, true, true, true, false, true);
8573 get { value = this ? anchor : Anchor { }; }
8576 property Point position
8578 property_category "Layout"
8581 if(value == null) return;
8583 anchor.left = value.x;
8584 anchor.top = value.y;
8585 anchor.right.type = none;
8586 anchor.bottom.type = none;
8591 normalAnchor = anchor;
8593 // Break the anchors for moveable/resizable windows
8597 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8599 normalAnchor.left = x;
8600 normalAnchor.top = y;
8601 normalAnchor.right.type = none;
8602 normalAnchor.bottom.type = none;
8603 normalSizeAnchor.size.width = w;
8604 normalSizeAnchor.size.height = h;
8608 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8610 stateAnchor = normalAnchor;
8611 stateSizeAnchor = normalSizeAnchor;
8613 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8614 Position(x,y, w, h, true, true, true, true, false, true);
8618 get { value = position; }
8621 property bool disabled
8623 property_category "Behavior"
8626 if(this && disabled != value)
8633 get { return (bool)disabled; }
8636 property bool isEnabled
8641 for(parent = this; parent; parent = parent.parent)
8648 property WindowState state
8650 property_category "Behavior"
8651 set { SetState(value, false, 0); }
8652 get { return this ? state : 0; }
8655 property bool visible
8657 property_category "Behavior"
8660 if(this && !value && !style.hidden && parent)
8662 bool wasActiveChild = parent.activeChild == this;
8663 Window client = null;
8665 style.hidden = true;
8666 if(style.isActiveClient)
8668 parent.numPositions--;
8669 if(state == minimized) parent.numIcons--;
8674 OldLink prevOrder = null;
8676 if(rootWindow == this)
8677 guiApp.interfaceDriver.SetRootWindowState(this, state, false);
8680 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
8683 box.left -= parent.clientStart.x;
8684 box.top -= parent.clientStart.y;
8685 box.right -= parent.clientStart.x;
8686 box.bottom -= parent.clientStart.y;
8690 if(_isModal && master && master.modalSlave == this)
8691 master.modalSlave = null;
8695 OldLink tmpPrev = order.prev;
8696 client = tmpPrev ? tmpPrev.data : null;
8697 if(client && !client.style.hidden && !client.destroyed && client.created)
8698 prevOrder = tmpPrev;
8701 client = tmpPrev ? tmpPrev.data : null;
8702 if(client == this) { client = null; break; }
8703 if(client && ((client.style.hidden) || client.destroyed || !client.created))
8705 tmpPrev = client.order.prev;
8710 prevOrder = tmpPrev;
8715 // If this window can be an active client, make sure the next window we activate can also be one
8716 if(!style.nonClient && style.isActiveClient)
8718 tmpPrev = prevOrder;
8721 client = tmpPrev ? tmpPrev.data : null;
8722 if(client == this) { client = null; break; }
8723 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
8725 tmpPrev = client.order.prev;
8730 prevOrder = tmpPrev;
8734 if(client && client.style.hidden) client = null;
8738 if((wasActiveChild /*parent.activeChild == this*/ || guiApp.interimWindow == this) && true /*activate*/)
8740 if(order && prevOrder && prevOrder.data != this)
8741 ((Window)prevOrder.data).ActivateEx(true, false, false, true, null, null);
8743 ActivateEx(false, false, false, true, null, null);
8745 // TESTING THIS HERE FOR HIDING ACTIVE CLIENT
8746 if(parent.activeClient == this)
8748 parent.activeClient = null;
8749 parent.UpdateActiveDocument(null);
8752 else if(parent.activeClient == this)
8754 parent.activeClient = client;
8755 parent.UpdateActiveDocument(this);
8758 // *** Not doing this anymore ***
8761 parent.childrenCycle.Delete(cycle);
8763 parent.childrenOrder.Delete(order);
8768 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8773 else if(this && value && style.hidden)
8775 style.hidden = false;
8778 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8779 if(rootWindow == this)
8780 guiApp.interfaceDriver.SetRootWindowState(this, state, true);
8782 if(_isModal && master)
8783 master.modalSlave = this;
8785 if(style.isActiveClient)
8787 positionID = parent.GetPositionID(this);
8788 parent.numPositions++;
8789 if(state == minimized) parent.numIcons++;
8792 // *** NOT DOING THIS ANYMORE ***
8794 if(!(style.inactive))
8796 if(!(style.noCycle))
8798 cycle = parent.childrenCycle.AddAfter(
8799 (parent.activeChild && parent.activeChild.cycle) ?
8800 parent.activeChild.cycle.prev : null, sizeof(OldLink));
8803 order = parent.childrenOrder.AddAfter(
8804 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8811 if(true || !parent.activeChild)
8812 ActivateEx(true, false, true, true, null, null);
8814 if(creationActivation == activate)
8815 ActivateEx(true, false, true, true, null, null);
8816 else if(creationActivation == flash && !object)
8819 //SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8823 ConsequentialMouseMove(false);
8829 style.hidden = !value;
8832 get { return (style.hidden || !setVisible) ? false : true; }
8835 property bool isDocument
8837 property_category "Document"
8838 set { style.isDocument = value; }
8839 get { return style.isDocument; }
8842 property bool mergeMenus
8844 property_category "Window Style"
8845 set { mergeMenus = value; }
8846 get { return (bool)mergeMenus; }
8849 property bool hasHorzScroll
8851 property_category "Window Style"
8856 if(!style.hasHorzScroll && created)
8858 CreateSystemChildren();
8859 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8862 else if(style.hasHorzScroll)
8866 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8868 style.hasHorzScroll = value;
8871 get { return style.hasHorzScroll; }
8874 property bool hasVertScroll
8876 property_category "Window Style"
8881 if(!style.hasVertScroll && created)
8883 style.hasVertScroll = true;
8884 CreateSystemChildren();
8885 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8888 else if(style.hasVertScroll)
8892 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8894 style.hasVertScroll = value;
8896 get { return style.hasVertScroll; }
8899 property bool dontHideScroll
8901 property_category "Behavior"
8904 scrollFlags.dontHide = value;
8907 //UpdateScrollBars(true, true);
8908 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
8912 // UpdateScrollBars(true, true);
8913 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
8916 get { return scrollFlags.dontHide; }
8919 property bool dontScrollVert
8921 property_category "Behavior"
8922 set { style.dontScrollVert = value; }
8923 get { return style.dontScrollVert; }
8925 property bool dontScrollHorz
8927 property_category "Behavior"
8928 set { style.dontScrollHorz = value; }
8929 get { return style.dontScrollHorz; }
8932 property bool snapVertScroll
8934 property_category "Behavior"
8937 scrollFlags.snapY = value;
8938 if(sbv) sbv.snap = value;
8940 get { return scrollFlags.snapY; }
8942 property bool snapHorzScroll
8944 property_category "Behavior"
8947 scrollFlags.snapX = value;
8948 if(sbh) sbh.snap = value;
8950 get { return scrollFlags.snapX; }
8953 property Point scroll
8955 property_category "Behavior"
8959 // TESTING THIS IMPLEMENTATION:
8960 SetScrollPosition(value.x, value.y);
8962 get { value = scroll; }
8965 property bool modifyVirtualArea
8967 property_category "Behavior"
8968 set { modifyVirtArea = value; }
8969 get { return (bool)modifyVirtArea; }
8972 property char * fileName
8974 property_category "Document"
8977 if(menu && ((!fileName && value) || (fileName && !value)))
8979 MenuItem item = menu.FindItem(MenuFileSave, 0);
8980 if(item) item.disabled = !modifiedDocument && value;
8985 if(value && value[0])
8986 fileName = CopyString(value);
8988 if(parent && this == parent.activeClient)
8989 parent.UpdateActiveDocument(null);
8993 // if(style.isDocument)
8995 fileMonitor.fileName = value;
8997 get { return fileName; }
9002 property_category "Data"
9007 property bool modifiedDocument
9009 property_category "Document"
9012 if(style.isDocument || fileName)
9016 MenuItem item = menu.FindItem(MenuFileSave, 0);
9017 if(item) item.disabled = !value && fileName;
9021 if(modifiedDocument != value)
9023 modifiedDocument = value;
9024 if(style.isDocument || fileName)
9028 get { return (bool)modifiedDocument; }
9031 property bool showInTaskBar
9033 property_category "Window Style"
9034 set { style.showInTaskBar = value; }
9035 get { return (style.showInTaskBar; }
9037 property FileDialog saveDialog { set { saveDialog = value; } };
9038 property bool isActiveClient
9040 property_category "Behavior"
9041 set { style.isActiveClient = value; }
9042 get { return style.isActiveClient; }
9045 property Cursor cursor
9047 property_category "Appearance"
9051 SelectMouseCursor();
9053 get { return cursor; }
9056 //#if !defined(ECERE_VANILLA)
9057 property char * name
9059 property_category "Design"
9062 return (this && object) ? object.name : null;
9067 activeDesigner.RenameObject(object, value);
9071 property char * displayDriver
9073 property_category "Behavior"
9076 dispDriver = GetDisplayDriver(value);
9077 //DisplayModeChanged();
9081 return dispDriver ? dispDriver.name : null;
9085 // RUNTIME PROPERTIES
9086 property bool autoCreate { set { autoCreate = value; } get { return (bool)autoCreate; } };
9087 property Size scrollArea
9089 property_category "Behavior"
9093 SetScrollArea(value.w, value.h, false);
9095 SetScrollArea(0,0, true);
9097 get { value = scrollArea; }
9100 return scrollArea.w > clientSize.w || scrollArea.h > clientSize.h;
9105 property_category "Layout"
9106 set { if(this) is3D = value; }
9107 get { return (bool)is3D; }
9110 // Runtime Only Properties (No Set, can display the displayable ones depending on the type?)
9112 // Will be merged with font later
9113 property Font fontObject { get { return usedFont ? usedFont.font : null; } };
9114 property Point clientStart { get { value = clientStart; } };
9115 property Point absPosition { get { value = absPosition; } };
9116 property Anchor normalAnchor { get {value = normalAnchor; } };
9117 // property Size normalSizeAnchor { get { value = normalSizeAnchor; } };
9118 property bool active { get { return (bool)active; } };
9119 property bool created { get { return (bool)created; } };
9120 property bool destroyed { get { return (bool)destroyed; } };
9121 property Window firstSlave { get { return slaves.first ? ((OldLink)slaves.first).data : null; } };
9122 property Window firstChild { get { return children.first; } };
9123 property Window lastChild { get { return children.last; } };
9124 property Window activeClient { get { return activeClient; } };
9125 property Window activeChild { get { return activeChild; } };
9126 property Display display { get { return display ? display : ((parent && parent.rootWindow) ? parent.rootWindow.display : null); } };
9127 property DisplaySystem displaySystem { get { return display ? display.displaySystem : null; } };
9128 property ScrollBar horzScroll { get { return sbh; } };
9129 property ScrollBar vertScroll { get { return sbv; } };
9130 property StatusBar statusBar { get { return statusBar; } };
9131 property Window rootWindow { get { return rootWindow; } };
9132 property bool closing { get { return (bool)closing; } set { closing = value; } };
9133 property int documentID { get { return documentID; } };
9134 property Window previous { get { return prev; } }
9135 property Window next { get { return next; } }
9136 property Window nextSlave { get { OldLink link = master ? master.slaves.FindLink(this) : null; return (link && link.next) ? link.next.data : null; } }
9137 property PopupMenu menuBar { get { return menuBar; } }
9138 property ScrollBar sbv { get { return sbv; } }
9139 property ScrollBar sbh { get { return sbh; } }
9140 property bool fullRender { set { fullRender = value; } get { return (bool)fullRender; } }
9141 property void * systemHandle { get { return windowHandle; } }
9142 property Button minimizeButton { get { return sysButtons[0]; } };
9143 property Button maximizeButton { get { return sysButtons[1]; } };
9144 property Button closeButton { get { return sysButtons[2]; } };
9145 property BitmapResource icon
9147 get { return icon; }
9151 if(icon) incref icon;
9153 guiApp.interfaceDriver.SetIcon(this, value);
9156 property bool moveable { get { return (bool)moveable; } set { moveable = value; } };
9157 property bool alphaBlend { get { return (bool)alphaBlend; } set { alphaBlend = value; } };
9158 property bool useSharedMemory { get { return (bool)useSharedMemory; } set { useSharedMemory = value; } };
9159 property CreationActivationOption creationActivation { get { return creationActivation; } set { creationActivation = value; } };
9160 property bool nativeDecorations { get { return (bool)nativeDecorations && (formDesigner || rootWindow == this); } set { nativeDecorations = value; } };
9161 property bool manageDisplay { get { return (bool)manageDisplay; } set { manageDisplay = value; } };
9167 WindowBits style; // Window Style
9168 char * caption; // Name / Caption
9169 Window parent; // Parent window
9170 OldList children; // List of children in Z order
9171 Window activeChild; // Child window having focus
9172 Window activeClient;
9173 Window previousActive; // Child active prior to activating the default child
9174 Window master; // Window owning and receiving notifications concerning this window
9175 OldList slaves; // List of windows belonging to this window
9176 Display display; // Display this window is drawn into
9178 Point position; // Position in parent window client area
9179 Point absPosition; // Absolute position
9180 Point clientStart; // Client area position from (0,0) in this window
9182 Size clientSize; // Client area size
9183 Size scrollArea; // Virtual Scroll area size
9184 Size reqScrollArea; // Requested virtual area size
9185 Point scroll; // Virtual area scrolling position
9186 public ScrollBar sbh, sbv; // Scrollbar window handles
9187 Cursor cursor; // Mouse cursor used for this window
9190 StatusBar statusBar;
9191 Button sysButtons[3];
9193 Box clientArea; // Client Area box clipped to parent
9195 HotKeySlot hotKey; // HotKey for this window
9199 ScrollFlags scrollFlags;// Window Scrollbar Flags
9200 int id; // Control ID
9202 ColorAlpha background; // Background color used to draw the window area
9204 subclass(DisplayDriver) dispDriver; // Display driver name for this window
9205 OldList childrenCycle; // Cycling order
9206 OldLink cycle; // Element of parent's cycling order
9207 OldList childrenOrder; // Circular Z-Order
9208 OldLink order; // Element of parent's circular Z-Order
9209 Window modalSlave; // Slave window blocking this window's interaction
9211 Window rootWindow; // Topmost system managed window
9212 void * windowHandle; // System window handle
9214 DialogResult returnCode;// Return code for modal windows
9216 Point sbStep; // Scrollbar line scrolling steps
9219 SizeAnchor stateSizeAnchor;
9221 Anchor normalAnchor;
9222 SizeAnchor normalSizeAnchor;
9224 Size skinMinSize; // Minimal window size based on style
9225 Point scrolledPos; // Scrolled position
9226 Box box; // Window box clipped to parent
9227 Box * against; // What to clip the box to
9229 Extent dirtyArea { /*first = -1, last = -1, free = -1*/ }; // Area marked for update by Update
9230 Extent renderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered
9231 Extent overRenderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered over children
9232 Extent clipExtent { /*first = -1, last = -1, free = -1*/ }; // Temporary extent against which to clip render area
9233 Extent scrollExtent { /*first = -1, last = -1, free = -1*/ }; // Area to scroll
9234 Point scrolledArea; // Distance to scroll area by
9235 Extent dirtyBack { /*first = -1, last = -1, free = -1*/ }; // Only used by root window
9237 OldList hotKeys; // List of the hotkeys of all children
9238 Window defaultControl; // Default child control
9242 ColorAlpha * palette; // Color palette used for this window
9244 int caretSize; // Size of caret, non zero if a caret is present
9245 Point caretPos; // Caret position
9247 void * systemParent; // Parent System Window for embedded windows
9254 WindowState lastState;
9256 FileMonitor fileMonitor
9258 this, FileChange { modified = true };
9260 bool OnFileNotify(FileChange action, char * param)
9263 fileMonitor.StopMonitoring();
9264 if(OnFileModified(action, param))
9265 fileMonitor.StartMonitoring();
9270 FontResource setFont, systemFont;
9271 FontResource usedFont;
9272 FontResource captionFont;
9274 FileDialog saveDialog;
9276 SizeAnchor sizeAnchor;
9278 // FormDesigner data
9281 Extent * tempExtents; //[4];
9282 BitmapResource icon;
9284 CreationActivationOption creationActivation;
9287 bool active:1; // true if window and ancestors are active
9288 bool acquiredInput:1; // true if the window is processing state based input
9289 bool modifiedDocument:1;
9290 bool disabled:1; // true if window cannot interact
9291 bool isForegroundWindow:1;// true while a root window is being activated
9292 bool visible:1; // Visibility flag
9293 bool destroyed:1; // true if window is being destroyed
9294 bool anchored:1; // true if this window is repositioned when the parent resizes
9295 bool dirty:1; // Flag set to true if any descendant must be redrawn
9301 bool modifyVirtArea:1;
9302 bool noAutoScrollArea:1;
9305 bool setVisible:1; // FOR FORM DESIGNER
9311 bool useSharedMemory:1;
9314 bool nativeDecorations:1;
9315 bool manageDisplay:1;
9316 bool formDesigner:1; // True if we this is running in the form editor
9319 // Checks used internally for them not to take effect in FormDesigner
9320 property bool _isModal { get { return !formDesigner ? style.modal : false; } }
9321 property subclass(DisplayDriver) _displayDriver { get { return !formDesigner ? dispDriver : null; } }
9323 WindowController controller;
9324 public property WindowController controller { get { return controller; } set { delete controller; controller = value; if(controller) incref controller; } }
9327 public class CommonControl : Window
9329 // creationActivation = doNothing;
9332 public class Percentage : float
9334 char * OnGetString(char * string, float * fieldData, bool * needClass)
9338 sprintf(string, "%.2f", this);
9339 c = strlen(string)-1;
9342 if(string[c] != '0')
9343 last = Max(last, c);
9344 if(string[c] == '.')
9357 public void ApplySkin(Class c, char * name, void ** vTbl)
9359 char className[1024];
9364 subclass(Window) wc = (subclass(Window))c;
9365 subclass(Window) base = (subclass(Window))c.base;
9367 sprintf(className, "%sSkin_%s", name, c.name);
9368 wc.pureVTbl = c._vTbl;
9369 c._vTbl = new void *[c.vTblSize];
9370 memcpy(c._vTbl, wc.pureVTbl, c.vTblSize * sizeof(void *));
9371 sc = eSystem_FindClass(c.module.application, className);
9375 for(m = 0; m < c.base.vTblSize; m++)
9377 if(c._vTbl[m] == base.pureVTbl[m])
9378 c._vTbl[m] = vTbl[m];
9383 for(m = 0; m < c.vTblSize; m++)
9385 if(sc._vTbl[m] != wc.pureVTbl[m])
9386 c._vTbl[m] = sc._vTbl[m];
9390 for(d = c.derivatives.first; d; d = d.next)
9392 ApplySkin(d.data, name, c._vTbl);
9396 public void UnapplySkin(Class c)
9398 char className[1024];
9400 subclass(Window) wc = (subclass(Window))c;
9401 subclass(Window) base = (subclass(Window))c.base;
9404 if(wc.pureVTbl && c._vTbl != wc.pureVTbl)
9407 c._vTbl = wc.pureVTbl;
9411 for(d = c.derivatives.first; d; d = d.next)
9413 UnapplySkin(d.data);
9417 void CheckFontIntegrity(Window window)
9422 if(window.usedFont && window.usedFont.font == 0xecececec)
9424 FontResource uf = window.usedFont;
9425 char * className = window._class.name;
9426 char * text = window.text;
9429 for(c = window.firstChild; c; c = c.next)
9430 CheckFontIntegrity(c);
9434 public class ControllableWindow : Window
9436 /*WindowController controller;
9437 public property WindowController controller { get { return controller; } set { delete controller; controller = value; incref controller; } }
9438 ~ControllableWindow() { delete controller; }*/
9441 class WindowControllerInterface : ControllableWindow
9443 bool OnKeyDown(Key key, unichar ch)
9445 bool result = ((int(*)())(void *)controller.OnKeyDown)((void *)controller.controlled, (void *)controller, key, ch);
9447 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown](controller.window, key, ch);
9451 bool OnKeyUp(Key key, unichar ch)
9453 bool result = ((int(*)())(void *)controller.OnKeyUp)((void *)controller.controlled, (void *)controller, key, ch);
9455 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp](controller.window, key, ch);
9459 bool OnKeyHit(Key key, unichar ch)
9461 bool result = ((int(*)())(void *)controller.OnKeyHit)((void *)controller.controlled, (void *)controller, key, ch);
9463 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit](controller.window, key, ch);
9467 bool OnMouseMove(int x, int y, Modifiers mods)
9469 bool result = ((int(*)())(void *)controller.OnMouseMove)((void *)controller.controlled, (void *)controller, x, y, mods);
9471 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove](controller.window, x, y, mods);
9475 bool OnLeftButtonDown(int x, int y, Modifiers mods)
9477 bool result = ((int(*)())(void *)controller.OnLeftButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9479 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown](controller.window, x, y, mods);
9483 bool OnLeftButtonUp(int x, int y, Modifiers mods)
9485 bool result = ((int(*)())(void *)controller.OnLeftButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9487 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp](controller.window, x, y, mods);
9491 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
9493 bool result = ((int(*)())(void *)controller.OnLeftDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9495 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick](controller.window, x, y, mods);
9499 bool OnRightButtonDown(int x, int y, Modifiers mods)
9501 bool result = ((int(*)())(void *)controller.OnRightButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9503 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown](controller.window, x, y, mods);
9507 bool OnRightButtonUp(int x, int y, Modifiers mods)
9509 bool result = ((int(*)())(void *)controller.OnRightButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9511 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp](controller.window, x, y, mods);
9515 bool OnRightDoubleClick(int x, int y, Modifiers mods)
9517 bool result = ((int(*)())(void *)controller.OnRightDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9519 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick](controller.window, x, y, mods);
9523 bool OnMiddleButtonDown(int x, int y, Modifiers mods)
9525 bool result = ((int(*)())(void *)controller.OnMiddleButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9527 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown](controller.window, x, y, mods);
9531 bool OnMiddleButtonUp(int x, int y, Modifiers mods)
9533 bool result = ((int(*)())(void *)controller.OnMiddleButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9535 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp](controller.window, x, y, mods);
9539 bool OnMiddleDoubleClick(int x, int y, Modifiers mods)
9541 bool result = ((int(*)())(void *)controller.OnMiddleDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9543 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick](controller.window, x, y, mods);
9547 void OnResize(int width, int height)
9549 ((int(*)())(void *)controller.OnResize)((void *)controller.controlled, (void *)controller, width, height);
9550 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnResize](controller.window, width, height);
9553 void OnRedraw(Surface surface)
9555 ((int(*)())(void *)controller.OnRedraw)((void *)controller.controlled, (void *)controller, surface);
9556 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRedraw](controller.window, surface);
9561 bool result = ((int(*)())(void *)controller.OnCreate)((void *)controller.controlled, (void *)controller);
9563 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnCreate](controller.window);
9568 public class WindowController<class V>
9571 property Window window
9575 uint size = class(Window).vTblSize;
9578 windowVTbl = new void *[size];
9579 memcpy(windowVTbl, value._vTbl, size * sizeof(void *));
9580 if(value._vTbl == value._class._vTbl)
9582 value._vTbl = new void *[value._class.vTblSize];
9583 memcpy(value._vTbl + size, value._class._vTbl + size, (value._class.vTblSize - size) * sizeof(void *));
9587 for(c = 0; c < size; c++)
9589 void * function = class(WindowControllerInterface)._vTbl[c];
9590 if(function != DefaultFunction)
9591 value._vTbl[c] = function;
9593 value._vTbl[c] = windowVTbl[c];
9598 memcpy(value._vTbl, windowVTbl, class(Window).vTblSize * sizeof(void *));
9601 get { return window; }
9603 property V controlled
9605 set { controlled = value; }
9606 get { return controlled; }
9608 virtual bool V::OnKeyDown(WindowController controller, Key key, unichar ch);
9609 virtual bool V::OnKeyUp(WindowController controller, Key key, unichar ch);
9610 virtual bool V::OnKeyHit(WindowController controller, Key key, unichar ch);
9611 virtual bool V::OnMouseMove(WindowController controller, int x, int y, Modifiers mods);
9612 virtual bool V::OnLeftButtonDown(WindowController controller, int x, int y, Modifiers mods);
9613 virtual bool V::OnLeftButtonUp(WindowController controller, int x, int y, Modifiers mods);
9614 virtual bool V::OnLeftDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9615 virtual bool V::OnRightButtonDown(WindowController controller, int x, int y, Modifiers mods);
9616 virtual bool V::OnRightButtonUp(WindowController controller, int x, int y, Modifiers mods);
9617 virtual bool V::OnRightDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9618 virtual bool V::OnMiddleButtonDown(WindowController controller, int x, int y, Modifiers mods);
9619 virtual bool V::OnMiddleButtonUp(WindowController controller, int x, int y, Modifiers mods);
9620 virtual bool V::OnMiddleDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9621 virtual void V::OnResize(WindowController controller, int width, int height);
9622 virtual void V::OnRedraw(WindowController controller, Surface surface);
9623 virtual bool V::OnCreate(WindowController controller);
9626 int (** windowVTbl)();