GTK #Eventbox MotionNotify无效

时间:2014-07-31 07:17:53

标签: c# mono gtk#

我的应用程序中有一个用于处理通知事件的EventBox(enternotify,motionNotify和LeaveNotify是我的兴趣事件)。在这个EventBox内部是一个HScale,我根据鼠标位置显示工具提示以寻找音频。但是动作nofity事件不会被解雇。

一些代码:

protected void ebAudiofileSeekerEnterNotifyEvent (object o, EnterNotifyEventArgs args)
    {
        log.debug("ebAudiofileSeekerEnterNotifyEvent called");
        int x = -1;
        int y = -1;
        int intX = -1;
        int intY = -1;
        int originX;
        int originY;
        this.GetPosition(out originX, out originY);
        Gdk.ModifierType modifierType = Gdk.ModifierType.None;
        this.Screen.RootWindow.GetPointer(out x, out y, out modifierType);
        this.hsAudiofileSeeker.TranslateCoordinates(this,this.hsAudiofileSeeker.Allocation.X,this.hsAudiofileSeeker.Allocation.Y,out intX,out intY);
        double valueAtPos = ((x - (intX + originX)) / (this.hsAudiofileSeeker.Allocation.Width * 1.0)) * this.hsAudiofileSeeker.Adjustment.Upper * 1.0;
        long ticksAtPosition = (this.objProgram.getAudioManager().getDuration().Ticks * (long)valueAtPos) / 100;
        TimeSpan timeSpanAtPosition = TimeSpan.FromTicks(ticksAtPosition);
        this.lblTooltipAudiofileSeeker.Text = (timeSpanAtPosition.Hours > 9 ? timeSpanAtPosition.Hours.ToString() : "0" + timeSpanAtPosition.Hours.ToString()) + ":" + (timeSpanAtPosition.Minutes > 9 ? timeSpanAtPosition.Minutes.ToString() : "0" + timeSpanAtPosition.Minutes.ToString()) + ":" + (timeSpanAtPosition.Seconds > 9 ? timeSpanAtPosition.Seconds.ToString() : "0" + timeSpanAtPosition.Seconds.ToString());
        this.hsAudiofileSeeker.TooltipWindow.Move(x, intY + originY);
        this.hsAudiofileSeeker.TooltipWindow.ShowAll();
    }

    protected void ebAudiofileSeekerMotionNotifyEvent (object o, MotionNotifyEventArgs args)
    {
        log.debug("ebAudiofileSeekerMotionNotifyEvent called");
        int x = -1;
        int y = -1;
        int intX = -1;
        int intY = -1;
        int originX;
        int originY;
        this.GetPosition(out originX, out originY);
        Gdk.ModifierType modifierType = Gdk.ModifierType.None;
        this.Screen.RootWindow.GetPointer(out x, out y, out modifierType);
        this.hsAudiofileSeeker.TranslateCoordinates(this,this.hsAudiofileSeeker.Allocation.X,this.hsAudiofileSeeker.Allocation.Y,out intX,out intY);
        double valueAtPos = ((x - (intX + originX)) / (this.hsAudiofileSeeker.Allocation.Width * 1.0)) * this.hsAudiofileSeeker.Adjustment.Upper * 1.0;
        long ticksAtPosition = (this.objProgram.getAudioManager().getDuration().Ticks * (long)valueAtPos) / 100;
        TimeSpan timeSpanAtPosition = TimeSpan.FromTicks(ticksAtPosition);
        this.lblTooltipAudiofileSeeker.Text = (timeSpanAtPosition.Hours > 9 ? timeSpanAtPosition.Hours.ToString() : "0" + timeSpanAtPosition.Hours.ToString()) + ":" + (timeSpanAtPosition.Minutes > 9 ? timeSpanAtPosition.Minutes.ToString() : "0" + timeSpanAtPosition.Minutes.ToString()) + ":" + (timeSpanAtPosition.Seconds > 9 ? timeSpanAtPosition.Seconds.ToString() : "0" + timeSpanAtPosition.Seconds.ToString());
        this.hsAudiofileSeeker.TooltipWindow.Move(x, intY + originY);
    }

    protected void ebAudiofileSeekerLeaveNotifyEvent (object o, LeaveNotifyEventArgs args)
    {
        log.debug("ebAudiofileSeekerLeaveNotifyEvent called");
        this.hsAudiofileSeeker.TooltipWindow.HideAll();
    }

ebAudiofileSeekerMotionNotifyEvent和ebAudiofileSeekerLeaveNotifyEvent工作,但不是动作事件,任何想法为什么?我有点困惑。 谢谢你的帮助。

2 个答案:

答案 0 :(得分:1)

您是否关闭了事件压缩?工具提示打开POINTER_MOTION_HINT_MASK,这会因事件压缩而混乱。

答案 1 :(得分:0)

我遇到了这个问题,将ebAudiofileSeeker Above Child属性设置为true,并为听众添加了以下代码:

protected void ebAudiofileSeekerEnterNotifyEvent (object o, EnterNotifyEventArgs args)
    {
        log.debug("ebAudiofileSeekerEnterNotifyEvent called");
        if (Program.getInstance().getAudioManager().Duration > TimeSpan.Zero)
        {
            int x = -1;
            int y = -1;
            int intX = -1;
            int intY = -1;
            int originX;
            int originY;
            this.GetPosition(out originX, out originY);
            Gdk.ModifierType modifierType = Gdk.ModifierType.None;
            this.Screen.RootWindow.GetPointer(out x, out y, out modifierType);
            this.hsAudiofileSeeker.TranslateCoordinates(this, this.hsAudiofileSeeker.Allocation.X, this.hsAudiofileSeeker.Allocation.Y, out intX, out intY);
            double valueAtPos = ((x - (intX + originX)) / (this.hsAudiofileSeeker.Allocation.Width * 1.0)) * this.hsAudiofileSeeker.Adjustment.Upper * 1.0;
            long ticksAtPosition = (Program.getInstance().getAudioManager().Duration.Ticks * (long)valueAtPos) / 100;
            TimeSpan timeSpanAtPosition = TimeSpan.FromTicks(ticksAtPosition);
            this.lblTooltipAudiofileSeeker.Text = (timeSpanAtPosition.Hours > 9 ? timeSpanAtPosition.Hours.ToString() : "0" + timeSpanAtPosition.Hours.ToString()) + ":" + (timeSpanAtPosition.Minutes > 9 ? timeSpanAtPosition.Minutes.ToString() : "0" + timeSpanAtPosition.Minutes.ToString()) + ":" + (timeSpanAtPosition.Seconds > 9 ? timeSpanAtPosition.Seconds.ToString() : "0" + timeSpanAtPosition.Seconds.ToString());
            this.hsAudiofileSeeker.TooltipWindow.Move(x, intY + originY);
            this.hsAudiofileSeeker.TooltipWindow.ShowAll();
        }
    }

protected void ebAudiofileSeekerMotionNotifyEvent (object o, MotionNotifyEventArgs args)
{
    log.debug("ebAudiofileSeekerMotionNotifyEvent called");
    if (Program.getInstance().getAudioManager().Duration > TimeSpan.Zero)
    {
        int x = -1;
        int y = -1;
        int intX = -1;
        int intY = -1;
        int originX;
        int originY;
        this.GetPosition(out originX, out originY);
        Gdk.ModifierType modifierType = Gdk.ModifierType.None;
        this.Screen.RootWindow.GetPointer(out x, out y, out modifierType);
        this.hsAudiofileSeeker.TranslateCoordinates(this, this.hsAudiofileSeeker.Allocation.X, this.hsAudiofileSeeker.Allocation.Y, out intX, out intY);
        double valueAtPos = ((x - (intX + originX)) / (this.hsAudiofileSeeker.Allocation.Width * 1.0)) * this.hsAudiofileSeeker.Adjustment.Upper * 1.0;
        log.debug("modifier = " + modifierType);
        if (modifierType.HasFlag(Gdk.ModifierType.Button1Mask))
        {
            log.debug("modifier is button 1, so change value");
            this.hsAudiofileSeeker.Value = valueAtPos;
        }
        long ticksAtPosition = (Program.getInstance().getAudioManager().Duration.Ticks * (long)valueAtPos) / 100;
        TimeSpan timeSpanAtPosition = TimeSpan.FromTicks(ticksAtPosition);
        this.lblTooltipAudiofileSeeker.Text = (timeSpanAtPosition.Hours > 9 ? timeSpanAtPosition.Hours.ToString() : "0" + timeSpanAtPosition.Hours.ToString()) + ":" + (timeSpanAtPosition.Minutes > 9 ? timeSpanAtPosition.Minutes.ToString() : "0" + timeSpanAtPosition.Minutes.ToString()) + ":" + (timeSpanAtPosition.Seconds > 9 ? timeSpanAtPosition.Seconds.ToString() : "0" + timeSpanAtPosition.Seconds.ToString());
        this.hsAudiofileSeeker.TooltipWindow.Move(x, intY + originY);
    }
}

protected void ebAudiofileSeekerLeaveNotifyEvent (object o, LeaveNotifyEventArgs args)
{
    log.debug("ebAudiofileSeekerLeaveNotifyEvent called");
    this.hsAudiofileSeeker.TooltipWindow.HideAll();
}

可以在此处找到代码:http://sourceforge.net/p/audiocuesheet/code/HEAD/tree/