프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Text / TextControl.cs @ 10df01b4

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