]> O.S.I.I.S - jp/crow.git/commitdiff
forward mouse event
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 2 Jan 2019 07:01:15 +0000 (08:01 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 2 Jan 2019 07:01:15 +0000 (08:01 +0100)
Crow/Templates/Popper.template
Crow/src/GraphicObjects/MenuItem.cs
Crow/src/GraphicObjects/TreeView.cs
Crow/src/GraphicObjects/Widget.cs
Crow/src/Interface.cs
Crow/src/PerformanceMeasure.cs
Crow/src/backends/win32/WinBackend.cs
Crow/src/backends/xcb/XCBBackend.cs
Crow/src/backends/xlib/XLibBackend.cs
CrowIDE/DefaultTemplateOverrides/MenuItem.template

index 47c6034c5acd7dfbb5a48ccf6c6074f7aa468240..6b9bef9f3331403ba80b0e4ffcf55b126d3bd214 100755 (executable)
@@ -1,7 +1,7 @@
 <?xml version="1.0"?>
 <CheckBox Caption="{./Caption}" IsChecked="{²./IsPopped}" Foreground="{./Foreground}" Background="{./Background}">
        <Template>
-               <Border Style="ControlBorder" Foreground="{./Foreground}" Background="{./Background}">
+               <Border Style="ControlBorder" Foreground="{./Foreground}" Background="{./Background}" ForwardMouseEvents="true">
                        <HorizontalStack Spacing="1">
                                <Image Style="Icon" Margin="1" Width="9" Height="9"     
                                        MouseEnter="{Background=White}" MouseLeave="{Background=Transparent}"
index 7ad9f758986aed3459bf7927e907887ba3c5587a..5cfce44f89bf22ae567ec8887616a05f2a9dcad3 100644 (file)
@@ -141,15 +141,6 @@ namespace Crow
                                mName = "IsEnabled";
                        NotifyValueChanged (mName, e.NewValue);
                }
-               void onMI_Click (object sender, MouseButtonEventArgs e)
-               {
-                       if (command != null) {
-                               command.Execute ();
-                               closeMenu ();
-                       }
-                       if(!IsOpened)
-                               (LogicalParent as Menu).AutomaticOpening = false;
-               }
                protected virtual void onOpen (object sender, EventArgs e){
                        Open.Raise (this, null);
                }
@@ -176,7 +167,18 @@ namespace Crow
                                IsOpened = false;
                        base.onMouseLeave (this, e);
                }
+               public override void onMouseClick (object sender, MouseButtonEventArgs e)
+               {
+                       if (command != null) {
+                               command.Execute ();
+                               closeMenu ();
+                       }
+                       if (hasClick)
+                               base.onMouseClick (sender, e);
 
+                       if (!IsOpened)
+                               (LogicalParent as Menu).AutomaticOpening = false;
+               }
                void closeMenu () {
                        MenuItem tmp = LogicalParent as MenuItem;
                        while (tmp != null) {
index 12910ac41c124d0e62592753fc82898b87892601..3bcf63824402a7cda916dcf3eeaa73b43bf7a455 100644 (file)
@@ -65,8 +65,6 @@ namespace Crow
                internal override void itemClick (object sender, MouseButtonEventArgs e)
                {
                        Widget tmp = sender as Widget;
-//                     if (!tmp.HasFocus)
-                               //return;
                        /*if (selectedItemContainer != null) {
                                selectedItemContainer.Foreground = Color.Transparent;
                                selectedItemContainer.Background = Color.Transparent;
index 2ecaf28e0aa261ae8b9456e88b27e38ab9552a52..f047e67acd736fa38aff1bc2c12ff8c11a2b08b8 100644 (file)
@@ -289,6 +289,7 @@ namespace Crow
                bool isActive;
                bool isHover;
                bool mouseRepeat;
+               bool forwardMouseEvents;
                protected bool isVisible = true;
                bool isEnabled = true;
                VerticalAlignment verticalAlignment = VerticalAlignment.Center;
@@ -778,6 +779,19 @@ namespace Crow
                                NotifyValueChanged ("MouseRepeat", mouseRepeat);
                        }
                }
+               /// <summary>
+               /// forward mouse events even if an handle is bound
+               /// </summary>
+               [DesignCategory ("Behaviour")][DefaultValue (false)]
+               public bool ForwardMouseEvents {
+                       get { return forwardMouseEvents; }
+                       set {
+                               if (forwardMouseEvents == value)
+                                       return;
+                               forwardMouseEvents = value;
+                               NotifyValueChanged ("ForwardMouseEvents", forwardMouseEvents);
+                       }
+               }
                bool clearBackground = false;
                /// <summary>
                /// background fill of the control, maybe solid color, gradient, image, or svg
@@ -1666,8 +1680,9 @@ namespace Crow
                        else if (LastPaintedSlot.Width != Slot.Width || LastPaintedSlot.Height != Slot.Height)
                                bmp.SetSize (Slot.Width, Slot.Height);*/
                        bmp?.Dispose ();
+                       //bmp = IFace.surf.CreateSimilar (Content.ColorAlpha, Slot.Width, Slot.Height);
                        bmp = new ImageSurface(Format.Argb32, Slot.Width, Slot.Height);
-                       
+
                        using (Context gr = new Context (bmp)) {
                                gr.Antialias = Interface.Antialias;
                                onDraw (gr);
@@ -1825,15 +1840,15 @@ namespace Crow
                                                IFace.ShowContextMenu (this);                                   
                                }
                        }*/
-                       if (MouseDown == null)
-                               focusParent?.onMouseDown (sender, e);
-                       else
+                       if (MouseDown != null)
                                MouseDown.Invoke (this, e);
+                       if (MouseDown == null || forwardMouseEvents)
+                               focusParent?.onMouseDown (sender, e);
                }
                public virtual void onMouseUp(object sender, MouseButtonEventArgs e){
-                       #if DEBUG_FOCUS
+#if DEBUG_FOCUS
                        Debug.WriteLine("MOUSE UP => " + this.ToString());
-                       #endif
+#endif
 
                        /*if (IFace.DragAndDropOperation != null){
                                if (IFace.DragAndDropOperation.DragSource == this) {
@@ -1845,36 +1860,36 @@ namespace Crow
                                }
                        }*/
 
-                       if (MouseUp == null)
-                               focusParent?.onMouseUp (sender, e);
-                       else 
+                       if (MouseUp != null)
                                MouseUp.Invoke (this, e);
+                       if (MouseUp == null || forwardMouseEvents)
+                               focusParent?.onMouseUp (sender, e);
+
                }
                public virtual void onMouseClick(object sender, MouseButtonEventArgs e){
 #if DEBUG_FOCUS
                        Debug.WriteLine("CLICK => " + this.ToString());
 #endif
-            if (MouseClick == null)
+                       if (MouseClick != null)
+                               MouseClick.Invoke (this, e);
+                       if (MouseClick == null || forwardMouseEvents)
                                focusParent?.onMouseClick (sender, e);
-                       else
-                               MouseClick.Invoke(this, e);
                }
                public virtual void onMouseDoubleClick(object sender, MouseButtonEventArgs e){
 #if DEBUG_FOCUS
                        Debug.WriteLine("DOUBLE CLICK => " + this.ToString());
 #endif
-                       if (MouseDoubleClick == null)
-                               focusParent?.onMouseDoubleClick (sender, e);
-                       else
+                       if (MouseDoubleClick != null)
                                MouseDoubleClick.Invoke (this, e);
+                       if (MouseDoubleClick == null || forwardMouseEvents)
+                               focusParent?.onMouseDoubleClick (sender, e);
                }
                public virtual void onMouseWheel(object sender, MouseWheelEventArgs e){
-            if (MouseWheelChanged == null)
+                       if (MouseWheelChanged != null)
+                               MouseWheelChanged.Invoke (this, e);
+                       if (MouseWheelChanged == null || forwardMouseEvents)
                                focusParent?.onMouseWheel (sender, e);
-                       else
-                               MouseWheelChanged.Invoke(this, e);
 
-            
                }
                public virtual void onMouseEnter(object sender, MouseMoveEventArgs e)
                {
index 7090eadd8492f90e74c11f96aaf1a7756a3f358e..170403c4670d0d742af9269143eb80f1d4f840a7 100644 (file)
@@ -118,20 +118,12 @@ namespace Crow
                protected bool running;
                protected virtual void InitBackend () {
             if (Environment.OSVersion.Platform == PlatformID.Unix)
-                backend = new Crow.XLib.XLibBackend();
-            else
-                backend = new Crow.Win32.Win32Backend();
+                               backend = new XLib.XLibBackend();
+                               //backend = new Crow.XCB.XCBBackend();
+                       else
+                               backend = new Crow.Win32.Win32Backend();
 
-                       //backend = new Crow.XLib.XLibBackend ();
                        backend.Init (this);
-
-                       /*initTooltip ();
-                       initContextMenus ();*/
-
-
-                       /*Thread t = new Thread (interfaceThread);
-                       t.IsBackground = true;
-                       t.Start ();*/
                }
                public void Run () {
                        //load default main.crow if present
@@ -141,18 +133,20 @@ namespace Crow
 
                        running = true;
 
+                       int frameCount = 0;
+
                        while (running) {
                                Update ();
                                ProcessEvents ();
-                       }
-               }
-
 
-               void interfaceThread()
-               {                       
-                       while (running) {
-                               Update ();
-                               Thread.Sleep (1);
+#if MEASURE_TIME
+                               if (frameCount++ < 1000)
+                                       continue;
+                               for (int i = 0; i < PerfMeasures.Count; i++) {
+                                       PerfMeasures [i].NotifyChanges ();
+                               }
+                               frameCount = 0;
+#endif
                        }
                }
 
@@ -273,8 +267,8 @@ namespace Crow
                /// </summary>
                protected static Interface CurrentInterface;
                Stopwatch lastClickTime = new Stopwatch();
-               Widget armedClick;//store widget with double click on first click
-               MouseButtonEventArgs armedClickEventArgs;
+               internal Widget armedClick;//store widget with double click on first click
+               internal MouseButtonEventArgs armedClickEventArgs;
 
                #endregion
 
@@ -941,14 +935,11 @@ namespace Crow
                        lock (UpdateMutex) {
                                clientRectangle = bounds;
 
-                               /*surf.Dispose ();
-                               surf = new Cairo.XlibSurface (xHandle, xwinHnd, xDefaultVisual, clientRectangle.Width, clientRectangle.Height);*/
                                if (surf is XlibSurface)
                                        (surf as XlibSurface).SetSize (clientRectangle.Width, clientRectangle.Height);
                                else if (surf is XcbSurface)
                                        (surf as XcbSurface).SetSize (clientRectangle.Width, clientRectangle.Height);
 
-
                                foreach (Widget g in GraphicTree)
                                        g.RegisterForLayouting (LayoutingType.All);
 
@@ -977,8 +968,9 @@ namespace Crow
                        int deltaY = y - Mouse.Y;
                        Mouse.X = x;
                        Mouse.Y = y;
-                       MouseMoveEventArgs e = new MouseMoveEventArgs (x, y, deltaX, deltaY);
-                       e.Mouse = Mouse;
+                       MouseMoveEventArgs e = new MouseMoveEventArgs (x, y, deltaX, deltaY) {
+                               Mouse = Mouse
+                       };
 
                        if (armedClick != null) {
                                armedClick.onMouseClick (armedClick, armedClickEventArgs);
@@ -1098,8 +1090,10 @@ namespace Crow
                                } else
                                        target = target.focusParent;
                        }
+                       if (target == null)
+                               _activeWidget?.onMouseClick (_activeWidget, e);
 
-//                     GraphicObject lastActive = _activeWidget;
+                       //                      GraphicObject lastActive = _activeWidget;
                        ActiveWidget = null;
 //                     if (!lastActive.MouseIsIn (Mouse.Position)) {
 //                             ProcessMouseMove (Mouse.X, Mouse.Y);
@@ -1117,24 +1111,12 @@ namespace Crow
                        lastMouseDown.Start ();
                        mouseRepeatCount = 0;
 
-                       lastMouseDownEvent = new MouseButtonEventArgs (button) { Mouse = Mouse };
-
-                       if (HoverWidget == null)
+                       if (_hoverWidget == null)
                                return false;
 
-                       Widget hoverFocused = HoverWidget;
-                       while (!hoverFocused.Focusable) {
-                               hoverFocused = hoverFocused.focusParent;
-                               if (hoverFocused == null) {
-                                       hoverFocused = HoverWidget;
-                                       break;
-                               }
-                       }
-
-                       _hoverWidget.onMouseDown(_hoverWidget,lastMouseDownEvent);
+                       lastMouseDownEvent = new MouseButtonEventArgs (button) { Mouse = Mouse };
 
-                       /*if (_focusedWidget == null)
-                               return true;*/
+                       _hoverWidget.onMouseDown (_hoverWidget, lastMouseDownEvent);
 
                        ActiveWidget = _hoverWidget;
                        return true;
@@ -1143,7 +1125,6 @@ namespace Crow
                /// Forward the mouse wheel event from the host to the crow interface
                /// </summary>
                /// <returns>return true, if interface handled the event, false otherwise.</returns>
-               /// <param name="button">Button index</param>
                public bool ProcessMouseWheelChanged(float delta)
                {
                        Mouse.SetScrollRelative (0, delta);
@@ -1165,23 +1146,13 @@ namespace Crow
                {
                        if (_focusedWidget != null)
                                _focusedWidget.onKeyUp (this, new KeyEventArgs (key, false));
-                       //                      if (keyboardRepeatThread != null) {
-                       //                              keyboardRepeatOn = false;
-                       //                              keyboardRepeatThread.Abort();
-                       //                              keyboardRepeatThread.Join ();
-                       //                      }
                }
                public void ProcessKeyDown (Key key)
                {
-                       //Keyboard.SetKeyState((Crow.Key)Key,true);
                        lastKeyDownEvt = new KeyEventArgs (key, true);
 
                        if (_focusedWidget != null)
                                _focusedWidget.onKeyDown (this, new KeyEventArgs (key, false));
-
-                       //                      keyboardRepeatThread = new Thread (keyboardRepeatThreadFunc);
-                       //                      keyboardRepeatThread.IsBackground = true;
-                       //                      keyboardRepeatThread.Start ();
                }
 
                public bool Shift {
index 3c978e8b473e379353b63c7aee19e80300eca9f1..e94692de6b26dd9c444aaf0683cb431a6a0d0947 100644 (file)
@@ -82,7 +82,6 @@ namespace Crow
                                maximum = timer.ElapsedTicks;                   
                }
                void ResetStats(){
-                       Debug.WriteLine("reset measure cpt:{0}",cptMeasures);
                        cptMeasures = total = current = maximum = 0;
                        minimum = long.MaxValue;
                }
index 66157fe76a9f50d25197f46a15b65cfdf9ce39e6..f05814bdf5c4f577c8df3a1eca6089bf06352eed 100644 (file)
@@ -466,7 +466,7 @@ namespace Crow.Win32
 
                public void SetCursor (MouseCursors newCur)
                {
-                       throw new NotImplementedException ();
+                       //throw new NotImplementedException ();
                }
 
                public void SetCursorPosition (int x, int y)
index 51ea91bde9a527017d764373e4483ab81ef34cdd..46d72670d553cdb5a0031c301f0a4a15c5987ab9 100644 (file)
@@ -516,7 +516,7 @@ namespace Crow.XCB
 
                public void SetCursor (MouseCursors newCur)
                {
-                       throw new NotImplementedException ();
+                       //throw new NotImplementedException ();
                }
 
                public void SetCursorPosition (int x, int y)
index 9271144f19915e4156ca0ac28121a5cbe3308649..dfb58e874d54a44835ade5930cc1f2e0052353dd 100644 (file)
@@ -86,7 +86,8 @@ namespace Crow.XLib
 
                [DllImport ("libXcursor.so.1")]
                static extern IntPtr XcursorImageLoadCursor (IntPtr dpy, IntPtr image);
-
+               [DllImport ("X11-xcb")]
+               static extern IntPtr XGetXCBConnection (IntPtr dpy);
                #endregion
 
                IntPtr xDisp, xwinHnd, xDefaultRootWin, xDefaultVisual;
@@ -95,7 +96,7 @@ namespace Crow.XLib
                XErrorHandler errorHnd;
 
                Interface iFace;
-               X11Keyboard keyboard;
+               XKB.XCBKeyboard Keyboard;
 
                IntPtr [] cursors = new IntPtr [(int)MouseCursors.MaxEnum];
 
@@ -109,6 +110,9 @@ namespace Crow.XLib
                        if (xDisp == IntPtr.Zero)
                                throw new NotSupportedException("[XLib] Failed to open display.");
 
+                       IntPtr xcbCon = XGetXCBConnection (xDisp);
+                       Keyboard = new XKB.XCBKeyboard (xcbCon, iFace);
+
                        xScreen = XDefaultScreen(xDisp);
 
                        xDefaultRootWin = XDefaultRootWindow (xDisp);
@@ -126,7 +130,7 @@ namespace Crow.XLib
 
                        XMapWindow (xDisp, xwinHnd);
 
-                       keyboard = new Crow.XLib.X11Keyboard (xDisp);
+                       //keyboard = new Crow.XLib.X11Keyboard (xDisp);
 
                        iFace.surf = new Crow.Cairo.XlibSurface (xDisp, xwinHnd, xDefaultVisual, iFace.ClientRectangle.Width, iFace.ClientRectangle.Height);
 
@@ -138,12 +142,12 @@ namespace Crow.XLib
 
                public void CleanUp ()
                {
-                       keyboard.Destroy ();
+                       Keyboard.Destroy ();
 
                        XCloseDisplay (xDisp);
                }
                public void Flush () {
-                       XSync (xDisp, 1);
+                       XSync (xDisp, 0);
                }
                public void ProcessEvents ()
                {
@@ -156,10 +160,10 @@ namespace Crow.XLib
                                        iFace.ProcessResize (new Rectangle (0, 0, xevent.ExposeEvent.width, xevent.ExposeEvent.height));
                                        break;
                                case XEventName.KeyPress:
-                                       keyboard.HandleEvent ((uint)xevent.KeyEvent.keycode, true);
+                                       Keyboard.HandleEvent ((uint)xevent.KeyEvent.keycode, true);
                                        break;
                                case XEventName.KeyRelease:
-                                       keyboard.HandleEvent ((uint)xevent.KeyEvent.keycode, false);
+                                       Keyboard.HandleEvent ((uint)xevent.KeyEvent.keycode, false);
                                        break;
                                case XEventName.MotionNotify:
                                        //Debug.WriteLine ("motion: ({0},{1})", xevent.MotionEvent.x, xevent.MotionEvent.y);
@@ -182,23 +186,18 @@ namespace Crow.XLib
                                }
                        }
                }
-               public bool IsDown (Key key) {
+               public bool IsDown (Key key)
+               {
                        return false;
                }
                public bool Shift {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return Keyboard.Shift; }
                }
                public bool Ctrl {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return Keyboard.Ctrl; }
                }
                public bool Alt {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return Keyboard.Alt; }
                }
                public void SetCursor (MouseCursors newCur)
                {
index bf01f99ddbb867e8e1fa4c29e347028d1b016b1c..2ed8496a0f941b65d70b8b1b9ac9896f2d0d7927 100644 (file)
@@ -1,11 +1,11 @@
 <?xml version="1.0"?>
 <Popper Font="{./Font}" Caption="{./Caption}"  Background="{./Background}" PopDirection="{./PopDirection}"
-       Foreground = "{./Foreground}" CanPop="{./HasChildren}" MouseClick="./onMI_Click"
+       Foreground = "{./Foreground}" CanPop="{./HasChildren}"
        IsPopped="{²./IsOpened}" PopWidth="{./PopWidth}" PopHeight="{./PopHeight}" IsEnabled="{./IsEnabled}">
        <Template>
                <CheckBox IsChecked="{²./IsPopped}" Caption="{./Caption}" Background="{./Background}" Foreground="{./Foreground}">
                        <Template>
-                               <Border Name="border1"
+                               <Border Name="border1" ForwardMouseEvents="true"
                                                MouseEnter="{Foreground=vgradient|0:White|0.2:Grey|0.9:Grey|1:Black}"
                                                MouseLeave="{Foreground=Transparent}"
                                                MouseDown="{Foreground=vgradient|0:Black|0.05:Grey|0.85:Grey|1:White}"