Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ImportedProjects
SVG
Commits
28b654f0
"vscode:/vscode.git/clone" did not exist on "793997f036aa1a3ae1820546bf75608ac905a184"
Commit
28b654f0
authored
Jul 31, 2013
by
Tebjan Halm
Browse files
added more events and fixed IdManager bug
parent
88f9340e
Changes
9
Hide whitespace changes
Inline
Side-by-side
Source/Basic Shapes/SvgVisualElement.cs
View file @
28b654f0
...
...
@@ -61,7 +61,6 @@ namespace Svg
set
{
this
.
Attributes
[
"clip-rule"
]
=
value
;
}
}
/// <summary>
/// Gets the associated <see cref="SvgClipPath"/> if one has been specified.
/// </summary>
...
...
@@ -72,7 +71,6 @@ namespace Svg
set
{
this
.
Attributes
[
"filter"
]
=
value
;
}
}
/// <summary>
/// Gets or sets a value to determine if anti-aliasing should occur when the element is being rendered.
/// </summary>
...
...
Source/Document Structure/SvgDefinitionList.cs
View file @
28b654f0
...
...
@@ -26,7 +26,6 @@ namespace Svg
// Do nothing. Children should NOT be rendered.
}
public
override
SvgElement
DeepCopy
()
{
return
DeepCopy
<
SvgDefinitionList
>();
...
...
Source/Painting/SvgGradientServer.cs
View file @
28b654f0
...
...
@@ -88,7 +88,7 @@ namespace Svg
/// <summary>
/// Gets or sets another gradient fill from which to inherit the stops from.
/// </summary>
[
SvgAttribute
Attribute
(
"href"
)]
[
SvgAttribute
(
"href"
)]
public
SvgGradientServer
InheritGradient
{
get
{
return
this
.
_inheritGradient
;
}
...
...
Source/SvgAttributeCollection.cs
View file @
28b654f0
...
...
@@ -87,7 +87,90 @@ namespace Svg
public
new
object
this
[
string
attributeName
]
{
get
{
return
this
.
GetInheritedAttribute
<
object
>(
attributeName
);
}
set
{
base
[
attributeName
]
=
value
;
}
set
{
if
(
base
.
ContainsKey
(
attributeName
))
{
var
oldVal
=
base
[
attributeName
];
base
[
attributeName
]
=
value
;
if
(
oldVal
!=
value
)
OnAttributeChanged
(
attributeName
,
value
);
}
else
{
base
[
attributeName
]
=
value
;
OnAttributeChanged
(
attributeName
,
value
);
}
}
}
/// <summary>
/// Fired when an Atrribute has changed
/// </summary>
public
event
EventHandler
<
AttributeEventArgs
>
AttributeChanged
;
protected
void
OnAttributeChanged
(
string
attribute
,
object
value
)
{
var
handler
=
AttributeChanged
;
if
(
handler
!=
null
)
{
handler
(
this
.
_owner
,
new
AttributeEventArgs
{
Attribute
=
attribute
,
Value
=
value
});
}
}
}
/// <summary>
/// A collection of Custom Attributes
/// </summary>
public
sealed
class
SvgCustomAttributeCollection
:
Dictionary
<
string
,
string
>
{
private
SvgElement
_owner
;
/// <summary>
/// Initialises a new instance of a <see cref="SvgAttributeCollection"/> with the given <see cref="SvgElement"/> as the owner.
/// </summary>
/// <param name="owner">The <see cref="SvgElement"/> owner of the collection.</param>
public
SvgCustomAttributeCollection
(
SvgElement
owner
)
{
this
.
_owner
=
owner
;
}
/// <summary>
/// Gets the attribute with the specified name.
/// </summary>
/// <param name="attributeName">A <see cref="string"/> containing the attribute name.</param>
/// <returns>The attribute value associated with the specified name; If there is no attribute the parent's value will be inherited.</returns>
public
new
string
this
[
string
attributeName
]
{
get
{
return
base
[
attributeName
];
}
set
{
if
(
base
.
ContainsKey
(
attributeName
))
{
var
oldVal
=
base
[
attributeName
];
base
[
attributeName
]
=
value
;
if
(
oldVal
!=
value
)
OnAttributeChanged
(
attributeName
,
value
);
}
else
{
base
[
attributeName
]
=
value
;
OnAttributeChanged
(
attributeName
,
value
);
}
}
}
/// <summary>
/// Fired when an Atrribute has changed
/// </summary>
public
event
EventHandler
<
AttributeEventArgs
>
AttributeChanged
;
protected
void
OnAttributeChanged
(
string
attribute
,
object
value
)
{
var
handler
=
AttributeChanged
;
if
(
handler
!=
null
)
{
handler
(
this
.
_owner
,
new
AttributeEventArgs
{
Attribute
=
attribute
,
Value
=
value
});
}
}
}
}
\ No newline at end of file
Source/SvgDocument.cs
View file @
28b654f0
...
...
@@ -44,6 +44,17 @@ namespace Svg
return
_idManager
;
}
}
/// <summary>
/// Overwrites the current IdManager with a custom implementation.
/// Be careful with this: If elements have been inserted into the document before,
/// you have to take care that the new IdManager also knows of them.
/// </summary>
/// <param name="manager"></param>
public
void
OverwriteIdManager
(
SvgElementIdManager
manager
)
{
_idManager
=
manager
;
}
/// <summary>
/// Gets or sets the Pixels Per Inch of the rendered image.
...
...
Source/SvgElement.cs
View file @
28b654f0
...
...
@@ -41,7 +41,7 @@ namespace Svg
private
SvgElementCollection
_children
;
private
static
readonly
object
_loadEventKey
=
new
object
();
private
Matrix
_graphicsMatrix
;
private
Dictionary
<
string
,
string
>
_customAttributes
;
private
SvgCustomAttributeCollection
_customAttributes
;
/// <summary>
/// Gets the name of the element.
...
...
@@ -121,24 +121,20 @@ namespace Svg
/// </summary>
public
virtual
SvgDocument
OwnerDocument
{
get
{
if
(
Parent
==
null
)
{
if
(
this
is
SvgDocument
)
{
return
(
SvgDocument
)
this
;
}
else
{
return
null
;
}
}
else
{
return
Parent
.
OwnerDocument
;
}
}
get
{
if
(
this
is
SvgDocument
)
{
return
this
as
SvgDocument
;
}
else
{
if
(
this
.
Parent
!=
null
)
return
Parent
.
OwnerDocument
;
else
return
null
;
}
}
}
/// <summary>
...
...
@@ -157,7 +153,10 @@ namespace Svg
}
}
public
Dictionary
<
string
,
string
>
CustomAttributes
/// <summary>
/// Gets a collection of custom attributes
/// </summary>
public
SvgCustomAttributeCollection
CustomAttributes
{
get
{
return
this
.
_customAttributes
;
}
}
...
...
@@ -301,7 +300,11 @@ namespace Svg
this
.
_children
=
new
SvgElementCollection
(
this
);
this
.
_eventHandlers
=
new
EventHandlerList
();
this
.
_elementName
=
string
.
Empty
;
this
.
_customAttributes
=
new
Dictionary
<
string
,
string
>();
this
.
_customAttributes
=
new
SvgCustomAttributeCollection
(
this
);
//subscribe to attribute events
Attributes
.
AttributeChanged
+=
Attributes_AttributeChanged
;
CustomAttributes
.
AttributeChanged
+=
Attributes_AttributeChanged
;
//find svg attribute descriptions
_svgPropertyAttributes
=
from
PropertyDescriptor
a
in
TypeDescriptor
.
GetProperties
(
this
)
...
...
@@ -316,6 +319,12 @@ namespace Svg
}
//dispatch attribute event
void
Attributes_AttributeChanged
(
object
sender
,
AttributeEventArgs
e
)
{
OnAttributeChanged
(
e
);
}
public
virtual
void
InitialiseFromXML
(
XmlTextReader
reader
,
SvgDocument
document
)
{
throw
new
NotImplementedException
();
...
...
@@ -628,6 +637,20 @@ namespace Svg
return
newObj
;
}
/// <summary>
/// Fired when an Atrribute of this Element has changed
/// </summary>
public
event
EventHandler
<
AttributeEventArgs
>
AttributeChanged
;
protected
void
OnAttributeChanged
(
AttributeEventArgs
args
)
{
var
handler
=
AttributeChanged
;
if
(
handler
!=
null
)
{
handler
(
this
,
args
);
}
}
#
region
graphical
EVENTS
...
...
@@ -640,7 +663,7 @@ namespace Svg
onmouseup = "<anything>"
onmouseover = "<anything>"
onmousemove = "<anything>"
onmouseout = "<anything>"
onmouseout = "<anything>"
*/
/// <summary>
...
...
@@ -662,6 +685,25 @@ namespace Svg
caller
.
RegisterAction
(
rpcID
+
"onmouseout"
,
OnMouseOut
);
}
}
/// <summary>
/// Use this method to provide your implementation ISvgEventCaller to unregister Actions
/// </summary>
/// <param name="caller"></param>
public
void
UnregisterEvents
(
ISvgEventCaller
caller
)
{
if
(
caller
!=
null
&&
!
string
.
IsNullOrWhiteSpace
(
this
.
ID
))
{
var
rpcID
=
this
.
ID
+
"/"
;
caller
.
UnregisterAction
(
rpcID
+
"onclick"
);
caller
.
UnregisterAction
(
rpcID
+
"onmousedown"
);
caller
.
UnregisterAction
(
rpcID
+
"onmouseup"
);
caller
.
UnregisterAction
(
rpcID
+
"onmousemove"
);
caller
.
UnregisterAction
(
rpcID
+
"onmouseover"
);
caller
.
UnregisterAction
(
rpcID
+
"onmouseout"
);
}
}
[
SvgAttribute
(
"onclick"
)]
public
event
EventHandler
<
MouseArg
>
Click
;
...
...
@@ -774,6 +816,15 @@ namespace Svg
#
endregion
graphical
EVENTS
}
/// <summary>
/// Describes the Attribute which was set
/// </summary>
public
class
AttributeEventArgs
:
EventArgs
{
public
string
Attribute
;
public
object
Value
;
}
//deriving class registers event actions and calls the actions if the event occurs
public
interface
ISvgEventCaller
...
...
@@ -783,6 +834,7 @@ namespace Svg
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
);
void
UnregisterAction
(
string
rpcID
);
}
/// <summary>
...
...
Source/SvgElementCollection.cs
View file @
28b654f0
...
...
@@ -78,7 +78,7 @@ namespace Svg
{
if
(
this
.
_owner
.
OwnerDocument
!=
null
)
{
this
.
_owner
.
OwnerDocument
.
IdManager
.
Add
(
item
);
item
.
ApplyRecursive
(
this
.
_owner
.
OwnerDocument
.
IdManager
.
Add
);
}
item
.
_parent
=
this
.
_owner
;
...
...
@@ -132,7 +132,7 @@ namespace Svg
if
(
this
.
_owner
.
OwnerDocument
!=
null
)
{
this
.
_owner
.
OwnerDocument
.
IdManager
.
Remove
(
item
);
item
.
ApplyRecursive
(
this
.
_owner
.
OwnerDocument
.
IdManager
.
Remove
);
}
}
}
...
...
Source/SvgElementIdManager.cs
View file @
28b654f0
...
...
@@ -52,6 +52,8 @@ namespace Svg
this
.
EnsureValidId
(
element
.
ID
);
this
.
_idValueMap
.
Add
(
element
.
ID
,
element
);
}
OnAdded
(
element
);
}
/// <summary>
...
...
@@ -64,6 +66,8 @@ namespace Svg
{
this
.
_idValueMap
.
Remove
(
element
.
ID
);
}
OnRemoved
(
element
);
}
/// <summary>
...
...
@@ -101,5 +105,32 @@ namespace Svg
this
.
_document
=
document
;
this
.
_idValueMap
=
new
Dictionary
<
string
,
SvgElement
>();
}
public
event
EventHandler
<
SvgElementEventArgs
>
ElementAdded
;
public
event
EventHandler
<
SvgElementEventArgs
>
ElementRemoved
;
protected
void
OnAdded
(
SvgElement
element
)
{
var
handler
=
ElementAdded
;
if
(
handler
!=
null
)
{
handler
(
this
.
_document
,
new
SvgElementEventArgs
{
Element
=
element
});
}
}
protected
void
OnRemoved
(
SvgElement
element
)
{
var
handler
=
ElementRemoved
;
if
(
handler
!=
null
)
{
handler
(
this
.
_document
,
new
SvgElementEventArgs
{
Element
=
element
});
}
}
}
public
class
SvgElementEventArgs
:
EventArgs
{
public
SvgElement
Element
;
}
}
\ No newline at end of file
Source/SvgExtentions.cs
View file @
28b654f0
...
...
@@ -52,5 +52,16 @@ namespace Svg
{
return
element
.
CustomAttributes
.
ContainsKey
(
name
)
&&
!
string
.
IsNullOrEmpty
(
element
.
CustomAttributes
[
name
]);
}
public
static
void
ApplyRecursive
(
this
SvgElement
elem
,
Action
<
SvgElement
>
action
)
{
action
(
elem
);
foreach
(
var
element
in
elem
.
Children
)
{
if
(!(
elem
is
SvgDocument
))
element
.
ApplyRecursive
(
action
);
}
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment