SvgElement.cs 42.7 KB
Newer Older
1001
        		caller.UnregisterAction(rpcID + "onmousemove");
joreg's avatar
joreg committed
1002
        		caller.UnregisterAction(rpcID + "onmousescroll");
1003
1004
1005
1006
        		caller.UnregisterAction(rpcID + "onmouseover");
        		caller.UnregisterAction(rpcID + "onmouseout");
        	}
        }
Eric Domke's avatar
Eric Domke committed
1007
#endif
1008

Tebjan Halm's avatar
Tebjan Halm committed
1009
1010
1011
        [SvgAttribute("onclick")]
        public event EventHandler<MouseArg> Click;

1012
1013
1014
1015
1016
        [SvgAttribute("onmousedown")]
        public event EventHandler<MouseArg> MouseDown;

        [SvgAttribute("onmouseup")]
        public event EventHandler<MouseArg> MouseUp;
1017
1018
        
        [SvgAttribute("onmousemove")]
1019
        public event EventHandler<MouseArg> MouseMove;
1020

joreg's avatar
joreg committed
1021
        [SvgAttribute("onmousescroll")]
1022
        public event EventHandler<MouseScrollArg> MouseScroll;
joreg's avatar
joreg committed
1023
        
1024
        [SvgAttribute("onmouseover")]
1025
        public event EventHandler<MouseArg> MouseOver;
1026
1027

        [SvgAttribute("onmouseout")]
1028
        public event EventHandler<MouseArg> MouseOut;
1029
        
Eric Domke's avatar
Eric Domke committed
1030
#if Net4
1031
        protected Action<float, float, int, int, bool, bool, bool, string> CreateMouseEventAction(Action<object, MouseArg> eventRaiser)
Tebjan Halm's avatar
Tebjan Halm committed
1032
        {
1033
1034
        	return (x, y, button, clickCount, altKey, shiftKey, ctrlKey, sessionID) =>
        		eventRaiser(this, new MouseArg { x = x, y = y, Button = button, ClickCount = clickCount, AltKey = altKey, ShiftKey = shiftKey, CtrlKey = ctrlKey, SessionID = sessionID });
1035
        }
Eric Domke's avatar
Eric Domke committed
1036
1037
#endif

1038
        //click
1039
1040
1041
1042
1043
1044
        protected void RaiseMouseClick(object sender, MouseArg e)
        {
        	var handler = Click;
        	if (handler != null)
        	{
        		handler(sender, e);
1045
1046
1047
            }
        }

1048
        //down
Tebjan Halm's avatar
Tebjan Halm committed
1049
1050
1051
        protected void RaiseMouseDown(object sender, MouseArg e)
        {
        	var handler = MouseDown;
1052
1053
            if (handler != null)
            {
Tebjan Halm's avatar
Tebjan Halm committed
1054
                handler(sender, e);
1055
1056
1057
            }
        }

1058
1059
1060
1061
        //up
        protected void RaiseMouseUp(object sender, MouseArg e)
        {
        	var handler = MouseUp;
1062
1063
            if (handler != null)
            {
1064
                handler(sender, e);
1065
1066
            }
        }
1067
1068

        protected void RaiseMouseMove(object sender, MouseArg e)
1069
1070
        {
        	var handler = MouseMove;
1071
1072
            if (handler != null)
            {
1073
                handler(sender, e);
1074
1075
            }
        }
joreg's avatar
joreg committed
1076
        
1077
1078
        //over
        protected void RaiseMouseOver(object sender, MouseArg args)
1079
1080
        {
        	var handler = MouseOver;
1081
1082
            if (handler != null)
            {
Tebjan Halm's avatar
Tebjan Halm committed
1083
                handler(sender, args);
Tebjan Halm's avatar
Tebjan Halm committed
1084
1085
1086
            }
        }

1087
        //out
1088
        protected void RaiseMouseOut(object sender, MouseArg args)
1089
        {
1090
        	var handler = MouseOut;
1091
1092
            if (handler != null)
            {
Tebjan Halm's avatar
Tebjan Halm committed
1093
                handler(sender, args);
1094
1095
            }
        }
joreg's avatar
joreg committed
1096
        
1097
1098
        
        //scroll
1099
        protected void OnMouseScroll(int scroll, bool ctrlKey, bool shiftKey, bool altKey, string sessionID)
joreg's avatar
joreg committed
1100
        {
1101
        	RaiseMouseScroll(this, new MouseScrollArg { Scroll = scroll, AltKey = altKey, ShiftKey = shiftKey, CtrlKey = ctrlKey, SessionID = sessionID});
joreg's avatar
joreg committed
1102
1103
        }
        
1104
        protected void RaiseMouseScroll(object sender, MouseScrollArg e)
joreg's avatar
joreg committed
1105
        {
1106
        	var handler = MouseScroll;
joreg's avatar
joreg committed
1107
1108
            if (handler != null)
            {
1109
                handler(sender, e);
joreg's avatar
joreg committed
1110
1111
            }
        }
1112
        
Tebjan Halm's avatar
Tebjan Halm committed
1113
1114
        #endregion graphical EVENTS
    }
1115
    
Tebjan Halm's avatar
Tebjan Halm committed
1116
1117
1118
1119
1120
1121
    public class SVGArg : EventArgs
    {
    	public string SessionID;
    }
    	
    
1122
1123
1124
    /// <summary>
    /// Describes the Attribute which was set
    /// </summary>
Tebjan Halm's avatar
Tebjan Halm committed
1125
    public class AttributeEventArgs : SVGArg
1126
1127
1128
1129
    {
    	public string Attribute;
    	public object Value;
    }
tebjan's avatar
tebjan committed
1130
    
tebjan's avatar
tebjan committed
1131
1132
1133
1134
1135
1136
1137
1138
    /// <summary>
    /// Content of this whas was set
    /// </summary>
    public class ContentEventArgs : SVGArg
    {
    	public string Content;
    }
    
tebjan's avatar
tebjan committed
1139
1140
1141
1142
1143
1144
    /// <summary>
    /// Describes the Attribute which was set
    /// </summary>
    public class ChildAddedEventArgs : SVGArg
    {
    	public SvgElement NewChild;
1145
    	public SvgElement BeforeSibling;
tebjan's avatar
tebjan committed
1146
    }
Tebjan Halm's avatar
Tebjan Halm committed
1147

Eric Domke's avatar
Eric Domke committed
1148
#if Net4
1149
1150
1151
    //deriving class registers event actions and calls the actions if the event occurs
    public interface ISvgEventCaller
    {
1152
        void RegisterAction(string rpcID, Action action);
1153
1154
1155
1156
        void RegisterAction<T1>(string rpcID, Action<T1> action);
        void RegisterAction<T1, T2>(string rpcID, Action<T1, T2> action);
        void RegisterAction<T1, T2, T3>(string rpcID, Action<T1, T2, T3> action);
        void RegisterAction<T1, T2, T3, T4>(string rpcID, Action<T1, T2, T3, T4> action);
Tebjan Halm's avatar
Tebjan Halm committed
1157
        void RegisterAction<T1, T2, T3, T4, T5>(string rpcID, Action<T1, T2, T3, T4, T5> action);
1158
1159
1160
        void RegisterAction<T1, T2, T3, T4, T5, T6>(string rpcID, Action<T1, T2, T3, T4, T5, T6> action);
        void RegisterAction<T1, T2, T3, T4, T5, T6, T7>(string rpcID, Action<T1, T2, T3, T4, T5, T6, T7> action);
        void RegisterAction<T1, T2, T3, T4, T5, T6, T7, T8>(string rpcID, Action<T1, T2, T3, T4, T5, T6, T7, T8> action);
1161
        void UnregisterAction(string rpcID);
1162
    }
Eric Domke's avatar
Eric Domke committed
1163
#endif
1164

Tebjan Halm's avatar
Tebjan Halm committed
1165
1166
1167
    /// <summary>
    /// Represents the state of the mouse at the moment the event occured.
    /// </summary>
Tebjan Halm's avatar
Tebjan Halm committed
1168
    public class MouseArg : SVGArg
Tebjan Halm's avatar
Tebjan Halm committed
1169
1170
1171
1172
1173
    {
        public float x;
        public float y;

        /// <summary>
1174
        /// 1 = left, 2 = middle, 3 = right
Tebjan Halm's avatar
Tebjan Halm committed
1175
        /// </summary>
1176
        public int Button;
1177
        
1178
1179
1180
        /// <summary>
        /// Amount of mouse clicks, e.g. 2 for double click
        /// </summary>
1181
        public int ClickCount = -1;
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
        
        /// <summary>
        /// Alt modifier key pressed
        /// </summary>
        public bool AltKey;
        
        /// <summary>
        /// Shift modifier key pressed
        /// </summary>
        public bool ShiftKey;
        
        /// <summary>
        /// Control modifier key pressed
        /// </summary>
        public bool CtrlKey;
1197
    }
joreg's avatar
joreg committed
1198
1199
1200
1201
    
    /// <summary>
    /// Represents a string argument
    /// </summary>
Tebjan Halm's avatar
Tebjan Halm committed
1202
    public class StringArg : SVGArg
joreg's avatar
joreg committed
1203
1204
1205
    {
        public string s;
    }
1206
1207
1208
1209
    
    public class MouseScrollArg : SVGArg
    {
    	public int Scroll;
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
    	
    	/// <summary>
        /// Alt modifier key pressed
        /// </summary>
        public bool AltKey;
        
        /// <summary>
        /// Shift modifier key pressed
        /// </summary>
        public bool ShiftKey;
        
        /// <summary>
        /// Control modifier key pressed
        /// </summary>
        public bool CtrlKey;
1225
    }
1226

1227
1228
1229
    public interface ISvgNode
    {
        string Content { get; }
1230
1231
1232
1233
1234
1235
        
        /// <summary>
        /// Create a deep copy of this <see cref="ISvgNode"/>.
        /// </summary>
        /// <returns>A deep copy of this <see cref="ISvgNode"/></returns>
        ISvgNode DeepCopy();
1236
1237
    }

1238
1239
1240
1241
    /// <summary>This interface mostly indicates that a node is not to be drawn when rendering the SVG.</summary>
    public interface ISvgDescriptiveElement {
    }

davescriven's avatar
davescriven committed
1242
1243
    internal interface ISvgElement
    {
1244
1245
		SvgElement Parent {get;}
		SvgElementCollection Children { get; }
1246
        IList<ISvgNode> Nodes { get; }
1247

Eric Domke's avatar
Eric Domke committed
1248
        void Render(ISvgRenderer renderer);
davescriven's avatar
davescriven committed
1249
    }
Tebjan Halm's avatar
Tebjan Halm committed
1250
}