SvgElement.cs 43 KB
Newer Older
Tebjan Halm's avatar
Tebjan Halm committed
1001
        	if (caller != null && !string.IsNullOrEmpty(this.ID))
1002
1003
1004
1005
1006
1007
1008
        	{
        		var rpcID = this.ID + "/";

        		caller.UnregisterAction(rpcID + "onclick");
        		caller.UnregisterAction(rpcID + "onmousedown");
        		caller.UnregisterAction(rpcID + "onmouseup");
        		caller.UnregisterAction(rpcID + "onmousemove");
joreg's avatar
joreg committed
1009
        		caller.UnregisterAction(rpcID + "onmousescroll");
1010
1011
1012
1013
        		caller.UnregisterAction(rpcID + "onmouseover");
        		caller.UnregisterAction(rpcID + "onmouseout");
        	}
        }
Eric Domke's avatar
Eric Domke committed
1014
#endif
1015

Tebjan Halm's avatar
Tebjan Halm committed
1016
1017
1018
        [SvgAttribute("onclick")]
        public event EventHandler<MouseArg> Click;

1019
1020
1021
1022
1023
        [SvgAttribute("onmousedown")]
        public event EventHandler<MouseArg> MouseDown;

        [SvgAttribute("onmouseup")]
        public event EventHandler<MouseArg> MouseUp;
1024
1025
        
        [SvgAttribute("onmousemove")]
1026
        public event EventHandler<MouseArg> MouseMove;
1027

joreg's avatar
joreg committed
1028
        [SvgAttribute("onmousescroll")]
1029
        public event EventHandler<MouseScrollArg> MouseScroll;
joreg's avatar
joreg committed
1030
        
1031
        [SvgAttribute("onmouseover")]
1032
        public event EventHandler<MouseArg> MouseOver;
1033
1034

        [SvgAttribute("onmouseout")]
1035
        public event EventHandler<MouseArg> MouseOut;
1036
        
Eric Domke's avatar
Eric Domke committed
1037
#if Net4
1038
        protected Action<float, float, int, int, bool, bool, bool, string> CreateMouseEventAction(Action<object, MouseArg> eventRaiser)
Tebjan Halm's avatar
Tebjan Halm committed
1039
        {
1040
1041
        	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 });
1042
        }
Eric Domke's avatar
Eric Domke committed
1043
1044
#endif

1045
        //click
1046
1047
1048
1049
1050
1051
        protected void RaiseMouseClick(object sender, MouseArg e)
        {
        	var handler = Click;
        	if (handler != null)
        	{
        		handler(sender, e);
1052
1053
1054
            }
        }

1055
        //down
Tebjan Halm's avatar
Tebjan Halm committed
1056
1057
1058
        protected void RaiseMouseDown(object sender, MouseArg e)
        {
        	var handler = MouseDown;
1059
1060
            if (handler != null)
            {
Tebjan Halm's avatar
Tebjan Halm committed
1061
                handler(sender, e);
1062
1063
1064
            }
        }

1065
1066
1067
1068
        //up
        protected void RaiseMouseUp(object sender, MouseArg e)
        {
        	var handler = MouseUp;
1069
1070
            if (handler != null)
            {
1071
                handler(sender, e);
1072
1073
            }
        }
1074
1075

        protected void RaiseMouseMove(object sender, MouseArg e)
1076
1077
        {
        	var handler = MouseMove;
1078
1079
            if (handler != null)
            {
1080
                handler(sender, e);
1081
1082
            }
        }
joreg's avatar
joreg committed
1083
        
1084
1085
        //over
        protected void RaiseMouseOver(object sender, MouseArg args)
1086
1087
        {
        	var handler = MouseOver;
1088
1089
            if (handler != null)
            {
Tebjan Halm's avatar
Tebjan Halm committed
1090
                handler(sender, args);
Tebjan Halm's avatar
Tebjan Halm committed
1091
1092
1093
            }
        }

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

Eric Domke's avatar
Eric Domke committed
1155
#if Net4
1156
1157
1158
    //deriving class registers event actions and calls the actions if the event occurs
    public interface ISvgEventCaller
    {
1159
        void RegisterAction(string rpcID, Action action);
1160
1161
1162
1163
        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
1164
        void RegisterAction<T1, T2, T3, T4, T5>(string rpcID, Action<T1, T2, T3, T4, T5> action);
1165
1166
1167
        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);
1168
        void UnregisterAction(string rpcID);
1169
    }
Eric Domke's avatar
Eric Domke committed
1170
#endif
1171

Tebjan Halm's avatar
Tebjan Halm committed
1172
1173
1174
    /// <summary>
    /// Represents the state of the mouse at the moment the event occured.
    /// </summary>
Tebjan Halm's avatar
Tebjan Halm committed
1175
    public class MouseArg : SVGArg
Tebjan Halm's avatar
Tebjan Halm committed
1176
1177
1178
1179
1180
    {
        public float x;
        public float y;

        /// <summary>
1181
        /// 1 = left, 2 = middle, 3 = right
Tebjan Halm's avatar
Tebjan Halm committed
1182
        /// </summary>
1183
        public int Button;
1184
        
1185
1186
1187
        /// <summary>
        /// Amount of mouse clicks, e.g. 2 for double click
        /// </summary>
1188
        public int ClickCount = -1;
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
        
        /// <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;
1204
    }
joreg's avatar
joreg committed
1205
1206
1207
1208
    
    /// <summary>
    /// Represents a string argument
    /// </summary>
Tebjan Halm's avatar
Tebjan Halm committed
1209
    public class StringArg : SVGArg
joreg's avatar
joreg committed
1210
1211
1212
    {
        public string s;
    }
1213
1214
1215
1216
    
    public class MouseScrollArg : SVGArg
    {
    	public int Scroll;
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
    	
    	/// <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;
1232
    }
1233

1234
1235
1236
    public interface ISvgNode
    {
        string Content { get; }
1237
1238
1239
1240
1241
1242
        
        /// <summary>
        /// Create a deep copy of this <see cref="ISvgNode"/>.
        /// </summary>
        /// <returns>A deep copy of this <see cref="ISvgNode"/></returns>
        ISvgNode DeepCopy();
1243
1244
    }

1245
1246
1247
1248
    /// <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
1249
1250
    internal interface ISvgElement
    {
1251
1252
		SvgElement Parent {get;}
		SvgElementCollection Children { get; }
1253
        IList<ISvgNode> Nodes { get; }
1254

Eric Domke's avatar
Eric Domke committed
1255
        void Render(ISvgRenderer renderer);
davescriven's avatar
davescriven committed
1256
    }
Tebjan Halm's avatar
Tebjan Halm committed
1257
}