markus / MarkupToPDF / Controls / Text / TextControl.cs @ 6b5d33c6
이력 | 보기 | 이력해설 | 다운로드 (38.8 KB)
1 |
using MarkupToPDF.Common; |
---|---|
2 |
using MarkupToPDF.Controls.Common; |
3 |
using System; |
4 |
using System.Collections.Generic; |
5 |
using System.ComponentModel; |
6 |
using System.Linq; |
7 |
using System.Text; |
8 |
using System.Threading.Tasks; |
9 |
using System.Windows; |
10 |
using System.Windows.Controls; |
11 |
using System.Windows.Media; |
12 |
using System.Windows.Shapes; |
13 |
|
14 |
namespace MarkupToPDF.Controls.Text |
15 |
{ |
16 |
[TemplatePart(Name = "PART_TextBox", Type = typeof(TextBox))] |
17 |
[TemplatePart(Name = "PART_TextBlock", Type = typeof(TextBlock))] |
18 |
[TemplatePart(Name = "PART_TextPath", Type = typeof(Path))] |
19 |
[TemplatePart(Name = "PART_Border", Type = typeof(Border))] |
20 |
[TemplatePart(Name = "PART_Grid", Type = typeof(Grid))] |
21 |
public class TextControl : CommentUserInfo, INotifyPropertyChanged, IMarkupControlData, IPath |
22 |
{ |
23 |
public event PropertyChangedEventHandler PropertyChanged; |
24 |
|
25 |
private const string PART_Grid = "PART_Grid"; |
26 |
private const string PART_Border = "PART_Border"; |
27 |
private const string PART_TextBox = "PART_TextBox"; |
28 |
private const string PART_TextPath = "PART_TextPath"; |
29 |
private const string PART_TextBlock = "PART_TextBlock"; |
30 |
//private const string PART_TextPrefix = "PART_TextPrefix"; |
31 |
|
32 |
public Path Base_TextPath = null; |
33 |
public Grid Base_Grid = null; |
34 |
public Border Base_Border = null; |
35 |
//public TextBlock Base_TextPrefixBlock = null; |
36 |
public TextBlock Base_TextBlock = null; |
37 |
public TextBox Base_TextBox = null; |
38 |
|
39 |
public RotateTransform _rotation = null; |
40 |
public TranslateTransform _translation = null; |
41 |
public ScaleTransform _scale = null; |
42 |
|
43 |
private const double _CloudArcDepth = 0.8; /// 2018.05.14 added by humkyung |
44 |
|
45 |
public bool IsSelected |
46 |
{ |
47 |
get |
48 |
{ |
49 |
return (bool)GetValue(IsSelectedProperty); |
50 |
} |
51 |
set |
52 |
{ |
53 |
SetValue(IsSelectedProperty, value); |
54 |
OnPropertyChanged("IsSelected"); |
55 |
} |
56 |
} |
57 |
|
58 |
#region Internal Method |
59 |
|
60 |
public TextControl() |
61 |
{ |
62 |
this.DefaultStyleKey = typeof(TextControl); |
63 |
} |
64 |
|
65 |
static TextControl() |
66 |
{ |
67 |
DefaultStyleKeyProperty.OverrideMetadata(typeof(TextControl), new FrameworkPropertyMetadata(typeof(TextControl))); |
68 |
ResourceDictionary dictionary = new ResourceDictionary(); |
69 |
dictionary.Source = new Uri("/MarkupToPDF;component/Themes/generic.xaml", UriKind.RelativeOrAbsolute); |
70 |
Application.Current.Resources.MergedDictionaries.Add(dictionary); |
71 |
|
72 |
} |
73 |
|
74 |
|
75 |
public override void OnApplyTemplate() |
76 |
{ |
77 |
base.OnApplyTemplate(); |
78 |
|
79 |
Base_TextPath = GetTemplateChild(PART_TextPath) as Path; |
80 |
Base_TextBox = GetTemplateChild(PART_TextBox) as TextBox; |
81 |
Base_TextBlock = GetTemplateChild(PART_TextBlock) as TextBlock; |
82 |
Base_Grid = GetTemplateChild(PART_Grid) as Grid; |
83 |
Base_Border = GetTemplateChild(PART_Border) as Border; |
84 |
|
85 |
this.Base_TextBox.SizeChanged += new SizeChangedEventHandler(Base_TextBox_SizeChanged); |
86 |
this.Base_TextBlock.SizeChanged += new SizeChangedEventHandler(Base_TextBlock_SizeChanged); |
87 |
this.Base_TextBox.GotFocus += new RoutedEventHandler(TextControl_GotFocus); |
88 |
this.Base_TextBox.LostFocus += new RoutedEventHandler(TextControl_LostFocus); |
89 |
|
90 |
DrawingCloud(); |
91 |
SetText(); |
92 |
} |
93 |
|
94 |
|
95 |
public void ApplyOverViewData() |
96 |
{ |
97 |
this.OverViewPathData = this.PathData; |
98 |
this.OverViewText = this.Text; |
99 |
this.OverViewPaint = this.Paint; |
100 |
|
101 |
} |
102 |
|
103 |
void Base_TextBlock_SizeChanged(object sender, SizeChangedEventArgs e) |
104 |
{ |
105 |
|
106 |
|
107 |
this.Text = Base_TextBox.Text; |
108 |
|
109 |
BoxWidth = e.NewSize.Width; |
110 |
BoxHeight = e.NewSize.Height; |
111 |
|
112 |
this.ApplyTemplate(); |
113 |
|
114 |
DrawingCloud(); |
115 |
} |
116 |
|
117 |
//void TextControl_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) |
118 |
//{ |
119 |
// this.Focus(); |
120 |
//} |
121 |
|
122 |
void Base_TextBox_SizeChanged(object sender, SizeChangedEventArgs e) |
123 |
{ |
124 |
if (Base_TextBox.Text.Contains("|OR||DZ|")) |
125 |
{ |
126 |
Base_TextBox.Text = this.Text; |
127 |
} |
128 |
|
129 |
this.Text = Base_TextBox.Text; |
130 |
BoxWidth = e.NewSize.Width; |
131 |
BoxHeight = e.NewSize.Height; |
132 |
this.ApplyTemplate(); |
133 |
DrawingCloud(); |
134 |
} |
135 |
|
136 |
void TextControl_GotFocus(object sender, RoutedEventArgs e) |
137 |
{ |
138 |
if (EnableEditing) |
139 |
{ |
140 |
IsEditing = true; |
141 |
EditingMode(); |
142 |
} |
143 |
else |
144 |
{ |
145 |
IsEditing = false; |
146 |
UnEditingMode(); |
147 |
} |
148 |
} |
149 |
|
150 |
void TextControl_LostFocus(object sender, RoutedEventArgs e) |
151 |
{ |
152 |
IsEditing = false; |
153 |
UnEditingMode(); |
154 |
ApplyOverViewData(); |
155 |
} |
156 |
|
157 |
//void TextControl_GotFocus(object sender, RoutedEventArgs e) |
158 |
//{ |
159 |
// Base_TextBox.Visibility = Visibility.Visible; |
160 |
// Base_TextBlock.Visibility = Visibility.Collapsed; |
161 |
// this.Base_TextBox.BorderThickness = new Thickness(1); |
162 |
// if (UnderLine != null) |
163 |
// { |
164 |
// Base_TextBlock.TextDecorations = UnderLine; |
165 |
// } |
166 |
// if (this.Text != null) |
167 |
// { |
168 |
// Base_TextBox.Text = this.Text; |
169 |
// } |
170 |
// IsEditing = true; |
171 |
//} |
172 |
//void TextControl_LostFocus(object sender, RoutedEventArgs e) |
173 |
//{ |
174 |
// Base_TextBox.Visibility = Visibility.Collapsed; |
175 |
// Base_TextBlock.Visibility = Visibility.Visible; |
176 |
// this.Text = Base_TextBox.Text; |
177 |
// if (UnderLine != null) |
178 |
// { |
179 |
// Base_TextBlock.TextDecorations = UnderLine; |
180 |
// } |
181 |
// Base_TextBlock.Margin = |
182 |
// new Thickness(Base_TextBox.Margin.Left + 4, Base_TextBox.Margin.Top + 4, Base_TextBox.Margin.Right + 4, Base_TextBox.Margin.Bottom + 4); |
183 |
// IsEditing = false; |
184 |
//} |
185 |
|
186 |
public void EditingMode() |
187 |
{ |
188 |
//this.Base_TextBox.Focus(); |
189 |
//System.Diagnostics.Debug.WriteLine(DateTime.Now.ToLongTimeString()); |
190 |
TextBoxVisibility = Visibility.Visible; |
191 |
//Base_TextBox.Visibility = System.Windows.Visibility.Visible; |
192 |
|
193 |
TextBlockVisibility = Visibility.Collapsed; |
194 |
//Base_TextBlock.Visibility = System.Windows.Visibility.Collapsed; |
195 |
|
196 |
|
197 |
//this.Base_TextBox.BorderThickness = new Thickness(1); |
198 |
|
199 |
if (UnderLine != null) |
200 |
Base_TextBlock.TextDecorations = UnderLine; |
201 |
|
202 |
if (this.Text != null) |
203 |
Base_TextBox.Text = this.Text; |
204 |
|
205 |
// Base_TextBox.Margin = |
206 |
//new Thickness(Base_TextBlock.Margin.Left + -2, Base_TextBlock.Margin.Top + 0, |
207 |
//Base_TextBlock.Margin.Right + 0, Base_TextBlock.Margin.Bottom + -2); |
208 |
} |
209 |
|
210 |
public void UnEditingMode() |
211 |
{ |
212 |
if (EnableEditing) |
213 |
this.Text = Base_TextBox.Text; |
214 |
|
215 |
TextBoxVisibility = Visibility.Collapsed; |
216 |
//Base_TextBox.Visibility = System.Windows.Visibility.Collapsed; |
217 |
|
218 |
TextBlockVisibility = Visibility.Visible; |
219 |
//Base_TextBlock.Visibility = System.Windows.Visibility.Visible; |
220 |
|
221 |
if (UnderLine != null) |
222 |
Base_TextBlock.TextDecorations = UnderLine; |
223 |
|
224 |
//Base_TextBox.Focusable = false; |
225 |
|
226 |
//Base_TextBlock.Margin = |
227 |
// new Thickness(Base_TextBox.Margin.Left + 4, Base_TextBox.Margin.Top + 4, |
228 |
// Base_TextBox.Margin.Right + 4, Base_TextBox.Margin.Bottom + 4); |
229 |
|
230 |
// Base_TextBlock.Margin = |
231 |
//new Thickness(Base_TextBox.Margin.Left + 2, Base_TextBox.Margin.Top + 2, |
232 |
// Base_TextBox.Margin.Right + 2, Base_TextBox.Margin.Bottom + 2); |
233 |
|
234 |
// Base_TextBlock.Margin = |
235 |
//new Thickness(Base_TextBox.Margin.Left + 5, Base_TextBox.Margin.Top + 0, |
236 |
//Base_TextBox.Margin.Right + 0, Base_TextBox.Margin.Bottom + 2); |
237 |
} |
238 |
|
239 |
public void SetText() |
240 |
{ |
241 |
this.ApplyTemplate(); |
242 |
if (IsHighLight) |
243 |
{ |
244 |
this.BackInnerColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.6), |
245 |
Colors.Yellow.R, Colors.Yellow.G, Colors.Yellow.B)); |
246 |
this.BackColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.1), |
247 |
Colors.Yellow.R, Colors.Yellow.G, Colors.Yellow.B)); |
248 |
} |
249 |
else |
250 |
{ |
251 |
this.BackInnerColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.6), |
252 |
Colors.White.R, Colors.White.G, Colors.White.B)); |
253 |
|
254 |
this.BackColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.1), |
255 |
Colors.White.R, Colors.White.G, Colors.White.B)); |
256 |
|
257 |
|
258 |
//this.BackColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.6), |
259 |
// Colors.White.R, Colors.White.G, Colors.White.B)); |
260 |
//this.BackColor = null; |
261 |
} |
262 |
if (Base_TextPath != null) |
263 |
{ |
264 |
Base_TextPath.StrokeThickness = LineSize.Left; |
265 |
} |
266 |
} |
267 |
|
268 |
public void DrawingCloud() |
269 |
{ |
270 |
this.ApplyTemplate(); |
271 |
|
272 |
List<Point> pCloud = new List<Point> |
273 |
{ |
274 |
new Point(0, 0), |
275 |
new Point(0, 0 + BoxHeight + 0), |
276 |
new Point(0 + BoxWidth + 2, 0 + BoxHeight + 0), |
277 |
new Point(0 + BoxWidth + 2 ,0), |
278 |
}; |
279 |
|
280 |
if (Base_TextPath != null) |
281 |
{ |
282 |
switch (ControlType_No) |
283 |
{ |
284 |
case 0: |
285 |
{ |
286 |
PathData = new PathGeometry(); |
287 |
PathDataInner = (GenerateInner(pCloud)); |
288 |
} |
289 |
break; |
290 |
case 1: |
291 |
{ |
292 |
PathData = (Generate_Rect(pCloud)); |
293 |
List<Point> pCloud2 = new List<Point> |
294 |
{ |
295 |
new Point(0, 0), |
296 |
new Point(0, 0 + BoxHeight + 0), |
297 |
new Point(0 + BoxWidth + 10, 0 + BoxHeight + 0), |
298 |
new Point(0 + BoxWidth + 10 ,0), |
299 |
}; |
300 |
PathDataInner = (GenerateInner(pCloud)); |
301 |
} |
302 |
break; |
303 |
case 2: |
304 |
{ |
305 |
PathData = (Generate(pCloud)); |
306 |
PathDataInner = (GenerateInner(pCloud)); |
307 |
} |
308 |
break; |
309 |
} |
310 |
} |
311 |
|
312 |
//SetText(); |
313 |
} |
314 |
#endregion Internal Method |
315 |
|
316 |
public void Dispose() |
317 |
{ |
318 |
GC.Collect(); |
319 |
GC.SuppressFinalize(this); |
320 |
} |
321 |
public void updateControl() |
322 |
{ |
323 |
this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y); |
324 |
this.EndPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y); |
325 |
} |
326 |
|
327 |
#region Drawing Cloud Method |
328 |
public static PathGeometry Generate_Rect(List<Point> pData) |
329 |
{ |
330 |
PathFigure pathFigure = new PathFigure(); |
331 |
pathFigure.StartPoint = pData[0]; |
332 |
|
333 |
PolyLineSegment polyline = new PolyLineSegment(pData, true); |
334 |
pathFigure.Segments.Add(polyline); |
335 |
|
336 |
PathGeometry rectPathGeometry = new PathGeometry(); |
337 |
rectPathGeometry.Figures = new PathFigureCollection(); |
338 |
pathFigure.IsClosed = true; |
339 |
pathFigure.IsFilled = false; |
340 |
rectPathGeometry.Figures.Add(pathFigure); |
341 |
|
342 |
|
343 |
return rectPathGeometry; |
344 |
} |
345 |
|
346 |
public static PathGeometry Generate(List<Point> pData) |
347 |
{ |
348 |
var _pathGeometry = new PathGeometry(); |
349 |
double area = MathSet.AreaOf(pData); |
350 |
bool reverse = (area > 0); |
351 |
int count = pData.Count; |
352 |
for (int i = 0; i < count; i++) |
353 |
{ |
354 |
PathFigure pathFigure = GenerateLineWithCloud(pData[i%count], pData[(i + 1)%count], 20, reverse); |
355 |
pathFigure.IsClosed = false; |
356 |
pathFigure.IsFilled = true; |
357 |
_pathGeometry.Figures.Add(pathFigure); |
358 |
} |
359 |
|
360 |
return _pathGeometry; |
361 |
} |
362 |
|
363 |
|
364 |
public static PathGeometry GenerateInner(List<Point> pData) |
365 |
{ |
366 |
var _pathGeometry = new PathGeometry(); |
367 |
double area = MathSet.AreaOf(pData); |
368 |
bool reverse = (area > 0); |
369 |
int count = pData.Count; |
370 |
|
371 |
PathFigure pathFigur2 = new PathFigure(); |
372 |
pathFigur2.StartPoint = pData[0]; |
373 |
|
374 |
PolyLineSegment polyline = new PolyLineSegment(pData, true); |
375 |
pathFigur2.Segments.Add(polyline); |
376 |
|
377 |
pathFigur2.IsClosed = true; |
378 |
pathFigur2.IsFilled = true; |
379 |
_pathGeometry.Figures.Add(pathFigur2); |
380 |
|
381 |
return _pathGeometry; |
382 |
} |
383 |
|
384 |
public static PathFigure GenerateLineWithCloud(Point p1, Point p2, double _arcLength, bool reverse) |
385 |
{ |
386 |
PathFigure pathFigure = new PathFigure(); |
387 |
pathFigure.StartPoint = p1; |
388 |
|
389 |
double arcLength = _arcLength; |
390 |
double dx = p2.X - p1.X; |
391 |
double dy = p2.Y - p1.Y; |
392 |
double l = MathSet.DistanceTo(p1, p2); |
393 |
double theta = Math.Atan2(Math.Abs(dy), Math.Abs(dx)) * 180 / Math.PI; |
394 |
Point lastPt = new Point(p1.X, p1.Y); |
395 |
double count = l / _arcLength; |
396 |
|
397 |
dx /= l; |
398 |
dy /= l; |
399 |
|
400 |
Double j = 1; |
401 |
for (j = 1; j < (count - 1); j++) |
402 |
{ |
403 |
ArcSegment arcSeg = new ArcSegment(); |
404 |
arcSeg.Size = new Size(arcLength * TextControl._CloudArcDepth, arcLength * TextControl._CloudArcDepth); |
405 |
arcSeg.Point = new Point(p1.X + j * dx * arcLength, p1.Y + j * dy * arcLength); |
406 |
lastPt = arcSeg.Point; |
407 |
arcSeg.RotationAngle = theta + 90; |
408 |
if (true == reverse) |
409 |
arcSeg.SweepDirection = SweepDirection.Clockwise; |
410 |
pathFigure.Segments.Add(arcSeg); |
411 |
} |
412 |
|
413 |
if ((count > j) || count > 0) |
414 |
{ |
415 |
arcLength = MathSet.DistanceTo(lastPt, p2); |
416 |
ArcSegment arcSeg = new ArcSegment(); |
417 |
arcSeg.Size = new Size(arcLength * TextControl._CloudArcDepth, arcLength * TextControl._CloudArcDepth); |
418 |
arcSeg.Point = new Point(p2.X, p2.Y); |
419 |
arcSeg.RotationAngle = theta; |
420 |
|
421 |
if (true == reverse) |
422 |
arcSeg.SweepDirection = SweepDirection.Clockwise; |
423 |
|
424 |
pathFigure.Segments.Add(arcSeg); |
425 |
|
426 |
} |
427 |
return pathFigure; |
428 |
} |
429 |
#endregion |
430 |
|
431 |
#region Dependency Properties |
432 |
public static readonly DependencyProperty ControlTypeProperty = |
433 |
DependencyProperty.Register("ControlType", typeof(ControlType), typeof(TextControl), new FrameworkPropertyMetadata(ControlType.TextControl)); |
434 |
|
435 |
public static readonly DependencyProperty ControlType_NoProperty = |
436 |
DependencyProperty.Register("ControlType_No", typeof(int), typeof(TextControl), new FrameworkPropertyMetadata(0)); |
437 |
|
438 |
public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register( |
439 |
"IsSelected", typeof(bool), typeof(TextControl), new FrameworkPropertyMetadata(false, IsSelectedChanged)); |
440 |
|
441 |
public static readonly DependencyProperty PathGeometryProperty = DependencyProperty.Register( |
442 |
"PathGeometry", typeof(PathGeometry), typeof(TextControl), new PropertyMetadata(null, SetPathGeometryChanged)); |
443 |
|
444 |
public static readonly DependencyProperty TextProperty = DependencyProperty.Register( |
445 |
"Text", typeof(string), typeof(TextControl), new PropertyMetadata(null)); |
446 |
|
447 |
public static readonly DependencyProperty OverViewTextProperty = DependencyProperty.Register( |
448 |
"OverViewText", typeof(string), typeof(TextControl), new PropertyMetadata(null)); |
449 |
|
450 |
public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register( |
451 |
"UserID", typeof(string), typeof(TextControl), new PropertyMetadata(null)); |
452 |
|
453 |
public static readonly DependencyProperty FontColorProperty = DependencyProperty.Register( |
454 |
"FontColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.Red))); |
455 |
|
456 |
//강인구 추가 |
457 |
public static readonly DependencyProperty IsHighlightProperty = DependencyProperty.Register( |
458 |
"IsHighLight", typeof(bool), typeof(TextControl), new PropertyMetadata(false, PointValueChanged)); |
459 |
|
460 |
public static readonly DependencyProperty BackColorProperty = DependencyProperty.Register( |
461 |
"BackColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.White))); |
462 |
|
463 |
public static readonly DependencyProperty BackInnerColorProperty = DependencyProperty.Register( |
464 |
"BackInnerColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.White))); |
465 |
|
466 |
public static readonly DependencyProperty UnderLineProperty = DependencyProperty.Register( |
467 |
"UnderLine", typeof(TextDecorationCollection), typeof(TextControl), new PropertyMetadata(null)); |
468 |
|
469 |
public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register( |
470 |
"LineSize", typeof(Thickness), typeof(TextControl), new PropertyMetadata(new Thickness(4), PointValueChanged)); //여기만 4인지 모르겠지만 4 그대로 두겠음 |
471 |
|
472 |
public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register( |
473 |
"PointSet", typeof(List<Point>), typeof(TextControl), new PropertyMetadata(new List<Point>())); |
474 |
|
475 |
public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register( |
476 |
"PathData", typeof(Geometry), typeof(TextControl), null); |
477 |
|
478 |
public static readonly DependencyProperty PathDataInnerProperty = DependencyProperty.Register( |
479 |
"PathDataInner", typeof(Geometry), typeof(TextControl), null); |
480 |
|
481 |
public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register( |
482 |
"OverViewPathDataProperty", typeof(Geometry), typeof(TextControl), null); |
483 |
|
484 |
public static readonly DependencyProperty TextStyleProperty = DependencyProperty.Register( |
485 |
"TextStyle", typeof(FontStyle), typeof(TextControl), new PropertyMetadata(FontStyles.Normal)); |
486 |
|
487 |
public static readonly DependencyProperty TextFamilyProperty = DependencyProperty.Register( |
488 |
"TextFamily", typeof(FontFamily), typeof(TextControl), new PropertyMetadata(new FontFamily("Arial"))); |
489 |
|
490 |
public static readonly DependencyProperty TextWeightProperty = DependencyProperty.Register( |
491 |
"TextWeight", typeof(FontWeight), typeof(TextControl), new PropertyMetadata(FontWeights.Normal)); |
492 |
|
493 |
public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register( |
494 |
"CenterX", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnCenterXYChanged)); |
495 |
|
496 |
public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register( |
497 |
"CenterY", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnCenterXYChanged)); |
498 |
|
499 |
public static readonly DependencyProperty CanvasXProperty = DependencyProperty.Register( |
500 |
"CanvasX", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnSetCansvasChanged)); |
501 |
|
502 |
public static readonly DependencyProperty CanvasYProperty = DependencyProperty.Register( |
503 |
"CanvasY", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnSetCansvasChanged)); |
504 |
|
505 |
public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register( |
506 |
"StartPoint", typeof(Point), typeof(TextControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
507 |
|
508 |
public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register( |
509 |
"EndPoint", typeof(Point), typeof(TextControl), new PropertyMetadata(new Point(100, 100), PointValueChanged)); |
510 |
|
511 |
public static readonly DependencyProperty TextSizeProperty = DependencyProperty.Register( |
512 |
"TextSize", typeof(Double), typeof(TextControl), new PropertyMetadata((Double)30, PointValueChanged)); |
513 |
|
514 |
public static readonly DependencyProperty PaintProperty = DependencyProperty.Register( |
515 |
"Paint", typeof(PaintSet), typeof(TextControl), new PropertyMetadata((PaintSet.None), PointValueChanged)); |
516 |
|
517 |
public static readonly DependencyProperty OverViewPaintProperty = DependencyProperty.Register( |
518 |
"OverViewPaint", typeof(PaintSet), typeof(TextControl), new PropertyMetadata((PaintSet.None), PointValueChanged)); |
519 |
|
520 |
public static readonly DependencyProperty AngleProperty = DependencyProperty.Register( |
521 |
"Angle", typeof(double), typeof(TextControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged))); |
522 |
|
523 |
public static readonly DependencyProperty IsEditingProperty = DependencyProperty.Register( |
524 |
"IsEditing", typeof(bool), typeof(TextControl), new PropertyMetadata((false), new PropertyChangedCallback(OnIsEditingChanged))); |
525 |
|
526 |
public static readonly DependencyProperty EnableEditingProperty = DependencyProperty.Register( |
527 |
"EnableEditing", typeof(bool), typeof(TextControl), new PropertyMetadata((true))); |
528 |
|
529 |
public static readonly DependencyProperty TextBoxVisibilityProperty = DependencyProperty.Register( |
530 |
"TextBoxVisibility", typeof(Visibility), typeof(TextControl), new PropertyMetadata((Visibility.Visible), OnTextBoxVisibilityChanged)); |
531 |
|
532 |
public static readonly DependencyProperty TextBlockVisibilityProperty = DependencyProperty.Register( |
533 |
"TextBlockVisibility", typeof(Visibility), typeof(TextControl), new PropertyMetadata((Visibility.Collapsed), OnTextBlockVisibilityChanged)); |
534 |
|
535 |
#endregion Dependency Properties |
536 |
|
537 |
#region dp Properties |
538 |
|
539 |
public bool IsEditing |
540 |
{ |
541 |
get { return (bool)GetValue(IsEditingProperty); } |
542 |
set |
543 |
{ |
544 |
if (this.IsEditing != value) |
545 |
{ |
546 |
SetValue(IsEditingProperty, value); |
547 |
|
548 |
OnPropertyChanged("IsEditing"); |
549 |
|
550 |
} |
551 |
} |
552 |
} |
553 |
|
554 |
public bool EnableEditing |
555 |
{ |
556 |
get { return (bool)GetValue(EnableEditingProperty); } |
557 |
set |
558 |
{ |
559 |
if (this.EnableEditing != value) |
560 |
{ |
561 |
SetValue(EnableEditingProperty, value); |
562 |
OnPropertyChanged("EnableEditing"); |
563 |
} |
564 |
} |
565 |
} |
566 |
|
567 |
public Thickness LineSize |
568 |
{ |
569 |
get |
570 |
{ |
571 |
return (Thickness)GetValue(LineSizeProperty); |
572 |
} |
573 |
set |
574 |
{ |
575 |
if (this.LineSize != value) |
576 |
{ |
577 |
SetValue(LineSizeProperty, value); |
578 |
OnPropertyChanged("LineSize"); |
579 |
} |
580 |
} |
581 |
} |
582 |
|
583 |
|
584 |
|
585 |
|
586 |
public ControlType ControlType |
587 |
{ |
588 |
get |
589 |
{ |
590 |
return (ControlType)GetValue(ControlTypeProperty); |
591 |
} |
592 |
set |
593 |
{ |
594 |
SetValue(ControlTypeProperty, value); |
595 |
} |
596 |
} |
597 |
public int ControlType_No |
598 |
{ |
599 |
get |
600 |
{ |
601 |
return (int)GetValue(ControlType_NoProperty); |
602 |
} |
603 |
set |
604 |
{ |
605 |
SetValue(ControlType_NoProperty, value); |
606 |
} |
607 |
} |
608 |
|
609 |
public string UserID |
610 |
{ |
611 |
get { return (string)GetValue(UserIDProperty); } |
612 |
set |
613 |
{ |
614 |
if (this.UserID != value) |
615 |
{ |
616 |
SetValue(UserIDProperty, value); |
617 |
OnPropertyChanged("UserID"); |
618 |
} |
619 |
} |
620 |
} |
621 |
|
622 |
public double CenterX |
623 |
{ |
624 |
get { return (double)GetValue(CenterXProperty); } |
625 |
set { SetValue(CenterXProperty, value); |
626 |
OnPropertyChanged("CenterX"); |
627 |
|
628 |
} |
629 |
} |
630 |
|
631 |
public double CenterY |
632 |
{ |
633 |
get { return (double)GetValue(CenterYProperty); } |
634 |
set { SetValue(CenterYProperty, value); |
635 |
OnPropertyChanged("CenterY"); |
636 |
} |
637 |
} |
638 |
|
639 |
public string Text |
640 |
{ |
641 |
get { return (string)GetValue(TextProperty); } |
642 |
set |
643 |
{ |
644 |
if (this.Text != value) |
645 |
{ |
646 |
SetValue(TextProperty, value); |
647 |
OnPropertyChanged("Text"); |
648 |
} |
649 |
} |
650 |
} |
651 |
|
652 |
public string OverViewText |
653 |
{ |
654 |
get { return (string)GetValue(OverViewTextProperty); } |
655 |
set |
656 |
{ |
657 |
if (this.OverViewText != value) |
658 |
{ |
659 |
SetValue(OverViewTextProperty, value); |
660 |
OnPropertyChanged("OverViewText"); |
661 |
} |
662 |
} |
663 |
} |
664 |
|
665 |
public Geometry OverViewPathData |
666 |
{ |
667 |
get { return (Geometry)GetValue(OverViewPathDataProperty); } |
668 |
set |
669 |
{ |
670 |
if (this.OverViewPathData != value) |
671 |
{ |
672 |
SetValue(OverViewPathDataProperty, value); |
673 |
OnPropertyChanged("OverViewPathData"); |
674 |
} |
675 |
} |
676 |
} |
677 |
|
678 |
public Visibility TextBoxVisibility |
679 |
{ |
680 |
get { return (Visibility)GetValue(TextBoxVisibilityProperty); } |
681 |
set |
682 |
{ |
683 |
if (this.TextBoxVisibility != value) |
684 |
{ |
685 |
SetValue(TextBoxVisibilityProperty, value); |
686 |
OnPropertyChanged("TextBoxVisibility"); |
687 |
} |
688 |
} |
689 |
} |
690 |
|
691 |
|
692 |
public Visibility TextBlockVisibility |
693 |
{ |
694 |
get { return (Visibility)GetValue(TextBlockVisibilityProperty); } |
695 |
set |
696 |
{ |
697 |
if (this.TextBlockVisibility != value) |
698 |
{ |
699 |
SetValue(TextBlockVisibilityProperty, value); |
700 |
OnPropertyChanged("TextBlockVisibility"); |
701 |
} |
702 |
} |
703 |
} |
704 |
|
705 |
|
706 |
|
707 |
public Double TextSize |
708 |
{ |
709 |
get { return (Double)GetValue(TextSizeProperty); } |
710 |
set |
711 |
{ |
712 |
if (this.TextSize != value) |
713 |
{ |
714 |
SetValue(TextSizeProperty, value); |
715 |
OnPropertyChanged("TextSize"); |
716 |
} |
717 |
} |
718 |
} |
719 |
|
720 |
public SolidColorBrush FontColor |
721 |
{ |
722 |
get { return (SolidColorBrush)GetValue(FontColorProperty); } |
723 |
set |
724 |
{ |
725 |
if (this.FontColor != value) |
726 |
{ |
727 |
SetValue(FontColorProperty, value); |
728 |
OnPropertyChanged("FontColor"); |
729 |
} |
730 |
} |
731 |
} |
732 |
|
733 |
public SolidColorBrush BackColor |
734 |
{ |
735 |
get { return (SolidColorBrush)GetValue(BackColorProperty); } |
736 |
set |
737 |
{ |
738 |
if (this.BackColor != value) |
739 |
{ |
740 |
SetValue(BackColorProperty, value); |
741 |
OnPropertyChanged("BackColor"); |
742 |
} |
743 |
} |
744 |
} |
745 |
|
746 |
public SolidColorBrush BackInnerColor |
747 |
{ |
748 |
get { return (SolidColorBrush)GetValue(BackInnerColorProperty); } |
749 |
set |
750 |
{ |
751 |
if (this.BackInnerColor != value) |
752 |
{ |
753 |
SetValue(BackInnerColorProperty, value); |
754 |
OnPropertyChanged("BackInnerColor"); |
755 |
} |
756 |
} |
757 |
} |
758 |
|
759 |
|
760 |
|
761 |
public TextDecorationCollection UnderLine |
762 |
{ |
763 |
get |
764 |
{ |
765 |
return (TextDecorationCollection)GetValue(UnderLineProperty); |
766 |
} |
767 |
set |
768 |
{ |
769 |
if (this.UnderLine != value) |
770 |
{ |
771 |
SetValue(UnderLineProperty, value); |
772 |
OnPropertyChanged("UnderLine"); |
773 |
} |
774 |
} |
775 |
} |
776 |
|
777 |
public double CanvasX |
778 |
{ |
779 |
get { return (double)GetValue(CanvasXProperty); } |
780 |
set |
781 |
{ |
782 |
if (this.CanvasX != value) |
783 |
{ |
784 |
SetValue(CanvasXProperty, value); |
785 |
OnPropertyChanged("CanvasX"); |
786 |
} |
787 |
} |
788 |
} |
789 |
|
790 |
public double CanvasY |
791 |
{ |
792 |
get { return (double)GetValue(CanvasYProperty); } |
793 |
set |
794 |
{ |
795 |
if (this.CanvasY != value) |
796 |
{ |
797 |
SetValue(CanvasYProperty, value); |
798 |
OnPropertyChanged("CanvasY"); |
799 |
} |
800 |
} |
801 |
} |
802 |
|
803 |
public Point EndPoint |
804 |
{ |
805 |
get { return (Point)GetValue(EndPointProperty); } |
806 |
set |
807 |
{ |
808 |
if (this.EndPoint != value) |
809 |
{ |
810 |
SetValue(EndPointProperty, value); |
811 |
OnPropertyChanged("EndPoint"); |
812 |
} |
813 |
} |
814 |
} |
815 |
|
816 |
public Point StartPoint |
817 |
{ |
818 |
get { return (Point)GetValue(StartPointProperty); } |
819 |
set |
820 |
{ |
821 |
if (this.StartPoint != value) |
822 |
{ |
823 |
SetValue(StartPointProperty, value); |
824 |
OnPropertyChanged("StartPoint"); |
825 |
} |
826 |
} |
827 |
} |
828 |
|
829 |
public FontStyle TextStyle |
830 |
{ |
831 |
get { return (FontStyle)GetValue(TextStyleProperty); } |
832 |
set |
833 |
{ |
834 |
if (this.TextStyle != value) |
835 |
{ |
836 |
SetValue(TextStyleProperty, value); |
837 |
OnPropertyChanged("TextStyle"); |
838 |
} |
839 |
} |
840 |
} |
841 |
|
842 |
public FontFamily TextFamily |
843 |
{ |
844 |
get { return (FontFamily)GetValue(TextFamilyProperty); } |
845 |
set |
846 |
{ |
847 |
if (this.TextFamily != value) |
848 |
{ |
849 |
SetValue(TextFamilyProperty, value); |
850 |
OnPropertyChanged("TextFamily"); |
851 |
} |
852 |
} |
853 |
} |
854 |
|
855 |
public FontWeight TextWeight |
856 |
{ |
857 |
get { return (FontWeight)GetValue(TextWeightProperty); } |
858 |
set |
859 |
{ |
860 |
if (this.TextWeight != value) |
861 |
{ |
862 |
SetValue(TextWeightProperty, value); |
863 |
OnPropertyChanged("TextWeight"); |
864 |
} |
865 |
} |
866 |
} |
867 |
|
868 |
public PaintSet Paint |
869 |
{ |
870 |
get { return (PaintSet)GetValue(PaintProperty); } |
871 |
set |
872 |
{ |
873 |
if (this.Paint != value) |
874 |
{ |
875 |
SetValue(PaintProperty, value); |
876 |
OnPropertyChanged("Paint"); |
877 |
} |
878 |
} |
879 |
} |
880 |
|
881 |
public PaintSet OverViewPaint |
882 |
{ |
883 |
get { return (PaintSet)GetValue(OverViewPaintProperty); } |
884 |
set |
885 |
{ |
886 |
if (this.OverViewPaint != value) |
887 |
{ |
888 |
SetValue(OverViewPaintProperty, value); |
889 |
OnPropertyChanged("OverViewPaint"); |
890 |
} |
891 |
} |
892 |
} |
893 |
|
894 |
double IPath.LineSize |
895 |
{ |
896 |
get |
897 |
{ |
898 |
return this.LineSize.Left; |
899 |
} |
900 |
set |
901 |
{ |
902 |
this.LineSize = new Thickness(value); |
903 |
OnPropertyChanged("LineSize"); |
904 |
} |
905 |
} |
906 |
|
907 |
|
908 |
public Geometry PathData |
909 |
{ |
910 |
get { return (Geometry)GetValue(PathDataProperty); } |
911 |
set { SetValue(PathDataProperty, value); |
912 |
OnPropertyChanged("PathData"); |
913 |
} |
914 |
} |
915 |
|
916 |
public Geometry PathDataInner |
917 |
{ |
918 |
get { return (Geometry)GetValue(PathDataInnerProperty); } |
919 |
set |
920 |
{ |
921 |
SetValue(PathDataInnerProperty, value); |
922 |
OnPropertyChanged("PathDataInner"); |
923 |
} |
924 |
} |
925 |
|
926 |
public double Angle |
927 |
{ |
928 |
get { return (double)GetValue(AngleProperty); } |
929 |
set |
930 |
{ |
931 |
if (this.Angle != value) |
932 |
{ |
933 |
SetValue(AngleProperty, value); |
934 |
|
935 |
OnPropertyChanged("Angle"); |
936 |
UpdateLayout(); |
937 |
} |
938 |
} |
939 |
} |
940 |
|
941 |
public bool IsHighLight |
942 |
{ |
943 |
get { return (bool)GetValue(IsHighlightProperty); } |
944 |
set |
945 |
{ |
946 |
if (this.IsHighLight != value) |
947 |
{ |
948 |
SetValue(IsHighlightProperty, value); |
949 |
OnPropertyChanged("IsHighLight"); |
950 |
} |
951 |
} |
952 |
} |
953 |
|
954 |
public List<Point> PointSet |
955 |
{ |
956 |
get { return (List<Point>)GetValue(PointSetProperty); } |
957 |
set { SetValue(PointSetProperty, value); |
958 |
OnPropertyChanged("PointSet"); |
959 |
} |
960 |
} |
961 |
|
962 |
#endregion Properties |
963 |
|
964 |
#region Properties |
965 |
|
966 |
|
967 |
|
968 |
public PathGeometry PathGeometry |
969 |
{ |
970 |
get { return (PathGeometry)GetValue(PathGeometryProperty); } |
971 |
set |
972 |
{ |
973 |
SetValue(PathGeometryProperty, value); |
974 |
OnPropertyChanged("PathGeometry"); |
975 |
} |
976 |
} |
977 |
|
978 |
private double _BoxWidth; |
979 |
public double BoxWidth |
980 |
{ |
981 |
get |
982 |
{ |
983 |
return _BoxWidth; |
984 |
} |
985 |
set |
986 |
{ |
987 |
_BoxWidth = value; |
988 |
OnPropertyChanged("BoxWidth"); |
989 |
} |
990 |
} |
991 |
|
992 |
private double _BoxHeight; |
993 |
public double BoxHeight |
994 |
{ |
995 |
get |
996 |
{ |
997 |
return _BoxHeight; |
998 |
} |
999 |
set |
1000 |
{ |
1001 |
_BoxHeight = value; |
1002 |
OnPropertyChanged("BoxHeight"); |
1003 |
} |
1004 |
} |
1005 |
|
1006 |
#endregion |
1007 |
|
1008 |
#region CallBack Method |
1009 |
public static void SetPathGeometryChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
1010 |
{ |
1011 |
var instance = (TextControl)sender; |
1012 |
|
1013 |
if (e.OldValue != e.NewValue && instance.Base_TextPath != null) |
1014 |
{ |
1015 |
instance.SetValue(e.Property, e.NewValue); |
1016 |
} |
1017 |
} |
1018 |
|
1019 |
|
1020 |
public static void OnTextBoxVisibilityChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
1021 |
{ |
1022 |
var instance = (TextControl)sender; |
1023 |
|
1024 |
if (e.OldValue != e.NewValue && instance.Base_TextPath != null) |
1025 |
{ |
1026 |
instance.SetValue(e.Property, e.NewValue); |
1027 |
} |
1028 |
} |
1029 |
|
1030 |
public static void OnTextBlockVisibilityChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
1031 |
{ |
1032 |
var instance = (TextControl)sender; |
1033 |
|
1034 |
if (e.OldValue != e.NewValue && instance.Base_TextPath != null) |
1035 |
{ |
1036 |
instance.SetValue(e.Property, e.NewValue); |
1037 |
} |
1038 |
} |
1039 |
|
1040 |
public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
1041 |
{ |
1042 |
var instance = (TextControl)sender; |
1043 |
|
1044 |
if (e.OldValue != e.NewValue && instance.Base_Border != null) |
1045 |
{ |
1046 |
instance.SetValue(e.Property, e.NewValue); |
1047 |
|
1048 |
if (instance.IsSelected) |
1049 |
{ |
1050 |
instance.FontColor = new SolidColorBrush(Colors.Blue); |
1051 |
//instance.Base_Border.BorderBrush = new SolidColorBrush(Colors.Blue); |
1052 |
} |
1053 |
else |
1054 |
{ |
1055 |
instance.FontColor = new SolidColorBrush(Colors.Red); |
1056 |
//instance.Base_Border.BorderBrush = new SolidColorBrush(Colors.Red); |
1057 |
//instance.FontColor = new SolidColorBrush(Colors.Transparent); |
1058 |
//instance.Base_Border.BorderBrush = new SolidColorBrush(Colors.Transparent); |
1059 |
} |
1060 |
|
1061 |
} |
1062 |
} |
1063 |
|
1064 |
public static void OnSetCansvasChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
1065 |
{ |
1066 |
var instance = (TextControl)sender; |
1067 |
|
1068 |
if (e.OldValue != e.NewValue && instance != null) |
1069 |
{ |
1070 |
instance.SetValue(e.Property, e.NewValue); |
1071 |
|
1072 |
Canvas.SetLeft(instance, instance.CanvasX); |
1073 |
|
1074 |
Canvas.SetTop(instance, instance.CanvasY); |
1075 |
} |
1076 |
} |
1077 |
|
1078 |
public static void OnIsEditingChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
1079 |
{ |
1080 |
var instance = (TextControl)sender; |
1081 |
|
1082 |
if (e.OldValue != e.NewValue && instance.Base_TextBlock != null) |
1083 |
{ |
1084 |
instance.SetValue(e.Property, e.NewValue); |
1085 |
|
1086 |
if (instance.EnableEditing) |
1087 |
{ |
1088 |
if (instance.IsEditing) |
1089 |
{ |
1090 |
instance.EditingMode(); |
1091 |
} |
1092 |
else |
1093 |
{ |
1094 |
instance.UnEditingMode(); |
1095 |
} |
1096 |
} |
1097 |
else |
1098 |
{ |
1099 |
instance.UnEditingMode(); |
1100 |
} |
1101 |
} |
1102 |
} |
1103 |
|
1104 |
public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
1105 |
{ |
1106 |
var instance = (TextControl)sender; |
1107 |
|
1108 |
if (e.OldValue != e.NewValue && instance.Base_TextBlock != null) |
1109 |
{ |
1110 |
instance.SetValue(e.Property, e.NewValue); |
1111 |
//instance.DrawingCloud(); |
1112 |
} |
1113 |
} |
1114 |
|
1115 |
public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
1116 |
{ |
1117 |
var instance = (TextControl)sender; |
1118 |
if (e.OldValue != e.NewValue && instance.Base_TextBlock != null) |
1119 |
{ |
1120 |
instance.SetValue(e.Property, e.NewValue); |
1121 |
//instance.DrawingCloud(); |
1122 |
} |
1123 |
} |
1124 |
|
1125 |
public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
1126 |
{ |
1127 |
var instance = (TextControl)sender; |
1128 |
if (e.OldValue != e.NewValue && instance!= null) |
1129 |
{ |
1130 |
instance.SetValue(e.Property, e.NewValue); |
1131 |
//instance.DrawingCloud(); |
1132 |
} |
1133 |
} |
1134 |
|
1135 |
#endregion CallBack Method |
1136 |
|
1137 |
protected void OnPropertyChanged(string propName) |
1138 |
{ |
1139 |
if (PropertyChanged != null) |
1140 |
PropertyChanged(this, new PropertyChangedEventArgs(propName)); |
1141 |
} |
1142 |
} |
1143 |
} |