7 import "GuiApplication"
28 #if !defined(ECERE_VANILLA) && !defined(ECERE_NO3D)
32 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
41 // Had to define this here for native decorations support, because the menu bar is part of total decoration's size, but not part of the system decorations
42 define skinMenuHeight = 25;
43 define statusBarHeight = 18;
45 default extern int __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
47 public enum DialogResult { cancel, yes, no, ok };
49 public class MouseButtons
52 bool left:1, right:1, middle:1;
55 public struct SizeAnchor
58 bool isClientW, isClientH;
63 #define SNAPDOWN(x, d) \
66 if(x < 0) x -= ((d) - Abs(x) % (d)); else x -= x % (d); \
69 #define SNAPUP(x, d) \
72 if(x > 0) x += ((d) - Abs(x) % (d)); else x += x % (d); \
75 /*static */define MAX_DIRTY_BACK = 10;
77 /////////////////////////////////////////////////////////////////////////////
78 ////////// EXTENT MANIPULATION //////////////////////////////////////////////
79 /////////////////////////////////////////////////////////////////////////////
81 #define ACCESS_ITEM(l, id) \
84 #define FASTLIST_LOOP(l, v) \
85 for(v = (BoxItem)l.first; v; v = (BoxItem)v.next)
87 #define FASTLIST_LOOPN(l, v, n) \
88 for(v = (BoxItem)l.first, n = (BoxItem)(v ? v.next : null); v; v = (BoxItem)next, n = (BoxItem)(v ? v.next : null))
91 #define ACCESS_ITEM(l, id) \
92 ((FastItem)(((id) == -1) ? null : (((byte *)((l).items)) + (id) * (l).itemSize)))
94 #define FASTLIST_LOOP(l, v) \
95 for(v = (void *)ACCESS_ITEM((l), (l).first); v; v = (void *)ACCESS_ITEM((l), v.next))
97 #define FASTLIST_LOOPN(l, v, n) \
98 for( v = (void *)ACCESS_ITEM((l), (l).first), \
99 n = v ? ((void *)ACCESS_ITEM((l), v.next)): null; \
100 v; v = n, n = n ? (void *)ACCESS_ITEM((l), n.next) : null)
103 private class FastItem : struct
108 private struct FastList
113 int count, size, itemSize;
120 first = last = free = -1;
128 // FASTLIST_LOOPN(this, item, next) { Delete(item); };
131 FastItem Add(uint itemSize)
134 if(free == -1 || !size)
141 newSize = (size + (size >> 1));
142 items = (FastItem)renew items byte[newSize * itemSize];
147 this.itemSize = itemSize;
148 items = (FastItem)new byte[newSize * itemSize];
151 for(c = size; c<newSize-1; c++)
153 ACCESS_ITEM(this, c).prev = -1;
154 ACCESS_ITEM(this, c).next = c+1;
156 ACCESS_ITEM(this, c).prev = -1;
157 ACCESS_ITEM(this, c).next = -1;
161 item = ACCESS_ITEM(this, free);
164 ACCESS_ITEM(this, item.prev).next = free;
174 void Delete(FastItem item)
177 ACCESS_ITEM(this, item.prev).next = item.next;
179 ACCESS_ITEM(this, item.next).prev = item.prev;
181 if(ACCESS_ITEM(this, first) == item)
183 if(ACCESS_ITEM(this, last) == item)
188 free = ((byte *)item - (byte *)items) / itemSize;
196 free = first = last = -1;
200 private class BoxItem : Item //FastItem
205 public /*private */struct Extent : OldList //FastList
214 //BoxItem extentBox = (BoxItem)Add(sizeof(class BoxItem));
215 Add(BoxItem { box = box });
218 void Copy(Extent source)
224 //FASTLIST_LOOP(source, extentBox)
225 for(extentBox = (BoxItem)source.first; extentBox; extentBox = (BoxItem)extentBox.next)
226 AddBox(extentBox.box);
229 void IntersectBox(Box box)
231 // Clip all boxes of extent against inside of the new box
232 BoxItem extentBox, next;
234 //FASTLIST_LOOPN(this, extentBox, next) // Macros still mess up the parser!
235 for(extentBox = (BoxItem)this.first; extentBox; extentBox = next)
237 next = (BoxItem)extentBox.next;
238 if(box.left > extentBox.box.left) extentBox.box.left = box.left;
239 if(box.top > extentBox.box.top) extentBox.box.top = box.top;
240 if(box.right < extentBox.box.right) extentBox.box.right = box.right;
241 if(box.bottom < extentBox.box.bottom) extentBox.box.bottom = box.bottom;
242 if(extentBox.box.right < extentBox.box.left || extentBox.box.bottom < extentBox.box.top)
247 void ExcludeBox(Box box, Extent temp)
254 for(extentBox = (BoxItem)temp.first; extentBox; extentBox = (BoxItem)extentBox.next)
256 if(extentBox.box.left < box.right && extentBox.box.right > box.left &&
257 extentBox.box.top < box.bottom && extentBox.box.bottom > box.top)
260 if(extentBox.box.top < box.top && extentBox.box.bottom >= box.top)
264 extentBox.box.left, extentBox.box.top,
265 extentBox.box.right, Min(extentBox.box.bottom, box.top -1)
271 if(extentBox.box.bottom > box.bottom && extentBox.box.top <= box.bottom)
275 extentBox.box.left, Max(extentBox.box.top,box.bottom +1),
276 extentBox.box.right, extentBox.box.bottom
282 if(extentBox.box.bottom >= box.top && extentBox.box.top <= box.bottom)
285 if(extentBox.box.left < box.left && extentBox.box.right >= box.left)
289 extentBox.box.left, Max(extentBox.box.top, box.top),
290 Min(extentBox.box.right, box.left-1), Min(extentBox.box.bottom, box.bottom)
296 if(extentBox.box.right > box.right && extentBox.box.left <= box.right)
300 Max(extentBox.box.left, box.right+1), Max(extentBox.box.top, box.top),
301 extentBox.box.right, Min(extentBox.box.bottom, box.bottom)
309 AddBox(extentBox.box);
315 void UnionBox(Box box, Extent temp)
317 BoxItem extentBox, next;
319 // First pass: check if this box is not already covered by one of the extent's box
320 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
322 if(extentBox.box.left <= box.left && extentBox.box.right >= box.right &&
323 extentBox.box.top <= box.top && extentBox.box.bottom >= box.bottom)
330 // Second pass: only keep boxes not completely covered in the new box
331 for(extentBox = (BoxItem)this.first; extentBox; extentBox = next)
333 next = (BoxItem)extentBox.next;
334 if(extentBox.box.left >= box.left && extentBox.box.right <= box.right &&
335 extentBox.box.top >= box.top && extentBox.box.bottom <= box.bottom)
339 // Add the exclusion to the extent
340 ExcludeBox(box, temp);
343 if(box.bottom >= box.top && box.right >= box.left)
345 // Optimization: if the resulting boxes touch, add them smarter
346 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
348 if(box.top == extentBox.box.top && box.bottom == extentBox.box.bottom)
350 if(Abs(box.right - extentBox.box.left) <= 1)
352 extentBox.box.left = box.left;
355 else if(Abs(box.left - extentBox.box.right) <= 1)
357 extentBox.box.right = box.right;
361 else if(box.left == extentBox.box.left && box.right == extentBox.box.right)
363 if(Abs(box.bottom - extentBox.box.top) <= 1)
365 extentBox.box.top = box.top;
368 else if(Abs(box.top - extentBox.box.bottom) <= 1)
370 extentBox.box.bottom = box.bottom;
382 void Union(Extent b, Extent temp)
386 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
387 UnionBox(extentBox.box, temp);
390 void Intersection(Extent b, Extent temp, Extent temp2, Extent temp3)
397 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
400 temp2.IntersectBox(extentBox.box);
407 void Exclusion(Extent b, Extent temp)
410 for(extentBox = (BoxItem)b.first; extentBox; extentBox = (BoxItem)extentBox.next)
411 ExcludeBox(extentBox.box, temp);
414 void Offset(int x, int y)
417 for(extentBox = (BoxItem)this.first; extentBox; extentBox = (BoxItem)extentBox.next)
419 extentBox.box.left += x;
420 extentBox.box.top += y;
421 extentBox.box.right += x;
422 extentBox.box.bottom += y;
427 private define MINIMIZED_WIDTH = 160;
428 private define CASCADE_SPACE = 16;
430 // namespace Windows;
432 private class ScrollFlags
434 bool snapX:1, snapY:1, dontHide:1;
437 public class BorderBits { public: bool contour:1, fixed:1, sizable:1, deep:1, bevel:1, thin:1; };
439 class WindowBits : BorderBits
441 BorderBits borderBits:6:0;
442 bool hidden:1, isActiveClient:1, hasHorzScroll:1, hasVertScroll:1, stayOnTop:1, modal:1, isDefault:1, inactive:1, isRemote:1, drawBehind:1;
443 bool interim:1, tabCycle:1, noCycle:1, dontScrollHorz:1, dontScrollVert:1, hasMaximize:1, hasMinimize:1, hasClose:1;
444 bool embedded:1, hasMenuBar:1, isDocument:1, showInTaskBar:1, hasStatusBar:1, nonClient:1, clickThrough:1;
447 public enum BorderStyle : BorderBits
450 contour = BorderBits { contour = true },
451 fixed = BorderBits { fixed = true } | contour,
452 sizable = BorderBits { sizable = true } | fixed,
453 thin = BorderBits { fixed = true, thin = true } | contour,
454 sizableThin = BorderBits { sizable = true } | thin,
455 deep = BorderBits { deep = true },
456 bevel = BorderBits { bevel = true },
457 sizableDeep = sizable|deep,
458 sizableBevel = sizable|bevel,
459 fixedDeep = fixed|deep,
460 fixedBevel = fixed|bevel,
461 deepContour = deep|contour
464 public enum CreationActivationOption
466 activate, flash, doNothing
469 public enum WindowState { normal, minimized, maximized };
471 private class ResPtr : struct
478 private class HotKeySlot : struct
480 HotKeySlot prev, next;
488 class_data char * icon;
490 class_default_property text;
491 // class_initialize GuiApplication::Initialize;
492 class_designer FormDesigner;
493 class_property char * icon
495 set { class_data(icon) = value; }
496 get { return class_data(icon); }
501 if(guiApp) guiApp.Initialize(true);
503 if(guiApp && guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
505 if(_vTbl == ((subclass(Window))_class).pureVTbl)
507 _vTbl = _class._vTbl;
509 else if(_vTbl != _class._vTbl)
512 for(m = 0; m < _class.vTblSize; m++)
514 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
515 _vTbl[m] = _class._vTbl[m];
520 //tempExtents[0] = { /*first = -1, last = -1, free = -1*/ };
521 //tempExtents[1] = { /*first = -1, last = -1, free = -1*/ };
522 //tempExtents[2] = { /*first = -1, last = -1, free = -1*/ };
523 //tempExtents[3] = { /*first = -1, last = -1, free = -1*/ };
527 // caption = CopyString(class.name);
529 children.offset = (byte*)&prev - (byte*)this;
530 childrenOrder.circ = true;
531 childrenCycle.circ = true;
533 maxSize = Size { MAXINT, MAXINT };
537 //style.isActiveClient = true;
540 modifyVirtArea = true;
541 manageDisplay = true;
543 // scrollFlags = ScrollFlags { snapX = true, snapY = true };
544 sbStep.x = sbStep.y = 8;
546 if(guiApp) // dynamic_cast<GuiApplication>(thisModule)
548 cursor = guiApp.GetCursor(arrow);
549 property::parent = guiApp.desktop;
561 stopwatching(parent, font);
562 if(parent.activeChild == this)
563 parent.activeChild = null;
564 if(parent.activeClient == this)
565 parent.activeClient = null;
570 // Prevent destructor from being called again...
576 /////////////////////////////////
579 OldLink slave = master.slaves.FindLink(this);
580 master.slaves.Delete(slave);
587 parent.childrenCycle.Remove(cycle);
589 parent.childrenOrder.Remove(order);
590 parent.children.Remove(this);
595 /////////////////////////////////
597 while(ptr = resources.first)
600 resources.Delete(ptr);
607 for(child = children.first; child; child = child.next)
609 // child.stopwatching(this, font);
611 eInstance_StopWatching(this, __ecereProp___ecereNameSpace__ecere__gui__Window_font, child);
612 // Don't want property here
613 *&child.parent = null;
616 while(slave = slaves.first)
618 // Don't want property here
619 *&((Window)slave.data).master = null;
620 slaves.Delete(slave);
623 // Because we do a decref in DestroyEx...
631 // Why was this commented?
632 //if(this != guiApp.desktop)
645 if(((subclass(Window))_class).pureVTbl)
647 if(_vTbl == _class._vTbl)
649 _vTbl = ((subclass(Window))_class).pureVTbl;
654 for(m = 0; m < _class.vTblSize; m++)
656 if(_vTbl[m] == _class._vTbl[m])
657 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
661 if(_vTbl == ((subclass(Window))_class).pureVTbl || _vTbl == _class._vTbl)
664 dirtyArea.Free(null);
665 renderArea.Free(null);
666 overRenderArea.Free(null);
667 clipExtent.Free(null);
668 scrollExtent.Free(null);
669 dirtyBack.Free(null);
673 tempExtents[0].Free(null);
674 tempExtents[1].Free(null);
675 tempExtents[2].Free(null);
676 tempExtents[3].Free(null);
681 //#if !defined(ECERE_VANILLA)
682 char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
684 if(this == activeDesigner)
688 char * name = property::name;
689 return name ? name : "";
694 #if !defined(ECERE_VANILLA) && !defined(ECERE_NOTRUETYPE)
695 bool OnGetDataFromString(char * string)
697 FormDesigner designer = (FormDesigner)activeDesigner.classDesigner;
700 if(!strcmp(string, "this") || !strcmp(string, designer.form.name))
701 this = designer.form;
702 else if(!strcmpi(string, "(Desktop)"))
703 this = activeDesigner;
705 return activeDesigner.FindObject(&this, string);
711 // --- Window updates system ---
713 // Setup a bitmap for Redrawing on client area of Window
714 Surface Redraw(Box box)
716 Surface surface = null;
718 Box clientArea = this.clientArea;
722 mox.left -= clientStart.x;
723 mox.top -= clientStart.y;
724 mox.right -= clientStart.x;
725 mox.bottom -= clientStart.y;
727 mox.Clip(clientArea);
728 // mox.ClipOffset(against, scrolledPos.x, scrolledPos.y);
730 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && mox.right >= mox.left && mox.bottom >= mox.top)
732 int x = absPosition.x + clientStart.x;
733 int y = absPosition.y + clientStart.y;
734 if(rootWindow.nativeDecorations)
736 x -= rootWindow.clientStart.x;
737 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
739 if(!guiApp.fullScreenMode || is3D)
741 x -= rootWindow.absPosition.x;
742 y -= rootWindow.absPosition.y;
746 x += rootWindow.parent.clientStart.x;
747 y += rootWindow.parent.clientStart.y;
749 mox.left += rootWindow.parent.clientStart.x;
750 mox.top += rootWindow.parent.clientStart.y;
751 mox.right += rootWindow.parent.clientStart.x;
752 mox.bottom += rootWindow.parent.clientStart.y;
757 surface = display.GetSurface(x, y, mox);
760 surface.width = clientSize.w;
761 surface.height = clientSize.h;
767 // Setup a bitmap for Redrawing on full Window
768 Surface RedrawFull(Box box)
770 Surface surface = null;
778 if((!guiApp.fullScreenMode || guiApp.desktop.active) && display && box.right >= box.left && box.bottom >= box.top)
780 int x = absPosition.x;
781 int y = absPosition.y;
782 if(rootWindow.nativeDecorations)
784 x -= rootWindow.clientStart.x;
785 y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
787 if(!guiApp.fullScreenMode || is3D)
789 x -= rootWindow.absPosition.x;
790 y -= rootWindow.absPosition.y;
793 x += rootWindow.parent.clientStart.x;
794 y += rootWindow.parent.clientStart.y;
796 mox.left += rootWindow.parent.clientStart.x;
797 mox.top += rootWindow.parent.clientStart.y;
798 mox.right += rootWindow.parent.clientStart.x;
799 mox.bottom += rootWindow.parent.clientStart.y;
804 surface = display.GetSurface(x, y, mox);
807 surface.width = size.w;
808 surface.height = size.h;
814 void FigureCaption(char * caption)
818 strcpy(caption, this.caption);
819 if(style.isDocument || fileName)
821 if(caption[0]) strcat(caption, " - ");
823 strcat(caption, fileName);
827 sprintf(title, "Untitled %d", documentID);
828 strcat(caption, title);
831 strcat(caption, " *");
833 if(activeClient && menuBar &&
834 activeClient.state == maximized)
836 if(activeClient.caption)
838 if(caption[0]) strcat(caption, " - ");
839 strcat(caption, activeClient.caption);
841 if(activeClient.style.isDocument || activeClient.fileName)
843 if(caption[0]) strcat(caption, " - ");
844 strcat(caption, "[");
845 if(activeClient.fileName)
846 strcat(caption, activeClient.fileName);
850 sprintf(title, "Untitled %d", activeClient.documentID);
851 strcat(caption, title);
853 if(activeClient.modifiedDocument)
854 strcat(caption, " *");
855 strcat(caption, "]");
860 // Code for returning dirty from ScrollDisplay:
862 for(d = 0; d<scrollExtent.count; d++)
864 Box * box = &scrollExtent.boxes[d];
870 Min(box.right, box.left-scroll.x),box.bottom
872 dirtyArea.UnionBox(update);
878 Max(box.left, box.right-scroll.x), box.top,
879 box.right, box.bottom
881 dirtyArea.UnionBox(update);
889 box.right, Min(box.bottom, box.top-scroll.y),
891 dirtyArea.UnionBox(update);
897 box.left, Max(box.top, box.bottom-scroll.y),
898 box.right, box.bottom
900 dirtyArea.UnionBox(update);
905 void UpdateDecorations(void)
907 // TODO: *** TEMPORARY HACK ***
914 Update({ -clientStart.x, -clientStart.y, -clientStart.x + size.w-1, 0 });
916 Update({ -clientStart.x, clientSize.h, -clientStart.x + size.w-1, -clientStart.y + size.h-1 });
918 Update({ -clientStart.x,0, -1, clientSize.h-1 });
920 Update({ clientSize.w, 0, -clientStart.x + size.w-1, clientSize.h-1 });
923 // Returns w & h for Position
924 void ComputeAnchors(Anchor anchor, SizeAnchor sizeAnchor, int *ox, int *oy, int *ow, int *oh)
926 Window parent = this.parent ? this.parent : guiApp.desktop;
927 int vpw = parent ? parent.clientSize.w : 0;
928 int vph = parent ? parent.clientSize.h : 0;
929 int pw = parent ? parent.clientSize.w : 0;
930 int ph = parent ? parent.clientSize.h : 0;
931 int w = sizeAnchor.size.w, h = sizeAnchor.size.h;
932 int x = anchor.left.distance, y = anchor.top.distance;
934 MinMaxValue ew = 0, eh = 0;
936 float cascadeW, cascadeH;
938 int tilingW, tilingH, tilingSplit, tilingLastH;
939 int addX = 0, addY = 0;
941 if(parent && rootWindow == this && guiApp && guiApp.interfaceDriver)
943 Window masterWindow = this;
944 Box box { addX, addY, addX + vpw - 1, addY + vph - 1 };
947 if(master == guiApp.desktop)
948 masterWindow = guiApp.desktop.activeChild;
950 masterWindow = master.rootWindow;
951 if(!masterWindow) masterWindow = this;
953 guiApp.interfaceDriver.GetScreenArea(masterWindow, box);
954 if((anchor.left.type == offset && anchor.right.type == offset) || anchor.left.type == none)
957 pw = vpw = box.right - box.left + 1;
959 if((anchor.top.type == offset && anchor.bottom.type == offset) || anchor.top.type == none)
962 ph = vph = box.bottom - box.top + 1;
978 vpw = pw = parent.size.w;
979 vph = ph = parent.size.h;
981 else if(!style.fixed /*|| style.isDocument*/)
983 if(!style.dontScrollHorz && parent.scrollArea.w) vpw = parent.scrollArea.w;
984 if(!style.dontScrollVert && parent.scrollArea.h) vph = parent.scrollArea.h;
986 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
989 Desktop3D_FixSize(&pw, &ph);
990 Desktop3D_FixSize(&vpw, &vph);
993 if(pw < skinMinSize.w) pw = skinMinSize.w;
994 if(ph < skinMinSize.h) ph = skinMinSize.h;
995 if(vpw < skinMinSize.w) vpw = skinMinSize.w;
996 if(vph < skinMinSize.h) vph = skinMinSize.h;
998 // TODO: Must fix what we're snapping
1001 if(anchor.left.type)
1003 SNAPUP(x, textCellW);
1005 else if(anchor.right.type)
1007 SNAPDOWN(x, textCellW);
1012 SNAPUP(y, textCellH);
1014 else if(anchor.bottom.type)
1016 SNAPDOWN(y, textCellH);
1020 // This is required to get proper initial decoration size using native decorations on Windows
1021 if(nativeDecorations && guiApp && guiApp.interfaceDriver && !visible)
1022 guiApp.interfaceDriver.PositionRootWindow(this, x, y, Max(1, size.w), Max(1, size.h), true, true);
1023 GetDecorationsSize(&ew, &eh);
1025 if(anchor.left.type >= cascade && (state == normal /*|| state == Hidden*/))
1027 if(parent.sbv && !parent.sbv.style.hidden)
1028 pw += guiApp.currentSkin.VerticalSBW();
1029 if(parent.sbh && !parent.sbh.style.hidden)
1030 ph += guiApp.currentSkin.HorizontalSBH();
1032 if(anchor.left.type == cascade)
1034 w = (int)(pw * 0.80);
1035 h = (int)(ph * 0.80);
1037 else if(anchor.left.type >= vTiled)
1042 numTiling = parent.numPositions - parent.numIcons;
1043 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1044 if(anchor.left.type == vTiled)
1046 tilingH = (int)sqrt(numTiling);
1047 tilingW = numTiling / tilingH;
1051 tilingW = (int)sqrt(numTiling);
1052 tilingH = numTiling / tilingW;
1055 leftOver = numTiling - tilingH * tilingW;
1058 tilingSplit = (tilingW - leftOver) * tilingH;
1059 tilingLastH = tilingH+1;
1062 tilingSplit = numTiling;
1064 if(positionID >= tilingSplit)
1066 x = pw * (tilingSplit / tilingH + (positionID - tilingSplit) / tilingLastH)/tilingW;
1067 y = ph * ((positionID - tilingSplit) % tilingLastH) / tilingLastH;
1068 x2 = pw * (tilingSplit/tilingH + (positionID - tilingSplit) / tilingLastH + 1)/tilingW;
1069 y2 = ph * (((positionID - tilingSplit) % tilingLastH) + 1) / tilingLastH;
1073 x = pw * (positionID / tilingH) / tilingW;
1074 y = ph * (positionID % tilingH) / tilingH;
1075 x2 = pw * (positionID / tilingH + 1) / tilingW;
1076 y2 = ph * ((positionID % tilingH) + 1) / tilingH;
1080 SNAPDOWN(x, textCellW);
1081 SNAPDOWN(y, textCellH);
1082 SNAPDOWN(x2, textCellW);
1083 SNAPDOWN(y2, textCellH);
1091 if(sizeAnchor.isClientW) w += ew;
1092 if(sizeAnchor.isClientH) h += eh;
1094 if(anchor.left.type == offset)
1095 x = anchor.left.distance;
1096 else if(anchor.left.type == relative)
1097 x = (anchor.left.percent < 0) ? ((int)(vpw * anchor.left.percent - 0.5)) : (int)(vpw * anchor.left.percent + 0.5);
1098 else if(anchor.right.type == relative)
1099 // ex = (anchor.right.percent < 0) ? ((int)(vpw * anchor.right.percent + 0)) : ((int)(vpw * anchor.right.percent + 0));
1100 ex = (anchor.right.percent < 0) ? ((int)(vpw * (1.0-anchor.right.percent) + 0)) : ((int)(vpw * (1.0-anchor.right.percent) + 0));
1101 else if(anchor.right.type == offset)
1102 ex = vpw - anchor.right.distance;
1104 if(anchor.top.type == offset)
1105 y = anchor.top.distance;
1106 else if(anchor.top.type == relative)
1107 y = (anchor.top.percent < 0) ? ((int)(vph * anchor.top.percent - 0.5)) : ((int)(vph * anchor.top.percent + 0.5));
1108 else if(anchor.bottom.type == relative)
1109 //ey = (anchor.bottom.percent < 0) ? ((int)(vph * anchor.bottom.percent + 0)) : ((int)(vph * anchor.bottom.percent + 0));
1110 ey = (anchor.bottom.percent < 0) ? ((int)(vph * (1.0-anchor.bottom.percent) + 0)) : ((int)(vph * (1.0-anchor.bottom.percent) + 0));
1111 else if(anchor.bottom.type == offset)
1112 ey = vph - anchor.bottom.distance;
1114 if(anchor.left.type && anchor.right.type)
1116 switch(anchor.right.type)
1119 ex = pw * (1.0f-anchor.right.percent);
1120 w = Max((int)(ex + 0.5) - x, 0);
1123 ex = vpw - anchor.right.distance;
1124 w = Max((int)(ex + 0.5) - x, 0);
1128 if(anchor.top.type && anchor.bottom.type)
1130 switch(anchor.bottom.type)
1133 ey = ph * (1.0f-anchor.bottom.percent);
1134 h = Max((int)(ey + 0.5) - y, 0);
1137 ey = vph - anchor.bottom.distance;
1138 h = Max((int)(ey + 0.5) - y, 0);
1147 if(state == normal /*|| state == Hidden*/)
1149 bool addSbV = false, addSbH = false;
1151 if(sizeAnchor.isClientW || (anchor.left.type && anchor.right.type)) w = Max(w, 1); else w = Max(w, 0);
1152 if(sizeAnchor.isClientH || (anchor.top.type && anchor.bottom.type)) h = Max(h, 1); else h = Max(h, 0);
1154 w = Max(w, minSize.w);
1155 h = Max(h, minSize.h);
1156 w = Min(w, maxSize.w);
1157 h = Min(h, maxSize.h);
1159 if((sizeAnchor.isClientW || !w || (anchor.left.type && anchor.right.type)) && reqScrollArea.h > h /*&& w*/ && sbv)
1161 if(w) w -= guiApp.currentSkin.VerticalSBW();
1164 if((sizeAnchor.isClientH || !h || (anchor.top.type && anchor.bottom.type)) && reqScrollArea.w > w /*&& h*/ && sbh)
1166 if(h) h -= guiApp.currentSkin.HorizontalSBH();
1170 if(!OnResizing(&w, &h))
1176 if((addSbV)) // || reqScrollArea.h > h) && sbv)
1177 w += guiApp.currentSkin.VerticalSBW();
1178 if((addSbH)) // || reqScrollArea.w > w) && sbh)
1179 h += guiApp.currentSkin.HorizontalSBH();
1181 w = Max(w, skinMinSize.w);
1182 h = Max(h, skinMinSize.h);
1195 SNAPDOWN(w, textCellW);
1196 SNAPDOWN(h, textCellH);
1199 if(anchor.left.type == cascade && (state == normal /*|| state == Hidden*/))
1201 if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24;
1204 (pw - w) / CASCADE_SPACE,
1205 (ph - h) / CASCADE_SPACE);
1211 cascW = (pw - w) / (numCascade-1);
1212 cascH = (ph - h) / (numCascade-1);
1213 SNAPDOWN(cascW, textCellW);
1214 SNAPDOWN(cascH, textCellH);
1215 cascadeW = (float)cascW;
1216 cascadeH = (float)cascH;
1220 numCascade = Max(numCascade, 2);
1221 cascadeW = (float)(pw - w) / (numCascade-1);
1222 cascadeH = (float)(ph - h) / (numCascade-1);
1225 x = (int)((positionID % numCascade) * cascadeW);
1226 y = (int)((positionID % numCascade) * cascadeH);
1228 else if(anchor.left.type < vTiled)
1230 if(!anchor.left.type || anchor.horz.type == middleRelative)
1232 if(!anchor.right.type)
1234 if(anchor.horz.type == middleRelative)
1235 x = (int)(vpw * (0.5 + anchor.horz.percent) - w / 2);
1237 x = vpw / 2 + anchor.horz.distance - w / 2;
1243 // case A_EDGE: x = x - w; break;
1245 if(!anchor.top.type || anchor.vert.type == middleRelative)
1247 if(!anchor.bottom.type)
1249 if(anchor.vert.type == middleRelative)
1250 y = (int)(vph * (0.5 + anchor.vert.percent) - h / 2);
1252 y = vph / 2 + anchor.vert.distance - h / 2;
1258 // case A_EDGE: y = y - h; break;
1261 if((state == normal /*|| state == Hidden*/) && !OnMoving(&x, &y, w, h))
1269 SNAPDOWN(x, textCellW);
1270 SNAPDOWN(y, textCellH);
1282 if(anchored && style.fixed && style.isActiveClient)
1287 void UpdateCaret(bool forceUpdate, bool erase)
1289 static Window lastWindow = null;
1290 static int caretX, caretY, caretSize;
1292 if(guiApp && guiApp.caretOwner == this)
1294 int x = caretPos.x - scroll.x;
1295 int y = caretPos.y - scroll.y;
1297 if((erase || this.caretSize) &&
1298 x >= clientArea.left && x <= clientArea.right &&
1299 y >= clientArea.top && y <= clientArea.bottom)
1303 guiApp.interfaceDriver.SetCaret(
1304 x + absPosition.x + clientStart.x,
1305 y + absPosition.y + clientStart.y, this.caretSize);
1306 guiApp.caretEnabled = true;
1308 if(erase || lastWindow != this || caretX != x || caretY != y || caretSize != this.caretSize || forceUpdate)
1312 if(lastWindow != this)
1314 updateBox.left = x + 1;
1316 updateBox.right = x + 2;
1317 updateBox.bottom = y + this.caretSize - 1;
1321 updateBox.left = Min(x + 1, caretX + 1);
1322 updateBox.top = Min(y, caretY);
1323 updateBox.right = Max(x + 2, caretX + 2);
1324 updateBox.bottom = Max(y + this.caretSize - 1, caretY + caretSize - 1);
1327 guiApp.caretOwner.Update(updateBox);
1334 caretSize = this.caretSize;
1340 guiApp.interfaceDriver.SetCaret(0,0,0);
1341 guiApp.caretEnabled = false;
1347 void SetPosition(int x, int y, int w, int h, bool modifyArea, bool modifyThisArea, bool modifyClientArea)
1352 scrolledPos.x = position.x = x;
1353 scrolledPos.y = position.y = y;
1355 clientSize.w = size.w = w;
1356 clientSize.h = size.h = h;
1358 if(parent && !style.nonClient)
1360 //if(!style.fixed || style.isDocument)
1362 if(!style.dontScrollHorz) scrolledPos.x -= parent.scroll.x;
1363 if(!style.dontScrollVert) scrolledPos.y -= parent.scroll.y;
1367 clientStart.x = clientStart.y = 0;
1369 SetWindowArea(&clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1371 //if(!activeClient || activeClient.state != maximized)
1372 if(!noAutoScrollArea)
1374 // Check if scroll area must be modified
1375 if(guiApp && !guiApp.modeSwitching && (sbv || sbh))
1377 bool foundChild = false;
1379 int cw = clientSize.w;// + ((!sbv || sbv.range > 1) ? guiApp.currentSkin.VerticalSBW() : 0);
1380 int ch = clientSize.h;// + ((!sbh || sbh.rangw > 1) ? guiApp.currentSkin.HorizontalSBH() : 0);
1381 for(child = children.first; child; child = child.next)
1383 if(child.modifyVirtArea && !child.style.hidden && child.created && /*!child.anchored &&*/
1384 !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1386 if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == offset)
1387 w = Max(w, child.position.x + child.size.w);
1388 else if(child.stateAnchor.right.type == none && child.stateAnchor.left.type == none)
1389 w = Max(w, Max(child.position.x, 0) + child.size.w);
1390 if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == offset)
1391 h = Max(h, child.position.y + child.size.h);
1392 else if(child.stateAnchor.bottom.type == none && child.stateAnchor.top.type == none)
1393 h = Max(h, Max(child.position.y, 0) + child.size.h);
1398 if(foundChild && (w > cw || h > ch))
1400 //if((w > reqScrollArea.w) || (h > reqScrollArea.w))
1402 int stepX = sbStep.x, stepY = sbStep.y;
1403 // Needed to make snapped down position match the skin's check of client area
1404 // against realvirtual
1407 SNAPDOWN(stepX, textCellW);
1408 SNAPDOWN(stepY, textCellH);
1409 stepX = Max(stepX, textCellW);
1410 stepY = Max(stepY, textCellH);
1412 if(scrollFlags.snapX)
1414 if(scrollFlags.snapY)
1417 reqScrollArea.w = w;
1418 reqScrollArea.h = h;
1421 else if(reqScrollArea.w || reqScrollArea.h)
1423 reqScrollArea.w = 0;
1424 reqScrollArea.h = 0;
1425 SetScrollPosition(0,0);
1430 // Automatic MDI Client Scrolling Area Adjustment
1431 if(parent && !parent.noAutoScrollArea)
1433 if(modifyArea && modifyVirtArea /*&& !anchored*/ && (parent.sbv || parent.sbh) &&
1434 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient)
1436 Window parent = this.parent;
1437 int w = parent.reqScrollArea.w;
1438 int h = parent.reqScrollArea.h;
1440 if(stateAnchor.right.type == none && stateAnchor.left.type == offset)
1441 w = Max(w, position.x + size.w);
1442 else if(stateAnchor.right.type == none && stateAnchor.left.type == none)
1443 w = Max(w, Max(position.x, 0) + size.w);
1444 if(stateAnchor.bottom.type == none && stateAnchor.top.type == offset)
1445 h = Max(h, position.y + size.h);
1446 else if(stateAnchor.bottom.type == none && stateAnchor.top.type == none)
1447 h = Max(h, Max(position.y, 0) + size.h);
1449 if((w > parent.clientSize.w && w > parent.reqScrollArea.w) ||
1450 (h > parent.clientSize.h && h > parent.reqScrollArea.h))
1452 /*bool resize = false;
1453 int stepX = parent.sbStep.x, stepY = parent.sbStep.y;
1454 // Needed to make snapped down position match the skin's check of client area
1455 // against realvirtual
1458 SNAPDOWN(stepX, textCellW);
1459 SNAPDOWN(stepY, textCellH);
1460 stepX = Max(stepX, textCellW);
1461 stepY = Max(stepY, textCellH);
1463 if(parent.scrollFlags.snapX)
1465 if(parent.scrollFlags.snapY)
1467 if(parent.reqScrollArea.w != w || parent.reqScrollArea.h != h)
1469 parent.reqScrollArea.w = w;
1470 parent.reqScrollArea.h = h;*/
1472 // parent.UpdateScrollBars(true, true);
1473 parent.Position(parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1474 false, true, true, true, false, false);
1479 GetRidOfVirtualArea();
1483 UpdateScrollBars(modifyThisArea, false);
1484 else if(guiApp.currentSkin)
1487 &clientStart.x, &clientStart.y, &size.w, &size.h, &clientSize.w, &clientSize.h);
1489 if(sbv && (scrollFlags.dontHide || sbv.range > 1))
1490 clientSize.w -= guiApp.currentSkin.VerticalSBW();
1491 if(sbh && (scrollFlags.dontHide || sbh.range > 1))
1492 clientSize.h -= guiApp.currentSkin.HorizontalSBH();
1495 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1496 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1498 absPosition = scrolledPos;
1499 if(guiApp && guiApp.driver != null && guiApp.interfaceDriver)
1500 guiApp.interfaceDriver.OffsetWindow(this, &absPosition.x, &absPosition.y);
1502 if(this != guiApp.desktop && parent)
1504 absPosition.x += parent.absPosition.x;
1505 absPosition.y += parent.absPosition.y;
1506 if(!style.nonClient && this != guiApp.desktop)
1508 absPosition.x += parent.clientStart.x;
1509 absPosition.y += parent.clientStart.y;
1513 box = Box { 0, 0, size.w - 1, size.h - 1 };
1518 // Clip against parent's client area
1519 box.ClipOffset(against, scrolledPos.x, scrolledPos.y);
1521 // Compute client area in this window coordinate system
1522 clientArea.left = 0;
1524 clientArea.right = clientSize.w - 1;
1525 clientArea.bottom = clientSize.h - 1;
1527 // Clip against parent's client area
1529 clientArea.ClipOffset(against, scrolledPos.x + clientStart.x, scrolledPos.y + clientStart.y);
1533 //absPosition.x -= parent.clientStart.x;
1534 //absPosition.y -= parent.clientStart.y;
1537 // Adjust all children
1538 for(child = children.first; child; child = child.next)
1539 child.SetPosition(child.position.x, child.position.y, child.size.w, child.size.h, false, true, true);
1541 UpdateCaret(false, false);
1544 void GetRidOfVirtualArea(void)
1546 if(parent && !parent.destroyed && style.fixed &&
1547 !style.dontScrollHorz && !style.dontScrollVert && !style.nonClient &&
1548 parent.reqScrollArea.w && parent.reqScrollArea.h)
1550 if(!parent.noAutoScrollArea)
1554 for(child = children.first; child; child = child.next)
1556 if(child.modifyVirtArea && !child.style.dontScrollHorz && !child.style.dontScrollVert && !child.style.nonClient)
1558 if(child.position.x + child.size.w > parent.clientSize.w + ((!parent.sbv || parent.sbv.style.hidden) ? 0 : guiApp.currentSkin.VerticalSBW()) ||
1559 child.position.y + child.size.h > parent.clientSize.h + ((!parent.sbh || parent.sbh.style.hidden) ? 0 : guiApp.currentSkin.HorizontalSBH()))
1568 Window parent = this.parent;
1570 parent.position.x, parent.position.y, parent.size.w, parent.size.h,
1571 false, true, true, true, false, false);
1573 parent.SetScrollArea(0,0,true);
1574 parent.SetScrollPosition(0,0);
1580 public void ExternalPosition(int x, int y, int w, int h)
1582 Position(x, y, w, h, false, true, true, true, false, false);
1585 // (w, h): Full window size
1586 bool Position(int x, int y, int w, int h, bool force, bool processAnchors, bool modifyArea, bool updateScrollBars, bool thisOnly, bool changeRootWindow)
1588 bool result = false;
1589 int oldCW = clientSize.w, oldCH = clientSize.h;
1590 bool clientResized, windowResized, windowMoved;
1592 bool realResized = size.w != w || size.h != h;
1594 // TOCHECK: This wasn't in ecere.dll
1595 //if(!parent) return true;
1596 if(destroyed) return false;
1598 windowMoved = position.x != x || position.y != y || force;
1600 // windowResized = realResized || force;
1601 windowResized = size.w != w || size.h != h || force;
1603 if(rootWindow != this && display && !display.flags.flipping && scrolledPos.x != MININT)
1609 scrolledPos.x - parent.clientStart.x + this.box.left, scrolledPos.y - parent.clientStart.y + this.box.top,
1610 scrolledPos.x - parent.clientStart.x + this.box.right,
1611 scrolledPos.y - parent.clientStart.y + this.box.bottom
1617 Box box { scrolledPos.x + this.box.left, scrolledPos.y + this.box.top, scrolledPos.x + this.box.right, scrolledPos.y + this.box.bottom};
1622 SetPosition(x, y, w, h, true, modifyArea, updateScrollBars);
1624 clientResized = oldCW != clientSize.w || oldCH != clientSize.h || force;
1625 if(clientResized && this == rootWindow && nativeDecorations)
1626 windowResized = true;
1628 if(display && rootWindow != this)
1631 if(guiApp && guiApp.windowMoving)
1633 if(guiApp.windowMoving.style.nonClient)
1634 guiApp.windowMoving.parent.SetMouseRangeToWindow();
1636 guiApp.windowMoving.parent.SetMouseRangeToClient();
1646 // Buttons bitmap resources crash if we do this while switching mode
1647 if(!guiApp || !guiApp.modeSwitching)
1650 // Process Anchored Children
1654 for(child = children.first; child; child = child.next)
1657 ((child.stateAnchor.left.type != offset ||
1658 child.stateAnchor.top.type != offset ||
1659 child.stateAnchor.right.type != none ||
1660 child.stateAnchor.bottom.type != none) ||
1661 child.state == maximized || child.state == minimized))
1663 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor,
1665 // child.Position(x, y, w, h, false, true, true, true, false);
1666 // This must be true cuz otherwise we're gonna miss everything since we SetPosition recursively already
1667 child.Position(x, y, w, h, true, true, true, true, false, true /*false*/);
1673 // Is this gonna cause other problems? Commented out for the FileDialog end bevel bug
1674 //if(updateScrollBars)
1676 OnResize(clientSize.w, clientSize.h);
1678 if((clientResized || windowMoved) && created)
1679 OnPosition(position.x, position.y, clientSize.w, clientSize.h);
1681 if(guiApp.interimWindow && guiApp.interimWindow.master.rootWindow == this)
1683 Window master = guiApp.interimWindow.master;
1684 master.OnPosition(master.position.x, master.position.y, master.clientSize.w, master.clientSize.h);
1687 if(rootWindow == this && !is3D)
1691 x -= guiApp.desktop.absPosition.x;
1692 y -= guiApp.desktop.absPosition.y;
1694 //guiApp.Log("Position %s\n", caption);
1695 if(windowResized || windowMoved)
1696 if(display && !display.flags.memBackBuffer && changeRootWindow)
1697 guiApp.interfaceDriver.PositionRootWindow(this, x, y, w, h, windowMoved, windowResized); //realResized);
1699 if(!guiApp.fullScreenMode && this != guiApp.desktop && (windowResized || windowMoved))
1700 for(child = parent.children.first; child && child != this; child = child.next)
1701 if(child.rootWindow)
1702 guiApp.interfaceDriver.UpdateRootWindow(child.rootWindow);
1706 if(windowMoved || windowResized)
1708 display.Lock(true /*false*/);
1711 display.Position(absPosition.x, absPosition.y);
1712 //display.Position(absPosition.x + clientStart.x, absPosition.y + clientStart.y);
1715 // result = realResized ? display.Resize(size.w, size.h) : true;
1716 if(nativeDecorations)
1718 int w = clientSize.w, h = clientSize.h;
1719 if(hasMenuBar) h += skinMenuHeight;
1720 if(hasStatusBar) h += statusBarHeight;
1721 if(sbv && sbv.visible) w += sbv.size.w;
1722 if(sbh && sbh.visible) h += sbh.size.h;
1723 result = manageDisplay ? display.Resize(w, h) : true;
1726 result = manageDisplay ? display.Resize(size.w, size.h) : true;
1730 else if(clientResized)
1732 // --- Major Slow Down / Fix OpenGL Resizing Main Window Lag
1735 if(!guiApp.fullScreenMode && !guiApp.modeSwitching && this == rootWindow)
1739 if(windowMoved || windowResized)
1744 if(guiApp.driver && changeRootWindow)
1746 if(windowResized || windowMoved)
1747 if(!display || display.flags.memBackBuffer)
1748 guiApp.interfaceDriver.PositionRootWindow(this,
1749 x, y, w, h, windowMoved, windowResized);
1750 guiApp.interfaceDriver.UpdateRootWindow(this);
1752 for(child = children.first; child; child = child.next)
1754 if(child.is3D && child.created)
1756 // Copy Display Content
1757 child.display.displaySystem = display.displaySystem;
1758 child.display.window = display.window;
1759 child.display.current = display.current;
1760 child.display.width = display.width;
1761 child.display.height = display.height;
1762 child.display.driverData = display.driverData;
1763 child.display.mutex = null;
1774 void UpdateScrollBars(bool flag, bool fullThing)
1777 bool resizeH = false, resizeV = false;
1778 bool scrolled = false;
1779 rvw = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.w;
1780 rvh = (activeChild && activeChild.state == maximized) ? 0 : reqScrollArea.h;
1782 if(destroyed) return;
1783 if(guiApp.currentSkin)
1785 MinMaxValue cw = 0, ch = 0;
1786 bool sbvVisible, sbhVisible;
1788 int positionH, positionV;
1790 // First get client area with no respect to scroll bars
1795 &clientStart.x, &clientStart.y, &size.w, &size.h, &cw, &ch);
1797 if(scrollFlags.dontHide)
1800 cw -= guiApp.currentSkin.VerticalSBW();
1802 ch -= guiApp.currentSkin.HorizontalSBH();
1804 // Update the scrollbar visibility
1810 sbh.disabled = rangeH <= 1;
1811 if(sbh.style.hidden)
1821 sbv.disabled = rangeV <= 1;
1822 if(sbv.style.hidden)
1830 // Then start off with horizontal scrollbar range
1833 positionH = sbh.thumbPosition;
1838 ch -= guiApp.currentSkin.HorizontalSBH();
1841 // Do the same for vertical scrollbar
1844 positionV = sbv.thumbPosition;
1850 cw -= guiApp.currentSkin.VerticalSBW();
1851 // Maybe we need to set the range on the horizontal scrollbar again
1856 sbh.Action(setRange, positionH, 0);
1857 if(rangeH <= 1 && sbh.range > 1)
1859 ch -= guiApp.currentSkin.HorizontalSBH();
1863 sbv.Action(setRange, positionV, 0);
1870 // Update the scrollbar visibility
1871 if(!scrollFlags.dontHide)
1873 if(sbh && ((rangeH <= 1 && !sbh.style.hidden) || (rangeH > 1 && sbh.style.hidden)))
1877 if(sbv && ((rangeV <= 1 && !sbv.style.hidden) || (rangeV > 1 && sbv.style.hidden)))
1884 if(guiApp.currentSkin)
1891 sbhVisible = sbh.style.hidden ? true : false;
1893 sbvVisible = sbv.style.hidden ? true : false;
1895 // Do our resize here
1896 if(flag && (resizeH || resizeV) && fullThing)
1898 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, false);
1903 OnResize(clientSize.w, clientSize.h);
1909 sbh.visible = sbhVisible;
1911 sbv.visible = sbvVisible;
1913 scrollArea.w = Max(clientSize.w, reqScrollArea.w);
1914 scrollArea.h = Max(clientSize.h, reqScrollArea.h);
1917 sbh.pageStep = clientSize.w;
1919 sbv.pageStep = clientSize.h;
1921 // Notify doesn't handle setRange anymore... process it here
1924 int positionH = sbh.thumbPosition;
1925 if(scroll.x != positionH)
1927 OnHScroll(setRange, positionH, 0);
1931 SNAPDOWN(positionH, textCellW);
1932 scroll.x = positionH;
1938 int seen = clientSize.w, total = reqScrollArea.w;
1941 if(scrollFlags.snapX)
1942 SNAPDOWN(seen, sbStep.x);
1944 if(!total) total = seen;
1945 range = total - seen + 1;
1947 range = Max(range, 1);
1949 if(x >= range) x = range - 1;
1951 if(scrollFlags.snapX)
1952 SNAPUP(x, sbStep.x);
1956 OnHScroll(setRange, x, 0);
1961 SNAPDOWN(x, textCellW);
1967 int positionV = sbv.thumbPosition;
1968 if(scroll.y != positionV)
1970 OnVScroll(setRange, positionV, 0);
1974 SNAPDOWN(positionV, textCellH);
1975 scroll.y = positionV;
1981 int seen = clientSize.h, total = reqScrollArea.h;
1984 if(scrollFlags.snapY)
1985 SNAPDOWN(seen, sbStep.y);
1987 if(!total) total = seen;
1988 range = total - seen + 1;
1989 range = Max(range, 1);
1991 if(y >= range) y = range - 1;
1993 if(scrollFlags.snapY)
1994 SNAPUP(y, sbStep.y);
1998 OnVScroll(setRange, y, 0);
2003 SNAPDOWN(y, textCellH);
2009 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2012 for(child = children.first; child; child = child.next)
2014 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2017 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2018 child.Position(x, y, w, h, false, true, false, true, false, false);
2025 // Process Scrollbars
2027 if(sbh) // && !sbh.style.hidden
2029 sbh.Move(clientStart.x, clientStart.y + clientSize.h, clientSize.w,0);
2030 // Need to set the range again (should improve...) since the scrollbars didn't have
2031 // the right size when UpdateScrollArea set the range on it
2034 sbh.seen = clientSize.w;
2038 if(sbv) // && !sbv.state.hidden
2040 sbv.Move(clientStart.x + clientSize.w, clientStart.y, 0, clientSize.h);
2041 // Need to set the range again (should improve...) since the scrollbars didn't have
2042 // the right size when UpdateScrollArea set the range on it
2045 sbv.seen = clientSize.h;
2050 // TESTING THIS LOWER
2051 if(scrolled || (resizeH || resizeV)) // This ensures children anchored to bottom/right gets repositioned correctly
2054 for(child = children.first; child; child = child.next)
2056 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2059 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2060 child.Position(x, y, w, h, false, true, false, true, false, false);
2066 bool MaximizeButtonClicked(Button button, int x, int y, Modifiers mods)
2068 SetState(maximized, false, mods);
2072 bool RestoreButtonClicked(Button button, int x, int y, Modifiers mods)
2074 SetState(normal, false, mods);
2078 bool MinimizeButtonClicked(Button button, int x, int y, Modifiers mods)
2080 SetState(minimized, false, mods);
2081 parent.CycleChildren(false, true, false, true);
2085 void ScrollBarNotification(ScrollBar control, ScrollBarAction action, int position, Key keyFlags)
2088 // Scroll bar notifications
2089 if(action != setRange)
2091 bool changed = false;
2095 if(scroll.x != position)
2097 OnHScroll(action, position, keyFlags);
2102 SNAPDOWN(position, textCellW);
2104 scroll.x = position;
2108 if(scroll.y != position)
2110 OnVScroll(action, position, keyFlags);
2115 SNAPDOWN(position, textCellH);
2117 scroll.y = position;
2121 bool childMove = false;
2122 for(child = children.first; child; child = child.next)
2124 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2127 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
2128 child.Position(x, y, w, h, false, true, false, true, false, false);
2132 // Testing this patch out to solve MDI workspace redraw bugs
2133 // We were already supposed to be updating parent's affected area in Position() but it doesn't seem to be working
2134 // Scroll offsets to blame?
2138 UpdateCaret(false, false);
2142 // Testing this patch out to solve MDI workspace redraw bugs
2143 for(child = children.first; child; child = child.next)
2145 if(!child.style.nonClient && child.state != maximized && (!child.style.dontScrollHorz || !child.style.dontScrollVert))
2154 void CreateSystemChildren(void)
2156 Window parent = this;
2157 bool scrollBarChanged = false;
2158 bool hasClose = false, hasMaxMin = false;
2159 Point scroll = this.scroll;
2161 if(state == maximized && this.parent.menuBar)
2163 if(this.parent.activeClient == this)
2164 parent = this.parent.menuBar;
2171 if(style.hasClose) hasClose = true;
2172 if(style.hasMaximize || style.hasMinimize)
2179 if(sysButtons[2] && (!hasClose || sysButtons[2].parent != parent))
2181 sysButtons[2].Destroy(0);
2182 sysButtons[2] = null;
2184 if(sysButtons[1] && (!hasMaxMin || sysButtons[1].parent != parent))
2186 sysButtons[1].Destroy(0);
2187 sysButtons[1] = null;
2189 if(sysButtons[0] && (!hasMaxMin || sysButtons[0].parent != parent))
2191 sysButtons[0].Destroy(0);
2192 sysButtons[0] = null;
2195 if(hasClose && parent)
2202 parent, master = this,
2203 inactive = true, nonClient = true, visible = false;
2205 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
2211 if(this.parent == guiApp.desktop)
2212 sysButtons[2].hotKey = altF4;
2213 else if(style.isActiveClient)
2214 sysButtons[2].hotKey = ctrlF4;
2215 sysButtons[2].Create();
2218 sysButtons[2].symbol = 'X';
2219 sysButtons[2].disabled = !style.hasClose;
2222 if(hasMaxMin && parent)
2226 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2227 if(state == maximized)
2230 method = RestoreButtonClicked;
2236 method = MaximizeButtonClicked;
2244 parent, master = this,
2245 hotKey = altEnter, inactive = true, nonClient = true, visible = false
2247 sysButtons[1].Create();
2249 sysButtons[1].NotifyClicked = method;
2251 sysButtons[1].symbol = symbol;
2252 sysButtons[1].disabled = !style.hasMaximize;
2255 if(hasMaxMin && parent)
2259 bool (* method)(Window window, Button button, int x, int y, Modifiers mods);
2260 if (state == minimized)
2263 method = RestoreButtonClicked;
2269 method = MinimizeButtonClicked;
2277 parent, master = this,
2278 hotKey = altM, inactive = true, nonClient = true, visible = false
2280 sysButtons[0].Create();
2282 sysButtons[0].NotifyClicked = method;
2284 sysButtons[0].symbol = symbol;
2285 sysButtons[0].disabled = !style.hasMinimize;
2288 // Create the scrollbars
2289 if(style.hasHorzScroll && !sbh)
2295 direction = horizontal,
2299 snap = scrollFlags.snapX,
2300 NotifyScrolling = ScrollBarNotification
2303 scrollBarChanged = true;
2305 else if(sbh && !style.hasHorzScroll)
2311 if(style.hasVertScroll && !sbv)
2317 direction = vertical,
2321 snap = scrollFlags.snapY,
2322 NotifyScrolling = ScrollBarNotification
2325 scrollBarChanged = true;
2327 else if(sbv && !style.hasVertScroll)
2332 if(scrollBarChanged)
2334 SetScrollLineStep(sbStep.x, sbStep.y);
2335 UpdateScrollBars(true, true);
2339 if(scrollBarChanged)
2341 if(sbh) sbh.thumbPosition = scroll.x;
2342 if(sbv) sbv.thumbPosition = scroll.y;
2346 void UpdateCaption(void)
2348 if(rootWindow == this)
2351 FigureCaption(caption);
2352 guiApp.interfaceDriver.SetRootWindowCaption(this, caption);
2354 UpdateDecorations();
2357 if(parent.rootWindow == parent && parent.activeClient == this) // Added this last check
2360 parent.FigureCaption(caption);
2361 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
2363 parent.UpdateDecorations();
2367 void UpdateActiveDocument(Window previous)
2369 Window activeClient = this.activeClient;
2370 Window activeChild = this.activeChild;
2377 activeClient.CreateSystemChildren();
2379 previous.CreateSystemChildren();
2390 if(activeClient && activeClient.menu && activeClient.state != minimized)
2394 //activeClient.menu.Clean(activeClient);
2395 menu.Merge(activeClient.menu, true, activeClient);
2399 if(activeChild && activeChild != activeClient && activeChild.menu && activeChild.state != minimized)
2402 menu.Merge(activeChild.menu, true, activeChild);
2405 // Build window list
2408 Menu windowMenu = menu.FindMenu("Window");
2413 for(id = 0, cycle = activeClient.cycle; cycle && id<10;)
2416 Window document = cycle.data;
2417 if(!document.style.nonClient && document.style.isActiveClient && document.visible)
2419 char name[2048], caption[2048];
2420 document.FigureCaption(caption);
2421 sprintf(name, "%d %s", id+1, caption);
2422 windowMenu.AddDynamic(MenuItem
2424 copyText = true, text = name, hotKey = Key { k1 + id }, id = id++,
2425 NotifySelect = MenuWindowSelectWindow
2429 if(activeClient.cycle == cycle) break;
2434 if((!previous && activeClient) || !activeClient)
2440 item = menu.FindItem(MenuWindowCloseAll, 0);
2441 if(item) item.disabled = false;
2442 item = menu.FindItem(MenuWindowNext, 0);
2443 if(item) item.disabled = false;
2444 item = menu.FindItem(MenuWindowPrevious, 0);
2445 if(item) item.disabled = false;
2446 item = menu.FindItem(MenuWindowCascade, 0);
2447 if(item) item.disabled = false;
2448 item = menu.FindItem(MenuWindowTileHorz, 0);
2449 if(item) item.disabled = false;
2450 item = menu.FindItem(MenuWindowTileVert, 0);
2451 if(item) item.disabled = false;
2452 item = menu.FindItem(MenuWindowArrangeIcons, 0);
2453 if(item) item.disabled = false;
2454 item = menu.FindItem(MenuWindowWindows, 0);
2455 if(item) item.disabled = false;
2458 item = menu.FindItem(MenuFileClose, 0);
2459 if(item) item.disabled = !activeClient || !activeClient.style.hasClose;
2460 item = menu.FindItem(MenuFileSaveAll, 0);
2461 if(item) item.disabled = numDocuments < 1;
2463 // This is called again for a child window change, with same active client
2464 OnActivateClient(activeClient, previous);
2467 void _ShowDecorations(Box box, bool post)
2469 if(rootWindow == this && nativeDecorations) return;
2470 if(visible && this != guiApp.desktop)
2472 Surface surface = RedrawFull(box);
2476 FigureCaption(caption);
2479 ShowDecorations(captionFont.font,
2482 active, //parent.activeClient == this
2483 guiApp.windowMoving == this);
2485 PreShowDecorations(captionFont.font,
2488 active, //parent.activeClient == this
2489 guiApp.windowMoving == this);
2496 void UpdateExtent(Box refresh)
2498 Surface surface = null;
2500 if(!manageDisplay) { OnRedraw(null);return; }
2501 _ShowDecorations(refresh, false);
2503 surface = Redraw(refresh);
2504 // Opaque background: just fill before EW_REDRAW (clear?)
2507 surface.SetBackground(background);
2508 surface.SetForeground(foreground);
2509 surface.DrawingChar(' ');
2510 if(this == rootWindow)
2512 if(style.drawBehind || background.a)
2513 surface.Clear(colorBuffer);
2515 else if(background.a)
2519 background.color = { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2520 surface.SetForeground((background.color.r > 128 || background.color.g > 128) ? black : white);
2523 if(display.flags.alpha && background.a < 255 && background)
2525 surface.Area(0,0,clientSize.w, clientSize.h);
2526 /*if(style.clearDepthBuffer)
2527 surface.Clear(depthBuffer);*/
2529 else if(/*style.clearDepthBuffer || */background.a)
2531 // surface.Clear((style.clearDepthBuffer ? depthBuffer : 0) | (background.a ? colorBuffer : 0));
2532 surface.Clear(colorBuffer);
2537 surface.TextFont(usedFont.font);
2538 surface.TextOpacity(false);
2542 // Draw the caret ...
2543 if(!disabled && this == guiApp.caretOwner && guiApp.caretEnabled /*&& !guiApp.interimWindow*/ && !guiApp.currentSkin.textMode)
2545 // surface.SetBackground(0xFFFFFF - background.color);
2546 surface.SetBackground(~background.color);
2548 caretPos.x - scroll.x + 1, caretPos.y - scroll.y,
2549 caretPos.x - scroll.x + 2, caretPos.y - scroll.y + caretSize - 1);
2555 void DrawOverChildren(Box refresh)
2557 Surface surface = Redraw(refresh);
2561 surface.DrawingChar(' ');
2562 surface.SetBackground(background);
2563 surface.SetForeground(foreground);
2565 surface.TextFont(usedFont.font);
2566 surface.TextOpacity(false);
2568 OnDrawOverChildren(surface);
2573 _ShowDecorations(refresh, true);
2576 void ComputeClipExtents(void)
2579 Extent clipExtent { /*first = -1, last = -1, free = -1*/ };
2581 clipExtent.Copy(this.clipExtent);
2583 for(child = children.last; child; child = child.prev)
2585 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2587 bool opaque = child.IsOpaque(); // TODO: acess background directly
2588 int dx = child.absPosition.x - absPosition.x, dy = child.absPosition.y - absPosition.y;
2590 child.clipExtent.Copy(clipExtent);
2591 child.clipExtent.Offset(-dx, -dy);
2592 child.clipExtent.IntersectBox(child.box);
2594 child.ComputeClipExtents();
2596 if(opaque && !child.style.nonClient)
2598 // Adjust the box for the parent:
2599 Box box { child.box.left + dx, child.box.top + dy, child.box.right + dx, child.box.bottom + dy };
2600 clipExtent.ExcludeBox(box, rootWindow.tempExtents[0]);
2605 // ??? Only do this for overlapped window or if parent has with clip children flag
2607 // Do this if window has clip children flag on (default false?)
2608 // this.clipExtent = clipExtent;
2610 clipExtent.Free(null);
2613 void ComputeRenderAreaNonOpaque(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2615 bool opaque = IsOpaque();
2617 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2618 if(rootWindow.nativeDecorations)
2620 offsetX -= rootWindow.clientStart.x;
2621 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2625 for(child = children.last; child; child = child.prev)
2627 ColorAlpha background = *(ColorAlpha *)&child.background;
2628 bool opaque = child.IsOpaque();
2629 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2633 // Adjust renderArea to the root window level
2634 Extent * renderArea = &rootWindow.tempExtents[1];
2636 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2637 if(child.rootWindow.nativeDecorations)
2639 offsetX -= child.rootWindow.clientStart.x;
2640 offsetY -= child.rootWindow.clientStart.y - (child.rootWindow.hasMenuBar ? skinMenuHeight : 0);
2644 Extent childRenderArea;
2646 if(backBufferUpdate != null)
2648 childRenderArea.Copy(backBufferUpdate);
2649 childRenderArea.Offset(-offsetX, -offsetY);
2652 childRenderArea.Copy(child.dirtyArea);
2654 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2655 renderArea.Copy(dirtyExtent);
2656 renderArea.Offset(-offsetX, -offsetY);
2657 childRenderArea.Union(renderArea);
2660 // Intersect with the clip extent
2661 childRenderArea.Intersection(child.clipExtent);
2664 renderArea->Copy(child.dirtyArea /*childRenderArea*/);
2665 renderArea->Offset(offsetX, offsetY);
2666 dirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2667 // overDirtyExtent.Union(renderArea);
2668 renderArea->Empty();
2669 // childRenderArea.Free();
2671 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2676 for(child = children.last; child; child = child.prev)
2678 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2680 child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2685 void ComputeRenderArea(Extent dirtyExtent, Extent overDirtyExtent, Extent backBufferUpdate)
2687 bool opaque = IsOpaque();
2688 Extent * dirtyExtentWindow = &rootWindow.tempExtents[1];
2690 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2691 if(rootWindow.nativeDecorations)
2693 offsetX -= rootWindow.clientStart.x;
2694 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2698 for(child = children.last; child; child = child.prev)
2700 //child.ComputeRenderAreaNonOpaque(dirtyExtent, overDirtyExtent, backBufferUpdate);
2702 ColorAlpha background = *(ColorAlpha *)&child.background;
2703 bool opaque = child.IsOpaque();
2704 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2708 int offsetX = child.absPosition.x - rootWindow.absPosition.x, offsetY = child.absPosition.y - rootWindow.absPosition.y;
2709 // Adjust renderArea to the root window level
2711 renderArea.Copy(child.dirtyArea);
2712 renderArea.Offset(offsetX, offsetY);
2713 dirtyExtent.Union(renderArea);
2714 overDirtyExtent.Union(renderArea);
2720 for(child = children.last; child; child = child.prev)
2722 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow)
2724 child.ComputeRenderArea(dirtyExtent, overDirtyExtent, backBufferUpdate);
2728 if(backBufferUpdate != null)
2730 renderArea.Copy(backBufferUpdate);
2731 renderArea.Offset(-offsetX, -offsetY);
2733 overRenderArea.Copy(backBufferUpdate);
2734 overRenderArea.Offset(-offsetX, -offsetY);
2740 renderArea.Copy(dirtyArea);
2742 overRenderArea.Copy(dirtyArea);
2745 // Add extent forced by transparency to the dirty area, adjusting dirty extent to the window
2746 dirtyExtentWindow->Copy(dirtyExtent);
2747 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2748 renderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2749 dirtyExtentWindow->Empty();
2751 // Intersect with the clip extent
2752 renderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2755 if(renderArea.count > 10)
2758 printf("\nToo many extents (%d):\n", renderArea.count);
2760 //extent.UnionBox({ 112, 6, 304, 7 }, rootWindow.tempExtents[0]);
2761 //extent.UnionBox({ 112, 8, 304, 17 }, rootWindow.tempExtents[0]);
2766 for(c = 0; c<10; c++)
2769 FASTLIST_LOOP(renderArea, extentBox)
2771 extent.UnionBox(extentBox.box, rootWindow.tempExtents[0]);
2773 renderArea.Copy(extent);
2775 FASTLIST_LOOP(renderArea, extentBox)
2778 printf("(%d, %d) - (%d, %d)\n",
2779 extentBox.box.left, extentBox.box.top,
2780 extentBox.box.right, extentBox.box.bottom);
2784 printf("\nNow %d\n", renderArea.count);
2790 // WHY WAS THIS COMMENTED ??
2792 // Add extent forced by DrawOverChildren to the dirty area, adjusting dirty extent to the window
2793 dirtyExtentWindow->Copy(overDirtyExtent);
2794 dirtyExtentWindow->Offset(-offsetX, -offsetY);
2795 overRenderArea.Union(dirtyExtentWindow, rootWindow.tempExtents[0]);
2796 dirtyExtentWindow->Empty();
2798 // Intersect with the clip extent
2799 overRenderArea.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2805 if(scrollExtent.count)
2807 // Subtract render extent from scrolling extent
2808 scrollExtent.Exclusion(renderArea, rootWindow.tempExtents[0]);
2810 if(backBufferUpdate == null)
2812 Extent * dirty = &rootWindow.tempExtents[3];
2815 // Intersect scrolling extent with clip extent
2816 scrollExtent.Intersection(clipExtent, rootWindow.tempExtents[0], rootWindow.tempExtents[1], rootWindow.tempExtents[2]);
2818 // offset this scroll to be at the root window level
2819 scrollExtent.Offset(offsetX, offsetY);
2820 // Add area that was scrolled to the dirty extents of the back buffer
2821 rootWindow.dirtyBack.Union(scrollExtent, rootWindow.tempExtents[0]);
2825 // Will need scrolledArea.x & scrolledArea.y to support multiple scrolls
2826 for(scrollBox = (BoxItem)scrollExtent.first; scrollBox; scrollBox = (BoxItem)scrollBox.next)
2827 display.Scroll(scrollBox.box, scrolledArea.x, scrolledArea.y, dirty);
2832 scrollExtent.Empty();
2834 // Add the exposed extent to the window render area
2835 dirty->Offset(-offsetX, -offsetY);
2836 renderArea.Union(dirty, rootWindow.tempExtents[0]);
2841 // Subtract the window's box from the transparency forced extent
2842 dirtyExtent.ExcludeBox({box.left + offsetX, box.top + offsetY, box.right + offsetX, box.bottom + offsetY }, rootWindow.tempExtents[0]);
2848 renderArea.Copy(this.renderArea);
2849 renderArea.Offset(offsetX, offsetY);
2850 dirtyExtent.Union(renderArea);
2856 Extent renderArea { };
2858 renderArea.Copy(overRenderArea);
2859 renderArea.Offset(offsetX, offsetY);
2860 overDirtyExtent.Union(renderArea, rootWindow.tempExtents[0]);
2865 if(backBufferUpdate != null)
2867 // Remove render area from dirty area
2868 dirtyArea.Exclusion(renderArea, rootWindow.tempExtents[0]);
2870 dirtyArea.Exclusion(overRenderArea, rootWindow.tempExtents[0]);
2877 // Remove the window render area from the dirty extents of the back buffer
2878 rootWindow.dirtyBack.Exclusion(renderArea);
2882 void Render(Extent updateExtent)
2886 Window rootWindow = this.rootWindow;
2887 int offsetX = absPosition.x - rootWindow.absPosition.x, offsetY = absPosition.y - rootWindow.absPosition.y;
2888 if(rootWindow.nativeDecorations)
2890 offsetX -= rootWindow.clientStart.x;
2891 offsetY -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0);
2894 if(rootWindow.fullRender)
2903 background = Color { (byte)GetRandom(0,255), (byte)GetRandom(0,255), (byte)GetRandom(0,255) };
2904 foreground = (background.color.r > 128 || background.color.g > 128) ? black : white;
2909 /*if(renderArea.count)
2910 printf("\n\nRendering %s (%x):\n------------------------------------------\n", _class.name, this);*/
2913 for(extentBox = (BoxItem)renderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
2915 Box box = extentBox.box;
2918 /*printf("(%d, %d) - (%d, %d)\n",
2919 extentBox.box.left, extentBox.box.top,
2920 extentBox.box.right, extentBox.box.bottom);*/
2925 box.left += offsetX;
2927 box.right += offsetX;
2928 box.bottom += offsetY;
2930 if(updateExtent != null)
2931 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
2935 for(child = children.first; child; child = child.next)
2936 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && !child.nonClient)
2937 child.Render(updateExtent);
2939 if(rootWindow.fullRender)
2940 DrawOverChildren(box);
2943 // TO DO: There's an issue about draw over children...
2944 // TO DO: Don't wanna go through this if method isn't used
2945 for(extentBox = (BoxItem)overRenderArea.first; extentBox; extentBox = (BoxItem)extentBox.next)
2946 //FASTLIST_LOOP(/*renderArea */overRenderArea, extentBox)
2948 Box box = extentBox.box;
2950 DrawOverChildren(box);
2952 box.left += offsetX;
2954 box.right += offsetX;
2955 box.bottom += offsetY;
2957 if(updateExtent != null)
2958 updateExtent.UnionBox(box, rootWindow.tempExtents[0]);
2961 for(child = children.first; child; child = child.next)
2962 if(!child.style.hidden && child.created && !child.is3D && child.rootWindow && child.nonClient)
2963 child.Render(updateExtent);
2966 overRenderArea.Empty();
2969 public void UpdateDisplay(void)
2971 if(!manageDisplay) { OnRedraw(null);return; }
2972 if(rootWindow && this != rootWindow)
2973 rootWindow.UpdateDisplay();
2976 Extent dirtyExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be forced due to transparency
2977 Extent overExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that forced for DrawOverChildren
2980 dirtyExtent.Clear();
2983 clipExtent.AddBox(box);
2985 display.StartUpdate();
2987 if(!rootWindow.fullRender)
2989 ComputeClipExtents();
2990 ComputeRenderAreaNonOpaque(dirtyExtent, overExtent, null);
2991 ComputeRenderArea(dirtyExtent, overExtent, null);
2994 clipExtent.Free(null);
2996 dirtyExtent.Free(null);
2997 overExtent.Free(null);
2999 if(display.flags.flipping)
3002 display.Update(null);
3006 Extent updateExtent { /*first = -1, last = -1, free = -1*/ }; // Extent that needs to be updated
3007 updateExtent.Clear();
3009 Render(updateExtent);
3011 updateExtent.UnionBox(this.box, tempExtents[0]);
3014 //printf("\n\nUpdate:\n------------------------------------------\n");
3017 //FASTLIST_LOOP(updateExtent, extentBox)
3018 for(extentBox = (BoxItem)updateExtent.first; extentBox; extentBox = (BoxItem)extentBox.next)
3021 /*printf("Updating (%d, %d) - (%d, %d)\n",
3022 extentBox.box.left, extentBox.box.top,
3023 extentBox.box.right, extentBox.box.bottom);*/
3026 display.Update(extentBox.box);
3029 updateExtent.Free(null);
3032 display.EndUpdate();
3040 void UpdateBackDisplay(Box box)
3046 Extent intersection { /*first = -1, last = -1, free = -1*/ };
3048 //printf("UpdateBackDisplay going through!\n");
3049 display.StartUpdate();
3053 intersection.Copy(dirtyBack);
3054 intersection.IntersectBox(box);
3056 dirtyExtent.Clear();
3059 clipExtent.AddBox(box);
3061 if(!rootWindow.fullRender)
3063 ComputeClipExtents();
3064 ComputeRenderArea(dirtyExtent, overExtent, intersection);
3067 clipExtent.Free(null);
3069 intersection.Free(null);
3070 dirtyExtent.Free(null);
3071 overExtent.Free(null);
3076 if(display.flags.flipping)
3077 display.Update(null);
3080 rootWindow.display.Update(box);
3083 display.EndUpdate();
3087 dirtyBack.ExcludeBox(box, rootWindow.tempExtents[0]);
3088 if(dirtyBack.count > MAX_DIRTY_BACK)
3090 BoxItem extentBox, next;
3091 BoxItem first = (BoxItem)ACCESS_ITEM(dirtyBack, dirtyBack.first);
3092 for(extentBox = (BoxItem)dirtyBack.first; extentBox; extentBox = next)
3094 next = (BoxItem)extentBox.next;
3095 if(extentBox != first)
3097 if(extentBox.box.left < first.box.left)
3098 first.box.left = extentBox.box.left;
3099 if(extentBox.box.top < first.box.top)
3100 first.box.top = extentBox.box.top;
3101 if(extentBox.box.right > first.box.right)
3102 first.box.right = extentBox.box.right;
3103 if(extentBox.box.bottom > first.box.bottom)
3104 first.box.bottom = extentBox.box.bottom;
3105 dirtyBack.Delete(extentBox);
3114 // --- Window positioning ---
3115 // --- Window identification ---
3117 // Returns window at position "Position"
3118 Window GetAtPosition(int x, int y, bool clickThru, bool acceptDisabled, Window last)
3120 Window child, result = null;
3122 box.left += absPosition.x;
3123 box.right += absPosition.x;
3124 box.top += absPosition.y;
3125 box.bottom += absPosition.y;
3127 if(!destroyed && visible && (acceptDisabled || !disabled))
3129 int lx = x - absPosition.x;
3130 int ly = y - absPosition.y;
3131 if(IsInside(lx, ly))
3132 // if(box.IsPointInside(Point{x, y}))
3134 if(!clickThru || !style.clickThrough) result = (this == last) ? null : this;
3135 // If the window is disabled, stop looking in children (for acceptDisabled mode)
3138 for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
3140 if(child != statusBar && child.rootWindow == rootWindow)
3142 Window childResult = child.GetAtPosition(x, y, clickThru, acceptDisabled, last);
3149 for(child = (last && last.parent == this) ? last.previous : children.last; child; child = child.prev)
3151 if(child != statusBar && child.rootWindow == rootWindow)
3153 Window childResult = child.GetAtPosition(x, y, false, acceptDisabled, last);
3165 Window FindModal(void)
3167 Window modalWindow = this, check;
3168 Window check2 = null;
3169 for(check = this; check.master; check = check.master)
3171 if(check.master.modalSlave && check.master.modalSlave.created && check != check.master.modalSlave)
3173 modalWindow = check.master.modalSlave;
3174 check = modalWindow;
3176 // TESTING THIS FOR DROPBOX...
3177 if(!rootWindow || !rootWindow.style.interim)
3179 for(check2 = check; check2.activeChild; check2 = check2.activeChild)
3181 if(check2.modalSlave && check2.modalSlave.created)
3183 modalWindow = check2.modalSlave;
3191 if(modalWindow == this)
3193 for(check = this; check.activeChild; check = check.activeChild)
3195 if(check.modalSlave)
3197 modalWindow = check.modalSlave;
3203 for(; modalWindow.modalSlave && modalWindow.modalSlave.created; modalWindow = modalWindow.modalSlave);
3204 return (modalWindow == this || this == guiApp.interimWindow || IsDescendantOf(modalWindow)) ? null : modalWindow;
3207 void StopMoving(void)
3209 if(this == guiApp.windowMoving)
3211 guiApp.windowMoving = null;
3212 UpdateDecorations();
3213 SetMouseRange(null);
3216 if(rootWindow.active)
3217 guiApp.interfaceDriver.StopMoving(rootWindow);
3220 guiApp.resizeX = guiApp.resizeY = guiApp.resizeEndX = guiApp.resizeEndY = false;
3221 guiApp.windowIsResizing = false;
3225 void SelectMouseCursor(void)
3230 Window cursorWindow = null;
3231 bool rx, ry, rex, rey;
3233 guiApp.desktop.GetMousePosition(&x, &y);
3234 mouseWindow = rootWindow ? rootWindow.GetAtPosition(x,y, true, false, null) : null;
3236 if((guiApp.windowMoving && !guiApp.windowIsResizing) || guiApp.windowScrolling)
3237 guiApp.SetCurrentCursor(guiApp.systemCursors[moving]);
3238 else if(mouseWindow)
3240 modalWindow = mouseWindow.FindModal();
3241 x -= mouseWindow.absPosition.x;
3242 y -= mouseWindow.absPosition.y;
3243 if(guiApp.windowIsResizing)
3245 rex = guiApp.resizeEndX;
3246 rey = guiApp.resizeEndY;
3247 rx = guiApp.resizeX;
3248 ry = guiApp.resizeY;
3249 if((rex && rey) || (rx && ry))
3250 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
3251 else if((rex && ry) || (rx && rey))
3252 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
3253 else if((ry || rey) && (!rx && !rex))
3254 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
3255 else if((rx || rex) && (!ry && !rey))
3256 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
3258 else if(!modalWindow && !guiApp.windowCaptured &&
3259 mouseWindow.IsMouseResizing(x, y, mouseWindow.size.w, mouseWindow.size.h,
3260 &rx, &ry, &rex, &rey))
3262 if((rex && rey) || (rx && ry))
3263 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNWSE]);
3264 else if((rex && ry) || (rx && rey))
3265 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNESW]);
3266 else if((ry || rey) && (!rx && !rex))
3267 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeNS]);
3268 else if((rx || rex) && (!ry && !rey))
3269 guiApp.SetCurrentCursor(guiApp.systemCursors[sizeWE]);
3271 else if(!guiApp.windowCaptured && !modalWindow && !guiApp.interimWindow)
3273 if(!mouseWindow.clientArea.IsPointInside({x - mouseWindow.clientStart.x, y - mouseWindow.clientStart.y}))
3274 cursorWindow = mouseWindow.parent;
3276 cursorWindow = mouseWindow;
3278 else if(!guiApp.interimWindow)
3279 cursorWindow = guiApp.windowCaptured;
3282 for(; !cursorWindow.cursor && !cursorWindow.style.nonClient; cursorWindow = cursorWindow.parent);
3283 guiApp.SetCurrentCursor(cursorWindow.cursor ? cursorWindow.cursor : guiApp.systemCursors[arrow]);
3285 else if(modalWindow)
3287 guiApp.SetCurrentCursor(guiApp.systemCursors[arrow]);
3289 else if(guiApp.interimWindow)
3291 if(guiApp.interimWindow.cursor)
3292 guiApp.SetCurrentCursor(guiApp.interimWindow.cursor);
3294 guiApp.SetCurrentCursor(mouseWindow.cursor ? mouseWindow.cursor : guiApp.systemCursors[arrow]);
3299 // --- State based input ---
3300 bool AcquireInputEx(bool state)
3305 guiApp.interfaceDriver.GetMousePosition(&guiApp.acquiredMouseX, &guiApp.acquiredMouseY);
3306 guiApp.interfaceDriver.SetMousePosition(clientSize.w/2 + absPosition.x, clientSize.h/2 + absPosition.y);
3308 result = guiApp.interfaceDriver.AcquireInput(rootWindow, state);
3310 guiApp.acquiredWindow = state ? this : null;
3313 SetMouseRangeToClient();
3314 guiApp.interfaceDriver.SetMouseCursor((SystemCursor)-1);
3319 SelectMouseCursor();
3321 if(!state) guiApp.interfaceDriver.SetMousePosition(guiApp.acquiredMouseX, guiApp.acquiredMouseY);
3325 // --- Window activation ---
3326 bool PropagateActive(bool active, Window previous, bool * goOnWithActivation, bool direct)
3329 if(!parent || !parent.style.inactive)
3331 Window parent = this.parent;
3334 if(rootWindow == this)
3335 Log(active ? "active\n" : "inactive\n");
3338 // Testing this here...
3339 if(!parent || parent == guiApp.desktop || parent.active)
3341 this.active = active;
3344 // TESTING THIS HERE
3345 UpdateDecorations();
3346 if(result = OnActivate(active, previous, goOnWithActivation, direct) && *goOnWithActivation && master)
3347 result = NotifyActivate(master, this, active, previous);
3350 this.active = !active;
3355 if(!parent || parent == guiApp.desktop || parent.active)
3357 this.active = active;
3359 AcquireInputEx(active);
3364 if(guiApp.caretOwner)
3368 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 1,
3369 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + 1,
3370 guiApp.caretOwner.caretPos.x - guiApp.caretOwner.scroll.x + 2,
3371 guiApp.caretOwner.caretPos.y - guiApp.caretOwner.scroll.y + guiApp.caretOwner.caretSize - 1
3373 guiApp.caretOwner.Update(extent);
3376 if(visible || !guiApp.caretOwner)
3377 guiApp.caretOwner = this;
3378 UpdateCaret(false, false);
3384 this.active = false;
3386 AcquireInputEx(active);
3388 if(!active && guiApp.caretOwner == this)
3390 UpdateCaret(false, true);
3391 guiApp.caretOwner = null;
3392 guiApp.interfaceDriver.SetCaret(0,0,0);
3393 guiApp.caretEnabled = false;
3398 if(!active && parent && parent.activeChild && parent.activeChild != this)
3399 if(!parent.activeChild.PropagateActive(false, previous, goOnWithActivation, true) || !*goOnWithActivation)
3405 if(!active && menuBar)
3408 menuBar.OnActivate(false, null, &goOn, true);
3409 menuBar.NotifyActivate(menuBar.master, menuBar, false, null);
3413 if(!activeChild.PropagateActive(active, previous, goOnWithActivation, false) || !*goOnWithActivation)
3422 void ConsequentialMouseMove(bool kbMoving)
3426 if(kbMoving || !guiApp.windowMoving)
3430 if(rootWindow == guiApp.desktop || rootWindow.parent == guiApp.desktop)
3432 guiApp.interfaceDriver.GetMousePosition(&x, &y);
3434 if(guiApp.windowMoving || rootWindow.GetAtPosition(x, y, true, false, null))
3435 rootWindow.MouseMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove, x, y, &mods, true, false);
3441 bool IsDescendantOf(Window ancestor)
3444 for(window = this; window && window != ancestor; window = window.parent);
3445 return window == ancestor;
3448 bool IsSlaveOf(Window master)
3451 for(window = this; window && window != master; window = window.master);
3452 return window == master;
3455 bool ActivateEx(bool active, bool activateParent, bool moveInactive, bool activateRoot, Window external, Window externalSwap)
3459 if(this && !destroyed /*&& state != Hidden*/)
3461 Window swap = externalSwap;
3469 if(activateParent &&
3470 (parent.activeChild != this ||
3471 (guiApp.interimWindow && !IsDescendantOf(guiApp.interimWindow))) &&
3472 active && _isModal &&
3473 parent != master && master)
3474 master.ActivateEx(true, true, false, activateRoot, external, externalSwap);
3480 bool real = parent.activeChild != this;
3482 // TEST THIS: New activateParent check here!!! CAUSED MENUS NOT GOING AWAY
3483 if(/*activateParent && */guiApp.interimWindow &&
3484 !IsDescendantOf(guiApp.interimWindow) &&
3485 !IsSlaveOf(guiApp.interimWindow))
3487 Window interimWindow = guiApp.interimWindow;
3488 while(interimWindow && interimWindow != this)
3490 Window master = interimWindow.master;
3492 guiApp.interimWindow = null;
3493 if(guiApp.caretOwner)
3494 guiApp.caretOwner.UpdateCaret(false, false);
3496 incref interimWindow;
3497 if(!interimWindow.PropagateActive(false, this, &goOn, true))
3502 delete interimWindow;
3503 interimWindow = (master && master.style.interim) ? master : null;
3508 guiApp.interimWindow = this;
3509 /*guiApp.interfaceDriver.SetCaret(0,0,0);
3510 guiApp.caretEnabled = false;*/
3511 UpdateCaret(false, true);
3516 bool acquireInput = false;
3518 parent.activeChild &&
3519 parent.activeChild.state == maximized &&
3520 parent != guiApp.desktop;
3522 if(!style.inactive) // (!style.isRemote || parent.active || parent.style.hidden))
3527 swap = parent.activeChild;
3528 if(swap && swap.destroyed) swap = null;
3529 if(swap && swap != this)
3532 if(!swap.PropagateActive(false, this, &goOn, true))
3533 swap = parent.activeChild;
3544 if(!parent || parent.activeChild != this || style.interim)
3547 result = PropagateActive(true, swap, &goOn, true);
3548 if(!result && !goOn)
3553 acquireInput = true;
3557 if(style.hasMaximize && parent != guiApp.desktop)
3560 SetState(maximized, false, 0);
3561 else if(state != maximized)
3564 for(child = parent.children.first; child; child = child.next)
3566 if(this != child && child.state == maximized)
3567 child.SetState(normal, false, 0);
3574 if(!style.inactive && !style.interim /*&& (!style.isRemote || parent.active || parent.style.hidden)*/)
3576 Window previous = parent.activeClient;
3577 parent.activeChild = this;
3578 if(!style.nonClient /*&& style.isActiveClient*/)
3580 if(style.isActiveClient && !style.hidden)
3581 parent.activeClient = this;
3582 parent.UpdateActiveDocument(previous);
3587 //if(!style.isRemote)
3589 if(rootWindow != this)
3591 if(activateParent && parent && !parent.active /*parent != parent.parent.activeChild*/)
3592 parent.ActivateEx(true, true, moveInactive, activateRoot, external, externalSwap);
3594 else if(!guiApp.fullScreenMode)
3596 Window modalRoot = FindModal();
3597 if(!modalRoot) modalRoot = this;
3598 if(!modalRoot.isForegroundWindow)
3600 modalRoot.isForegroundWindow = true;
3601 // To check : Why is parent null?
3602 if(activateRoot && modalRoot.parent && !modalRoot.parent.display && external != modalRoot)
3604 guiApp.interfaceDriver.ActivateRootWindow(modalRoot);
3606 modalRoot.isForegroundWindow = false;
3611 if(result && real && (!style.inactive || moveInactive) && parent)
3613 Window last = parent.children.last;
3615 if(!style.stayOnTop)
3616 for(; last && last.style.stayOnTop; last = last.prev);
3618 parent.children.Move(this, last);
3620 // Definitely don't want that: why not?
3624 parent.childrenOrder.Move(order, parent.childrenOrder.last);
3630 if(!parent || style.interim || (parent.activeChild == this && !style.inactive))
3637 parent.activeChild = null;
3638 if(!style.nonClient /*&& style.isActiveClient*/)
3640 Window previous = parent.activeClient;
3641 if(style.isActiveClient)
3642 parent.activeClient = null;
3643 parent.UpdateActiveDocument(previous);
3647 if(this == guiApp.interimWindow)
3649 guiApp.interimWindow = null;
3650 if(guiApp.caretOwner)
3651 guiApp.caretOwner.UpdateCaret(false, false);
3653 if(!PropagateActive(false, externalSwap, &goOn, true) || !goOn)
3660 if(!active || !swap)
3661 UpdateDecorations();
3663 swap.UpdateDecorations();
3665 if(active && rootWindow != this)
3666 ConsequentialMouseMove(false);
3673 // --- Input Messages ---
3674 void ::UpdateMouseMove(int mouseX, int mouseY, bool consequential)
3676 static bool reEntrancy = false;
3677 if(reEntrancy) return;
3681 guiApp.cursorUpdate = true;
3682 if(guiApp.windowScrolling && !consequential)
3684 guiApp.windowScrolling.SetScrollPosition(
3685 (guiApp.windowScrolling.sbh) ?
3686 (guiApp.windowScrollingBefore.x - mouseX + guiApp.windowScrollingStart.x) : 0,
3687 (guiApp.windowScrolling.sbv) ?
3688 (guiApp.windowScrollingBefore.y - mouseY + guiApp.windowScrollingStart.y) : 0);
3690 if(guiApp.windowMoving)
3692 if(mouseX != guiApp.movingLast.x || mouseY != guiApp.movingLast.y)
3694 Window window = guiApp.windowMoving;
3696 int w = window.size.w;
3697 int h = window.size.h;
3702 rx = mouseX - guiApp.windowMovingStart.x;
3703 ry = mouseY - guiApp.windowMovingStart.y;
3706 window.GetDecorationsSize(&ew, &eh);
3708 if(guiApp.windowIsResizing)
3710 x = window.scrolledPos.x;
3711 y = window.scrolledPos.y;
3715 aw = Max(guiApp.windowResizingBefore.w - rx,window.skinMinSize.w);
3716 rx = guiApp.windowResizingBefore.w - aw;
3717 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3718 w = guiApp.windowResizingBefore.w - rx;
3722 ah = Max(guiApp.windowResizingBefore.h - ry,window.skinMinSize.h);
3723 ry = guiApp.windowResizingBefore.h - ah;
3724 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3725 ry = Max(ry, -guiApp.windowMovingBefore.y);
3726 h = guiApp.windowResizingBefore.h - ry;
3728 if(guiApp.resizeEndX)
3730 w = guiApp.windowResizingBefore.w + rx;
3733 if(guiApp.resizeEndY) h = guiApp.windowResizingBefore.h + ry;
3741 w = Max(w, window.minSize.w);
3742 h = Max(h, window.minSize.h);
3743 w = Min(w, window.maxSize.w);
3744 h = Min(h, window.maxSize.h);
3746 if(!window.OnResizing(&w, &h))
3748 w = window.clientSize.w;
3749 h = window.clientSize.h;
3752 w = Max(w, window.skinMinSize.w);
3753 h = Max(h, window.skinMinSize.h);
3760 SNAPDOWN(w, textCellW);
3761 SNAPDOWN(h, textCellH);
3766 aw = Max(w,window.skinMinSize.w);
3767 rx = guiApp.windowResizingBefore.w - aw;
3768 rx = Min(guiApp.windowMovingBefore.x + rx, window.parent.clientSize.w-1) - guiApp.windowMovingBefore.x;
3769 w = guiApp.windowResizingBefore.w - rx;
3773 ah = Max(h,window.skinMinSize.h);
3774 ry = guiApp.windowResizingBefore.h - ah;
3775 ry = Min(guiApp.windowMovingBefore.y + ry, window.parent.clientSize.h-1) - guiApp.windowMovingBefore.y;
3776 ry = Max(ry, -guiApp.windowMovingBefore.y);
3777 h = guiApp.windowResizingBefore.h - ry;
3782 if(!guiApp.windowIsResizing || guiApp.resizeX)
3783 x = guiApp.windowMovingBefore.x + rx;
3784 if(!guiApp.windowIsResizing || guiApp.resizeY)
3785 y = guiApp.windowMovingBefore.y + ry;
3787 if(!guiApp.windowIsResizing)
3790 if(window.parent == guiApp.desktop && guiApp.virtualScreen.w)
3792 x = Min(x, (guiApp.virtualScreen.w + guiApp.virtualScreenPos.x) -1);
3793 y = Min(y, (guiApp.virtualScreen.h + guiApp.virtualScreenPos.y) -1);
3794 x = Max(x,-(w-1) + guiApp.virtualScreenPos.x);
3795 y = Max(y,-(h-1) + guiApp.virtualScreenPos.y);
3799 x = Min(x, (window.parent.reqScrollArea.w ? window.parent.reqScrollArea.w : window.parent.clientSize.w) -1);
3800 y = Min(y, (window.parent.reqScrollArea.h ? window.parent.reqScrollArea.h : window.parent.clientSize.h) -1);
3806 if(!guiApp.windowIsResizing || (guiApp.resizeX || guiApp.resizeY))
3808 if(!window.OnMoving(&x, &y, w, h))
3810 x = window.scrolledPos.x;
3811 y = window.scrolledPos.y;
3817 SNAPDOWN(x, textCellW);
3818 SNAPDOWN(y, textCellH);
3821 if(!window.style.nonClient)
3823 if(!window.style.fixed /*|| window.style.isDocument*/)
3825 if(!window.style.dontScrollHorz)
3826 x += window.parent.scroll.x;
3827 if(!window.style.dontScrollVert)
3828 y += window.parent.scroll.y;
3832 // Break the anchors for moveable/resizable windows
3833 // Will probably cause problem with IDE windows... Will probably need a way to specify if anchors should break
3834 if(window.style.fixed)
3836 if(window.state == normal)
3838 window.normalAnchor = Anchor { left = x, top = y };
3839 window.normalSizeAnchor = SizeAnchor { { w, h } };
3840 window.anchored = false;
3844 window.stateAnchor = Anchor { left = x, top = y };
3845 window.stateSizeAnchor = SizeAnchor { { w, h } };
3847 window.Position(x, y, w, h, false, true, guiApp.windowIsResizing, guiApp.windowIsResizing, false, true);
3848 // TOCHECK: Investigate why the following only redraws the scrollbars
3849 //window.Position(x, y, w, h, false, true, true, true, false, true);
3851 guiApp.movingLast.x = mouseX;
3852 guiApp.movingLast.y = mouseY;
3858 public bool MouseMessage(uint method, int x, int y, Modifiers * mods, bool consequential, bool activate)
3861 bool wasMoving = guiApp.windowMoving ? true : false;
3862 bool wasScrolling = guiApp.windowScrolling ? true : false;
3864 while(result && w != this)
3866 Window msgWindow = GetAtPosition(x,y, false, true, w);
3867 Window trueWindow = GetAtPosition(x,y, false, false, w);
3868 bool windowDragged = false;
3873 window = (w && !w.disabled) ? w : null;
3875 if(trueWindow) incref trueWindow;
3877 if(consequential) mods->isSideEffect = true;
3879 UpdateMouseMove(x, y, consequential);
3881 if(guiApp.windowCaptured && (guiApp.windowCaptured.rootWindow == this))
3883 if(!guiApp.windowCaptured.isEnabled)
3884 guiApp.windowCaptured.ReleaseCapture();
3886 window = guiApp.windowCaptured;
3889 if(trueWindow && activate &&
3890 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
3891 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
3892 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
3893 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
3895 if(mods->alt && !mods->ctrl && !mods->shift)
3897 Window moved = trueWindow;
3898 for(moved = trueWindow; moved; moved = moved.parent)
3899 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
3904 windowDragged = true;
3906 // Cancel the ALT menu toggling...
3907 window.rootWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
3912 if(window && activate &&
3913 (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown ||
3914 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown ||
3915 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown ||
3916 method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick))
3918 Window modalWindow = window.FindModal();
3920 /*if(mods->alt && !mods->shift && !mods->ctrl)
3922 Window moved = window;
3923 for(moved = window; moved; moved = moved.parent)
3924 if(method == OnRightButtonDown || ((moved.style.fixed || moved.moveable) && moved.state != maximized))
3929 windowDragged = true;
3931 // Cancel the ALT menu toggling...
3932 window.rootWindow.KeyMessage(OnKeyDown, 0, 0);
3938 Window activateWindow = modalWindow ? modalWindow : window;
3939 if(activateWindow && !activateWindow.isRemote)
3941 bool doActivation = true;
3942 //bool needToDoActivation = false;
3943 Window check = activateWindow;
3945 for(check = activateWindow; check && check != guiApp.desktop; check = check.parent)
3947 if(!check.style.inactive)
3949 //needToDoActivation = true;
3951 doActivation = false;
3956 if(!needToDoActivation)
3957 doActivation = false;
3960 if((doActivation && (activateWindow.parent != guiApp.desktop || guiApp.fullScreen)) ||
3961 (guiApp.interimWindow && !window.IsDescendantOf(guiApp.interimWindow)))
3963 // Let the OnLeftButtonDown do the activating instead
3964 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
3972 incref activateWindow;
3973 if(!activateWindow.ActivateEx(true, true, false, true, null, null))
3975 delete activateWindow;
3979 if(activateWindow._refCount == 1)
3981 delete activateWindow;
3985 delete activateWindow;
3987 mods->isActivate = true;
3991 if(!modalWindow && window && !window.destroyed)
3993 if(!guiApp.windowCaptured || windowDragged)
3995 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown)
3997 bool moving = ((window.state != maximized &&
3998 window.IsMouseMoving(
3999 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4000 || (guiApp.windowMoving && !guiApp.windowIsResizing);
4002 if(!moving && window.IsMouseResizing(
4003 x - window.absPosition.x,
4004 y - window.absPosition.y,
4005 window.size.w, window.size.h,
4006 &guiApp.resizeX, &guiApp.resizeY, &guiApp.resizeEndX, &guiApp.resizeEndY))
4008 guiApp.windowIsResizing = true;
4009 guiApp.windowResizingBefore.w = window.size.w;
4010 guiApp.windowResizingBefore.h = window.size.h;
4012 if(guiApp.windowIsResizing || windowDragged || moving)
4015 guiApp.windowMoving = window;
4016 guiApp.windowMovingStart.x = guiApp.movingLast.x = x;
4017 guiApp.windowMovingStart.y = guiApp.movingLast.y = y;
4018 guiApp.windowMovingBefore.x = window.position.x;//s;
4019 guiApp.windowMovingBefore.y = window.position.y;//s;
4020 if(guiApp.windowMoving == guiApp.windowMoving.rootWindow)
4021 guiApp.interfaceDriver.StartMoving(guiApp.windowMoving.rootWindow, 0,0,false);
4024 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown)
4026 if(window.style.fixed &&
4028 window.IsMouseMoving(
4029 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h)))
4031 window.ShowSysMenu(x, y);
4035 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown)
4037 if(window.sbv || window.sbh)
4040 guiApp.windowScrolling = window;
4041 guiApp.windowScrollingStart.x = x;
4042 guiApp.windowScrollingStart.y = y;
4043 guiApp.windowScrollingBefore.x = window.scroll.x;
4044 guiApp.windowScrollingBefore.y = window.scroll.y;
4047 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick)
4049 if(window.style.hasMaximize &&
4050 window.IsMouseMoving(
4051 x - window.absPosition.x, y - window.absPosition.y, window.size.w, window.size.h))
4054 (window.state == maximized) ? normal : maximized, false, *mods);
4062 if(guiApp.windowMoving)
4064 if(guiApp.windowMoving.parent)
4066 if(guiApp.windowMoving.style.nonClient)
4067 guiApp.windowMoving.parent.SetMouseRangeToWindow();
4069 guiApp.windowMoving.parent.SetMouseRangeToClient();
4073 window.UpdateDecorations();
4076 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp)
4078 // Log("\n*** LEFT BUTTON UP ***\n");
4079 if(guiApp.windowMoving)
4080 guiApp.windowMoving.StopMoving();
4082 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp)
4084 if(guiApp.windowScrolling)
4086 Window windowScrolling = guiApp.windowScrolling;
4087 guiApp.windowScrolling = null;
4088 windowScrolling.ReleaseCapture();
4092 if(!result || (window && window.destroyed)) window = null;
4094 if(window && window.FindModal())
4097 if(trueWindow && trueWindow.FindModal())
4105 msgWindow = GetAtPosition(x,y, true, false);
4107 msgWindow.SelectMouseCursor();
4110 if(guiApp.windowCaptured || trueWindow)
4112 Window prevWindow = guiApp.prevWindow;
4113 if(guiApp.prevWindow && trueWindow != guiApp.prevWindow)
4115 guiApp.prevWindow.mouseInside = false;
4116 guiApp.prevWindow = null;
4118 // Eventually fix this not to include captured?
4119 if(!prevWindow.OnMouseLeave(*mods))
4122 if(result && trueWindow && !trueWindow.destroyed/* && trueWindow == window*/)
4124 Box box = trueWindow.box;
4125 box.left += trueWindow.absPosition.x;
4126 box.right += trueWindow.absPosition.x;
4127 box.top += trueWindow.absPosition.y;
4128 box.bottom += trueWindow.absPosition.y;
4130 if(box.IsPointInside({x, y}) && trueWindow != /*guiApp.*/prevWindow /*!trueWindow.mouseInside*/)
4132 int overX = x - (trueWindow.absPosition.x + trueWindow.clientStart.x);
4133 int overY = y - (trueWindow.absPosition.y + trueWindow.clientStart.y);
4135 overX = Max(Min(overX, 32767),-32768);
4136 overY = Max(Min(overY, 32767),-32768);
4138 trueWindow.mouseInside = true;
4139 if(!trueWindow.OnMouseOver(overX, overY, *mods))
4143 if(trueWindow && trueWindow._refCount > 1 && !trueWindow.destroyed)
4144 guiApp.prevWindow = trueWindow;
4146 guiApp.prevWindow = null;
4148 SelectMouseCursor();
4150 if(window && !guiApp.windowMoving && !wasMoving && !wasScrolling)
4152 int clientX = x - (window.absPosition.x + window.clientStart.x);
4153 int clientY = y - (window.absPosition.y + window.clientStart.y);
4155 bool (* MouseMethod)(Window instance, int x, int y, Modifiers mods);
4157 clientX = Max(Min(clientX, 32767),-32768);
4158 clientY = Max(Min(clientY, 32767),-32768);
4160 MouseMethod = (void *)window._vTbl[method];
4162 if(MouseMethod /*&& !consequential*/ && !window.disabled)
4165 if(!MouseMethod(window, clientX, clientY, *mods))
4172 if(result && w && w.clickThrough && w.parent)
4177 if(!result || !w || !w.clickThrough)
4184 // --- Mouse cursor management ---
4186 bool KeyMessage(uint method, Key key, unichar character)
4191 if(guiApp.interimWindow)
4192 this = guiApp.interimWindow;
4195 if((SmartKey)key != alt && (SmartKey)key != Key::control && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && parent && this != parent.menuBar)
4199 if(!style.inactive || rootWindow != this)
4201 bool (*KeyMethod)(Window window, Key key, unichar ch) = (void *)_vTbl[method];
4202 Window modalWindow = FindModal();
4203 Window interimMaster = master ? master.rootWindow : null;
4207 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4208 status = OnSysKeyDown(key, character);
4209 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4210 status = OnSysKeyHit(key, character);
4211 else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4212 status = OnSysKeyUp(key, character);
4219 // Process Key Message for Internal UI Keyboard actions
4220 if(status && !destroyed && menuBar && state != minimized)
4223 if((SmartKey)key != alt)
4224 menuBar.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown, 0, 0);
4227 SmartKey sk = (SmartKey) key;
4228 if((character && !key.alt && !key.ctrl) || sk == left || sk == right || sk == up || sk == down || sk == home || sk == end || sk == escape || sk == alt)
4230 status = menuBar.KeyMessage(method, key, character);
4235 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4236 menuBar.OnKeyHit(escape, 0);
4238 if(!menuBar.focus && guiApp.caretOwner)
4239 guiApp.caretOwner.UpdateCaret(true, false);
4242 if(!destroyed && status)
4244 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4248 case left: case up: case right: case down:
4249 if(guiApp.windowMoving == this)
4252 int w = guiApp.windowMoving.size.w;
4253 int h = guiApp.windowMoving.size.h;
4254 int x = guiApp.windowMoving.scrolledPos.x;
4255 int y = guiApp.windowMoving.scrolledPos.y;
4259 if(key == down || key == up)
4260 step = Max(step, textCellH);
4262 step = Max(step, textCellW);
4265 if(guiApp.windowIsResizing)
4269 case left: w-=step; break;
4270 case right: w+=step; break;
4271 case up: h-=step; break;
4272 case down: h+=step; break;
4279 case left: x-=step; break;
4280 case right: x+=step; break;
4281 case up: y-=step; break;
4282 case down: y+=step; break;
4286 if(guiApp.resizeX) x += w - guiApp.windowMoving.size.w;
4287 if(guiApp.resizeY) y += h - guiApp.windowMoving.size.h;
4289 if(!guiApp.windowIsResizing || guiApp.resizeX)
4290 x = (x - guiApp.windowMovingBefore.x) + guiApp.windowMovingStart.x;
4292 x = (w - guiApp.windowResizingBefore.w) + guiApp.windowMovingStart.x;
4294 if(!guiApp.windowIsResizing || guiApp.resizeY)
4295 y = (y - guiApp.windowMovingBefore.y) + guiApp.windowMovingStart.y;
4297 y = (h - guiApp.windowResizingBefore.h) + guiApp.windowMovingStart.y;
4299 guiApp.interfaceDriver.SetMousePosition(x, y);
4300 ConsequentialMouseMove(true);
4308 if(guiApp.windowMoving && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4310 guiApp.windowMoving.StopMoving();
4311 ConsequentialMouseMove(false);
4319 ShowSysMenu(absPosition.x, absPosition.y);
4327 if(!destroyed && status && state != minimized)
4329 // Process all the way down the children
4330 if(activeChild && !activeChild.disabled)
4332 status = activeChild.KeyMessage(method, key, character);
4334 if(status && activeClient && activeChild != activeClient && !activeClient.disabled && (key.alt || key.ctrl) &&
4335 key.code != left && key.code != right && key.code != up && key.code != down)
4337 status = activeClient.KeyMessage(method, key, character);
4341 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4343 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && !defaultControl.disabled && state != minimized)
4344 // && defaultControl != activeChild)
4346 delete previousActive;
4347 previousActive = activeChild;
4348 if(previousActive) incref previousActive;
4350 ConsequentialMouseMove(false);
4351 if((defaultControl.active ||
4352 defaultControl.ActivateEx(true, true, false, true, null, null)) && !defaultControl.disabled)
4353 defaultControl.KeyMessage(method, defaultKey, character);
4359 if(!destroyed && status && (!modalWindow || this == guiApp.desktop))
4361 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4368 ShowSysMenu(absPosition.x, absPosition.y);
4375 if(this != guiApp.desktop)
4377 if(!guiApp.windowMoving && !guiApp.windowCaptured)
4379 if(state != maximized && (key.shift ? style.sizeable : style.fixed))
4381 MenuMoveOrSize(key.shift, true);
4385 else if(guiApp.windowMoving)
4387 guiApp.windowMoving.StopMoving();
4388 ConsequentialMouseMove(false);
4396 if(!destroyed && status && state != minimized)
4398 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4402 case tab: case shiftTab:
4404 Window cycleParent = this;
4405 if(this == guiApp.interimWindow && !master.style.interim && !cycleParent.style.tabCycle)
4406 cycleParent = master.parent;
4408 if(!guiApp.windowCaptured && cycleParent.style.tabCycle)
4410 if(cycleParent.CycleChildren(!key.shift, false, false, true))
4412 Window child = cycleParent.activeChild;
4414 // Scroll the window to include the active control
4416 if(cycleParent.sbh && !child.style.dontScrollHorz)
4418 if(child.scrolledPos.x < 0)
4419 cycleParent.sbh.Action(Position,
4420 cycleParent.scroll.x + child.scrolledPos.x, 0);
4421 else if(child.scrolledPos.x + child.size.w > cycleParent.clientSize.w)
4422 cycleParent.sbh.Action(Position,
4423 cycleParent.scroll.x + child.scrolledPos.x + child.size.w - cycleParent.clientSize.w, 0);
4425 if(cycleParent.sbv && !child.style.dontScrollVert)
4427 if(child.scrolledPos.y < 0)
4428 cycleParent.sbv.Action(Position,
4429 cycleParent.scroll.y + child.scrolledPos.y, 0);
4430 else if(child.scrolledPos.y + child.size.w > window.clientSize.h)
4431 cycleParent.sbv.Action(Position,
4432 cycleParent.scroll.y + child.scrolledPos.y+child.size.h - cycleParent.clientSize.h, 0);
4435 cycleParent.ConsequentialMouseMove(false);
4441 case f6: case shiftF6:
4442 if(!guiApp.windowMoving /*!guiApp.windowCaptured*/)
4444 // NOT NEEDED... guiApp.windowMoving.ReleaseCapture();
4445 if(parent == guiApp.desktop)
4446 if(guiApp.desktop.CycleChildren(key.shift, true, false, true))
4451 if(style.tabCycle ||
4452 CycleChildren(key.shift, true, false, true))
4460 // mIRC Style Window Shortcuts
4461 case alt1: case alt2: case alt3: case alt4: case alt5:
4462 case alt6: case alt7: case alt8: case alt9: case alt0:
4467 for(document = children.first; document; document = document.next)
4469 if(document.style.isDocument && document.documentID - 1 == key.code - k1)
4471 if(document == activeChild)
4473 if(document.state == minimized)
4474 document.SetState(normal, false, key);
4477 document.SetState(minimized, false, key);
4478 CycleChildren(false, true, false);
4483 if(activeChild.state == maximized && document.style.hasMaximize)
4484 document.SetState(maximized, false, key);
4485 else if(document.state == minimized)
4486 document.SetState(normal, false, key);
4487 document.Activate();
4502 if(!destroyed && status)
4504 if(state == minimized)
4509 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4511 if((SmartKey)key == enter && !key.alt && !key.ctrl && defaultControl && previousActive)
4513 if(defaultControl.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, key, character))
4514 previousActive.ActivateEx(true, false, false, true, null, null);
4515 delete previousActive;
4521 if(!destroyed && status)
4523 status = ProcessHotKeys(method, key, character);
4525 if(!destroyed && status && !modalWindow && state != minimized)
4528 status = KeyMethod(this, key, character);
4529 if(!destroyed && status && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown)
4530 status = OnKeyHit(key, character);
4531 if(!destroyed && status && (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown || method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit))
4533 bool result = false;
4536 case ctrlUp: case ctrlDown:
4537 if(sbv && !guiApp.windowScrolling)
4538 result = sbv.Action((key == ctrlUp) ? up : down, 0, key);
4540 case wheelUp: case wheelDown:
4541 if(sbv && !guiApp.windowScrolling)
4543 result = sbv.Action((key == wheelUp) ? wheelUp : wheelDown, 0, key);
4544 // Do we want to do a consequential move regardless of result in this case?
4545 ConsequentialMouseMove(false);
4548 case ctrlPageUp: case ctrlPageDown:
4549 if(sbh && !guiApp.windowScrolling)
4550 result = sbh.Action((key == ctrlPageUp) ? up : down, 0, key);
4555 ConsequentialMouseMove(false);
4560 if(status && !destroyed && menuBar && state != minimized)
4561 status = menuBar.KeyMessage(method, key, character);
4563 if(style.interim && /*destroyed && */status && interimMaster)
4565 // Testing this... for Ctrl-O to open dialog when autocompletion listbox is popped...
4566 status = interimMaster.KeyMessage(method, key, character);
4573 bool ProcessHotKeys(uint method, Key key, unichar character)
4578 for(hotKey = hotKeys.first; hotKey; hotKey = hotKey.next)
4579 if((hotKey.key == key || (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp && hotKey.key.code == key.code)) &&
4580 !hotKey.window.disabled && (hotKey.window.style.nonClient || state != minimized))
4582 Window hotKeyWindow = hotKey.window;
4583 Window parent = hotKeyWindow.parent;
4584 Window prevActiveWindow = activeChild;
4586 // Don't process non-visible buttons, but make an exception for the Alt-F4 with Native Decorations turned on
4587 if(hotKeyWindow.style.hidden && (!hotKeyWindow.style.nonClient || !parent || !parent.nativeDecorations || (hotKeyWindow != parent.sysButtons[2] && hotKeyWindow != parent.sysButtons[1] )))
4590 if(prevActiveWindow) incref prevActiveWindow;
4591 incref hotKeyWindow;
4592 if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown && !hotKeyWindow.style.nonClient)
4593 if(!hotKeyWindow.ActivateEx(true, true, false, true, null, null))
4596 delete hotKeyWindow;
4597 delete prevActiveWindow;
4601 if(hotKeyWindow.style.nonClient && method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)
4602 method = __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown;
4603 if(!hotKeyWindow.KeyMessage(method, Key::hotKey, character))
4605 // ********* WORKING ON THIS ***********
4606 if(prevActiveWindow && !guiApp.interimWindow)
4607 prevActiveWindow.ActivateEx(true, false, false, false, null, null);
4610 else if(hotKeyWindow.style.inactive)
4611 status = hotKeyWindow.KeyMessage(__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp, Key::hotKey, character);
4613 delete prevActiveWindow;
4614 delete hotKeyWindow;
4615 // For Key Ups, don't set status to false... (e.g.: Releasing Enter vs AltEnter hot key)
4616 if(method != __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp)
4620 if(status && tabCycle)
4623 for(child = children.first; child; child = child.next)
4625 if(child.tabCycle && !child.ProcessHotKeys(method, key, character))
4636 // --- Windows and graphics initialization / termination ---
4637 bool SetupRoot(void)
4641 // Setup relationship with outside world (bb root || !bb)
4642 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || this == guiApp.desktop ||
4643 (_displayDriver && dispDriver != parent.dispDriver))
4647 tempExtents = new0 Extent[4];
4652 /*if(guiApp.fullScreenMode)
4653 rootWindow = guiApp.desktop;
4655 //rootWindow = parent.created ? parent.rootWindow : null;
4656 rootWindow = parent.rootWindow;
4659 against = &parent.box;
4661 against = &parent.clientArea;
4664 for(child = children.first; child; child = child.next)
4667 return (rootWindow && (rootWindow == this || rootWindow.created)) ? true : false;
4670 bool Setup(bool positionChildren)
4672 bool result = false;
4675 if((!guiApp.fullScreenMode && parent == guiApp.desktop) || (guiApp.fullScreenMode && (this == guiApp.desktop || (_displayDriver && dispDriver != parent.dispDriver))))
4677 subclass(DisplayDriver) dDriver = (dispDriver && !formDesigner) ? dispDriver : GetDisplayDriver(guiApp.defaultDisplayDriver);
4678 DisplaySystem displaySystem = dDriver ? dDriver.displaySystem : null;
4680 windowHandle = dDriver.printer ? null : guiApp.interfaceDriver.CreateRootWindow(this);
4682 // This was here, is it really needed?
4683 //guiApp.interfaceDriver.ActivateRootWindow(this);
4687 displaySystem = DisplaySystem {};
4688 if(!displaySystem.Create(dDriver.name, guiApp.fullScreenMode ? windowHandle : windowHandle /*null*/, guiApp.fullScreenMode))
4690 delete displaySystem;
4695 display = Display { alphaBlend = alphaBlend, useSharedMemory = useSharedMemory, windowDriverData = windowData };
4696 if(display.Create(displaySystem, windowHandle))
4703 guiApp.interfaceDriver.SetIcon(this, icon);
4705 else if(this != guiApp.desktop)
4707 display = rootWindow ? rootWindow.display : null;
4713 if(guiApp.acquiredWindow && rootWindow == guiApp.acquiredWindow.rootWindow)
4714 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, true);
4716 for(child = children.first; child; child = child.next)
4718 if(child.created && !child.Setup(false))
4724 bool SetupDisplay(void)
4726 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
4727 if(is3D) return Window3D_SetupDisplay(this); else
4734 class_data void ** pureVTbl;
4736 bool LoadGraphics(bool creation, bool resetAnchors)
4738 bool result = false;
4739 bool success = false;
4741 WindowState stateBackup = state;
4744 if(!rootWindow.created)
4748 if(((subclass(Window))_class).pureVTbl)
4750 if(_vTbl == _class._vTbl)
4752 _vTbl = ((subclass(Window))_class).pureVTbl;
4757 for(m = 0; m < _class.vTblSize; m++)
4759 if(_vTbl[m] == _class._vTbl[m])
4760 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
4764 if(guiApp.currentSkin && ((subclass(Window))_class).pureVTbl)
4766 if(_vTbl == ((subclass(Window))_class).pureVTbl)
4768 _vTbl = _class._vTbl;
4773 for(m = 0; m < _class.vTblSize; m++)
4775 if(_vTbl[m] == ((subclass(Window))_class).pureVTbl[m])
4776 _vTbl[m] = _class._vTbl[m];
4781 if(guiApp.fullScreenMode || this != guiApp.desktop)
4783 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
4789 display.Lock(false);
4790 if(rootWindow == this)
4792 // Set Color Palette
4793 display.SetPalette(palette, true);
4797 if(guiApp.fullScreenMode && this == guiApp.desktop)
4802 for(c=0; c<SystemCursor::enumSize; c++)
4803 if(!guiApp.systemCursors[c].bitmap)
4805 guiApp.systemCursors[c].bitmapName = guiApp.currentSkin.CursorsBitmaps(c,
4806 &guiApp.systemCursors[c].hotSpotX,&guiApp.systemCursors[c].hotSpotY, &guiApp.systemCursors[c].paletteShades);
4807 if(guiApp.systemCursors[c].bitmapName)
4809 guiApp.systemCursors[c].bitmap = eBitmap_LoadT(guiApp.systemCursors[c].bitmapName, null,
4810 guiApp.systemCursors[c].paletteShades ? null : guiApp.desktop.display.displaySystem);
4811 if(guiApp.systemCursors[c].bitmap)
4812 guiApp.systemCursors[c].bitmap.paletteShades = guiApp.systemCursors[c].paletteShades;
4817 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
4819 cursor.bitmap = eBitmap_LoadT(cursor.bitmapName, null,
4820 cursor.paletteShades ? null : guiApp.desktop.display.displaySystem);
4822 cursor.bitmap.paletteShades = cursor.paletteShades;
4826 guiApp.cursorUpdate = true;
4829 ConsequentialMouseMove(false);
4835 // Load Window Graphic Resources
4838 if(usedFont == setFont || usedFont == window.systemFont)
4839 RemoveResource(usedFont);
4842 RemoveResource(setFont); // TESTING setFont instead of usedFont);
4845 RemoveResource(systemFont);
4848 RemoveResource(captionFont);
4850 for(ptr = resources.first; ptr; ptr = ptr.next)
4852 ptr.loaded = display.displaySystem.LoadResource(ptr.resource);
4855 AddResource(setFont);
4857 AddResource(systemFont);
4859 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
4866 //if(master && master.font)
4867 if(parent && parent.font)
4871 faceName = parent.font.faceName,
4872 size = parent.font.size,
4873 bold = parent.font.bold,
4874 italic = parent.font.italic,
4875 underline = parent.font.underline
4877 //font = parent.font;
4878 watch(parent) { font { } };
4881 font = guiApp.currentSkin.SystemFont();
4888 captionFont = guiApp.currentSkin.CaptionFont();
4889 AddResource(captionFont);
4891 if(OnLoadGraphics())
4897 //SetScrollLineStep(sbStep.x, sbStep.y);
4899 if(this != guiApp.desktop)
4903 normalAnchor = anchor;
4904 normalSizeAnchor = sizeAnchor;
4907 // Break the anchors for moveable/resizable windows
4909 if(style.fixed && style.isDocument)
4911 ComputeAnchors(ax, ay, aw, ah, &x, &y, &w, &h);
4923 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
4924 stateSizeAnchor = SizeAnchor {};
4929 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
4934 left = (iconID % maxIcons) * MINIMIZED_WIDTH,
4935 bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24)
4938 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
4942 stateAnchor = normalAnchor;
4943 stateSizeAnchor = normalSizeAnchor;
4946 position = Point { };
4947 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
4958 if(Position(x, y, w, h, true, false, true, true, true, true))
4960 if((this != guiApp.desktop || guiApp.fullScreenMode) && rootWindow == this)
4963 guiApp.interfaceDriver.SetRootWindowState(this, normal, true);
4980 success = result = true;
4983 if(!creation && result)
4985 // Load menu bar first because sys buttons are on it...
4988 if(!menuBar.LoadGraphics(false, resetAnchors))
4994 for(child = children.first; child; child = child.next)
4996 if(child.created && child != menuBar && !child.LoadGraphics(false, resetAnchors))
5003 CreateSystemChildren();
5007 if(this == guiApp.desktop && !guiApp.fullScreenMode)
5010 guiApp.interfaceDriver.ActivateRootWindow(activeChild);
5015 //guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, caption);
5016 guiApp.LogErrorCode(IERR_GRAPHICS_LOADING_FAILED, class.name);
5019 // Do this here to avoid problems on Windows
5020 if(stateBackup == maximized)
5021 property::state = maximized;
5025 void UnloadGraphics(bool destroyWindows)
5029 // Free children's graphics
5030 for(child = children.first; child; child = child.next)
5031 child.UnloadGraphics(destroyWindows);
5034 display.Lock(false);
5037 if(guiApp.fullScreenMode && this == guiApp.desktop)
5042 for(c=0; c<SystemCursor::enumSize; c++)
5043 if(guiApp.systemCursors[c].bitmap)
5044 delete guiApp.systemCursors[c].bitmap;
5046 for(cursor = guiApp.customCursors.first; cursor; cursor = cursor.next)
5047 delete cursor.bitmap;
5049 guiApp.cursorBackground.Free();
5052 if(display && display.displaySystem)
5056 for(ptr = resources.first; ptr; ptr = ptr.next)
5060 display.displaySystem.UnloadResource(ptr.resource, ptr.loaded);
5065 // Free window graphics
5068 // Free skin graphics
5069 if(rootWindow == this)
5071 DisplaySystem displaySystem = display.displaySystem;
5074 display.driverData = null;
5075 display.displaySystem = null;
5079 if(displaySystem && !displaySystem.numDisplays && !is3D)
5080 delete displaySystem;
5089 if(guiApp.acquiredWindow && this == guiApp.acquiredWindow.rootWindow)
5090 guiApp.interfaceDriver.AcquireInput(guiApp.acquiredWindow.rootWindow, false);
5092 if(this == guiApp.desktop || parent == guiApp.desktop)
5094 if((guiApp.fullScreenMode || this != guiApp.desktop) && rootWindow == this && windowHandle && destroyWindows)
5095 guiApp.interfaceDriver.DestroyRootWindow(this);
5099 // --- Window Hiding ---
5101 void SetVisibility(bool state)
5103 bool visible = (style.hidden || !created) ? false : state;
5104 if(visible != this.visible)
5108 this.visible = visible;
5109 for(child = children.first; child; child = child.next)
5110 child.SetVisibility(visible);
5112 ConsequentialMouseMove(false);
5116 // --- Windows and graphics initialization / termination ---
5118 bool DisplayModeChanged(void)
5120 bool result = false;
5121 if(!guiApp.fullScreenMode && !guiApp.modeSwitching/* && guiApp.desktop.active*/)
5123 guiApp.modeSwitching = true;
5124 UnloadGraphics(false);
5126 if(LoadGraphics(false, false))
5128 guiApp.modeSwitching = false;
5133 // --- Window updates system ---
5135 void UpdateDirty(Box updateBox)
5137 if(!manageDisplay) { OnRedraw(null);return; }
5140 if(display && (!guiApp.fullScreenMode || guiApp.desktop.active) && !guiApp.modeSwitching)
5143 if(display.flags.flipping)
5146 rootWindow.UpdateDisplay();
5149 UpdateBackDisplay(updateBox);
5151 if(guiApp.fullScreenMode)
5153 guiApp.cursorUpdate = true;
5154 guiApp.PreserveAndDrawCursor();
5156 if(guiApp.fullScreenMode)
5157 guiApp.RestoreCursorBackground();
5163 // This function is strictly called as a result of system window activation
5164 bool ExternalActivate(bool active, bool activateRoot, Window window, Window swap)
5167 Window interimMaster = null;
5168 Window interimWindow = guiApp.interimWindow;
5169 if(interimWindow && interimWindow.master)
5170 interimMaster = interimWindow.master.rootWindow;
5172 if(active && state == minimized) // && (!window.nativeDecorations || window.rootWindow != window)
5173 // SetState(normal, false, 0);
5174 SetState(lastState, false, 0);
5176 if(interimMaster && swap == interimMaster && interimMaster.IsSlaveOf(window))
5180 /* WTH is this doing here?
5181 while(swap && swap.activeChild)
5183 swap = swap.activeChild;
5186 // TESTING THIS BEFORE...
5187 if(interimWindow && this == interimMaster)
5191 // Window interimSwap = this;
5192 Window menuBar = this.menuBar;
5193 if(menuBar && interimWindow.master == menuBar)
5196 while(interimSwap && interimSwap.activeChild)
5197 interimSwap = interimSwap.activeChild;
5199 result = interimWindow.ActivateEx(false, false, false, activateRoot, null,
5200 (menuBar && interimWindow.master == menuBar) ? menuBar : interimSwap);
5202 result = /*interimWindow.*/ActivateEx(false, false, false, activateRoot, null, menuBar);
5203 //result = ActivateEx(true, true, false, activateRoot, window, null);
5208 // Testing & FindModal() here: broke reactivating when a modal dialog is up (didn't root activate dialog)
5209 result = ActivateEx(active, active, false, activateRoot /*&& FindModal()*/, window, swap);
5211 if(interimWindow == this && interimMaster && !active)
5213 while(interimMaster && interimMaster.interim && interimMaster.master)
5215 // printf("Going up one master %s\n", interimMaster._class.name);
5216 interimMaster = interimMaster.master.rootWindow;
5218 // printf("Unactivating interim master %s (%x)\n", interimMaster._class.name, interimMaster);
5219 interimMaster.ActivateEx(active, active, false, activateRoot, window, swap);
5225 bool DestroyEx(int returnCode)
5228 Timer timer, nextTimer;
5230 OldLink prevOrder = null;
5231 Window client = null;
5233 if(parent) stopwatching(parent, font);
5235 // if(window.modalSlave) return false;
5236 if(destroyed || !created)
5243 OldLink slave = master.slaves.FindLink(this);
5244 master.slaves.Delete(slave);
5247 // TOFIX IMMEDIATELY: COMMENTED THIS OUT... causes problem second time creating file dialog
5253 this.returnCode = (DialogResult)returnCode;
5255 AcquireInput(false);
5260 master.hotKeys.Delete(hotKey);
5264 if(guiApp.prevWindow == this)
5266 guiApp.prevWindow = null;
5269 if(guiApp.caretOwner == this)
5271 guiApp.interfaceDriver.SetCaret(0,0,0);
5272 UpdateCaret(false, true);
5273 guiApp.caretEnabled = false;
5278 parent.childrenCycle.Remove(cycle);
5282 OldLink tmpPrev = order.prev;
5283 if(tmpPrev && !(((Window)tmpPrev.data).style.hidden) && !(((Window)tmpPrev.data).destroyed) && (((Window)tmpPrev.data).created))
5284 prevOrder = tmpPrev;
5287 client = tmpPrev ? tmpPrev.data : null;
5288 if(client == this) { client = null; break; }
5289 if(client && (client.style.hidden || client.destroyed || !client.created))
5290 tmpPrev = client.order.prev;
5294 prevOrder = tmpPrev;
5299 // If this window can be an active client, make sure the next window we activate can also be one
5300 if(!style.nonClient && style.isActiveClient)
5302 tmpPrev = prevOrder;
5305 client = tmpPrev ? tmpPrev.data : null;
5306 if(client == this) { client = null; break; }
5307 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
5308 tmpPrev = client.order.prev;
5312 prevOrder = tmpPrev;
5316 if(client && client.style.hidden) client = null;
5318 // parent.childrenOrder.Remove(order);
5321 if(parent && style.isActiveClient && visible)
5323 if(state == minimized) parent.numIcons--;
5324 parent.numPositions--;
5327 // TESTING THIS HERE!
5331 // If no display, don't bother deactivating stuff (causes unneeded problems when trying
5332 // to create a window inside a rootwindow that's being destroyed)
5333 // DISABLED THIS BECAUSE OF CREATING WINDOW IN DESKTOP IN WINDOWED MODE
5335 if(master && !master.destroyed /*&&
5336 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5338 if(master.defaultControl == this)
5339 master.defaultControl = null;
5341 if(parent && !parent.destroyed /*&&
5342 rootWindow && rootWindow.display && !rootWindow.destroyed*/)
5344 if((parent.activeChild == this /*|| parent.activeClient == this */|| guiApp.interimWindow == this))
5346 if(order && prevOrder && prevOrder.data != this && active)
5348 //((Window)prevOrder.data).ActivateEx(true, false, false, false /*true*/, null);
5350 ((Window)prevOrder.data).ActivateEx(true, false, false, (rootWindow == this) ? true : false, null, null);
5351 if(parent.activeClient == this)
5353 parent.activeClient = null;
5354 parent.UpdateActiveDocument(null);
5359 if(guiApp.interimWindow == this)
5362 PropagateActive(false, null, &goOn, true);
5366 //if(window.parent.activeChild == window)
5367 parent.activeChild = null;
5368 if(!style.nonClient /*&& style.isActiveClient*/)
5370 Window previous = parent.activeClient;
5371 if(style.isActiveClient)
5372 parent.activeClient = null;
5373 parent.UpdateActiveDocument(previous);
5378 else if(parent.activeClient == this)
5380 parent.activeClient = client;
5381 parent.UpdateActiveDocument(this);
5385 if(guiApp.interimWindow == this)
5387 guiApp.interimWindow = null;
5388 if(guiApp.caretOwner)
5390 Window desktop = guiApp.desktop;
5391 if(desktop.activeChild && desktop.activeChild.menuBar && !desktop.activeChild.menuBar.focus)
5392 guiApp.caretOwner.UpdateCaret(false, false);
5397 if(_isModal && master && master.modalSlave == this)
5398 master.modalSlave = null;
5402 if(!guiApp.caretOwner && parent.caretSize)
5404 guiApp.caretOwner = parent;
5405 parent.UpdateCaret(false, false);
5406 parent.Update(null);
5409 // Why was this commented out?
5410 GetRidOfVirtualArea();
5416 dirtyArea.Free(null);
5417 dirtyBack.Free(null);
5418 scrollExtent.Free(null);
5420 /* ATTEMPTING TO MOVE THAT ABOVE
5429 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5430 for(;(child = window.children.first);)
5432 for(; child && (child.destroyed || !child.created); child = child.next);
5441 UnloadGraphics(true);
5444 delete previousActive;
5447 // statusBar = null;
5450 if(master && !master.destroyed)
5452 //master.NotifyDestroyed(this, this.returnCode);
5453 NotifyDestroyed(master, this, this.returnCode);
5456 for(timer = guiApp.windowTimers.first; timer; timer = nextTimer)
5458 nextTimer = timer.next;
5459 if(timer.window == this)
5461 // WHY WERE WE SETTING THIS TO NULL? NO MORE WINDOW WHEN RECREATING...
5462 // timer.window = null;
5468 if(this == guiApp.windowMoving)
5471 if(guiApp.windowCaptured == this)
5473 //guiApp.windowCaptured = null;
5475 if(rootWindow != this && rootWindow)
5476 rootWindow.ConsequentialMouseMove(false);
5484 //for(child = children.first; next = child ? child.next : null, child; child = next)
5485 for(;(child = children.first); )
5487 for(; child && (child.destroyed || !child.created); child = child.next);
5497 /* // MOVED THIS UP...
5500 //for(child = window.children.first; next = child ? child.next : null, child; child = next)
5501 for(;(child = window.children.first); )
5503 for(; child && (child.destroyed || !child.created); child = child.next);
5512 while((slave = slaves.first))
5514 for(; slave && (((Window)slave.data).destroyed || !((Window)slave.data).created); slave = slave.next);
5516 ((Window)slave.data).DestroyEx(0);
5521 if(guiApp.caretOwner == this)
5522 guiApp.caretOwner = null;
5524 sysButtons[0] = null;
5525 sysButtons[1] = null;
5526 sysButtons[2] = null;
5529 if(rootWindow != this)
5531 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
5534 box.left -= parent.clientStart.x;
5535 box.top -= parent.clientStart.y;
5536 box.right -= parent.clientStart.x;
5537 box.bottom -= parent.clientStart.y;
5539 if(parent) parent.Update(box);
5544 OldLink slave = master.slaves.FindVoid(this);
5545 master.slaves.Delete(slave);
5551 parent.children.Remove(this);
5556 //autoCreate = false;
5559 // SHOULD THIS BE HERE? FIXED CRASH WITH GOTO DIALOG
5560 if(((subclass(Window))_class).pureVTbl)
5562 if(_vTbl == _class._vTbl)
5564 _vTbl = ((subclass(Window))_class).pureVTbl;
5569 for(m = 0; m < _class.vTblSize; m++)
5571 if(_vTbl[m] == _class._vTbl[m])
5572 _vTbl[m] = ((subclass(Window))_class).pureVTbl[m];
5581 void SetStateEx(WindowState newState, bool activate)
5584 WindowState prevState = state;
5588 if(prevState != newState)
5589 lastState = prevState;
5591 if(rootWindow != this || !nativeDecorations)
5593 if(style.isActiveClient && !style.hidden && prevState == minimized)
5596 // This block used to be at the end of the function... moved it for flicker problem in X
5597 // ------------------------------------------------------
5601 stateAnchor = normalAnchor;
5602 stateSizeAnchor = normalSizeAnchor;
5605 stateAnchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
5606 stateSizeAnchor = SizeAnchor {};
5610 int maxIcons = parent.clientSize.w / MINIMIZED_WIDTH;
5613 byte * idBuffer = new0 byte[size];
5615 for(child = parent.children.first; child; child = child.next)
5617 if(child != this && child.state == minimized)
5619 if(child.iconID > size - 2)
5621 idBuffer = renew0 idBuffer byte[size*2];
5622 memset(idBuffer + size, 0, size);
5625 idBuffer[child.iconID] = (byte)bool::true;
5628 for(c = 0; c<size; c++)
5633 if(style.isActiveClient && !style.hidden)
5636 stateAnchor = Anchor { left = (iconID % maxIcons) * MINIMIZED_WIDTH, bottom = (iconID / maxIcons) * (guiApp.textMode ? 16 : 24) };
5637 stateSizeAnchor = SizeAnchor { size.w = MINIMIZED_WIDTH };
5641 // TOCHECK: Why was this here?
5642 //position.x = (tx > 0) ? tx & 0xFFFFF : tx;
5643 //position.y = (ty > 0) ? ty & 0xFFFFF : ty;
5644 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5646 Position(x, y, w, h, true, true, true, true, false, true);
5648 if(!style.inactive && !style.interim && this == parent.activeClient)
5649 parent.UpdateActiveDocument(null);
5652 CreateSystemChildren();
5653 // ------------------------------------------------------
5656 int GetPositionID(Window forChild)
5660 byte * idBuffer = new0 byte[size];
5663 for(child = children.first; child; child = child.next)
5665 if(child.style.isActiveClient && !child.style.hidden && child != forChild)
5667 if(child.positionID > size - 2)
5669 idBuffer = renew0 idBuffer byte[size*2];
5670 memset(idBuffer + size, 0, size);
5673 idBuffer[child.positionID] = (byte)bool::true;
5676 for(c = 0; c<size; c++)
5683 // --- Window related graphics ---
5685 void SetPalette(ColorAlpha * newPalette, bool colorMatch)
5687 palette = newPalette;
5688 if(rootWindow.display)
5689 rootWindow.display.SetPalette(palette, colorMatch);
5692 public bool AcquireInput(bool acquired)
5695 if(acquiredInput != acquired)
5697 if(active || (!visible && creationActivation == activate))
5698 result = AcquireInputEx(acquired);
5703 acquiredInput = acquired ? result : !result;
5708 void ListChildren(ListBox listBox)
5712 for(child = children.first; child; child = child.next)
5714 if(child.cycle && !child.style.nonClient && child.style.isActiveClient && child.visible)
5716 DataRow row = listBox.AddRow();
5717 row.tag = (int)child;
5718 child.FigureCaption(caption);
5719 row.SetData(null, caption);
5724 void UpdateVisual(Box extent)
5726 if(guiApp.driver != null)
5728 if(guiApp.fullScreenMode && guiApp.desktop.display)
5730 guiApp.desktop.mutex.Wait();
5731 guiApp.desktop.display.Lock(true);
5734 if(guiApp.desktop.active)
5736 if(guiApp.desktop.dirty || guiApp.cursorUpdate)
5738 if(guiApp.desktop.display.flags.flipping)
5739 guiApp.desktop.Update(null);
5740 guiApp.desktop.UpdateDisplay();
5741 guiApp.cursorUpdate = true;
5743 if(guiApp.cursorUpdate || guiApp.desktop.dirty)
5745 guiApp.PreserveAndDrawCursor();
5746 // guiApp.desktop.display.ShowScreen();
5747 guiApp.cursorUpdate = false;
5748 guiApp.desktop.dirty = false;
5749 guiApp.RestoreCursorBackground();
5753 guiApp.desktop.display.Unlock();
5754 guiApp.desktop.mutex.Release();
5758 Window rootWindow = this.rootWindow;
5759 rootWindow.mutex.Wait();
5764 guiApp.SignalEvent();
5767 guiApp.waitMutex.Wait();
5768 guiApp.interfaceDriver.Lock(rootWindow);
5769 if(!rootWindow.style.hidden && rootWindow.dirty)
5771 if(rootWindow.display)
5773 rootWindow.UpdateDisplay();
5774 //rootWindow.display.ShowScreen(null);
5776 rootWindow.dirty = false;
5778 guiApp.interfaceDriver.Unlock(rootWindow);
5779 guiApp.waitMutex.Release();
5782 rootWindow.mutex.Release();
5787 void UnlockDisplay(void)
5789 guiApp.interfaceDriver.Unlock(rootWindow);
5792 void LockDisplay(void)
5794 guiApp.interfaceDriver.Lock(rootWindow);
5797 Surface GetSurface(Box box)
5799 return Redraw((box == null) ? this.box : box);
5802 void SetMousePosition(int x, int y)
5804 guiApp.interfaceDriver.SetMousePosition(x + absPosition.x + clientStart.x, y + absPosition.y + clientStart.y);
5808 void IntegrationActivate(bool active)
5810 if(!guiApp.modeSwitching && !guiApp.fullScreenMode)
5812 isForegroundWindow = true;
5813 ActivateEx(active, active, false, false, null, null);
5814 isForegroundWindow = false;
5819 Window QueryCapture(void)
5821 return guiApp.windowCaptured;
5824 int GetDocumentID(void)
5828 byte * idBuffer = new0 byte[size];
5831 for(child = children.first; child; child = child.next)
5833 if(child.style.isDocument)
5835 if(child.documentID-1 > size - 2)
5837 idBuffer = renew0 idBuffer byte[size*2];
5838 memset(idBuffer + size, 0, size);
5841 idBuffer[child.documentID-1] = 1;
5844 for(c = 0; c<size; c++)
5852 void SetInitSize(Size size)
5855 sizeAnchor.size = size;
5856 normalSizeAnchor = sizeAnchor;
5858 // Break the anchors for moveable/resizable windows
5859 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
5861 stateAnchor = normalAnchor;
5862 stateSizeAnchor = normalSizeAnchor;
5864 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
5865 Position(x,y, w, h, true, true, true, true, false, true);
5869 void MenuMoveOrSize(bool resize, bool setCursorPosition)
5871 if(this != guiApp.desktop && state != maximized && (resize ? (state != minimized && style.sizable) : (style.fixed || moveable)))
5873 guiApp.windowIsResizing = resize;
5874 guiApp.windowMoving = this;
5875 guiApp.windowMovingStart = guiApp.movingLast = absPosition;
5876 if(guiApp.windowIsResizing)
5878 guiApp.windowMovingStart.x += size.w - 1;
5879 guiApp.windowMovingStart.y += size.h - 1;
5881 guiApp.windowMovingBefore = scrolledPos;
5882 guiApp.windowResizingBefore = size;
5883 guiApp.windowMoving.UpdateDecorations();
5884 if(guiApp.windowIsResizing)
5885 guiApp.resizeEndX = guiApp.resizeEndY = true;
5887 if(setCursorPosition)
5888 guiApp.interfaceDriver.SetMousePosition(guiApp.windowMovingStart.x, guiApp.windowMovingStart.y);
5892 guiApp.interfaceDriver.GetMousePosition(&x, &y);
5893 guiApp.windowMovingStart.x += x - absPosition.x;
5894 guiApp.windowMovingStart.y += y - absPosition.y;
5897 if(guiApp.windowMoving)
5899 if(guiApp.windowMoving.style.nonClient)
5900 guiApp.windowMoving.parent.SetMouseRangeToWindow();
5902 guiApp.windowMoving.parent.SetMouseRangeToClient();
5907 if(this == rootWindow)
5908 guiApp.interfaceDriver.StartMoving(rootWindow, guiApp.windowMovingStart.x, guiApp.windowMovingStart.y, true);
5916 bool result = false;
5920 else if(guiApp && guiApp.driver != null)
5922 void * systemParent = null;
5923 OldLink slaveHolder;
5925 bool visible = !style.hidden;
5929 systemParent = parent;
5930 parent = guiApp.desktop;
5932 last = parent ? parent.children.last : null;
5934 if((parent && parent != guiApp.desktop && !parent.created) ||
5935 (master && master != guiApp.desktop && !master.created))
5939 property::parent = guiApp.desktop;
5940 if(!master) master = parent;
5942 if(_isModal && master.modalSlave)
5943 property::master = master.modalSlave;
5947 parent.children.Remove(this);
5950 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
5951 if(slaveHolder.data == this)
5953 master.slaves.Delete(slaveHolder);
5958 if(parent == guiApp.desktop && !mutex)
5961 if(style.isDocument)
5964 parent.numDocuments--;
5965 documentID = parent.GetDocumentID();
5968 if(!style.stayOnTop)
5969 for(; last && last.style.stayOnTop; last = last.prev);
5971 parent.children.Insert((last == this) ? null : last, this);
5972 //parent.children.Add(this);
5975 dispDriver = parent.dispDriver;
5978 master.modalSlave = this;
5980 box = Box { MAXINT, MAXINT, MININT, MININT }; //-MAXINT, -MAXINT };
5985 master.slaves.Add(slaveHolder = OldLink { data = this });
5990 master.hotKeys.Add(hotKey = HotKeySlot { key = setHotKey, window = this });
5992 if(style.isDefault && !master.defaultControl)
5993 master.defaultControl = this;
5995 stateAnchor = normalAnchor = anchor;
5996 stateSizeAnchor = normalSizeAnchor = sizeAnchor;
5998 // TOCHECK: Why is this here?
5999 //position.x = (ax > 0) ? ax & 0xFFFFF : ax;
6000 //position.y = (ay > 0) ? ay & 0xFFFFF : ay;
6002 this.visible = false;
6003 style.hidden = true;
6006 // autoCreate = true;
6014 if(parent == guiApp.desktop)
6015 Log("LoadGraphics %s\n", caption);
6017 if(LoadGraphics(true, false))
6025 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
6032 if(style.hasMenuBar /*&& menu*/)
6038 menu = menu, isMenuBar = true, anchor = Anchor { top = 23, left = 1, right = 1 },
6039 interim = false, inactive = true, nonClient = true, size.h = 24
6047 // Create the system buttons
6048 CreateSystemChildren();
6050 UpdateActiveDocument(null);
6052 if(style.isDocument)
6056 MenuItem item = menu.FindItem(MenuFileSave, 0);
6057 if(item) item.disabled = !modifiedDocument && fileName;
6062 if(parent == guiApp.desktop)
6063 Log("Preemptive SetState %s\n", caption);
6066 // Preemptive Set State to ensure proper anchoring
6067 SetStateEx(state, false);
6069 style.hidden = true;
6075 for(child = children.first; child; child = next)
6078 if(!child.created && (child.autoCreate || child.wasCreated))
6085 for(link = slaves.first; link; link = next)
6087 Window slave = link.data;
6089 if(!slave.created && (slave.autoCreate || slave.wasCreated))
6098 if(parent == guiApp.desktop)
6099 Log("Real SetState %s\n", caption);
6102 if(isActiveClient && visible)
6104 parent.numPositions--;
6105 if(state == minimized) parent.numIcons--;
6108 // Real set state & activate for proper display & activation
6109 property::visible = visible;
6110 // SetState(state & 0x00000003, true, 0);
6115 /*if(rootWindow == this)
6116 guiApp.interfaceDriver.ActivateRootWindow(this);
6118 if(creationActivation == activate)
6119 ActivateEx(true, false, true, true, null, null);
6120 else if(creationActivation == flash)
6125 rootWindow.ConsequentialMouseMove(false);
6136 guiApp.LogErrorCode(IERR_WINDOW_CREATION_FAILED, caption);
6142 // Testing this here... Otherwise a failed LoadGraphics stalls the application
6144 //style.hidden = true; // !visible;
6145 style.hidden = !visible;
6146 if(master.modalSlave == this)
6147 master.modalSlave = null;
6154 void WriteCaption(Surface surface, int x, int y)
6157 Interface::WriteKeyedTextDisabled(surface, x,y, caption, hotKey ? hotKey.key : 0, !isEnabled);
6160 void Update(Box region)
6166 rootWindow = this.rootWindow;
6168 // rootWindow.mutex.Wait();
6169 if(!destroyed && visible && display)
6174 // Testing this to avoid repetitve full update to take time...
6175 if(dirtyArea.count == 1)
6177 BoxItem item = (BoxItem)ACCESS_ITEM(dirtyArea, dirtyArea.first);
6178 if(item.box.left <= box.left &&
6179 item.box.top <= box.top &&
6180 item.box.right >= box.right &&
6181 item.box.bottom >= box.bottom)
6183 rootWindow.dirty = true;
6188 if(display.flags.flipping && !rootWindow.dirty)
6190 if(this == rootWindow)
6194 rootWindow.Update(null);
6199 rootWindow.dirty = true;
6204 realBox.left += clientStart.x;
6205 realBox.top += clientStart.y;
6206 realBox.right += clientStart.x;
6207 realBox.bottom += clientStart.y;
6213 if(realBox.right >= realBox.left &&
6214 realBox.bottom >= realBox.top)
6216 // if(!rootWindow.fullRender)
6217 dirtyArea.UnionBox(realBox, rootWindow.tempExtents[0]);
6219 for(child = children.first; child; child = child.next)
6224 box.left -= child.absPosition.x - absPosition.x;
6225 box.top -= child.absPosition.y - absPosition.y;
6226 box.right -= child.absPosition.x - absPosition.x;
6227 box.bottom -= child.absPosition.y - absPosition.y;
6228 if(box.right >= child.box.left && box.left <= child.box.right &&
6229 box.bottom >= child.box.top && box.top <= child.box.bottom)
6231 box.left -= child.clientStart.x;
6232 box.top -= child.clientStart.y;
6233 box.right -= child.clientStart.x;
6234 box.bottom -= child.clientStart.y;
6240 realBox.left += absPosition.x - rootWindow.absPosition.x;
6241 realBox.top += absPosition.y - rootWindow.absPosition.y;
6242 realBox.right += absPosition.x - rootWindow.absPosition.x;
6243 realBox.bottom += absPosition.y - rootWindow.absPosition.y;
6244 rootWindow.dirtyBack.UnionBox(realBox, rootWindow.tempExtents[0]);
6247 else if(this == guiApp.desktop)
6250 for(window = children.first; window; window = window.next)
6256 Box childBox = region;
6258 childBox.left -= window.absPosition.x - guiApp.desktop.absPosition.x;
6259 childBox.top -= window.absPosition.y - guiApp.desktop.absPosition.y;
6260 childBox.right -= window.absPosition.x - guiApp.desktop.absPosition.x;
6261 childBox.bottom -= window.absPosition.y - guiApp.desktop.absPosition.y;
6263 window.Update(childBox);
6266 window.Update(null);
6271 // rootWindow.mutex.Release();
6278 if(guiApp.windowCaptured != this)
6280 if(guiApp.windowCaptured)
6284 //Logf("Captured %s (%s)\n", caption, class.name);
6285 guiApp.interfaceDriver.SetMouseCapture(rootWindow);
6286 guiApp.windowCaptured = this;
6292 bool Destroy(int code)
6297 if(!destroyed && !CloseConfirmation(false)) return false;
6301 // TOCHECK: Should autoCreate be set to false here?
6312 void Move(int x, int y, int w, int h)
6314 normalAnchor = Anchor { left = x, top = y };
6315 normalSizeAnchor = SizeAnchor { size = { w, h } };
6317 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
6319 if(destroyed) return;
6321 stateAnchor = normalAnchor;
6322 stateSizeAnchor = normalSizeAnchor;
6324 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
6325 Position(x,y, w, h, true, true, true, true, false, true);
6329 DialogResult Modal(void)
6335 // FIXES MEMORY LEAK IF Create() FAILED
6341 void SetScrollArea(int width, int height, bool snapToStep)
6343 bool resize = false;
6346 int stepX = sbStep.x, stepY = sbStep.y;
6347 // Needed to make snapped down position match the skin's check of client area
6348 // against realvirtual
6351 SNAPDOWN(stepX, textCellW);
6352 SNAPDOWN(stepY, textCellH);
6353 stepX = Max(stepX, textCellW);
6354 stepY = Max(stepY, textCellH);
6356 if(scrollFlags.snapX)
6357 SNAPUP(width, stepX);
6358 if(scrollFlags.snapY)
6359 SNAPUP(height, stepY);
6362 reqScrollArea.w = width;
6363 reqScrollArea.h = height;
6364 noAutoScrollArea = (width > 0 || height > 0);
6366 UpdateScrollBars(true, true);
6369 void SetScrollPosition(int x, int y)
6372 sbh.Action(setPosition, x, 0);
6376 int seen = clientSize.w, total = reqScrollArea.w;
6378 if(scrollFlags.snapX)
6379 SNAPDOWN(seen, sbStep.x);
6381 if(!total) total = seen;
6382 range = total - seen + 1;
6383 range = Max(range, 1);
6385 if(x >= range) x = range - 1;
6387 if(scrollFlags.snapX)
6388 SNAPUP(x, sbStep.x);
6391 OnHScroll(setPosition, x, 0);
6395 SNAPDOWN(x, textCellW);
6401 sbv.Action(setPosition, y, 0);
6405 int seen = clientSize.h, total = reqScrollArea.h;
6408 if(scrollFlags.snapY)
6409 SNAPDOWN(seen, sbStep.y);
6411 if(!total) total = seen;
6412 range = total - seen + 1;
6413 range = Max(range, 1);
6415 if(y >= range) y = range - 1;
6417 if(scrollFlags.snapY)
6418 SNAPUP(y, sbStep.y);
6421 OnVScroll(setPosition, y, 0);
6424 SNAPDOWN(y, textCellH);
6429 UpdateCaret(false, false);
6432 void SetScrollLineStep(int stepX, int stepY)
6438 SNAPDOWN(stepX, textCellW);
6439 SNAPDOWN(stepY, textCellH);
6440 stepX = Max(stepX, textCellW);
6441 stepY = Max(stepY, textCellH);
6444 sbh.lineStep = stepX;
6446 sbv.lineStep = stepY;
6449 void SetState(WindowState newState, bool activate, Modifiers mods)
6453 if(state == newState || OnStateChange(newState, mods))
6455 WindowState prevState = state;
6459 // This used to be at the end of the brackets... moved for X, testing...
6460 // This has the effect of activating the window through the system...
6461 if(rootWindow == this)
6462 guiApp.interfaceDriver.SetRootWindowState(this, newState, !style.hidden);
6464 SetStateEx(newState, activate);
6466 if(rootWindow == this && !rootWindow.nativeDecorations)
6468 int x = position.x, y = position.y;
6471 x -= guiApp.desktop.absPosition.x;
6472 y -= guiApp.desktop.absPosition.y;
6474 guiApp.interfaceDriver.PositionRootWindow(this, x, y, size.w, size.h, true, true);
6478 //state = prevState;
6480 if(state != maximized && style.hasMaximize)
6483 for(child = parent.children.first; child; child = child.next)
6485 if(child != this && child.state == maximized)
6486 child.SetStateEx(normal, false);
6490 if(!style.nonClient && (sbv || sbh) && this != parent.sbv && this != parent.sbh)
6491 parent.UpdateScrollBars(true, true);
6494 // Do we really need this stuff here?
6495 // Shouldn't the Activate stuff take care of it?
6496 if(parent.rootWindow == parent && style)
6499 parent.FigureCaption(caption);
6500 guiApp.interfaceDriver.SetRootWindowCaption(parent, caption);
6501 parent.UpdateDecorations();
6505 rootWindow.ConsequentialMouseMove(false);
6512 BitmapResource GetIcon(SkinBitmap iconID)
6514 return guiApp.currentSkin.GetBitmap(iconID);
6517 void SetMouseRange(Box range)
6519 if(range || guiApp.fullScreenMode)
6524 clip.left = range.left + absPosition.x + clientStart.x;
6525 clip.top = range.top + absPosition.y + clientStart.y;
6526 clip.right = range.right + absPosition.x + clientStart.x;
6527 clip.bottom = range.bottom + absPosition.y + clientStart.y;
6531 clip.left = guiApp.desktop.box.left;
6532 clip.top = guiApp.desktop.box.top;
6533 clip.right = guiApp.desktop.box.right;
6534 clip.bottom = guiApp.desktop.box.bottom;
6536 guiApp.interfaceDriver.SetMouseRange(rootWindow, clip);
6539 guiApp.interfaceDriver.SetMouseRange(rootWindow, null);
6542 void SetMouseRangeToClient(void)
6544 if(guiApp.fullScreenMode || this != guiApp.desktop)
6546 Box box {0, 0, clientSize.w - 1, clientSize.h - 1 };
6547 box.Clip(clientArea);
6551 SetMouseRange(null);
6554 void SetMouseRangeToWindow(void)
6556 Box box { -clientStart.x, -clientStart.y, size.w-1, size.h-1 };
6557 if(this == guiApp.desktop)
6558 SetMouseRangeToClient();
6563 // x, y: Desktop Coordinates
6564 void ShowSysMenu(int x, int y)
6567 PopupMenu windowMenu { master = this, interim = true, position = { x + 1 - guiApp.desktop.position.x, y + 1 - guiApp.desktop.position.y }, menu = menu };
6570 menu, "Restore", r, NotifySelect = MenuWindowRestore,
6571 disabled = (!style.hasMaximize && !style.hasMinimize) || state == normal, bitmap = guiApp.currentSkin.GetBitmap(restore)
6575 menu, "Move", m, NotifySelect = MenuWindowMove,
6576 disabled = !style.fixed || state == maximized
6580 menu, "Size", s, NotifySelect = MenuWindowSize,
6581 disabled = !style.sizable || state != normal
6585 menu, "Minimize", n, NotifySelect = MenuWindowMinimize,
6586 disabled = !style.hasMinimize || state == minimized, bitmap = guiApp.currentSkin.GetBitmap(minimize)
6590 menu, "Maximize", KeyCode::x, NotifySelect = MenuWindowMaximize,
6591 disabled = !style.hasMaximize || state == maximized, bitmap = guiApp.currentSkin.GetBitmap(maximize)
6595 menu, "Stay On Top", t, NotifySelect = MenuWindowStayOnTop,
6596 disabled = !style.fixed, checkable = true, checked = style.stayOnTop
6598 MenuDivider { menu };
6601 menu, "Close", c, (parent == guiApp.desktop) ? altF4 : ( style.isActiveClient ? ctrlF4 : 0), NotifySelect = MenuWindowClose,
6602 bold = true, disabled = !style.hasClose, bitmap = guiApp.currentSkin.GetBitmap(close)
6604 windowMenu.Create();
6609 ActivateEx(true, true, true, true, null, null);
6612 void MakeActive(void)
6614 ActivateEx(true, false, true, false, null, null);
6617 void SoftActivate(void)
6619 if(guiApp.desktop.active)
6625 void Deactivate(void)
6627 ActivateEx(false, true, true, true, null, null);
6632 guiApp.interfaceDriver.FlashRootWindow(rootWindow);
6635 bool CycleChildren(bool backward, bool clientOnly, bool tabCycleOnly, bool cycleParents)
6637 bool result = false;
6638 if(activeChild && activeChild.cycle)
6640 Window modalWindow, child = activeChild;
6641 if(!clientOnly /*&& parent.tabCycle*/)
6643 Window next = child;
6646 if(next.cycle == (backward ? childrenCycle.first : childrenCycle.last))
6650 if(parent && parent.CycleChildren(backward, false, true, true))
6658 next = next.cycle.prev.data;
6660 next = next.cycle.next.data;
6661 if(!next.disabled && !next.inactive /*isRemote*/ && next.created && !next.nonClient && (!clientOnly || next.style.isActiveClient) && !next.style.hidden && next.FindModal() != activeChild)
6666 if(!clientOnly && child.cycle == (backward ? childrenCycle.first : childrenCycle.last) &&
6667 parent.tabCycle && parent.CycleChildren(backward, false, false))
6671 if(tabCycleOnly && !tabCycle) return false;
6678 child = child.cycle.prev.data;
6680 child = child.cycle.next.data;
6681 if(child == child.parent.activeChild)
6683 else if(!child.disabled && child.created && (!clientOnly || child.style.isActiveClient) && !child.style.hidden && child.FindModal() != activeChild)
6686 modalWindow = child.FindModal();
6689 // Scroll the window to include the active control
6690 if(sbh && !child.style.dontScrollHorz)
6692 if(child.scrolledPos.x < 0)
6693 sbh.Action(setPosition, scroll.x + child.scrolledPos.x, 0);
6694 else if(child.scrolledPos.x + child.size.w > clientSize.w)
6695 sbh.Action(setPosition, scroll.x + child.scrolledPos.x + child.size.w - clientSize.w, 0);
6697 if(sbv && !child.style.dontScrollVert)
6699 if(child.scrolledPos.y < 0)
6700 sbv.Action(setPosition, scroll.y + child.scrolledPos.y, 0);
6701 else if(child.scrolledPos.y + child.size.h > clientSize.h)
6702 sbv.Action(setPosition, scroll.y + child.scrolledPos.y + child.size.h - clientSize.h, 0);
6706 child = modalWindow ? modalWindow : child;
6707 child.ActivateEx(true, true, true, true, null, null);
6708 if(child.tabCycle && child.childrenCycle.first)
6709 child = ((OldLink)(backward ? child.childrenCycle.first : child.childrenCycle.last)).data;
6717 ConsequentialMouseMove(false);
6721 void AddResource(Resource resource)
6725 ResPtr ptr { resource = resource };
6729 // Load Graphics here if window is created already
6730 if(/*created && */display)
6732 display.Lock(false);
6733 ptr.loaded = display.displaySystem.LoadResource(resource);
6737 // Temporary hack to load font right away for listbox in dropbox ...
6738 else if(master && master.display)
6740 master.display.Lock(false);
6741 master.display.displaySystem.LoadResource(resource);
6742 master.display.Unlock();
6748 void RemoveResource(Resource resource)
6753 for(ptr = resources.first; ptr; ptr = ptr.next)
6755 if(ptr.resource == resource)
6761 // Unload Graphics here if window is created already
6762 if(/*created && */display)
6766 display.Lock(false);
6767 display.displaySystem.UnloadResource(resource, ptr.loaded);
6773 resources.Delete(ptr);
6778 void SetCaret(int x, int y, int size)
6785 if(active && !style.interim)
6787 if(visible || !guiApp.caretOwner)
6788 guiApp.caretOwner = size ? this : null;
6790 UpdateCaret(false, false);
6793 guiApp.interfaceDriver.SetCaret(0,0,0);
6794 UpdateCaret(false, true);
6795 guiApp.caretEnabled = false;
6798 else if(style.inactive && active)
6800 guiApp.interfaceDriver.SetCaret(0,0,0);
6801 UpdateCaret(false, true);
6802 guiApp.caretEnabled = false;
6807 void Scroll(int x, int y)
6809 bool opaque = !style.drawBehind || background.a;
6810 if(opaque && display && display.flags.scrolling)
6812 Box box = clientArea;
6813 box.left += clientStart.x;
6814 box.top += clientStart.y;
6815 box.right += clientStart.x;
6816 box.bottom += clientStart.y;
6818 //scrollExtent.Free(null);
6819 scrollExtent.AddBox(box);
6820 scrolledArea.x += x;
6821 scrolledArea.y += y;
6823 //scrollExtent.Free();
6824 //scrollExtent.AddBox(clientArea);
6825 //scrollExtent.Offset(clientStart.x, clientStart.y);
6826 //scrolledArea.x = x;
6827 //scrolledArea.y = y;
6833 rootWindow.dirty = true;
6836 void ReleaseCapture()
6838 if(guiApp && guiApp.windowCaptured && guiApp.windowCaptured == this)
6840 Window oldCaptured = guiApp.windowCaptured;
6841 guiApp.windowCaptured = null;
6842 guiApp.prevWindow = null;
6845 //guiApp.Log("Released Capture\n");
6847 guiApp.interfaceDriver.SetMouseCapture(null);
6849 //oldCaptured.OnMouseCaptureLost();
6852 oldCaptured.ConsequentialMouseMove(false);
6857 void SetText(char * format, ...)
6864 char caption[MAX_F_STRING];
6866 va_start(args, format);
6867 vsprintf(caption, format, args);
6870 this.caption = new char[strlen(caption)+1];
6872 strcpy(this.caption, caption);
6881 bool Grab(Bitmap bitmap, Box box, bool decorations)
6883 bool result = false;
6884 if(display || this == guiApp.desktop)
6886 Box clip = {MININT, MININT, MAXINT, MAXINT};
6892 clip.Clip(clientArea);
6894 clip.Clip(this.box);
6896 if(rootWindow != this)
6898 clip.left += absPosition.y;
6899 clip.top += absPosition.y;
6900 clip.right += absPosition.x;
6901 clip.bottom += absPosition.y;
6904 clip.left += decorations ? 0 : clientStart.x;
6905 clip.top += decorations ? 0 : clientStart.y;
6906 clip.right += decorations ? 0 : clientStart.x;
6907 clip.bottom += decorations ? 0 : clientStart.y;
6909 if(display && display.flags.flipping)
6911 rootWindow.Update(null);
6912 rootWindow.UpdateDisplay();
6919 result = window.display.displaySystem.driver.GrabScreen(null, bitmap, clip.left, clip.top,
6920 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6924 result = display.Grab(bitmap, clip.left, clip.top,
6925 clip.right - clip.left + 1, clip.bottom - clip.top + 1);
6927 if(bitmap.pixelFormat != pixelFormat888 && bitmap.pixelFormat != pixelFormat8)
6929 if(!bitmap.Convert(null, pixelFormat888, null))
6936 void GetMousePosition(int * x, int * y)
6938 int mouseX = 0, mouseY = 0;
6939 if(!guiApp.acquiredWindow && (guiApp.desktop.active || !guiApp.fullScreenMode))
6942 guiApp.interfaceDriver.GetMousePosition(&mouseX, &mouseY);
6943 if(this != guiApp.desktop)
6945 mouseX -= absPosition.x + clientStart.x;
6946 mouseY -= absPosition.y + clientStart.y;
6953 DialogResult DoModal()
6955 DialogResult returnCode = 0;
6956 int terminated = terminateX;
6959 while(!destroyed && guiApp.driver != null)
6961 if(terminateX != terminated)
6963 terminated = terminateX;
6964 guiApp.desktop.Destroy(0);
6965 if(guiApp.desktop.created)
6968 //printf("Resetting terminate X to 0\n");
6974 guiApp.UpdateDisplay();
6975 if(!guiApp.ProcessInput(false))
6978 returnCode = this.returnCode;
6991 return !destroyed && guiApp.driver != null && terminateX < 2;
6994 DialogResult DoModalEnd()
6996 DialogResult returnCode = this.returnCode;
7001 // --- Window manipulation ---
7002 /*bool GetDisabled()
7004 bool disabled = this.disabled;
7006 for(window = this; (window = window.master); )
7017 // --- Mouse Manipulation ---
7018 void GetNCMousePosition(int * x, int * y)
7020 GetMousePosition(x, y);
7021 if(x) *x += clientStart.x;
7022 if(y) *y += clientStart.y;
7025 // --- Carets manipulation ---
7026 void GetCaretPosition(Point caretPos)
7028 caretPos = this.caretPos;
7031 int GetCaretSize(void)
7036 bool ButtonCloseDialog(Button button, int x, int y, Modifiers mods)
7042 bool CloseConfirmation(bool parentClosing)
7055 if(!OnClose(parentClosing))
7058 // If you want to skip this, simply set modifiedDocument to false in OnClose
7059 if(result && (/*fileName || */style.isDocument) && modifiedDocument)
7061 DialogResult dialogRes;
7064 sprintf(message, "Save changes to %s?", fileName);
7066 sprintf(message, "Save changes to Untitled %d?", documentID);
7068 dialogRes = MessageBox { master = master, type = yesNoCancel, text = parent.caption, contents = message }.Modal();
7070 if(dialogRes == yes)
7072 // TOFIX: Precomp error if brackets are taken out
7073 result = (DialogResult)MenuFileSave(null, 0) != cancel;
7075 else if(dialogRes == cancel)
7081 for(slave = slaves.first; slave; slave = slave.next)
7082 if(!((Window)slave.data).CloseConfirmation(true))
7084 // ((Window)slave.data).CloseConfirmation(true);
7092 for(child = children.first; child; child = child.next)
7093 if(child.master != this && !child.CloseConfirmation(true))
7103 // Static methods... move them somewhere else?
7104 void ::RestoreCaret()
7106 if(guiApp.caretOwner)
7107 guiApp.caretOwner.UpdateCaret(false, false);
7110 void ::FreeMouseRange()
7112 guiApp.interfaceDriver.SetMouseRange(null, null);
7116 bool MenuFileClose(MenuItem selection, Modifiers mods)
7118 Window document = activeChild;
7120 document.Destroy(0);
7124 bool MenuFileExit(MenuItem selection, Modifiers mods)
7130 bool MenuFileSave(MenuItem selection, Modifiers mods)
7134 fileMonitor.fileName = null;
7137 if(OnSaveFile(fileName))
7139 //if(OnFileModified != Window::OnFileModified)
7142 fileMonitor.fileName = fileName;
7148 MessageBox dialog { master = master, type = yesNoCancel, text = "Error writing file", contents = "Save as a different file?" };
7149 DialogResult answer = dialog.Modal();
7151 if(answer != yes) return (bool)answer;
7154 return MenuFileSaveAs(selection, mods);
7157 bool MenuFileSaveAs(MenuItem selection, Modifiers mods)
7159 DialogResult result = (DialogResult)bool::true;
7160 FileDialog fileDialog = saveDialog;
7163 fileDialog = FileDialog {};
7168 fileDialog.filePath = fileName;
7171 char filePath[MAX_FILENAME];
7172 sprintf(filePath, "Untitled %d", documentID);
7173 fileDialog.filePath = filePath;
7175 fileMonitor.fileName = null;
7177 fileDialog.type = save;
7178 fileDialog.text = "Save As";
7182 fileDialog.master = master.parent ? master : this;
7183 if(fileDialog.Modal() == ok)
7185 char * filePath = fileDialog.filePath;
7187 if(OnSaveFile(filePath))
7190 property::fileName = filePath;
7191 NotifySaved(master, this, filePath);
7196 MessageBox dialog { master = master.parent ? master : this, type = yesNoCancel, text = "Error writing file", contents = "Save as a different file?" };
7197 DialogResult answer = dialog.Modal();
7212 //if(OnFileModified != Window::OnFileModified && fileName)
7215 fileMonitor.fileName = fileName;
7219 return (bool)result; // Actually returning result from Yes/NoCancel message box
7222 bool MenuFileSaveAll(MenuItem selection, Modifiers mods)
7224 Window document = activeChild;
7226 for(document = children.first; document; document = next)
7228 next = document.next;
7229 if(document.style.isDocument || document.fileName)
7230 document.MenuFileSave(selection, mods);
7235 bool MenuWindowArrangeIcons(MenuItem selection, Modifiers mods)
7239 for(document = children.first; document; document = document.next)
7240 //if(document.style.isDocument && document.state == minimized)
7241 if(document.style.isActiveClient && document.state == minimized)
7242 document.SetState(minimized, false, mods);
7246 bool MenuWindowCascade(MenuItem selection, Modifiers mods)
7248 Window document = activeChild;
7251 Window firstDocument = null;
7253 OldLink cycle = document.cycle.prev;
7258 if(child.style.isActiveClient && !child.style.hidden)
7262 firstDocument = child;
7263 if(child.state == minimized)
7264 child.SetState(minimized, false, mods);
7267 child.positionID = id++;
7268 child.SetState(normal, false, mods);
7269 child.anchor.left.type = cascade;
7272 child.normalSizeAnchor = *&child.sizeAnchor;
7273 child.normalAnchor = child.anchor;
7275 // Break the anchors for moveable/resizable windows
7276 if(child.style.fixed)
7278 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7280 (*&child.normalAnchor).left = x;
7281 (*&child.normalAnchor).top = y;
7282 (*&child.normalAnchor).right.type = none;
7283 (*&child.normalAnchor).bottom.type = none;
7285 child.normalSizeAnchor.isClientW = false;
7286 child.normalSizeAnchor.isClientH = false;
7287 child.normalSizeAnchor.size.w = w;
7288 child.normalSizeAnchor.size.h = h;
7289 child.anchored = false;
7292 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7294 child.stateAnchor = child.normalAnchor;
7295 child.stateSizeAnchor = child.normalSizeAnchor;
7297 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7298 child.Position(x, y, w, h, true, true, true, true, false, false);
7303 last = children.last;
7304 if(!child.style.stayOnTop)
7305 for(; last && last.style.stayOnTop; last = last.prev);
7306 children.Move(child, last);
7307 childrenOrder.Move(child.order, childrenOrder.last);
7309 if(cycle == document.cycle) break;
7313 firstDocument.Activate();
7318 bool MenuWindowClose(MenuItem selection, Modifiers mods)
7325 // Close all closes all active clients, not all documents
7326 bool MenuWindowCloseAll(MenuItem selection, Modifiers mods)
7328 Window next, document;
7330 for(document = children.first; document; document = next)
7332 for(next = document.next; next && !(next.style.isActiveClient; next = next.next);
7333 if(document.style.isActiveClient)
7334 if(!document.Destroy(0) && !document.style.hidden)
7340 bool MenuWindowMaximize(MenuItem selection, Modifiers mods)
7342 if(style.hasMaximize && state != maximized)
7343 SetState(maximized, 0, 0);
7347 bool MenuWindowMinimize(MenuItem selection, Modifiers mods)
7349 if(style.hasMinimize && state != minimized)
7351 SetState(minimized, 0, 0);
7352 parent.CycleChildren(false, true, false, true);
7357 bool MenuWindowMove(MenuItem selection, Modifiers mods)
7359 MenuMoveOrSize(false, selection ? true : false);
7363 bool MenuWindowNext(MenuItem selection, Modifiers mods)
7365 CycleChildren(false, true, false, true);
7369 bool MenuWindowPrevious(MenuItem selection, Modifiers mods)
7371 CycleChildren(true, true, false, true);
7375 bool MenuWindowSize(MenuItem selection, Modifiers mods)
7377 MenuMoveOrSize(true, true);
7381 bool MenuWindowRestore(MenuItem selection, Modifiers mods)
7384 SetState(normal, 0, 0);
7388 bool MenuWindowSelectWindow(MenuItem selection, Modifiers mods)
7391 int id = selection.id;
7392 OldLink cycle = activeClient.cycle;
7394 //for(c = 0, cycle = activeChild.cycle; c<id; cycle = cycle.next, c++);
7397 Window sibling = cycle.data;
7398 if(sibling.style.isActiveClient)
7406 document = cycle.data;
7407 document.Activate();
7409 //if(activeChild.state == maximized)
7410 // document.SetState(maximized, false, mods);
7411 //else if(document.state == minimized)
7412 // document.SetState(normal, false, mods);
7416 bool MenuWindowStayOnTop(MenuItem selection, Modifiers mods)
7418 stayOnTop = !style.stayOnTop;
7422 bool MenuWindowTileHorz(MenuItem selection, Modifiers mods)
7424 Window document = activeChild;
7427 Window firstDocument = null;
7428 OldLink cycle = document.cycle;
7432 Window child = cycle.data;
7433 if(child.style.isActiveClient && !child.style.hidden)
7435 if(!firstDocument) firstDocument = child;
7436 if(child.state == minimized)
7437 child.SetState(minimized, false, mods);
7440 child.positionID = id++;
7441 child.SetState(normal, false, mods);
7442 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7444 child.anchor.left.type = hTiled;
7447 child.normalSizeAnchor = *&child.sizeAnchor;
7448 child.normalAnchor = child.anchor;
7450 // Break the anchors for moveable/resizable windows
7451 if(child.style.fixed)
7453 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7455 (*&child.normalAnchor).left = x;
7456 (*&child.normalAnchor).top = y;
7457 (*&child.normalAnchor).right.type = none;
7458 (*&child.normalAnchor).bottom.type = none;
7459 child.normalSizeAnchor.isClientW = false;
7460 child.normalSizeAnchor.isClientH = false;
7461 child.normalSizeAnchor.size.w = w;
7462 child.normalSizeAnchor.size.h = h;
7463 child.anchored = false;
7466 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7468 child.stateAnchor = child.normalAnchor;
7469 child.stateSizeAnchor = child.normalSizeAnchor;
7471 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7472 child.Position(x,y, w, h, true, true, true, true, false, true);
7477 if((cycle = cycle.next) == document.cycle) break;
7480 firstDocument.Activate();
7485 bool MenuWindowTileVert(MenuItem selection, Modifiers mods)
7487 Window document = activeChild;
7490 Window firstDocument = null;
7492 OldLink cycle = document.cycle;
7497 //if(child.style.isDocument)
7498 if(child.style.isActiveClient && !child.style.hidden)
7500 if(!firstDocument) firstDocument = child;
7501 if(child.state == minimized)
7502 child.SetState(minimized, false, mods);
7505 child.positionID = id++;
7506 child.SetState(normal, false, mods);
7507 child.ActivateEx(true, false, false, false, null, null); // To move active clients on top of other windows
7509 child.anchor.left.type = vTiled;
7512 child.normalSizeAnchor = *&child.sizeAnchor;
7513 child.normalAnchor = child.anchor;
7515 // Break the anchors for moveable/resizable windows
7516 if(child.style.fixed)
7518 child.ComputeAnchors(child.anchor, *&child.sizeAnchor, &x, &y, &w, &h);
7520 (*&child.normalAnchor).left = x;
7521 (*&child.normalAnchor).top = y;
7522 (*&child.normalAnchor).right.type = none;
7523 (*&child.normalAnchor).bottom.type = none;
7524 child.normalSizeAnchor.isClientW = false;
7525 child.normalSizeAnchor.isClientH = false;
7526 child.normalSizeAnchor.size.w = w;
7527 child.normalSizeAnchor.size.h = h;
7528 child.anchored = false;
7531 if(child.state == normal /*|| child.state == Hidden */) // Hidden is new here ...
7533 child.stateAnchor = child.normalAnchor;
7534 child.stateSizeAnchor = child.normalSizeAnchor;
7536 child.ComputeAnchors(child.stateAnchor, child.stateSizeAnchor, &x, &y, &w, &h);
7537 child.Position(x,y, w, h, true, true, true, true, false, true);
7542 if((cycle = cycle.next) == document.cycle) break;
7545 firstDocument.Activate();
7550 bool MenuWindowWindows(MenuItem selection, Modifiers mods)
7552 WindowList dialog { master = this };
7553 Window document = (Window)dialog.Modal();
7556 if(activeChild.state == maximized)
7557 document.SetState(maximized, false, mods);
7558 else if(document.state == minimized)
7559 document.SetState(normal, false, mods);
7560 document.Activate();
7566 virtual bool OnCreate(void);
7567 virtual void OnDestroy(void);
7568 virtual void OnDestroyed(void);
7569 virtual bool OnClose(bool parentClosing);
7570 virtual bool OnStateChange(WindowState state, Modifiers mods);
7571 virtual bool OnPostCreate(void);
7572 virtual bool OnMoving(int *x, int *y, int w, int h);
7573 virtual bool OnResizing(int *width, int *height);
7574 virtual void OnResize(int width, int height);
7575 virtual void OnPosition(int x, int y, int width, int height);
7576 virtual bool OnLoadGraphics(void);
7577 virtual void OnApplyGraphics(void);
7578 virtual void OnUnloadGraphics(void);
7579 virtual void OnRedraw(Surface surface);
7580 virtual bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct);
7581 virtual void OnActivateClient(Window client, Window previous);
7582 virtual bool OnKeyDown(Key key, unichar ch);
7583 virtual bool OnKeyUp(Key key, unichar ch);
7584 virtual bool OnKeyHit(Key key, unichar ch);
7585 virtual bool OnSysKeyDown(Key key, unichar ch);
7586 virtual bool OnSysKeyUp(Key key, unichar ch);
7587 virtual bool OnSysKeyHit(Key key, unichar ch);
7588 virtual bool OnMouseOver(int x, int y, Modifiers mods);
7589 virtual bool OnMouseLeave(Modifiers mods);
7590 virtual bool OnMouseMove(int x, int y, Modifiers mods);
7591 virtual bool OnLeftButtonDown(int x, int y, Modifiers mods);
7592 virtual bool OnLeftButtonUp(int x, int y, Modifiers mods);
7593 virtual bool OnLeftDoubleClick(int x, int y, Modifiers mods);
7594 virtual bool OnRightButtonDown(int x, int y, Modifiers mods);
7595 virtual bool OnRightButtonUp(int x, int y, Modifiers mods);
7596 virtual bool OnRightDoubleClick(int x, int y, Modifiers mods);
7597 virtual bool OnMiddleButtonDown(int x, int y, Modifiers mods);
7598 virtual bool OnMiddleButtonUp(int x, int y, Modifiers mods);
7599 virtual bool OnMiddleDoubleClick(int x, int y, Modifiers mods);
7600 virtual void OnMouseCaptureLost(void);
7601 virtual void OnHScroll(ScrollBarAction action, int position, Key key);
7602 virtual void OnVScroll(ScrollBarAction action, int position, Key key);
7603 virtual void OnDrawOverChildren(Surface surface);
7604 virtual bool OnFileModified(FileChange fileChange, char * param);
7605 virtual bool OnSaveFile(char * fileName);
7607 // Skins Virtual Functions
7608 virtual void GetDecorationsSize(MinMaxValue * w, MinMaxValue * h);
7609 virtual void SetWindowMinimum(MinMaxValue * mw, MinMaxValue * mh);
7610 virtual void SetWindowArea(int * x, int * y, MinMaxValue * w, MinMaxValue * h, MinMaxValue * cw, MinMaxValue * ch)
7615 virtual void ShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7616 virtual void PreShowDecorations(Font captionFont, Surface surface, char * name, bool active, bool moving);
7617 virtual bool IsMouseMoving(int x, int y, int w, int h);
7618 virtual bool IsMouseResizing(int x, int y, int w, int h, bool *resizeX, bool *resizeY, bool *resizeEndX, bool *resizeEndY);
7619 virtual void UpdateNonClient();
7620 virtual void SetBox(Box box);
7621 virtual bool IsInside(int x, int y)
7623 return box.IsPointInside({x, y});
7625 virtual bool IsOpaque()
7627 return (!style.drawBehind || background.a == 255);
7631 virtual bool Window::NotifyActivate(Window window, bool active, Window previous);
7632 virtual void Window::NotifyDestroyed(Window window, DialogResult result);
7633 virtual void Window::NotifySaved(Window window, char * filePath);
7638 property Window parent
7640 property_category "Layout"
7643 if(value || guiApp.desktop)
7646 Window oldParent = parent;
7647 Anchor anchor = this.anchor;
7649 if(value && value.IsDescendantOf(this)) return;
7650 if(value && value == this)
7652 if(!value) value = guiApp.desktop;
7654 if(value == oldParent) return;
7656 if(!master || (master == this.parent && master == guiApp.desktop))
7657 property::master = value;
7661 parent.children.Remove(this);
7665 box.left - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7666 box.top - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y,
7667 box.right - absPosition.x + parent.absPosition.x + style.nonClient * parent.clientStart.x,
7668 box.bottom - absPosition.y + parent.absPosition.y + style.nonClient * parent.clientStart.y
7672 last = value.children.last;
7674 if(style.isDocument)
7677 parent.numDocuments--;
7678 documentID = value.GetDocumentID();
7681 if(style.isActiveClient && !style.hidden)
7683 if(parent && parent != guiApp.desktop && !(style.hidden))
7685 if(state == minimized) parent.numIcons--;
7686 parent.numPositions--;
7690 if(!style.stayOnTop)
7691 for(; last && last.style.stayOnTop; last = last.prev);
7693 value.children.Insert(last, this);
7695 // *** NEW HERE: ***
7697 parent.childrenCycle.Delete(cycle);
7699 parent.childrenOrder.Delete(order);
7707 int x = position.x, y = position.y, w = size.w, h = size.h;
7711 x += parent.absPosition.x - value.absPosition.x + parent.clientStart.x - value.clientStart.x;
7712 y += parent.absPosition.y - value.absPosition.y + parent.clientStart.y - value.clientStart.y;
7714 vpw = value.clientSize.w;
7715 vph = value.clientSize.h;
7721 else if(style.fixed)
7723 if(!style.dontScrollHorz && value.scrollArea.w) vpw = value.scrollArea.w;
7724 if(!style.dontScrollVert && value.scrollArea.h) vph = value.scrollArea.h;
7727 anchor = this.anchor;
7729 if(anchor.left.type == offset) anchor.left.distance = x;
7730 else if(anchor.left.type == relative) anchor.left.percent = (float)x / vpw;
7731 if(anchor.top.type == offset) anchor.top.distance = y;
7732 else if(anchor.top.type == relative) anchor.top.percent = (float)y / vph;
7733 if(anchor.right.type == offset) anchor.right.distance = vpw - (x + w);
7734 //else if(anchor.right.type == relative) anchor.right.percent = 1.0-(float) (vpw - (x + w)) / vpw;
7735 else if(anchor.right.type == relative) anchor.right.percent = (float) (vpw - (x + w)) / vpw;
7736 if(anchor.bottom.type == offset) anchor.bottom.distance = vph - (y + h);
7737 //else if(anchor.bottom.type == relative) anchor.bottom.percent = 1.0-(float) (vph - (y + h)) / vph;
7738 else if(anchor.bottom.type == relative) anchor.bottom.percent = (float) (vph - (y + h)) / vph;
7740 if(!anchor.left.type && !anchor.right.type)
7742 anchor.horz.distance = (x + w / 2) - (vpw / 2);
7743 //anchor.horz.type = anchor.horz.distance ? AnchorValueOffset : 0;
7745 else if(anchor.horz.type == middleRelative) anchor.horz.percent = (float) ((x + w / 2) - (vpw / 2)) / vpw;
7746 if(!anchor.top.type && !anchor.bottom.type)
7748 anchor.vert.distance = (y + h / 2) - (vph / 2);
7749 //anchor.vert.type = anchor.vert.distance ? AnchorValueOffset : 0;
7751 else if(anchor.vert.type == middleRelative) anchor.vert.percent = (float)((y + h / 2) - (vph / 2)) / vph;
7759 parent.childrenCycle.Insert(
7760 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
7761 cycle = OldLink { data = this });
7762 parent.childrenOrder.Insert(
7763 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
7764 order = OldLink { data = this });
7767 if(!style.hidden && style.isActiveClient)
7769 positionID = parent.GetPositionID(this);
7770 parent.numPositions++;
7771 if(state == minimized) parent.numIcons--;
7774 // *** FONT INHERITANCE ***
7775 if(!setFont && oldParent)
7776 stopwatching(oldParent, font);
7780 RemoveResource(systemFont);
7783 // TESTING WITH WATCHERS:
7784 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7785 // usedFont = setFont ? setFont : (systemFont);
7789 if(guiApp.currentSkin)
7791 systemFont = guiApp.currentSkin.SystemFont();
7794 usedFont = systemFont;
7795 AddResource(systemFont);
7803 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
7812 if(value.rootWindow && value.rootWindow.display && rootWindow)
7814 bool reloadGraphics = (oldParent.rootWindow == oldParent && value.rootWindow) || (!value.rootWindow && rootWindow == this) ||
7815 (value.rootWindow.display && value.rootWindow.display.displaySystem != rootWindow.display.displaySystem);
7818 UnloadGraphics(false);
7821 LoadGraphics(false, false);
7824 if(value.rootWindow != rootWindow)
7825 DisplayModeChanged();
7829 scrolledPos.x = MININT; // Prevent parent update
7830 property::anchor = anchor;
7834 if(guiApp.currentSkin)
7835 guiApp.currentSkin.SetWindowMinimum(this, &skinMinSize.w, &skinMinSize.h);
7837 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
7838 Position(x, y, w, h, true, true, true, true, false, true);
7843 // else parent = value;
7846 get { return parent; }
7849 property Window master
7851 property_category "Behavior"
7854 //if(this == value) return;
7855 if(value && value.IsSlaveOf(this)) return;
7861 OldLink slaveHolder;
7862 for(slaveHolder = master.slaves.first; slaveHolder; slaveHolder = slaveHolder.next)
7863 if(slaveHolder.data == this)
7865 master.slaves.Delete(slaveHolder);
7872 value.slaves.Add(OldLink { data = this });
7877 master.hotKeys.Remove(hotKey);
7878 value.hotKeys.Add(hotKey);
7881 if(master && master.defaultControl == this)
7882 master.defaultControl = null;
7884 if(style.isDefault && !value.defaultControl)
7885 value.defaultControl = this;
7891 get { return master ? master : parent; }
7894 property char * text
7896 property_category "Appearance"
7903 caption = new char[strlen(value)+1];
7905 strcpy(caption, value);
7910 get { return caption; }
7915 property_category "Behavior"
7924 master.hotKeys.Add(hotKey = HotKeySlot { });
7928 hotKey.window = this;
7933 master.hotKeys.Delete(hotKey);
7938 get { return hotKey ? hotKey.key : 0; }
7941 property Color background
7943 property_category "Appearance"
7946 background.color = value;
7951 if(this == rootWindow)
7952 guiApp.interfaceDriver.SetRootWindowColor(this);
7955 get { return background.color; }
7958 property Percentage opacity
7960 property_category "Appearance"
7963 background.a = (byte)Min(Max((int)(value * 255), 0), 255);
7964 drawBehind = background.a ? false : true;
7966 get { return background.a / 255.0f; }
7969 property Color foreground
7971 property_category "Appearance"
7979 get { return foreground; }
7982 property BorderStyle borderStyle
7984 property_category "Appearance"
7987 if(!((BorderBits)value).fixed)
7989 style.hasClose = false;
7990 style.hasMaximize = false;
7991 style.hasMinimize = false;
7993 style.borderBits = value;
7997 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
7999 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8000 Position(x, y, w, h, true, true, true, true, false, true);
8001 CreateSystemChildren();
8004 get { return (BorderStyle)style.borderBits; }
8007 property Size minClientSize
8009 property_category "Layout"
8010 set { minSize = value; }
8011 get { value = minSize; }
8014 property Size maxClientSize
8016 property_category "Layout"
8017 set { maxSize = value; }
8018 get { value = maxSize; }
8021 property bool hasMaximize
8023 property_category "Window Style"
8026 style.hasMaximize = value;
8027 if(value) { style.fixed = true; style.contour = true; }
8031 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8033 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8034 Position(x, y, w, h, true, true, true, true, false, true);
8036 CreateSystemChildren();
8039 get { return style.hasMaximize; }
8042 property bool hasMinimize
8044 property_category "Window Style"
8047 style.hasMinimize = value;
8048 if(value) { style.fixed = true; style.contour = true; }
8052 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8054 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8055 Position(x, y, w, h, true, true, true, true, false, true);
8057 CreateSystemChildren();
8060 get { return style.hasMinimize; }
8063 property bool hasClose
8065 property_category "Window Style"
8068 style.hasClose = value;
8069 if(value) { style.fixed = true; style.contour = true; }
8073 SetWindowMinimum(&skinMinSize.w, &skinMinSize.h);
8074 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8075 Position(x, y, w, h, true, true, true, true, false, true);
8076 CreateSystemChildren();
8079 get { return style.hasClose; }
8082 property bool nonClient
8084 property_category "Layout"
8087 style.nonClient = value;
8089 style.stayOnTop = true;
8091 get { return style.nonClient; }
8094 property bool inactive
8096 property_category "Behavior"
8101 // *** NEW HERE: ***
8105 parent.childrenCycle.Delete(cycle);
8107 parent.childrenOrder.Delete(order);
8114 active = false; // true;
8115 if(parent.activeChild == this)
8116 parent.activeChild = null;
8117 if(parent.activeClient == this)
8118 parent.activeClient = null;
8127 parent.childrenCycle.Insert(
8128 (parent.activeChild && parent.activeChild.cycle) ? parent.activeChild.cycle.prev : null,
8129 cycle = OldLink { data = this });
8131 parent.childrenOrder.Insert(
8132 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8133 order = OldLink { data = this });
8136 style.inactive = value;
8138 get { return style.inactive; }
8141 property bool clickThrough
8143 property_category "Behavior"
8144 set { style.clickThrough = value; }
8145 get { return style.clickThrough; }
8148 property bool isRemote
8150 property_category "Behavior"
8151 set { style.isRemote = value; }
8152 get { return style.isRemote; }
8155 property bool noCycle
8157 property_category "Behavior"
8158 set { style.noCycle = value; }
8159 get { return style.noCycle; }
8162 property bool isModal
8164 property_category "Behavior"
8165 set { style.modal = value; }
8166 get { return style.modal; }
8169 property bool interim
8171 property_category "Behavior"
8172 set { style.interim = value; }
8173 get { return style.interim; }
8176 property bool tabCycle
8178 property_category "Behavior"
8179 set { style.tabCycle = value; }
8180 get { return style.tabCycle; }
8183 property bool isDefault
8185 property_category "Behavior"
8193 /*for(sibling = parent.children.first; sibling; sibling = sibling.next)
8194 if(sibling != this && sibling.style.isDefault)
8195 sibling.style.isDefault = false;*/
8196 if(master.defaultControl)
8197 master.defaultControl.style.isDefault = false;
8198 master.defaultControl = this;
8200 else if(master.defaultControl == this)
8201 master.defaultControl = null;
8205 style.isDefault = value;
8207 Position(position.x, position.y, size.w, size.h, true, true, true,true,true, true);
8209 get { return style.isDefault; }
8212 property bool drawBehind
8214 property_category "Window Style"
8215 set { style.drawBehind = value; }
8216 get { return style.drawBehind; }
8219 property bool hasMenuBar
8221 property_category "Window Style"
8231 if(created && !menuBar)
8238 anchor = Anchor { top = 23, left = 1, right = 1 },
8240 inactive = true, nonClient = true
8245 else if(created && menuBar)
8250 style.hasMenuBar = value;
8252 get { return style.hasMenuBar; }
8255 property bool hasStatusBar
8257 property_category "Window Style"
8264 statusBar = StatusBar { this };
8272 style.hasStatusBar = value;
8274 get { return style.hasStatusBar; }
8276 property bool stayOnTop
8278 property_category "Window Style"
8283 if(created && !style.stayOnTop)
8285 if(rootWindow == this)
8286 guiApp.interfaceDriver.OrderRootWindow(this, true);
8287 else if(parent.children.last != this)
8289 parent.children.Move(this, parent.children.last);
8293 style.stayOnTop = true;
8297 if(created && style.stayOnTop)
8299 if(rootWindow == this)
8300 guiApp.interfaceDriver.OrderRootWindow(this, false);
8307 for(order = (this.order == parent.childrenOrder.first) ? null : this.order.prev;
8308 order && ((Window)order.data).style.stayOnTop;
8309 order = (order == parent.childrenOrder.first) ? null : order.prev);
8310 last = order ? order.data : null;
8314 for(last = parent.children.last;
8315 last && last.style.stayOnTop;
8319 parent.children.Move(this, last);
8323 style.stayOnTop = false;
8326 get { return style.stayOnTop; }
8331 property_category "Window Style"
8341 if(menuBar && !value)
8348 if(!menuBar && style.hasMenuBar && value)
8352 this, menu = value, isMenuBar = true,
8353 anchor = Anchor { left = 1, top = 23, right = 1 }, size.h = 24,
8354 inactive = true, nonClient = true
8358 UpdateActiveDocument(null);
8361 get { return menu; }
8364 property FontResource font
8366 property_category "Appearance"
8368 isset { return setFont ? true : false; }
8373 if(value && !setFont) { stopwatching(parent, font); }
8374 else if(!value && setFont)
8380 usedFont = setFont ? setFont : (parent.parent ? parent.usedFont : systemFont);
8389 RemoveResource(setFont);
8394 RemoveResource(systemFont);
8401 AddResource(setFont);
8404 usedFont = setFont ? setFont : ((parent && parent.parent) ? parent.usedFont : systemFont);
8407 systemFont = guiApp.currentSkin.SystemFont();
8409 usedFont = systemFont;
8410 AddResource(systemFont);
8418 get { return usedFont; }
8421 property SizeAnchor sizeAnchor
8423 property_category "Layout"
8426 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8427 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8428 sizeAnchor.isClientW != sizeAnchor.isClientH;
8435 normalSizeAnchor = sizeAnchor;
8437 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8439 stateAnchor = normalAnchor;
8440 stateSizeAnchor = normalSizeAnchor;
8442 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8443 Position(x,y, w, h, true, true, true, true, false, true);
8450 { sizeAnchor.isClientW ? clientSize.w : size.w, sizeAnchor.isClientH ? clientSize.h : size.h },
8451 sizeAnchor.isClientW,
8452 sizeAnchor.isClientH
8459 property_category "Layout"
8462 Anchor thisAnchor = anchor;
8463 SizeAnchor thisSizeAnchor = sizeAnchor;
8464 bool leftRight = (anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none);
8465 bool topBottom = (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none);
8466 bool isClient = !sizeAnchor.isClientW && !sizeAnchor.isClientH;
8467 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8468 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8469 !sizeAnchor.isClientW && !sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8475 sizeAnchor.isClientW = false;
8476 sizeAnchor.isClientH = false;
8477 sizeAnchor.size = value;
8479 normalSizeAnchor = sizeAnchor;
8481 if(state == normal /*|| state == Hidden*/) // Hidden is new here ...
8483 stateAnchor = normalAnchor;
8484 stateSizeAnchor = normalSizeAnchor;
8486 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8487 Position(x, y, w, h, true, true, true, true, false, true);
8490 get { value = size; }
8493 property Size clientSize
8495 property_category "Layout"
8498 return ((anchor.left.type == none || anchor.left.type == middleRelative || anchor.right.type == none) ||
8499 (anchor.top.type == none || anchor.top.type == middleRelative || anchor.bottom.type == none)) &&
8500 sizeAnchor.isClientW && sizeAnchor.isClientH && sizeAnchor.size.w && sizeAnchor.size.h;
8505 sizeAnchor.isClientW = true;
8506 sizeAnchor.isClientH = true;
8507 sizeAnchor.size = value;
8509 normalSizeAnchor = sizeAnchor;
8511 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8513 stateAnchor = normalAnchor;
8514 stateSizeAnchor = normalSizeAnchor;
8516 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8517 Position(x,y, w, h, true, true, true, true, false, true);
8520 get { value = clientSize; }
8523 property Size initSize { get { value = sizeAnchor.size; } };
8525 property Anchor anchor
8527 property_category "Layout"
8528 isset { return (anchor.left.type != offset || anchor.top.type != offset || anchor.right.type || anchor.bottom.type); }
8534 if(anchor.left.type && anchor.right.type && (!value.left.type || !value.right.type))
8536 normalSizeAnchor.isClientW = sizeAnchor.isClientW = false;
8537 normalSizeAnchor.size.w = sizeAnchor.size.w = size.w;
8539 if(anchor.top.type && anchor.bottom.type && (!value.top.type || !value.bottom.type))
8541 normalSizeAnchor.isClientH = sizeAnchor.isClientH = false;
8542 normalSizeAnchor.size.h = sizeAnchor.size.h = size.h;
8546 if(anchor.right.type && (anchor.horz.type == middleRelative || !anchor.left.type))
8548 anchor.left.distance = 0;
8549 anchor.horz.type = 0;
8551 if(anchor.bottom.type && (anchor.vert.type == middleRelative || !anchor.top.type))
8553 anchor.top.distance = 0;
8554 anchor.vert.type = 0;
8563 normalAnchor = anchor;
8565 // Break the anchors for moveable/resizable windows
8566 /*if(style.fixed ) //&& value.left.type == cascade)
8568 ComputeAnchors(anchor, sizeAnchor, &x, &y, &w, &h);
8570 this.anchor = normalAnchor = Anchor { left = x, top = y };
8571 normalSizeAnchor = SizeAnchor { { w, h } };
8574 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8576 stateAnchor = normalAnchor;
8577 stateSizeAnchor = normalSizeAnchor;
8579 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8580 Position(x, y, w, h, true, true, true, true, false, true);
8589 get { value = this ? anchor : Anchor { }; }
8592 property Point position
8594 property_category "Layout"
8597 if(value == null) return;
8599 anchor.left = value.x;
8600 anchor.top = value.y;
8601 anchor.right.type = none;
8602 anchor.bottom.type = none;
8607 normalAnchor = anchor;
8609 // Break the anchors for moveable/resizable windows
8613 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8615 normalAnchor.left = x;
8616 normalAnchor.top = y;
8617 normalAnchor.right.type = none;
8618 normalAnchor.bottom.type = none;
8619 normalSizeAnchor.size.width = w;
8620 normalSizeAnchor.size.height = h;
8624 if(state == normal /*|| state == Hidden */) // Hidden is new here ...
8626 stateAnchor = normalAnchor;
8627 stateSizeAnchor = normalSizeAnchor;
8629 ComputeAnchors(stateAnchor, stateSizeAnchor, &x, &y, &w, &h);
8630 Position(x,y, w, h, true, true, true, true, false, true);
8634 get { value = position; }
8637 property bool disabled
8639 property_category "Behavior"
8642 if(this && disabled != value)
8649 get { return (bool)disabled; }
8652 property bool isEnabled
8657 for(parent = this; parent; parent = parent.parent)
8664 property WindowState state
8666 property_category "Behavior"
8667 set { SetState(value, false, 0); }
8668 get { return this ? state : 0; }
8671 property bool visible
8673 property_category "Behavior"
8676 if(this && !value && !style.hidden && parent)
8678 bool wasActiveChild = parent.activeChild == this;
8679 Window client = null;
8681 style.hidden = true;
8682 if(style.isActiveClient)
8684 parent.numPositions--;
8685 if(state == minimized) parent.numIcons--;
8690 OldLink prevOrder = null;
8692 if(rootWindow == this)
8693 guiApp.interfaceDriver.SetRootWindowState(this, state, false);
8696 Box box { scrolledPos.x, scrolledPos.y, scrolledPos.x + size.w - 1, scrolledPos.y + size.h - 1 };
8699 box.left -= parent.clientStart.x;
8700 box.top -= parent.clientStart.y;
8701 box.right -= parent.clientStart.x;
8702 box.bottom -= parent.clientStart.y;
8706 if(_isModal && master && master.modalSlave == this)
8707 master.modalSlave = null;
8711 OldLink tmpPrev = order.prev;
8712 client = tmpPrev ? tmpPrev.data : null;
8713 if(client && !client.style.hidden && !client.destroyed && client.created)
8714 prevOrder = tmpPrev;
8717 client = tmpPrev ? tmpPrev.data : null;
8718 if(client == this) { client = null; break; }
8719 if(client && ((client.style.hidden) || client.destroyed || !client.created))
8721 tmpPrev = client.order.prev;
8726 prevOrder = tmpPrev;
8731 // If this window can be an active client, make sure the next window we activate can also be one
8732 if(!style.nonClient && style.isActiveClient)
8734 tmpPrev = prevOrder;
8737 client = tmpPrev ? tmpPrev.data : null;
8738 if(client == this) { client = null; break; }
8739 if(client && (client.style.nonClient || !client.style.isActiveClient || client.style.hidden || client.destroyed || !client.created))
8741 tmpPrev = client.order.prev;
8746 prevOrder = tmpPrev;
8750 if(client && client.style.hidden) client = null;
8754 if((wasActiveChild /*parent.activeChild == this*/ || guiApp.interimWindow == this) && true /*activate*/)
8756 if(order && prevOrder && prevOrder.data != this)
8757 ((Window)prevOrder.data).ActivateEx(true, false, false, true, null, null);
8759 ActivateEx(false, false, false, true, null, null);
8761 // TESTING THIS HERE FOR HIDING ACTIVE CLIENT
8762 if(parent.activeClient == this)
8764 parent.activeClient = null;
8765 parent.UpdateActiveDocument(null);
8768 else if(parent.activeClient == this)
8770 parent.activeClient = client;
8771 parent.UpdateActiveDocument(this);
8774 // *** Not doing this anymore ***
8777 parent.childrenCycle.Delete(cycle);
8779 parent.childrenOrder.Delete(order);
8784 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8789 else if(this && value && style.hidden)
8791 style.hidden = false;
8794 SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8795 if(rootWindow == this)
8796 guiApp.interfaceDriver.SetRootWindowState(this, state, true);
8798 if(_isModal && master)
8799 master.modalSlave = this;
8801 if(style.isActiveClient)
8803 positionID = parent.GetPositionID(this);
8804 parent.numPositions++;
8805 if(state == minimized) parent.numIcons++;
8808 // *** NOT DOING THIS ANYMORE ***
8810 if(!(style.inactive))
8812 if(!(style.noCycle))
8814 cycle = parent.childrenCycle.AddAfter(
8815 (parent.activeChild && parent.activeChild.cycle) ?
8816 parent.activeChild.cycle.prev : null, sizeof(OldLink));
8819 order = parent.childrenOrder.AddAfter(
8820 (parent.activeChild && parent.activeChild.order) ? parent.activeChild.order.prev : parent.childrenOrder.last,
8827 if(true || !parent.activeChild)
8828 ActivateEx(true, false, true, true, null, null);
8830 if(creationActivation == activate)
8831 ActivateEx(true, false, true, true, null, null);
8832 else if(creationActivation == flash && !object)
8835 //SetVisibility(!parent.style.hidden && (style.hidden ? false : true));
8839 ConsequentialMouseMove(false);
8845 style.hidden = !value;
8848 get { return (style.hidden || !setVisible) ? false : true; }
8851 property bool isDocument
8853 property_category "Document"
8854 set { style.isDocument = value; }
8855 get { return style.isDocument; }
8858 property bool mergeMenus
8860 property_category "Window Style"
8861 set { mergeMenus = value; }
8862 get { return (bool)mergeMenus; }
8865 property bool hasHorzScroll
8867 property_category "Window Style"
8872 if(!style.hasHorzScroll && created)
8874 CreateSystemChildren();
8875 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8878 else if(style.hasHorzScroll)
8882 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8884 style.hasHorzScroll = value;
8887 get { return style.hasHorzScroll; }
8890 property bool hasVertScroll
8892 property_category "Window Style"
8897 if(!style.hasVertScroll && created)
8899 style.hasVertScroll = true;
8900 CreateSystemChildren();
8901 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8904 else if(style.hasVertScroll)
8908 Position(position.x, position.y, size.w, size.h, false, true, false, false, false, true);
8910 style.hasVertScroll = value;
8912 get { return style.hasVertScroll; }
8915 property bool dontHideScroll
8917 property_category "Behavior"
8920 scrollFlags.dontHide = value;
8923 //UpdateScrollBars(true, true);
8924 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
8928 // UpdateScrollBars(true, true);
8929 Position(position.x, position.y, size.w, size.h, false, true, true, true, true, true);
8932 get { return scrollFlags.dontHide; }
8935 property bool dontScrollVert
8937 property_category "Behavior"
8938 set { style.dontScrollVert = value; }
8939 get { return style.dontScrollVert; }
8941 property bool dontScrollHorz
8943 property_category "Behavior"
8944 set { style.dontScrollHorz = value; }
8945 get { return style.dontScrollHorz; }
8948 property bool snapVertScroll
8950 property_category "Behavior"
8953 scrollFlags.snapY = value;
8954 if(sbv) sbv.snap = value;
8956 get { return scrollFlags.snapY; }
8958 property bool snapHorzScroll
8960 property_category "Behavior"
8963 scrollFlags.snapX = value;
8964 if(sbh) sbh.snap = value;
8966 get { return scrollFlags.snapX; }
8969 property Point scroll
8971 property_category "Behavior"
8975 // TESTING THIS IMPLEMENTATION:
8976 SetScrollPosition(value.x, value.y);
8978 get { value = scroll; }
8981 property bool modifyVirtualArea
8983 property_category "Behavior"
8984 set { modifyVirtArea = value; }
8985 get { return (bool)modifyVirtArea; }
8988 property char * fileName
8990 property_category "Document"
8993 if(menu && ((!fileName && value) || (fileName && !value)))
8995 MenuItem item = menu.FindItem(MenuFileSave, 0);
8996 if(item) item.disabled = !modifiedDocument && value;
9001 if(value && value[0])
9002 fileName = CopyString(value);
9004 if(parent && this == parent.activeClient)
9005 parent.UpdateActiveDocument(null);
9009 // if(style.isDocument)
9011 fileMonitor.fileName = value;
9013 get { return fileName; }
9018 property_category "Data"
9023 property bool modifiedDocument
9025 property_category "Document"
9028 if(style.isDocument || fileName)
9032 MenuItem item = menu.FindItem(MenuFileSave, 0);
9033 if(item) item.disabled = !value && fileName;
9037 if(modifiedDocument != value)
9039 modifiedDocument = value;
9040 if(style.isDocument || fileName)
9044 get { return (bool)modifiedDocument; }
9047 property bool showInTaskBar
9049 property_category "Window Style"
9050 set { style.showInTaskBar = value; }
9051 get { return (style.showInTaskBar; }
9053 property FileDialog saveDialog { set { saveDialog = value; } };
9054 property bool isActiveClient
9056 property_category "Behavior"
9057 set { style.isActiveClient = value; }
9058 get { return style.isActiveClient; }
9061 property Cursor cursor
9063 property_category "Appearance"
9067 SelectMouseCursor();
9069 get { return cursor; }
9072 //#if !defined(ECERE_VANILLA)
9073 property char * name
9075 property_category "Design"
9078 return (this && object) ? object.name : null;
9083 activeDesigner.RenameObject(object, value);
9087 property char * displayDriver
9089 property_category "Behavior"
9092 dispDriver = GetDisplayDriver(value);
9093 //DisplayModeChanged();
9097 return dispDriver ? dispDriver.name : null;
9101 // RUNTIME PROPERTIES
9102 property bool autoCreate { set { autoCreate = value; } get { return (bool)autoCreate; } };
9103 property Size scrollArea
9105 property_category "Behavior"
9109 SetScrollArea(value.w, value.h, false);
9111 SetScrollArea(0,0, true);
9113 get { value = scrollArea; }
9116 return scrollArea.w > clientSize.w || scrollArea.h > clientSize.h;
9121 property_category "Layout"
9122 set { if(this) is3D = value; }
9123 get { return (bool)is3D; }
9126 // Runtime Only Properties (No Set, can display the displayable ones depending on the type?)
9128 // Will be merged with font later
9129 property Font fontObject { get { return usedFont ? usedFont.font : null; } };
9130 property Point clientStart { get { value = clientStart; } };
9131 property Point absPosition { get { value = absPosition; } };
9132 property Anchor normalAnchor { get {value = normalAnchor; } };
9133 // property Size normalSizeAnchor { get { value = normalSizeAnchor; } };
9134 property bool active { get { return (bool)active; } };
9135 property bool created { get { return (bool)created; } };
9136 property bool destroyed { get { return (bool)destroyed; } };
9137 property Window firstSlave { get { return slaves.first ? ((OldLink)slaves.first).data : null; } };
9138 property Window firstChild { get { return children.first; } };
9139 property Window lastChild { get { return children.last; } };
9140 property Window activeClient { get { return activeClient; } };
9141 property Window activeChild { get { return activeChild; } };
9142 property Display display { get { return display ? display : ((parent && parent.rootWindow) ? parent.rootWindow.display : null); } };
9143 property DisplaySystem displaySystem { get { return display ? display.displaySystem : null; } };
9144 property ScrollBar horzScroll { get { return sbh; } };
9145 property ScrollBar vertScroll { get { return sbv; } };
9146 property StatusBar statusBar { get { return statusBar; } };
9147 property Window rootWindow { get { return rootWindow; } };
9148 property bool closing { get { return (bool)closing; } set { closing = value; } };
9149 property int documentID { get { return documentID; } };
9150 property Window previous { get { return prev; } }
9151 property Window next { get { return next; } }
9152 property Window nextSlave { get { OldLink link = master ? master.slaves.FindLink(this) : null; return (link && link.next) ? link.next.data : null; } }
9153 property PopupMenu menuBar { get { return menuBar; } }
9154 property ScrollBar sbv { get { return sbv; } }
9155 property ScrollBar sbh { get { return sbh; } }
9156 property bool fullRender { set { fullRender = value; } get { return (bool)fullRender; } }
9157 property void * systemHandle { get { return windowHandle; } }
9158 property Button minimizeButton { get { return sysButtons[0]; } };
9159 property Button maximizeButton { get { return sysButtons[1]; } };
9160 property Button closeButton { get { return sysButtons[2]; } };
9161 property BitmapResource icon
9163 get { return icon; }
9167 if(icon) incref icon;
9169 guiApp.interfaceDriver.SetIcon(this, value);
9172 property bool moveable { get { return (bool)moveable; } set { moveable = value; } };
9173 property bool alphaBlend { get { return (bool)alphaBlend; } set { alphaBlend = value; } };
9174 property bool useSharedMemory { get { return (bool)useSharedMemory; } set { useSharedMemory = value; } };
9175 property CreationActivationOption creationActivation { get { return creationActivation; } set { creationActivation = value; } };
9176 property bool nativeDecorations { get { return (bool)nativeDecorations && (formDesigner || rootWindow == this); } set { nativeDecorations = value; } };
9177 property bool manageDisplay { get { return (bool)manageDisplay; } set { manageDisplay = value; } };
9183 WindowBits style; // Window Style
9184 char * caption; // Name / Caption
9185 Window parent; // Parent window
9186 OldList children; // List of children in Z order
9187 Window activeChild; // Child window having focus
9188 Window activeClient;
9189 Window previousActive; // Child active prior to activating the default child
9190 Window master; // Window owning and receiving notifications concerning this window
9191 OldList slaves; // List of windows belonging to this window
9192 Display display; // Display this window is drawn into
9194 Point position; // Position in parent window client area
9195 Point absPosition; // Absolute position
9196 Point clientStart; // Client area position from (0,0) in this window
9198 Size clientSize; // Client area size
9199 Size scrollArea; // Virtual Scroll area size
9200 Size reqScrollArea; // Requested virtual area size
9201 Point scroll; // Virtual area scrolling position
9202 public ScrollBar sbh, sbv; // Scrollbar window handles
9203 Cursor cursor; // Mouse cursor used for this window
9206 StatusBar statusBar;
9207 Button sysButtons[3];
9209 Box clientArea; // Client Area box clipped to parent
9211 HotKeySlot hotKey; // HotKey for this window
9215 ScrollFlags scrollFlags;// Window Scrollbar Flags
9216 int id; // Control ID
9218 ColorAlpha background; // Background color used to draw the window area
9220 subclass(DisplayDriver) dispDriver; // Display driver name for this window
9221 OldList childrenCycle; // Cycling order
9222 OldLink cycle; // Element of parent's cycling order
9223 OldList childrenOrder; // Circular Z-Order
9224 OldLink order; // Element of parent's circular Z-Order
9225 Window modalSlave; // Slave window blocking this window's interaction
9227 Window rootWindow; // Topmost system managed window
9228 void * windowHandle; // System window handle
9230 DialogResult returnCode;// Return code for modal windows
9232 Point sbStep; // Scrollbar line scrolling steps
9235 SizeAnchor stateSizeAnchor;
9237 Anchor normalAnchor;
9238 SizeAnchor normalSizeAnchor;
9240 Size skinMinSize; // Minimal window size based on style
9241 Point scrolledPos; // Scrolled position
9242 Box box; // Window box clipped to parent
9243 Box * against; // What to clip the box to
9245 Extent dirtyArea { /*first = -1, last = -1, free = -1*/ }; // Area marked for update by Update
9246 Extent renderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered
9247 Extent overRenderArea { /*first = -1, last = -1, free = -1*/ }; // Temporary extent: Area that is going to be rendered over children
9248 Extent clipExtent { /*first = -1, last = -1, free = -1*/ }; // Temporary extent against which to clip render area
9249 Extent scrollExtent { /*first = -1, last = -1, free = -1*/ }; // Area to scroll
9250 Point scrolledArea; // Distance to scroll area by
9251 Extent dirtyBack { /*first = -1, last = -1, free = -1*/ }; // Only used by root window
9253 OldList hotKeys; // List of the hotkeys of all children
9254 Window defaultControl; // Default child control
9258 ColorAlpha * palette; // Color palette used for this window
9260 int caretSize; // Size of caret, non zero if a caret is present
9261 Point caretPos; // Caret position
9263 void * systemParent; // Parent System Window for embedded windows
9270 WindowState lastState;
9272 FileMonitor fileMonitor
9274 this, FileChange { modified = true };
9276 bool OnFileNotify(FileChange action, char * param)
9279 fileMonitor.StopMonitoring();
9280 if(OnFileModified(action, param))
9281 fileMonitor.StartMonitoring();
9286 FontResource setFont, systemFont;
9287 FontResource usedFont;
9288 FontResource captionFont;
9290 FileDialog saveDialog;
9292 SizeAnchor sizeAnchor;
9294 // FormDesigner data
9297 Extent * tempExtents; //[4];
9298 BitmapResource icon;
9300 CreationActivationOption creationActivation;
9303 bool active:1; // true if window and ancestors are active
9304 bool acquiredInput:1; // true if the window is processing state based input
9305 bool modifiedDocument:1;
9306 bool disabled:1; // true if window cannot interact
9307 bool isForegroundWindow:1;// true while a root window is being activated
9308 bool visible:1; // Visibility flag
9309 bool destroyed:1; // true if window is being destroyed
9310 bool anchored:1; // true if this window is repositioned when the parent resizes
9311 bool dirty:1; // Flag set to true if any descendant must be redrawn
9317 bool modifyVirtArea:1;
9318 bool noAutoScrollArea:1;
9321 bool setVisible:1; // FOR FORM DESIGNER
9327 bool useSharedMemory:1;
9330 bool nativeDecorations:1;
9331 bool manageDisplay:1;
9332 bool formDesigner:1; // True if we this is running in the form editor
9335 // Checks used internally for them not to take effect in FormDesigner
9336 property bool _isModal { get { return !formDesigner ? style.modal : false; } }
9337 property subclass(DisplayDriver) _displayDriver { get { return !formDesigner ? dispDriver : null; } }
9339 WindowController controller;
9340 public property WindowController controller { get { return controller; } set { delete controller; controller = value; if(controller) incref controller; } }
9343 public class CommonControl : Window
9345 // creationActivation = doNothing;
9348 public property String toolTip
9350 property_category "Appearance"
9353 if(created) CommonControl::OnDestroy();
9355 toolTip = value ? ToolTip { tip = value; } : null;
9357 if(created) CommonControl::OnCreate();
9359 get { return toolTip ? toolTip.tip : null; }
9365 // (Very) Ugly work around for the fact that the parent watcher
9366 // won't fire when it's already been disconnected...
9367 eInstance_FireSelfWatchers(toolTip,
9368 __ecereProp___ecereNameSpace__ecere__gui__Window_parent);
9374 toolTip.parent = this;
9383 public class Percentage : float
9385 char * OnGetString(char * string, float * fieldData, bool * needClass)
9389 sprintf(string, "%.2f", this);
9390 c = strlen(string)-1;
9393 if(string[c] != '0')
9394 last = Max(last, c);
9395 if(string[c] == '.')
9408 public void ApplySkin(Class c, char * name, void ** vTbl)
9410 char className[1024];
9415 subclass(Window) wc = (subclass(Window))c;
9416 subclass(Window) base = (subclass(Window))c.base;
9418 sprintf(className, "%sSkin_%s", name, c.name);
9419 wc.pureVTbl = c._vTbl;
9420 c._vTbl = new void *[c.vTblSize];
9421 memcpy(c._vTbl, wc.pureVTbl, c.vTblSize * sizeof(void *));
9422 sc = eSystem_FindClass(c.module.application, className);
9426 for(m = 0; m < c.base.vTblSize; m++)
9428 if(c._vTbl[m] == base.pureVTbl[m])
9429 c._vTbl[m] = vTbl[m];
9434 for(m = 0; m < c.vTblSize; m++)
9436 if(sc._vTbl[m] != wc.pureVTbl[m])
9437 c._vTbl[m] = sc._vTbl[m];
9441 for(d = c.derivatives.first; d; d = d.next)
9443 ApplySkin(d.data, name, c._vTbl);
9447 public void UnapplySkin(Class c)
9449 char className[1024];
9451 subclass(Window) wc = (subclass(Window))c;
9452 subclass(Window) base = (subclass(Window))c.base;
9455 if(wc.pureVTbl && c._vTbl != wc.pureVTbl)
9458 c._vTbl = wc.pureVTbl;
9462 for(d = c.derivatives.first; d; d = d.next)
9464 UnapplySkin(d.data);
9468 void CheckFontIntegrity(Window window)
9473 if(window.usedFont && window.usedFont.font == 0xecececec)
9475 FontResource uf = window.usedFont;
9476 char * className = window._class.name;
9477 char * text = window.text;
9480 for(c = window.firstChild; c; c = c.next)
9481 CheckFontIntegrity(c);
9485 public class ControllableWindow : Window
9487 /*WindowController controller;
9488 public property WindowController controller { get { return controller; } set { delete controller; controller = value; incref controller; } }
9489 ~ControllableWindow() { delete controller; }*/
9492 class WindowControllerInterface : ControllableWindow
9494 bool OnKeyDown(Key key, unichar ch)
9496 bool result = ((int(*)())(void *)controller.OnKeyDown)((void *)controller.controlled, (void *)controller, key, ch);
9498 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown](controller.window, key, ch);
9502 bool OnKeyUp(Key key, unichar ch)
9504 bool result = ((int(*)())(void *)controller.OnKeyUp)((void *)controller.controlled, (void *)controller, key, ch);
9506 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp](controller.window, key, ch);
9510 bool OnKeyHit(Key key, unichar ch)
9512 bool result = ((int(*)())(void *)controller.OnKeyHit)((void *)controller.controlled, (void *)controller, key, ch);
9514 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit](controller.window, key, ch);
9518 bool OnMouseMove(int x, int y, Modifiers mods)
9520 bool result = ((int(*)())(void *)controller.OnMouseMove)((void *)controller.controlled, (void *)controller, x, y, mods);
9522 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMouseMove](controller.window, x, y, mods);
9526 bool OnLeftButtonDown(int x, int y, Modifiers mods)
9528 bool result = ((int(*)())(void *)controller.OnLeftButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9530 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonDown](controller.window, x, y, mods);
9534 bool OnLeftButtonUp(int x, int y, Modifiers mods)
9536 bool result = ((int(*)())(void *)controller.OnLeftButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9538 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftButtonUp](controller.window, x, y, mods);
9542 bool OnLeftDoubleClick(int x, int y, Modifiers mods)
9544 bool result = ((int(*)())(void *)controller.OnLeftDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9546 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnLeftDoubleClick](controller.window, x, y, mods);
9550 bool OnRightButtonDown(int x, int y, Modifiers mods)
9552 bool result = ((int(*)())(void *)controller.OnRightButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9554 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonDown](controller.window, x, y, mods);
9558 bool OnRightButtonUp(int x, int y, Modifiers mods)
9560 bool result = ((int(*)())(void *)controller.OnRightButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9562 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightButtonUp](controller.window, x, y, mods);
9566 bool OnRightDoubleClick(int x, int y, Modifiers mods)
9568 bool result = ((int(*)())(void *)controller.OnRightDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9570 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRightDoubleClick](controller.window, x, y, mods);
9574 bool OnMiddleButtonDown(int x, int y, Modifiers mods)
9576 bool result = ((int(*)())(void *)controller.OnMiddleButtonDown)((void *)controller.controlled, (void *)controller, x, y, mods);
9578 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonDown](controller.window, x, y, mods);
9582 bool OnMiddleButtonUp(int x, int y, Modifiers mods)
9584 bool result = ((int(*)())(void *)controller.OnMiddleButtonUp)((void *)controller.controlled, (void *)controller, x, y, mods);
9586 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleButtonUp](controller.window, x, y, mods);
9590 bool OnMiddleDoubleClick(int x, int y, Modifiers mods)
9592 bool result = ((int(*)())(void *)controller.OnMiddleDoubleClick)((void *)controller.controlled, (void *)controller, x, y, mods);
9594 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnMiddleDoubleClick](controller.window, x, y, mods);
9598 void OnResize(int width, int height)
9600 ((int(*)())(void *)controller.OnResize)((void *)controller.controlled, (void *)controller, width, height);
9601 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnResize](controller.window, width, height);
9604 void OnRedraw(Surface surface)
9606 ((int(*)())(void *)controller.OnRedraw)((void *)controller.controlled, (void *)controller, surface);
9607 controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnRedraw](controller.window, surface);
9612 bool result = ((int(*)())(void *)controller.OnCreate)((void *)controller.controlled, (void *)controller);
9614 result = controller.windowVTbl[__ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnCreate](controller.window);
9619 public class WindowController<class V>
9622 property Window window
9626 uint size = class(Window).vTblSize;
9629 windowVTbl = new void *[size];
9630 memcpy(windowVTbl, value._vTbl, size * sizeof(void *));
9631 if(value._vTbl == value._class._vTbl)
9633 value._vTbl = new void *[value._class.vTblSize];
9634 memcpy(value._vTbl + size, value._class._vTbl + size, (value._class.vTblSize - size) * sizeof(void *));
9638 for(c = 0; c < size; c++)
9640 void * function = class(WindowControllerInterface)._vTbl[c];
9641 if(function != DefaultFunction)
9642 value._vTbl[c] = function;
9644 value._vTbl[c] = windowVTbl[c];
9649 memcpy(value._vTbl, windowVTbl, class(Window).vTblSize * sizeof(void *));
9652 get { return window; }
9654 property V controlled
9656 set { controlled = value; }
9657 get { return controlled; }
9659 virtual bool V::OnKeyDown(WindowController controller, Key key, unichar ch);
9660 virtual bool V::OnKeyUp(WindowController controller, Key key, unichar ch);
9661 virtual bool V::OnKeyHit(WindowController controller, Key key, unichar ch);
9662 virtual bool V::OnMouseMove(WindowController controller, int x, int y, Modifiers mods);
9663 virtual bool V::OnLeftButtonDown(WindowController controller, int x, int y, Modifiers mods);
9664 virtual bool V::OnLeftButtonUp(WindowController controller, int x, int y, Modifiers mods);
9665 virtual bool V::OnLeftDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9666 virtual bool V::OnRightButtonDown(WindowController controller, int x, int y, Modifiers mods);
9667 virtual bool V::OnRightButtonUp(WindowController controller, int x, int y, Modifiers mods);
9668 virtual bool V::OnRightDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9669 virtual bool V::OnMiddleButtonDown(WindowController controller, int x, int y, Modifiers mods);
9670 virtual bool V::OnMiddleButtonUp(WindowController controller, int x, int y, Modifiers mods);
9671 virtual bool V::OnMiddleDoubleClick(WindowController controller, int x, int y, Modifiers mods);
9672 virtual void V::OnResize(WindowController controller, int width, int height);
9673 virtual void V::OnRedraw(WindowController controller, Surface surface);
9674 virtual bool V::OnCreate(WindowController controller);
9677 int (** windowVTbl)();