프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / MarkupToPDF / Controls / Text / TextControl.cs @ 5a9353a9

이력 | 보기 | 이력해설 | 다운로드 (41.8 KB)

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