프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Text / TextControl.cs @ e1c892f7

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

1
using MarkupToPDF.Common;
2
using MarkupToPDF.Controls.Common;
3
using MarkupToPDF.Serialize.Core;
4
using MarkupToPDF.Serialize.S_Control;
5
using System;
6
using System.Collections.Generic;
7
using System.ComponentModel;
8
using System.Linq;
9
using System.Text;
10
using System.Threading.Tasks;
11
using System.Windows;
12
using System.Windows.Controls;
13
using System.Windows.Media;
14
using System.Windows.Shapes;
15

    
16
namespace MarkupToPDF.Controls.Text
17
{    
18
    public class TextControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IPath, ITextControl, IMarkupControlData
19
    {
20
        public event PropertyChangedEventHandler PropertyChanged;
21

    
22
        private const string PART_Grid = "PART_Grid";
23
        private const string PART_Border = "PART_Border";
24
        private const string PART_TextBox = "PART_TextBox";
25
        private const string PART_TextPath = "PART_TextPath";
26
        private const string PART_TextBlock = "PART_TextBlock";
27
        private const string PART_Canvas = "PART_TextControlCanvas";
28
        private const string PART_BaseTextbox_Caret = "Caret";
29
        
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 Canvas Base_Canvas = null;
36
        //public TextBlock Base_TextPrefixBlock = null;
37
        public TextBlock Base_TextBlock = null;
38
        public TextBox Base_TextBox = null;
39
        public Border BaseTextbox_Caret = null;
40

    
41
        public RotateTransform _rotation = null;
42
        public TranslateTransform _translation = null;
43
        public ScaleTransform _scale = null;
44

    
45
        private const double _CloudArcDepth = 0.8;  /// 2018.05.14 added by humkyung
46

    
47
        public override bool IsSelected
48
        {
49
            get
50
            {
51
                return (bool)GetValue(IsSelectedProperty);
52
            }
53
            set
54
            {
55
                SetValue(IsSelectedProperty, value);
56
                OnPropertyChanged("IsSelected");
57
            }
58
        }
59

    
60
        #region Internal Method
61

    
62
        public TextControl()
63
        {
64
            //this.DefaultStyleKey = typeof(TextControl);
65
        }
66

    
67
        static TextControl()
68
        {
69
            DefaultStyleKeyProperty.OverrideMetadata(typeof(TextControl), new FrameworkPropertyMetadata(typeof(TextControl)));
70
            //ResourceDictionary dictionary = new ResourceDictionary();
71
            //dictionary.Source = new Uri("/MarkupToPDF;component/Themes/generic.xaml", UriKind.RelativeOrAbsolute);
72
            //if (!Application.Current.Resources.MergedDictionaries.Any(x => x.Source == dictionary.Source))
73
            //    Application.Current.Resources.MergedDictionaries.Add(dictionary);
74

    
75
        }
76

    
77

    
78
        public override void OnApplyTemplate()
79
        {
80
            base.OnApplyTemplate();
81

    
82
            Base_TextPath = GetTemplateChild(PART_TextPath) as Path;
83
            Base_TextBox = GetTemplateChild(PART_TextBox) as TextBox;
84
            Base_TextBlock = GetTemplateChild(PART_TextBlock) as TextBlock;
85
            Base_Grid = GetTemplateChild(PART_Grid) as Grid;
86
            Base_Border = GetTemplateChild(PART_Border) as Border;
87
            Base_Canvas = GetTemplateChild(PART_Canvas) as Canvas;
88
            BaseTextbox_Caret = GetTemplateChild(PART_BaseTextbox_Caret) as Border;
89
            this.Base_TextBox.Text = this.Text;
90
            this.Base_TextBox.CaretIndex = this.Base_TextBox.Text.Length;
91
            this.Base_TextBox.CaretBrush = new SolidColorBrush(Colors.Transparent);
92
            this.Base_TextBox.ApplyTemplate();
93
            MoveCustomCaret();
94

    
95
            this.Base_TextBox.SizeChanged += new SizeChangedEventHandler(Base_TextBox_SizeChanged);
96
            this.Base_TextBox.TextChanged += new TextChangedEventHandler(Base_TextBox_TextChanged);
97
            this.Base_TextBlock.SizeChanged += new SizeChangedEventHandler(Base_TextBlock_SizeChanged);
98
            this.Base_TextBox.GotFocus += new RoutedEventHandler(Base_TextBox_GotFocus);
99
            this.Base_TextBox.LostFocus += new RoutedEventHandler(Base_TextBox_LostFocus);            
100
            this.Base_TextBox.SelectionChanged += (sender, e) => MoveCustomCaret();
101
            
102
            
103
            SetText();
104
            DrawingCloud();
105
        }
106

    
107
        public void SetFontFamily(FontFamily fontFamily)
108
        {
109
            
110
            if (this.Base_TextBlock != null) {
111
                this.Base_TextBlock.FontFamily = fontFamily;
112
            }
113

    
114
            if (this.Base_TextBox != null) {
115
                this.Base_TextBox.FontFamily = fontFamily;
116
            }
117
            this.FontFamily = fontFamily;
118
            this.TextFamily = fontFamily;
119
        }
120

    
121

    
122
        /// <summary>
123
        /// Moves the custom caret on the canvas.
124
        /// </summary>
125
        public void MoveCustomCaret()
126
        {
127

    
128
            var caretLocation = this.Base_TextBox.GetRectFromCharacterIndex(this.Base_TextBox.CaretIndex).Location;
129

    
130
            if (!double.IsInfinity(caretLocation.X)) {
131
                Canvas.SetLeft(this.BaseTextbox_Caret, caretLocation.X);
132
            }
133

    
134
            if (!double.IsInfinity(caretLocation.Y)) {
135
                Canvas.SetTop(this.BaseTextbox_Caret, caretLocation.Y);
136
            }
137
        }
138

    
139
        
140

    
141
        public override void ApplyOverViewData()
142
        {
143
            this.OverViewPathData = this.PathData;
144
            if (Text == "")
145
                this.Text = this.OverViewText;
146
            else
147
                this.OverViewText = this.Text;
148
            
149
            this.OverViewPaint = this.Paint;
150

    
151
        }        
152

    
153
        void Base_TextBox_SizeChanged(object sender, SizeChangedEventArgs e)
154
        {
155
            BoxWidth = e.NewSize.Width;
156
            BoxHeight = e.NewSize.Height;
157

    
158
            DrawingCloud();
159
        }
160
        private void Base_TextBlock_SizeChanged(object sender, SizeChangedEventArgs e)
161
        {
162
            BoxWidth = e.NewSize.Width;
163
            BoxHeight = e.NewSize.Height;
164

    
165
            DrawingCloud();
166
        }
167
        private void Base_TextBox_TextChanged(object sender, TextChangedEventArgs e)
168
        {
169
            if (IsEditingMode)
170
            {
171
                if (Base_TextBox.Text.Contains("|OR||DZ|"))
172
                {
173
                    Base_TextBox.Text = this.Text;
174
                }
175

    
176
                this.Text = Base_TextBox.Text;
177

    
178
            }            
179
            DrawingCloud();
180
        }
181
        void Base_TextBox_GotFocus(object sender, RoutedEventArgs e)
182
        {
183
            this.BaseTextbox_Caret.Visibility = Visibility.Visible;
184
            this.IsEditingMode = true;
185
        }
186

    
187
        void Base_TextBox_LostFocus(object sender, RoutedEventArgs e)
188
        {
189
            this.Text = Base_TextBox.Text;
190
            this.BaseTextbox_Caret.Visibility = Visibility.Collapsed;
191
            this.IsEditingMode = false;
192
            ApplyOverViewData();
193
        }
194

    
195
        //void TextControl_GotFocus(object sender, RoutedEventArgs e)
196
        //{
197
        //    Base_TextBox.Visibility = Visibility.Visible;
198
        //    Base_TextBlock.Visibility = Visibility.Collapsed;
199
        //    this.Base_TextBox.BorderThickness = new Thickness(1);
200
        //    if (UnderLine != null)
201
        //    {
202
        //        Base_TextBlock.TextDecorations = UnderLine;
203
        //    }
204
        //    if (this.Text != null)
205
        //    {
206
        //        Base_TextBox.Text = this.Text;
207
        //    }
208
        //    IsEditing = true;
209
        //}
210
        //void TextControl_LostFocus(object sender, RoutedEventArgs e)
211
        //{
212
        //    Base_TextBox.Visibility = Visibility.Collapsed;
213
        //    Base_TextBlock.Visibility = Visibility.Visible;
214
        //    this.Text = Base_TextBox.Text;
215
        //    if (UnderLine != null)
216
        //    {
217
        //        Base_TextBlock.TextDecorations = UnderLine;
218
        //    }
219
        //    Base_TextBlock.Margin =
220
        //       new Thickness(Base_TextBox.Margin.Left + 4, Base_TextBox.Margin.Top + 4, Base_TextBox.Margin.Right + 4, Base_TextBox.Margin.Bottom + 4);
221
        //    IsEditing = false;
222
        //}
223
        public void EditingMode()
224
        {            
225
            TextBoxVisibility = Visibility.Visible;
226
            TextBlockVisibility = Visibility.Collapsed;
227
            this.BaseTextbox_Caret.Visibility = Visibility.Visible;
228

    
229
            if (UnderLine != null)
230
                Base_TextBlock.TextDecorations = UnderLine;
231

    
232
        }
233

    
234
        public void UnEditingMode()
235
        {            
236
            TextBoxVisibility = Visibility.Collapsed;         
237
            TextBlockVisibility = Visibility.Visible; 
238
            this.BaseTextbox_Caret.Visibility = Visibility.Collapsed;
239

    
240
            if (UnderLine != null)
241
                Base_TextBlock.TextDecorations = UnderLine;
242

    
243
            
244
        }
245
        public void SetText()
246
        {
247
            if (IsHighLight)
248
            {
249
                this.BackInnerColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.6),
250
                    Colors.Yellow.R, Colors.Yellow.G, Colors.Yellow.B));
251
                this.BackColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.1),
252
                    Colors.Yellow.R, Colors.Yellow.G, Colors.Yellow.B));
253
            }
254
            else
255
            {
256
                //this.BackInnerColor = new SolidColorBrush(Color.FromArgb(0x003, 0xFF, 0xFF, 0xFF));
257
                //this.BackColor = new SolidColorBrush(Color.FromArgb(0x003, 0xFF, 0xFF, 0xFF));
258

    
259
                this.BackInnerColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.6),
260
                    Colors.White.R, Colors.White.G, Colors.White.B));
261

    
262
                this.BackColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.1),
263
                    Colors.White.R, Colors.White.G, Colors.White.B));
264
            }
265
            if (Base_TextPath != null)
266
            {
267
                Base_TextPath.StrokeThickness = LineSize.Left;
268
            }
269
            
270
        }
271

    
272
        public void DrawingCloud()
273
        {
274
            
275
            List<Point> pCloud = new List<Point>
276
            {
277
                new Point(0, 0),
278
                new Point(0, 0 + BoxHeight + 0),
279
                new Point(0 + BoxWidth + 2, 0 + BoxHeight + 0),
280
                new Point(0 + BoxWidth + 2 ,0)
281
            };
282
            //this.Base_TextBox.Select(Base_TextBox.Text.Length, 0);
283
            if (Base_TextPath != null)
284
            {
285
                switch (ControlType_No)
286
                {
287
                    case 0:
288
                        {
289
                            PathData = new PathGeometry();
290
                            PathDataInner = (GenerateInner(pCloud));
291
                        }
292
                        break;
293
                    case 1:
294
                        {
295
                            PathData = (Generate_Rect(pCloud));
296
                            List<Point> pCloud2 = new List<Point>
297
                            {
298
                                new Point(0, 0),
299
                                new Point(0, 0 + BoxHeight + 0),
300
                                new Point(0 + BoxWidth + 10, 0 + BoxHeight + 0),
301
                                new Point(0 + BoxWidth + 10 ,0)
302
                            };
303
                            PathDataInner = (GenerateInner(pCloud));
304
                        }
305
                        break;
306
                    case 2:
307
                        {
308
                            PathData = (Generate(pCloud));
309
                            PathDataInner = (GenerateInner(pCloud));
310
                        }
311
                        break;
312
                }
313
            }
314

    
315
            //SetText();
316
        }
317
        #endregion Internal Method
318

    
319
        public void Dispose()
320
        {
321
            //GC.Collect();
322
            //GC.SuppressFinalize(this);
323
            this.Base_Border = null;
324
            this.Base_Canvas = null;
325
            this.Base_Grid = null;
326
            this.Base_TextBlock = null;
327
            this.Base_TextBox = null;
328
        }
329

    
330
        public override void UpdateControl()
331
        {
332
            if (this.PointSet.Count > 1)
333
            {
334
                this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
335
                this.EndPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
336
            }
337
        }
338

    
339
        #region Drawing Cloud Method
340
        public static PathGeometry Generate_Rect(List<Point> pData)
341
        {
342
            PathFigure pathFigure = new PathFigure();
343
            pathFigure.StartPoint = pData[0];
344

    
345
            PolyLineSegment polyline = new PolyLineSegment(pData, true);
346
            pathFigure.Segments.Add(polyline);
347

    
348
            PathGeometry rectPathGeometry = new PathGeometry();
349
            rectPathGeometry.Figures = new PathFigureCollection();
350
            pathFigure.IsClosed = true;
351
            pathFigure.IsFilled = false;
352
            rectPathGeometry.Figures.Add(pathFigure);
353

    
354

    
355
            return rectPathGeometry;
356
        }
357

    
358
        public static PathGeometry Generate(List<Point> pData)
359
        {
360
            var _pathGeometry = new PathGeometry();
361
            double area = MathSet.AreaOf(pData);
362
            bool reverse = (area > 0);
363
            int count = pData.Count;
364
            for (int i = 0; i < count; i++)
365
            {
366
                PathFigure pathFigure = GenerateLineWithCloud(pData[i % count], pData[(i + 1) % count], 20, reverse);
367
                pathFigure.IsClosed = false;
368
                pathFigure.IsFilled = true;
369
                _pathGeometry.Figures.Add(pathFigure);
370
            }
371

    
372
            return _pathGeometry;
373
        }
374

    
375

    
376
        public static PathGeometry GenerateInner(List<Point> pData)
377
        {
378
            var _pathGeometry = new PathGeometry();
379
            double area = MathSet.AreaOf(pData);
380
            bool reverse = (area > 0);
381
            int count = pData.Count;
382

    
383
            PathFigure pathFigur2 = new PathFigure();
384
            pathFigur2.StartPoint = pData[0];
385

    
386
            PolyLineSegment polyline = new PolyLineSegment(pData, true);
387
            pathFigur2.Segments.Add(polyline);
388

    
389
            pathFigur2.IsClosed = true;
390
            pathFigur2.IsFilled = true;
391
            _pathGeometry.Figures.Add(pathFigur2);
392

    
393
            return _pathGeometry;
394
        }
395

    
396
        public static PathFigure GenerateLineWithCloud(Point p1, Point p2, double _arcLength, bool reverse)
397
        {
398
            PathFigure pathFigure = new PathFigure();
399
            pathFigure.StartPoint = p1;
400

    
401
            double arcLength = _arcLength;
402
            double dx = p2.X - p1.X;
403
            double dy = p2.Y - p1.Y;
404
            double l = MathSet.DistanceTo(p1, p2);
405
            double theta = Math.Atan2(Math.Abs(dy), Math.Abs(dx)) * 180 / Math.PI;
406
            Point lastPt = new Point(p1.X, p1.Y);
407
            double count = l / _arcLength;
408

    
409
            dx /= l;
410
            dy /= l;
411

    
412
            Double j = 1;
413
            for (j = 1; j < (count - 1); j++)
414
            {
415
                ArcSegment arcSeg = new ArcSegment();
416
                arcSeg.Size = new Size(arcLength * TextControl._CloudArcDepth, arcLength * TextControl._CloudArcDepth);
417
                arcSeg.Point = new Point(p1.X + j * dx * arcLength, p1.Y + j * dy * arcLength);
418
                lastPt = arcSeg.Point;
419
                arcSeg.RotationAngle = theta + 90;
420
                if (true == reverse)
421
                    arcSeg.SweepDirection = SweepDirection.Clockwise;
422
                pathFigure.Segments.Add(arcSeg);
423
            }
424

    
425
            if ((count > j) || count > 0)
426
            {
427
                arcLength = MathSet.DistanceTo(lastPt, p2);
428
                ArcSegment arcSeg = new ArcSegment();
429
                arcSeg.Size = new Size(arcLength * TextControl._CloudArcDepth, arcLength * TextControl._CloudArcDepth);
430
                arcSeg.Point = new Point(p2.X, p2.Y);
431
                arcSeg.RotationAngle = theta;
432

    
433
                if (true == reverse)
434
                    arcSeg.SweepDirection = SweepDirection.Clockwise;
435

    
436
                pathFigure.Segments.Add(arcSeg);
437

    
438
            }
439
            return pathFigure;
440
        }
441
        #endregion
442

    
443
        #region Dependency Properties
444
        public static readonly DependencyProperty ControlTypeProperty =
445
        DependencyProperty.Register("ControlType", typeof(ControlType), typeof(TextControl), new FrameworkPropertyMetadata(ControlType.TextControl));
446

    
447
        public static readonly DependencyProperty ControlType_NoProperty =
448
        DependencyProperty.Register("ControlType_No", typeof(int), typeof(TextControl), new FrameworkPropertyMetadata(0));
449

    
450
        public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register(
451
            "IsSelected", typeof(bool), typeof(TextControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
452

    
453
        public static readonly DependencyProperty PathGeometryProperty = DependencyProperty.Register(
454
            "PathGeometry", typeof(PathGeometry), typeof(TextControl), new PropertyMetadata(null, SetPathGeometryChanged));
455

    
456
        public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
457
            "Text", typeof(string), typeof(TextControl), new PropertyMetadata(null));
458

    
459
        public static readonly DependencyProperty OverViewTextProperty = DependencyProperty.Register(
460
            "OverViewText", typeof(string), typeof(TextControl), new PropertyMetadata(null, new PropertyChangedCallback(TextChanged)));
461

    
462
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
463
            "UserID", typeof(string), typeof(TextControl), new PropertyMetadata(null));
464

    
465
        /*public static readonly DependencyProperty FontColorProperty = DependencyProperty.Register(
466
            "FontColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));*/
467

    
468
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
469
            "StrokeColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
470

    
471
        //강인구 추가
472
        public static readonly DependencyProperty IsHighlightProperty = DependencyProperty.Register(
473
            "IsHighLight", typeof(bool), typeof(TextControl), new PropertyMetadata(false, PointValueChanged));
474

    
475
        public static readonly DependencyProperty BackColorProperty = DependencyProperty.Register(
476
            "BackColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.White)));
477

    
478
        public static readonly DependencyProperty BackInnerColorProperty = DependencyProperty.Register(
479
            "BackInnerColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.White)));
480

    
481
        public static readonly DependencyProperty UnderLineProperty = DependencyProperty.Register(
482
            "UnderLine", typeof(TextDecorationCollection), typeof(TextControl), new PropertyMetadata(null));
483

    
484
        public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register(
485
            "LineSize", typeof(Thickness), typeof(TextControl), new PropertyMetadata(new Thickness(4), PointValueChanged)); //여기만 4인지 모르겠지만 4 그대로 두겠음
486

    
487
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
488
            "PointSet", typeof(List<Point>), typeof(TextControl), new PropertyMetadata(new List<Point>()));
489

    
490
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
491
            "PathData", typeof(Geometry), typeof(TextControl), null);
492

    
493

    
494

    
495
        public static readonly DependencyProperty PathDataInnerProperty = DependencyProperty.Register(
496
    "PathDataInner", typeof(Geometry), typeof(TextControl), null);
497

    
498
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
499
            "OverViewPathDataProperty", typeof(Geometry), typeof(TextControl), null);
500

    
501
        public static readonly DependencyProperty TextStyleProperty = DependencyProperty.Register(
502
            "TextStyle", typeof(FontStyle), typeof(TextControl), new PropertyMetadata(FontStyles.Normal));
503

    
504
        public static readonly DependencyProperty TextFamilyProperty = DependencyProperty.Register(
505
            "TextFamily", typeof(FontFamily), typeof(TextControl), new PropertyMetadata(new FontFamily("Arial")));
506

    
507
        public static readonly DependencyProperty TextWeightProperty = DependencyProperty.Register(
508
            "TextWeight", typeof(FontWeight), typeof(TextControl), new PropertyMetadata(FontWeights.Normal));
509

    
510
        public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register(
511
            "CenterX", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnCenterXYChanged));
512

    
513
        public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register(
514
            "CenterY", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnCenterXYChanged));
515

    
516
        public static readonly DependencyProperty CanvasXProperty = DependencyProperty.Register(
517
           "CanvasX", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
518

    
519
        public static readonly DependencyProperty CanvasYProperty = DependencyProperty.Register(
520
            "CanvasY", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
521

    
522
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
523
              "StartPoint", typeof(Point), typeof(TextControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
524

    
525
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
526
             "EndPoint", typeof(Point), typeof(TextControl), new PropertyMetadata(new Point(100, 100), PointValueChanged));
527

    
528
        public static readonly DependencyProperty TextSizeProperty = DependencyProperty.Register(
529
               "TextSize", typeof(Double), typeof(TextControl), new PropertyMetadata((Double)30, PointValueChanged));
530

    
531
        public static readonly DependencyProperty PaintProperty = DependencyProperty.Register(
532
                "Paint", typeof(PaintSet), typeof(TextControl), new PropertyMetadata((PaintSet.None), PointValueChanged));
533

    
534
        public static readonly DependencyProperty OverViewPaintProperty = DependencyProperty.Register(
535
                "OverViewPaint", typeof(PaintSet), typeof(TextControl), new PropertyMetadata((PaintSet.None), PointValueChanged));
536

    
537
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register(
538
            "Angle", typeof(double), typeof(TextControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
539

    
540
        public static readonly DependencyProperty EnableEditingProperty = DependencyProperty.Register(
541
           "EnableEditing", typeof(bool), typeof(TextControl), new PropertyMetadata((true), new PropertyChangedCallback(OnIsEditingChanged)));
542

    
543
        public static readonly DependencyProperty TextBoxVisibilityProperty = DependencyProperty.Register(
544
        "TextBoxVisibility", typeof(Visibility), typeof(TextControl), new PropertyMetadata((Visibility.Visible), OnTextBoxVisibilityChanged));
545

    
546
        public static readonly DependencyProperty TextBlockVisibilityProperty = DependencyProperty.Register(
547
        "TextBlockVisibility", typeof(Visibility), typeof(TextControl), new PropertyMetadata((Visibility.Collapsed), OnTextBlockVisibilityChanged));
548

    
549
        #endregion Dependency Properties
550

    
551
        #region dp Properties
552

    
553

    
554
        public override SolidColorBrush StrokeColor
555
        {
556
            get { return (SolidColorBrush)GetValue(StrokeColorProperty); }
557
            set
558
            {
559
                if (this.StrokeColor != value)
560
                {
561
                    SetValue(StrokeColorProperty, value);
562
                }
563
            }
564
        }
565

    
566

    
567

    
568
        public bool EnableEditing
569
        {
570
            get { return (bool)GetValue(EnableEditingProperty); }
571
            set
572
            {
573
                if (this.EnableEditing != value)
574
                {
575
                    SetValue(EnableEditingProperty, value);
576
                    OnPropertyChanged("EnableEditing");
577
                }
578
            }
579
        }
580

    
581
        public Thickness LineSize
582
        {
583
            get
584
            {
585
                return (Thickness)GetValue(LineSizeProperty);
586
            }
587
            set
588
            {
589
                if (this.LineSize != value)
590
                {
591
                    SetValue(LineSizeProperty, value);
592
                    OnPropertyChanged("LineSize");
593
                }
594
            }
595
        }
596

    
597
        public override ControlType ControlType
598
        {
599
            get
600
            {
601
                return (ControlType)GetValue(ControlTypeProperty);
602
            }
603
            set
604
            {
605
                SetValue(ControlTypeProperty, value);
606
            }
607
        }
608
        public int ControlType_No
609
        {
610
            get
611
            {
612
                return (int)GetValue(ControlType_NoProperty);
613
            }
614
            set
615
            {
616
                SetValue(ControlType_NoProperty, value);
617
            }
618
        }
619

    
620
        public string UserID
621
        {
622
            get { return (string)GetValue(UserIDProperty); }
623
            set
624
            {
625
                if (this.UserID != value)
626
                {
627
                    SetValue(UserIDProperty, value);
628
                    OnPropertyChanged("UserID");
629
                }
630
            }
631
        }
632

    
633
        public double CenterX
634
        {
635
            get { return (double)GetValue(CenterXProperty); }
636
            set
637
            {
638
                SetValue(CenterXProperty, value);
639
                OnPropertyChanged("CenterX");
640

    
641
            }
642
        }
643

    
644
        public double CenterY
645
        {
646
            get { return (double)GetValue(CenterYProperty); }
647
            set
648
            {
649
                SetValue(CenterYProperty, value);
650
                OnPropertyChanged("CenterY");
651
            }
652
        }
653

    
654
        public string Text
655
        {
656
            get { return (string)GetValue(TextProperty); }
657
            set
658
            {
659
                if (this.Text != value)
660
                {
661
                    SetValue(TextProperty, value);
662
                    OnPropertyChanged("Text");
663
                }
664
            }
665
        }
666

    
667
        public string OverViewText
668
        {
669
            get { return (string)GetValue(OverViewTextProperty); }
670
            set
671
            {
672
                if (this.OverViewText != value)
673
                {
674
                    SetValue(OverViewTextProperty, value);
675
                    OnPropertyChanged("OverViewText");
676
                }
677
            }
678
        }
679

    
680
        public Geometry OverViewPathData
681
        {
682
            get { return (Geometry)GetValue(OverViewPathDataProperty); }
683
            set
684
            {
685
                if (this.OverViewPathData != value)
686
                {
687
                    SetValue(OverViewPathDataProperty, value);
688
                    OnPropertyChanged("OverViewPathData");
689
                }
690
            }
691
        }
692

    
693
        public Visibility TextBoxVisibility
694
        {
695
            get { return (Visibility)GetValue(TextBoxVisibilityProperty); }
696
            set
697
            {
698
                if (this.TextBoxVisibility != value)
699
                {
700
                    SetValue(TextBoxVisibilityProperty, value);
701
                    OnPropertyChanged("TextBoxVisibility");
702
                }
703
            }
704
        }
705

    
706

    
707
        public Visibility TextBlockVisibility
708
        {
709
            get { return (Visibility)GetValue(TextBlockVisibilityProperty); }
710
            set
711
            {
712
                if (this.TextBlockVisibility != value)
713
                {
714
                    SetValue(TextBlockVisibilityProperty, value);
715
                    OnPropertyChanged("TextBlockVisibility");
716
                }
717
            }
718
        }
719

    
720

    
721

    
722
        public Double TextSize
723
        {
724
            get { return (Double)GetValue(TextSizeProperty); }
725
            set
726
            {
727
                if (this.TextSize != value)
728
                {
729
                    SetValue(TextSizeProperty, value);
730
                    OnPropertyChanged("TextSize");
731
                }
732
            }
733
        }
734
        /*
735
        public SolidColorBrush FontColor
736
        {
737
            get { return (SolidColorBrush)GetValue(FontColorProperty); }
738
            set
739
            {
740
                if (this.FontColor != value)
741
                {
742
                    SetValue(FontColorProperty, value);
743
                    OnPropertyChanged("FontColor");
744
                }
745
            }
746
        }*/
747

    
748
        public SolidColorBrush BackColor
749
        {
750
            get { return (SolidColorBrush)GetValue(BackColorProperty); }
751
            set
752
            {
753
                if (this.BackColor != value)
754
                {
755
                    SetValue(BackColorProperty, value);
756
                    OnPropertyChanged("BackColor");
757
                }
758
            }
759
        }
760

    
761
        public SolidColorBrush BackInnerColor
762
        {
763
            get { return (SolidColorBrush)GetValue(BackInnerColorProperty); }
764
            set
765
            {
766
                if (this.BackInnerColor != value)
767
                {
768
                    SetValue(BackInnerColorProperty, value);
769
                    OnPropertyChanged("BackInnerColor");
770
                }
771
            }
772
        }
773

    
774

    
775

    
776
        public TextDecorationCollection UnderLine
777
        {
778
            get
779
            {
780
                return (TextDecorationCollection)GetValue(UnderLineProperty);
781
            }
782
            set
783
            {
784
                if (this.UnderLine != value)
785
                {
786
                    SetValue(UnderLineProperty, value);
787
                    OnPropertyChanged("UnderLine");
788
                }
789
            }
790
        }
791

    
792
        public double CanvasX
793
        {
794
            get { return (double)GetValue(CanvasXProperty); }
795
            set
796
            {
797
                if (this.CanvasX != value)
798
                {
799
                    SetValue(CanvasXProperty, value);
800
                    OnPropertyChanged("CanvasX");
801
                }
802
            }
803
        }
804

    
805
        public double CanvasY
806
        {
807
            get { return (double)GetValue(CanvasYProperty); }
808
            set
809
            {
810
                if (this.CanvasY != value)
811
                {
812
                    SetValue(CanvasYProperty, value);
813
                    OnPropertyChanged("CanvasY");
814
                }
815
            }
816
        }
817

    
818
        public Point EndPoint
819
        {
820
            get { return (Point)GetValue(EndPointProperty); }
821
            set
822
            {
823
                if (this.EndPoint != value)
824
                {
825
                    SetValue(EndPointProperty, value);
826
                    OnPropertyChanged("EndPoint");
827
                }
828
            }
829
        }
830

    
831
        public Point StartPoint
832
        {
833
            get { return (Point)GetValue(StartPointProperty); }
834
            set
835
            {
836
                if (this.StartPoint != value)
837
                {
838
                    SetValue(StartPointProperty, value);
839
                    OnPropertyChanged("StartPoint");
840
                }
841
            }
842
        }
843

    
844
        public FontStyle TextStyle
845
        {
846
            get { return (FontStyle)GetValue(TextStyleProperty); }
847
            set
848
            {
849
                if (this.TextStyle != value)
850
                {
851
                    SetValue(TextStyleProperty, value);
852
                    OnPropertyChanged("TextStyle");
853
                }
854
            }
855
        }
856

    
857
        public FontFamily TextFamily
858
        {
859
            get { return (FontFamily)GetValue(TextFamilyProperty); }
860
            set
861
            {
862
                if (this.TextFamily != value)
863
                {
864
                    SetValue(TextFamilyProperty, value);
865
                    OnPropertyChanged("TextFamily");
866
                }
867
            }
868
        }
869

    
870
        public FontWeight TextWeight
871
        {
872
            get { return (FontWeight)GetValue(TextWeightProperty); }
873
            set
874
            {
875
                if (this.TextWeight != value)
876
                {
877
                    SetValue(TextWeightProperty, value);
878
                    OnPropertyChanged("TextWeight");
879
                }
880
            }
881
        }
882

    
883
        public PaintSet Paint
884
        {
885
            get { return (PaintSet)GetValue(PaintProperty); }
886
            set
887
            {
888
                if (this.Paint != value)
889
                {
890
                    SetValue(PaintProperty, value);
891
                    OnPropertyChanged("Paint");
892
                }
893
            }
894
        }
895

    
896
        public PaintSet OverViewPaint
897
        {
898
            get { return (PaintSet)GetValue(OverViewPaintProperty); }
899
            set
900
            {
901
                if (this.OverViewPaint != value)
902
                {
903
                    SetValue(OverViewPaintProperty, value);
904
                    OnPropertyChanged("OverViewPaint");
905
                }
906
            }
907
        }
908

    
909
        double IPath.LineSize
910
        {
911
            get
912
            {
913
                return this.LineSize.Left;
914
            }
915
            set
916
            {
917
                this.LineSize = new Thickness(value);
918
                OnPropertyChanged("LineSize");
919
            }
920
        }
921

    
922

    
923
        public Geometry PathData
924
        {
925
            get { return (Geometry)GetValue(PathDataProperty); }
926
            set
927
            {
928
                SetValue(PathDataProperty, value);
929
                OnPropertyChanged("PathData");
930
            }
931
        }
932

    
933
        public Geometry PathDataInner
934
        {
935
            get { return (Geometry)GetValue(PathDataInnerProperty); }
936
            set
937
            {
938
                SetValue(PathDataInnerProperty, value);
939
                OnPropertyChanged("PathDataInner");
940
            }
941
        }
942

    
943
        public override double CommentAngle
944
        {
945
            get { return (double)GetValue(AngleProperty); }
946
            set
947
            {
948
                if (this.CommentAngle != value)
949
                {
950
                    SetValue(AngleProperty, value);
951

    
952
                    OnPropertyChanged("Angle");
953
                    UpdateLayout();
954
                }
955
            }
956
        }
957

    
958
        public bool IsHighLight
959
        {
960
            get { return (bool)GetValue(IsHighlightProperty); }
961
            set
962
            {
963
                if (this.IsHighLight != value)
964
                {
965
                    SetValue(IsHighlightProperty, value);
966
                    OnPropertyChanged("IsHighLight");
967
                }
968
            }
969
        }
970

    
971
        public List<Point> PointSet
972
        {
973
            get { return (List<Point>)GetValue(PointSetProperty); }
974
            set
975
            {
976
                SetValue(PointSetProperty, value);
977
                OnPropertyChanged("PointSet");
978
            }
979
        }
980

    
981
        #endregion Properties
982

    
983
        #region Properties
984

    
985
        private bool _IsEditingMode;
986
        public bool IsEditingMode
987
        {
988
            get
989
            {
990
                return _IsEditingMode;
991
            }
992
            set
993
            {
994
                _IsEditingMode = value;
995
                OnPropertyChanged("IsEditingMode");
996
            }
997
        }
998

    
999
        public PathGeometry PathGeometry
1000
        {
1001
            get { return (PathGeometry)GetValue(PathGeometryProperty); }
1002
            set
1003
            {
1004
                SetValue(PathGeometryProperty, value);
1005
                OnPropertyChanged("PathGeometry");
1006
            }
1007
        }
1008

    
1009
        private double _BoxWidth;
1010
        public double BoxWidth
1011
        {
1012
            get
1013
            {
1014
                return _BoxWidth;
1015
            }
1016
            set
1017
            {
1018
                _BoxWidth = value;
1019
                OnPropertyChanged("BoxWidth");
1020
            }
1021
        }
1022

    
1023
        private double _BoxHeight;
1024
        public double BoxHeight
1025
        {
1026
            get
1027
            {
1028
                return _BoxHeight;
1029
            }
1030
            set
1031
            {
1032
                _BoxHeight = value;
1033
                OnPropertyChanged("BoxHeight");
1034
            }
1035
        }
1036

    
1037
        #endregion
1038

    
1039
        #region CallBack Method
1040
        public static void SetPathGeometryChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1041
        {
1042
            var instance = (TextControl)sender;
1043

    
1044
            if (e.OldValue != e.NewValue && instance.Base_TextPath != null)
1045
            {
1046
                instance.SetValue(e.Property, e.NewValue);
1047
            }
1048
        }
1049

    
1050

    
1051
        public static void OnTextBoxVisibilityChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1052
        {
1053
            var instance = (TextControl)sender;
1054

    
1055
            if (e.OldValue != e.NewValue && instance.Base_TextPath != null)
1056
            {
1057
                instance.SetValue(e.Property, e.NewValue);
1058
            }
1059
        }
1060

    
1061
        public static void OnTextBlockVisibilityChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1062
        {
1063
            var instance = (TextControl)sender;
1064

    
1065
            if (e.OldValue != e.NewValue && instance.Base_TextPath != null)
1066
            {
1067
                instance.SetValue(e.Property, e.NewValue);
1068
            }
1069
        }
1070

    
1071
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1072
        {
1073
            //var instance = (TextControl)sender;
1074

    
1075
            //if (e.OldValue != e.NewValue && instance.Base_Border != null)
1076
            //{
1077
            //    instance.SetValue(e.Property, e.NewValue);
1078

    
1079
            //    if (instance.IsSelected)
1080
            //    {
1081
            //        instance.StrokeColor = new SolidColorBrush(Colors.Blue);
1082
            //        //instance.Base_Border.BorderBrush = new SolidColorBrush(Colors.Blue);
1083
            //    }
1084
            //    else
1085
            //    {
1086
            //        instance.StrokeColor = new SolidColorBrush(Colors.Red);
1087
            //        //instance.Base_Border.BorderBrush = new SolidColorBrush(Colors.Red);
1088
            //        //instance.FontColor = new SolidColorBrush(Colors.Transparent);
1089
            //        //instance.Base_Border.BorderBrush = new SolidColorBrush(Colors.Transparent);
1090
            //    }
1091

    
1092
            //}
1093
        }
1094

    
1095
        public static void OnSetCansvasChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1096
        {
1097
            var instance = (TextControl)sender;
1098

    
1099
            if (e.OldValue != e.NewValue && instance != null)
1100
            {
1101
                instance.SetValue(e.Property, e.NewValue);
1102

    
1103
                Canvas.SetLeft(instance, instance.CanvasX);
1104
                Canvas.SetTop(instance, instance.CanvasY);
1105
            }
1106
        }
1107

    
1108
        public static void OnIsEditingChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1109
        {
1110
            var instance = (TextControl)sender;
1111

    
1112
            if (e.OldValue != e.NewValue && instance.Base_TextBlock != null)
1113
            {
1114
                instance.SetValue(e.Property, e.NewValue);
1115

    
1116
                if (instance.EnableEditing)
1117
                {
1118
                    instance.EditingMode();
1119
                }
1120
                else
1121
                {
1122
                    instance.UnEditingMode();
1123
                }
1124
            }
1125
        }
1126
        public static void TextChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1127
        {
1128
            var instance = (TextControl)sender;
1129

    
1130
            if (e.OldValue != e.NewValue)
1131
            {
1132
                instance.SetValue(e.Property, e.NewValue);
1133
            }
1134
        }
1135

    
1136
        public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1137
        {
1138
            var instance = (TextControl)sender;
1139

    
1140
            if (e.OldValue != e.NewValue && instance.Base_TextBlock != null)
1141
            {
1142
                instance.SetValue(e.Property, e.NewValue);
1143
                //instance.DrawingCloud();
1144
            }
1145
        }
1146

    
1147
        public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1148
        {
1149
            var instance = (TextControl)sender;
1150
            if (e.OldValue != e.NewValue && instance.Base_TextBlock != null)
1151
            {
1152
                instance.SetValue(e.Property, e.NewValue);
1153
                //instance.DrawingCloud();
1154
            }
1155
        }
1156

    
1157
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1158
        {
1159
            var instance = (TextControl)sender;
1160
            
1161
            if (e.OldValue != e.NewValue && instance.Base_TextBox != null)
1162
            {                       
1163
                instance.SetText();
1164
                instance.DrawingCloud();
1165
            }
1166

    
1167
        }
1168

    
1169
        #endregion CallBack Method
1170

    
1171
        protected void OnPropertyChanged(string propName)
1172
        {
1173
            if (PropertyChanged != null)
1174
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
1175
        }
1176

    
1177
        /// <summary>
1178
        /// return textcontrols' area
1179
        /// </summary>
1180
        public override Rect ItemRect
1181
        {
1182
            get
1183
            {
1184
                Point start = new Point(this.CanvasX, this.CanvasY);
1185

    
1186
                Point length = new Point();
1187
                double angle = this.CommentAngle * Math.PI / 180;
1188

    
1189
                length.X = this.BoxWidth * Math.Cos(angle) - this.BoxHeight * Math.Sin(angle);
1190
                length.Y = this.BoxWidth * Math.Sin(angle) + this.BoxHeight * Math.Cos(angle);
1191

    
1192
                Point end = new Point(start.X + length.X, start.Y + length.Y);
1193
                return new Rect(start, end);
1194
            }
1195
        }
1196

    
1197
        /// <summary>
1198
        /// translate control along given dx,dy
1199
        /// </summary>
1200
        /// <param name="dx"></param>
1201
        /// <param name="dy"></param>
1202
        public override void OnTranslate(double dx, double dy)
1203
        {
1204
            //this.CanvasX = Canvas.GetLeft(this) + dx;
1205
            //this.CanvasY = Canvas.GetTop(this) + dy;
1206
            this.StartPoint = new Point(this.StartPoint.X + dx, this.StartPoint.Y + dy);
1207
            this.EndPoint = new Point(this.EndPoint.X + dx, this.EndPoint.Y + dy);
1208

    
1209
            this.SetValue(TextControl.CanvasXProperty, Canvas.GetLeft(this) + dx);
1210
            this.SetValue(TextControl.CanvasYProperty, Canvas.GetTop(this) + dy);
1211

    
1212

    
1213

    
1214

    
1215
            //Canvas.SetLeft(this, Canvas.GetLeft(this) + dx);
1216
            //Canvas.SetTop(this, Canvas.GetTop(this) + dy);
1217
        }
1218

    
1219
        /// <summary>
1220
        /// Serialize this
1221
        /// </summary>
1222
        /// <param name="sUserId"></param>
1223
        /// <returns></returns>
1224
        public override string Serialize()
1225
        {
1226
            using (S_TextControl STemp = new S_TextControl())
1227
            {
1228
                STemp.TransformPoint = "0|0";
1229
                STemp.SizeSet = String.Format("{0}|{1}", this.LineSize.Left.ToString(), this.TextSize.ToString());
1230
                STemp.Text = this.Text;
1231
                STemp.UserID = this.UserID;
1232
                STemp.FontColor = this.StrokeColor.Color.ToString();
1233
                //STemp.FontColor = "#FFFFFF00";
1234

    
1235
                if (this.StartPoint == new Point())
1236
                    STemp.StartPoint = new Point(this.CanvasX, this.CanvasY);
1237
                else
1238
                    STemp.StartPoint = this.StartPoint;
1239

    
1240
                STemp.EndPoint = this.EndPoint;
1241
                STemp.Opac = this.Opacity;
1242
                STemp.PointSet = this.PointSet;
1243
                STemp.Angle = this.CommentAngle;
1244
                STemp.paintMethod = this.ControlType_No;
1245
                STemp.BoxW = this.BoxWidth;
1246
                STemp.BoxH = this.BoxHeight;
1247
                STemp.isHighLight = this.IsHighLight;
1248
                STemp.Name = this.GetType().Name.ToString();
1249
                STemp.fontConfig = new List<string>()
1250
                            {
1251
                                this.TextFamily.ToString(),
1252
                                this.TextStyle.ToString(),
1253
                                this.TextWeight.ToString(),
1254
                            };
1255

    
1256

    
1257

    
1258
                if (this.UnderLine != null)
1259
                {
1260
                    STemp.fontConfig.Add("true");
1261
                }
1262

    
1263
                ///강인구 추가(2017.11.02)
1264
                ///Memo 추가
1265
                STemp.Memo = this.Memo;
1266

    
1267
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
1268
            }
1269
        }
1270

    
1271
        /// <summary>
1272
        /// create a textcontrol from given string
1273
        /// </summary>
1274
        /// <param name="str"></param>
1275
        /// <returns></returns>
1276
        public static TextControl FromString(string str, SolidColorBrush brush, string sProjectNo)
1277
        {
1278
            using (S_TextControl s = JsonSerializerHelper.JsonDeserialize<S_TextControl>(str))
1279
            {
1280
                string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1281
                TextControl instance = new TextControl()
1282
                {
1283
                    Text = s.Text,
1284
                    StartPoint = s.StartPoint,
1285
                    EndPoint = s.EndPoint,
1286
                    CanvasX = s.StartPoint.X,
1287
                    CanvasY = s.StartPoint.Y,
1288
                    BoxWidth = s.BoxW,
1289
                    BoxHeight = s.BoxH,
1290
                    ControlType_No = s.paintMethod,
1291
                    LineSize = new Thickness(Convert.ToDouble(data2.First())),
1292
                    TextSize = Convert.ToDouble(data2[1]),
1293
                    StrokeColor = brush,
1294
                    FontSize = 10,
1295
                    UserID = s.UserID,
1296
                    IsHighLight = s.isHighLight,
1297
                    CommentAngle = s.Angle,
1298
                    PointSet = s.PointSet,
1299
                    Opacity = s.Opac,
1300
                    
1301
                    TextFamily = new FontFamily(s.fontConfig[0]),
1302
                    //인구 추가(2018.04.17)
1303
                    TextStyle = StringToFont.ConFontStyle(s.fontConfig[1]),
1304
                    TextWeight = StringToFont.ConFontWeight(s.fontConfig[2]),
1305
                };
1306

    
1307
                if (s.fontConfig.Count() == 4)
1308
                {
1309
                    instance.UnderLine = TextDecorations.Underline;
1310
                }
1311

    
1312
                return instance;
1313
            }
1314
        }
1315
    }
1316
}
클립보드 이미지 추가 (최대 크기: 500 MB)