X-Git-Url: https://ecere.com/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=ecere%2Fsrc%2Fgui%2FWindow.ec;h=596563401a88a3b481c47ee7e546e840dbc35b77;hb=HEAD;hp=c0dd965559069f133656e195ed18b1a9b8b6e8d3;hpb=90d01a7536fd52eaf0c8cd255e55969928a135f5;p=sdk diff --git a/ecere/src/gui/Window.ec b/ecere/src/gui/Window.ec index c0dd965..5965634 100644 --- a/ecere/src/gui/Window.ec +++ b/ecere/src/gui/Window.ec @@ -42,6 +42,37 @@ import "MessageBox" import "WindowList" import "i18n" +#if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__) && !defined(__EMSCRIPTEN__) +#define property _property +#define new _new +#define class _class +#define uint _uint + +#define Window X11Window +#define Cursor X11Cursor +#define Font X11Font +#define Display X11Display +#define Time X11Time +#define KeyCode X11KeyCode +#define Picture X11Picture + +#include + +#undef Window +#undef Cursor +#undef Font +#undef Display +#undef Time +#undef KeyCode +#undef Picture + +#undef uint +#undef new +#undef property +#undef class + +#endif + // 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 #ifdef HIGH_DPI define skinMenuHeight = 40; @@ -494,7 +525,7 @@ private class HotKeySlot : struct public struct TouchPointerInfo { int id; - int x, y; + Point point; float size, pressure; }; @@ -581,15 +612,26 @@ private: OldLink slave; ResPtr ptr; +#if !defined(__EMSCRIPTEN__) if(fileMonitor) { int i, lockCount = guiApp.lockMutex.lockCount; +#if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__) && !defined(__EMSCRIPTEN__) + if(xGlobalDisplay) + XUnlockDisplay(xGlobalDisplay); +#endif + for(i = 0; i < lockCount; i++) guiApp.lockMutex.Release(); delete fileMonitor; for(i = 0; i < lockCount; i++) guiApp.lockMutex.Wait(); +#if (defined(__unix__) || defined(__APPLE__)) && !defined(__ANDROID__) && !defined(__EMSCRIPTEN__) + if(xGlobalDisplay) + XLockDisplay(xGlobalDisplay); +#endif } +#endif if(parent) { @@ -674,7 +716,9 @@ private: delete statusBar; OnDestroyed(); +#if !defined(__EMSCRIPTEN__) delete mutex; +#endif delete icon; if(((subclass(Window))_class).pureVTbl) @@ -829,7 +873,9 @@ private: x -= rootWindow.clientStart.x; y -= rootWindow.clientStart.y - (rootWindow.hasMenuBar ? skinMenuHeight : 0); } +#if !defined(__EMSCRIPTEN__) if(!guiApp.fullScreenMode || is3D) +#endif { x -= rootWindow.absPosition.x; y -= rootWindow.absPosition.y; @@ -1137,13 +1183,23 @@ private: if(parent.numIcons) ph -= guiApp.textMode ? 16 : 24; if(anchor.left.type == vTiled) { - tilingH = (int)sqrt(numTiling); - tilingW = numTiling / tilingH; + if(numTiling) + { + tilingH = (int)sqrt(numTiling); + tilingW = numTiling / tilingH; + } + else + tilingH = tilingW = 0; } else { - tilingW = (int)sqrt(numTiling); - tilingH = numTiling / tilingW; + if(numTiling) + { + tilingW = (int)sqrt(numTiling); + tilingH = numTiling / tilingW; + } + else + tilingH = tilingW = 0; } leftOver = numTiling - tilingH * tilingW; @@ -1155,19 +1211,30 @@ private: else tilingSplit = numTiling; - if(positionID >= tilingSplit) + if(tilingW && tilingH) { - x = xOffset + pw * (tilingSplit / tilingH + (positionID - tilingSplit) / tilingLastH)/tilingW; - y = yOffset + ph * ((positionID - tilingSplit) % tilingLastH) / tilingLastH; - x2 = xOffset + pw * (tilingSplit/tilingH + (positionID - tilingSplit) / tilingLastH + 1)/tilingW; - y2 = yOffset + ph * (((positionID - tilingSplit) % tilingLastH) + 1) / tilingLastH; + if(positionID >= tilingSplit) + { + x = xOffset + pw * (tilingSplit / tilingH + (positionID - tilingSplit) / tilingLastH)/tilingW; + y = yOffset + ph * ((positionID - tilingSplit) % tilingLastH) / tilingLastH; + x2 = xOffset + pw * (tilingSplit/tilingH + (positionID - tilingSplit) / tilingLastH + 1)/tilingW; + y2 = yOffset + ph * (((positionID - tilingSplit) % tilingLastH) + 1) / tilingLastH; + } + else + { + x = xOffset + pw * (positionID / tilingH) / tilingW; + y = yOffset + ph * (positionID % tilingH) / tilingH; + x2 = xOffset + pw * (positionID / tilingH + 1) / tilingW; + y2 = yOffset + ph * ((positionID % tilingH) + 1) / tilingH; + } } else { - x = xOffset + pw * (positionID / tilingH) / tilingW; - y = yOffset + ph * (positionID % tilingH) / tilingH; - x2 = xOffset + pw * (positionID / tilingH + 1) / tilingW; - y2 = yOffset + ph * ((positionID % tilingH) + 1) / tilingH; + // How can this happen? From ec2 parsing test + x = 0; + y = 0; + x2 = 0; + y2 = 0; } if(guiApp.textMode) { @@ -1795,7 +1862,11 @@ private: if(display && !display.flags.memBackBuffer && changeRootWindow) guiApp.interfaceDriver.PositionRootWindow(this, x, y, w, h, windowMoved, windowResized); //realResized); - if(!guiApp.fullScreenMode && this != guiApp.desktop && (windowResized || windowMoved)) + if( +#if !defined(__EMSCRIPTEN__) + !guiApp.fullScreenMode && +#endif + this != guiApp.desktop && (windowResized || windowMoved)) for(child = parent.children.first; child && child != this; child = child.next) if(child.rootWindow) guiApp.interfaceDriver.UpdateRootWindow(child.rootWindow); @@ -1841,7 +1912,7 @@ private: display.Unlock(); } } - if(guiApp.driver && changeRootWindow && windowHandle) + if(guiApp.driver && !guiApp.modeSwitching && changeRootWindow && windowHandle) { if(windowResized || windowMoved) if(!display || display.flags.memBackBuffer) @@ -1860,7 +1931,9 @@ private: child.display.width = display.width; child.display.height = display.height; child.display.driverData = display.driverData; +#if !defined(__EMSCRIPTEN__) child.display.mutex = null; +#endif } } } @@ -2690,6 +2763,7 @@ private: // Default Settings surface.TextFont(usedFont.font); surface.TextOpacity(false); + surface.outlineColor = black; OnRedraw(surface); @@ -2718,6 +2792,7 @@ private: surface.TextFont(usedFont.font); surface.TextOpacity(false); + surface.outlineColor = black; OnDrawOverChildren(surface); @@ -3140,6 +3215,7 @@ private: clipExtent.AddBox(box); + display.Lock(true); display.StartUpdate(); if(!rootWindow.fullRender) @@ -3188,6 +3264,7 @@ private: } display.EndUpdate(); + display.Unlock(); dirtyBack.Empty(); dirty = false; @@ -3779,7 +3856,10 @@ private: if(activateParent && parent && !parent.active /*parent != parent.parent.activeChild*/) parent.ActivateEx(true, true, moveInactive, activateRoot, external, externalSwap); } - else if(!guiApp.fullScreenMode) + else +#if !defined(__EMSCRIPTEN__) + if(!guiApp.fullScreenMode) +#endif { Window modalRoot = FindModal(); if(!modalRoot) modalRoot = this; @@ -4046,14 +4126,14 @@ private: public bool MultiTouchMessage(TouchPointerEvent event, Array infos, Modifiers * mods, bool consequential, bool activate) { bool result = true; - if(infos.count) + if((infos && infos.count) || (event == up || event == pointerUp)) { Window w = null; while(result && w != this) { // TODO: How to handle this? - int x = infos[0].x; - int y = infos[0].y; + int x = (infos && infos.count) ? infos[0].point.x : 0; + int y = (infos && infos.count) ? infos[0].point.y : 0; Window msgWindow = GetAtPosition(x,y, false, true, w); Window window; delete w; @@ -4061,6 +4141,14 @@ private: if(w) incref w; window = (w && !w.disabled) ? w : null; + if(guiApp.windowCaptured && (guiApp.windowCaptured.rootWindow == this)) + { + if(!guiApp.windowCaptured.isEnabled) + guiApp.windowCaptured.ReleaseCapture(); + else + window = guiApp.windowCaptured; + } + if(consequential) mods->isSideEffect = true; if(!result || (window && window.destroyed)) window = null; @@ -4068,16 +4156,20 @@ private: { if(window.OnMultiTouch && !window.disabled) { - Array in { size = infos.size }; - memcpy(in.array, infos.array, sizeof(TouchPointerInfo) * infos.size); - - for(i : in) + Array in = null; + if(infos && infos.count) { - i.x -= (window.absPosition.x + window.clientStart.x); - i.y -= (window.absPosition.y + window.clientStart.y); + in = { size = infos.size }; + memcpy(in.array, infos.array, sizeof(TouchPointerInfo) * infos.size); + + for(i : in) + { + i.point.x -= (window.absPosition.x + window.clientStart.x); + i.point.y -= (window.absPosition.y + window.clientStart.y); - i.x = Max(Min(i.x, 32767),-32768); - i.y = Max(Min(i.y, 32767),-32768); + i.point.x = Max(Min(i.point.x, 32767),-32768); + i.point.y = Max(Min(i.point.y, 32767),-32768); + } } incref window; @@ -4101,6 +4193,7 @@ private: bool result = true; bool wasMoving = guiApp.windowMoving ? true : false; bool wasScrolling = guiApp.windowScrolling ? true : false; + bool firstPass = true; Window w = null; while(result && w != this) { @@ -4350,7 +4443,7 @@ private: msgWindow.SelectMouseCursor(); */ - if(guiApp.windowCaptured || trueWindow) + if(firstPass && (guiApp.windowCaptured || trueWindow)) { Window prevWindow = guiApp.prevWindow; List overWindows = guiApp.overWindows; @@ -4358,13 +4451,13 @@ private: while(it.Next()) { - Window w = it.data; - if(trueWindow != w && !trueWindow.IsDescendantOf(w)) + Window ww = it.data; + if(trueWindow != ww && !trueWindow.IsDescendantOf(ww)) { it.pointer = null; - result = w.OnMouseLeave(*mods); + result = ww.OnMouseLeave(*mods); if(!result) break; - overWindows.TakeOut(w); + overWindows.TakeOut(ww); } } @@ -4408,10 +4501,10 @@ private: } if(trueWindow && trueWindow._refCount > 1 && !trueWindow.destroyed) { - for(w : guiApp.overWindows; w == trueWindow) + for(wi : guiApp.overWindows; wi == trueWindow) { OnMouseLeave(0); - guiApp.overWindows.TakeOut(w); + guiApp.overWindows.TakeOut(wi); break; } guiApp.prevWindow = trueWindow; @@ -4456,6 +4549,7 @@ private: */ if(!result || !w || !w.clickThrough) break; + firstPass = false; } delete w; return result; @@ -4486,7 +4580,9 @@ private: if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown) status = OnSysKeyDown(key, character); - else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit) + if(status && + (method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyDown || + method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyHit)) status = OnSysKeyHit(key, character); else if(method == __ecereVMethodID___ecereNameSpace__ecere__gui__Window_OnKeyUp) status = OnSysKeyUp(key, character); @@ -4926,8 +5022,12 @@ private: Window child; // Setup relationship with outside world (bb root || !bb) +#if defined(__EMSCRIPTEN__) + if(this == guiApp.desktop) +#else if((!guiApp.fullScreenMode && parent == guiApp.desktop) || this == guiApp.desktop || (_displayDriver && parent.dispDriver && dispDriver != parent.dispDriver)) +#endif { rootWindow = this; if(!tempExtents) @@ -4959,7 +5059,11 @@ private: bool result = false; Window child; +#if defined(__EMSCRIPTEN__) + if(this == guiApp.desktop) +#else if((!guiApp.fullScreenMode && parent == guiApp.desktop) || (guiApp.fullScreenMode && (this == guiApp.desktop || (_displayDriver && parent.dispDriver && dispDriver != parent.dispDriver)))) +#endif { subclass(DisplayDriver) dDriver = (dispDriver && !formDesigner) ? dispDriver : GetDisplayDriver(guiApp.defaultDisplayDriver); DisplaySystem displaySystem = dDriver ? dDriver.displaySystem : null; @@ -4972,7 +5076,7 @@ private: if(!displaySystem) { - displaySystem = DisplaySystem {}; + displaySystem = DisplaySystem { glCapabilities = glCapabilities }; if(!displaySystem.Create(dDriver.name, guiApp.fullScreenMode ? windowHandle : windowHandle /*null*/, guiApp.fullScreenMode)) { delete displaySystem; @@ -4980,7 +5084,7 @@ private: } if(displaySystem) { - display = Display { alphaBlend = alphaBlend, useSharedMemory = useSharedMemory, windowDriverData = windowData }; + display = Display { alphaBlend = alphaBlend, useSharedMemory = useSharedMemory, glCapabilities = glCapabilities, windowDriverData = windowData }; if(display.Create(displaySystem, windowHandle)) result = true; else @@ -5065,7 +5169,11 @@ private: } } - if(guiApp.fullScreenMode || this != guiApp.desktop) + if( +#if !defined(__EMSCRIPTEN__) + guiApp.fullScreenMode || +#endif + this != guiApp.desktop) { SetWindowMinimum(&skinMinSize.w, &skinMinSize.h); if(display) @@ -5993,7 +6101,7 @@ private: public bool AcquireInput(bool acquired) { bool result = true; - if(acquiredInput != acquired) + if((guiApp.acquiredWindow && acquiredInput) != acquired) { if(active || (!visible && creationActivation == activate)) result = AcquireInputEx(acquired); @@ -6026,9 +6134,15 @@ private: { if(guiApp.driver != null) { +#if !defined(__EMSCRIPTEN__) if(guiApp.fullScreenMode && guiApp.desktop.display) +#else + if(true) +#endif { +#if !defined(__EMSCRIPTEN__) guiApp.desktop.mutex.Wait(); +#endif guiApp.desktop.display.Lock(true); Update(extent); @@ -6052,12 +6166,16 @@ private: } guiApp.desktop.display.Unlock(); +#if !defined(__EMSCRIPTEN__) guiApp.desktop.mutex.Release(); +#endif } else { Window rootWindow = this.rootWindow; +#if !defined(__EMSCRIPTEN__) rootWindow.mutex.Wait(); +#endif display.Lock(true); Update(extent); @@ -6065,7 +6183,9 @@ private: guiApp.SignalEvent(); else { +#if !defined(__EMSCRIPTEN__) guiApp.waitMutex.Wait(); +#endif guiApp.interfaceDriver.Lock(rootWindow); if(!rootWindow.style.hidden && rootWindow.dirty) { @@ -6077,10 +6197,14 @@ private: rootWindow.dirty = false; } guiApp.interfaceDriver.Unlock(rootWindow); +#if !defined(__EMSCRIPTEN__) guiApp.waitMutex.Release(); +#endif } display.Unlock(); +#if !defined(__EMSCRIPTEN__) rootWindow.mutex.Release(); +#endif } } } @@ -6190,7 +6314,7 @@ private: guiApp.interfaceDriver.SetMousePosition(guiApp.windowMovingStart.x, guiApp.windowMovingStart.y); else { - int x, y; + int x = 0, y = 0; guiApp.interfaceDriver.GetMousePosition(&x, &y); guiApp.windowMovingStart.x += x - absPosition.x; guiApp.windowMovingStart.y += y - absPosition.y; @@ -6213,6 +6337,7 @@ private: void SetupFileMonitor() { +#if !defined(__EMSCRIPTEN__) if(!fileMonitor) { fileMonitor = FileMonitor @@ -6231,6 +6356,7 @@ private: }; incref fileMonitor; } +#endif } public: @@ -6281,8 +6407,10 @@ public: } } +#if !defined(__EMSCRIPTEN__) if(parent == guiApp.desktop && !mutex) mutex = Mutex {}; +#endif if(style.isDocument) { @@ -7263,10 +7391,16 @@ public: clip.bottom += absPosition.y; } - clip.left += decorations ? 0 : clientStart.x; - clip.top += decorations ? 0 : clientStart.y; - clip.right += decorations ? 0 : clientStart.x; - clip.bottom += decorations ? 0 : clientStart.y; + if(!nativeDecorations) + { + clip.left += decorations ? 0 : clientStart.x; + clip.top += decorations ? 0 : clientStart.y; + clip.right += decorations ? 0 : clientStart.x; + clip.bottom += decorations ? 0 : clientStart.y; + } + + if(decorations && this == guiApp.desktop) + clip = { 0, 0, guiApp.virtualScreen.w, guiApp.virtualScreen.h }; if(display && display.flags.flipping) { @@ -7506,7 +7640,9 @@ public: SetupFileMonitor(); if(fileName) { +#if !defined(__EMSCRIPTEN__) fileMonitor.fileName = null; +#endif saving = true; if(OnSaveFile(fileName)) @@ -7514,7 +7650,9 @@ public: //if(OnFileModified != Window::OnFileModified) { saving = false; +#if !defined(__EMSCRIPTEN__) fileMonitor.fileName = fileName; +#endif } return true; } @@ -7549,7 +7687,9 @@ public: sprintf(filePath, "Untitled %d", documentID); fileDialog.filePath = filePath; } +#if !defined(__EMSCRIPTEN__) fileMonitor.fileName = null; +#endif fileDialog.type = save; fileDialog.text = $"Save As"; @@ -7586,11 +7726,13 @@ public: break; } } +#if !defined(__EMSCRIPTEN__) //if(OnFileModified != Window::OnFileModified && fileName) { if(fileName) fileMonitor.fileName = fileName; } +#endif delete fileDialog; } return (bool)result; // Actually returning result from Yes/NoCancel message box @@ -7925,16 +8067,23 @@ public: bool MenuWindowWindows(MenuItem selection, Modifiers mods) { - WindowList dialog { master = this }; - Window document = (Window)(intptr)dialog.Modal(); - if(document) + WindowList { - if(activeChild.state == maximized) - document.SetState(maximized, false, mods); - else if(document.state == minimized) - document.SetState(normal, false, mods); - document.Activate(); - } + master = this; isModal = true; + + void NotifyDestroyed(Window window, DialogResult result) + { + Window document = (Window)(intptr)result; + if(document) + { + if(activeChild.state == maximized) + document.SetState(maximized, false, 0); + else if(document.state == minimized) + document.SetState(normal, false, 0); + document.Activate(); + } + } + }.Create(); return true; } @@ -7989,10 +8138,11 @@ public: virtual void OnChildResized(Window child, int x, int y, int w, int h); // Skins Virtual Functions - virtual void GetDecorationsSize(MinMaxValue * w, MinMaxValue * h); - virtual void SetWindowMinimum(MinMaxValue * mw, MinMaxValue * mh); + virtual void GetDecorationsSize(MinMaxValue * w, MinMaxValue * h) { *w = 0, *h = 0; } + virtual void SetWindowMinimum(MinMaxValue * mw, MinMaxValue * mh) { *mw = 0, *mh = 0; } virtual void SetWindowArea(int * x, int * y, MinMaxValue * w, MinMaxValue * h, MinMaxValue * cw, MinMaxValue * ch) { + *x = 0, *y = 0; *cw = *w; *ch = *h; } @@ -9420,8 +9570,10 @@ public: UpdateCaption(); // if(style.isDocument) +#if !defined(__EMSCRIPTEN__) if(!saving) fileMonitor.fileName = value; +#endif } get { return fileName; } }; @@ -9605,8 +9757,38 @@ public: } }; property bool moveable { get { return (bool)moveable; } set { moveable = value; } }; - property bool alphaBlend { get { return (bool)alphaBlend; } set { alphaBlend = value; } }; + property bool alphaBlend { get { return (bool)alphaBlend; } set { alphaBlend = value; if(value) nativeDecorations = false; /* Native Decorations are not supported with alphaBlend */ } }; property bool useSharedMemory { get { return (bool)useSharedMemory; } set { useSharedMemory = value; } }; + property GLCapabilities glCapabilities + { + get { return glCapabilities; } + set + { + bool reload = display != null && + (glCapabilities.nonPow2Textures != value.nonPow2Textures || + glCapabilities.intAndDouble != value.intAndDouble || + glCapabilities.vertexBuffer != value.vertexBuffer || + glCapabilities.compatible != value.compatible || + glCapabilities.legacyFormats != value.legacyFormats || + glCapabilities.debug != value.debug || + glCapabilities.vertexPointer != value.vertexPointer || + glCapabilities.quads != value.quads); + guiApp.modeSwitching = true; + if(reload) + UnloadGraphics(false); + + glCapabilities = value; + + if(reload) + { + if(SetupDisplay()) + LoadGraphics(false, false); + } + else if(display) + display.glCapabilities = value; + guiApp.modeSwitching = false; + } + }; property CreationActivationOption creationActivation { get { return creationActivation; } set { creationActivation = value; } }; property bool nativeDecorations { @@ -9735,10 +9917,14 @@ private: int numIcons; int positionID; +#if !defined(__EMSCRIPTEN__) Mutex mutex; +#endif WindowState lastState; +#if !defined(__EMSCRIPTEN__) FileMonitor fileMonitor; +#endif FontResource setFont, systemFont; FontResource usedFont; @@ -9755,6 +9941,8 @@ private: BitmapResource icon; void * windowData; CreationActivationOption creationActivation; + GLCapabilities glCapabilities; + glCapabilities = { true, true, true, true, true, true, true, true, true /*false*/, true, true, true, true, true, true, true }; struct { bool active:1; // true if window and ancestors are active