프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Text / TextControl.cs @ 90db87f6

이력 | 보기 | 이력해설 | 다운로드 (44 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
    [TemplatePart(Name = "PART_TextBox", Type = typeof(TextBox))]
19
    [TemplatePart(Name = "PART_TextBlock", Type = typeof(TextBlock))]
20
    [TemplatePart(Name = "PART_TextPath", Type = typeof(Path))]
21
    [TemplatePart(Name = "PART_Border", Type = typeof(Border))]
22
    [TemplatePart(Name = "PART_Grid", Type = typeof(Grid))]
23
    public class TextControl : CommentUserInfo, INotifyPropertyChanged, IMarkupControlData, IPath
24
    {
25
        public event PropertyChangedEventHandler PropertyChanged;
26

    
27
        private const string PART_Grid = "PART_Grid";
28
        private const string PART_Border = "PART_Border";
29
        private const string PART_TextBox = "PART_TextBox";
30
        private const string PART_TextPath = "PART_TextPath";
31
        private const string PART_TextBlock = "PART_TextBlock";
32
        private const string PART_Canvas = "PART_TextControlCanvas";
33
        //private const string PART_TextPrefix = "PART_TextPrefix";
34

    
35
        public Path Base_TextPath = null;
36
        public Grid Base_Grid = null;
37
        public Border Base_Border = null;
38
        public Canvas Base_Canvas = null;
39
        //public TextBlock Base_TextPrefixBlock = null;
40
        public TextBlock Base_TextBlock = null;
41
        public TextBox Base_TextBox = null;
42

    
43
        public RotateTransform _rotation = null;
44
        public TranslateTransform _translation = null;
45
        public ScaleTransform _scale = null;
46

    
47
        private const double _CloudArcDepth = 0.8;  /// 2018.05.14 added by humkyung
48

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

    
62
        #region Internal Method
63

    
64
        public TextControl()
65
        {
66
            this.DefaultStyleKey = typeof(TextControl);
67
        }
68

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

    
76
        }
77

    
78

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

    
83
            Base_TextPath = GetTemplateChild(PART_TextPath) as Path;
84
            Base_TextBox = GetTemplateChild(PART_TextBox) as TextBox;
85
            Base_TextBlock = GetTemplateChild(PART_TextBlock) as TextBlock;
86
            Base_Grid = GetTemplateChild(PART_Grid) as Grid;
87
            Base_Border = GetTemplateChild(PART_Border) as Border;
88
            Base_Canvas = GetTemplateChild(PART_Canvas) as Canvas;
89

    
90
            this.Base_TextBox.SizeChanged += new SizeChangedEventHandler(Base_TextBox_SizeChanged);
91
            this.Base_TextBlock.SizeChanged += new SizeChangedEventHandler(Base_TextBlock_SizeChanged);
92
            this.Base_TextBox.GotFocus += new RoutedEventHandler(TextControl_GotFocus);
93
            this.Base_TextBox.LostFocus += new RoutedEventHandler(TextControl_LostFocus);
94
            this.Base_TextBox.TextChanged += Base_TextBox_TextChanged;
95

    
96
            DrawingCloud();
97
            SetText();
98
        }
99

    
100
        private void Base_TextBox_TextChanged(object sender, TextChangedEventArgs e)
101
        {
102
            if (Base_TextBox.Text.Contains("|OR||DZ|")) {
103
                Base_TextBox.Text = this.Text;
104
            }
105
            this.Text = Base_TextBox.Text;
106
            DrawingCloud();
107
        }
108

    
109
        public override void ApplyOverViewData()
110
        {
111
            this.OverViewPathData = this.PathData;
112
            this.OverViewText = this.Text;
113
            this.OverViewPaint = this.Paint;
114

    
115
        }
116

    
117
        void Base_TextBlock_SizeChanged(object sender, SizeChangedEventArgs e)
118
        {
119
            BoxWidth = e.NewSize.Width;
120
            BoxHeight = e.NewSize.Height;
121
            DrawingCloud();
122
        }
123

    
124
        void Base_TextBox_SizeChanged(object sender, SizeChangedEventArgs e)
125
        {
126
            if (Base_TextBox.Text.Contains("|OR||DZ|")) {
127
                Base_TextBox.Text = this.Text;
128
            }
129

    
130
            this.Text = Base_TextBox.Text;
131
            BoxWidth = e.NewSize.Width;
132
            BoxHeight = e.NewSize.Height;
133
            DrawingCloud();
134
        }
135

    
136
        void TextControl_GotFocus(object sender, RoutedEventArgs e)
137
        {
138
            if (EnableEditing)
139
            {
140
                EditingMode();
141
            }
142
            else
143
            {
144
                UnEditingMode();
145
            }
146
        }
147

    
148
        void TextControl_LostFocus(object sender, RoutedEventArgs e)
149
        {
150
            UnEditingMode();
151
            ApplyOverViewData();
152
        }
153

    
154
        //void TextControl_GotFocus(object sender, RoutedEventArgs e)
155
        //{
156
        //    Base_TextBox.Visibility = Visibility.Visible;
157
        //    Base_TextBlock.Visibility = Visibility.Collapsed;
158
        //    this.Base_TextBox.BorderThickness = new Thickness(1);
159
        //    if (UnderLine != null)
160
        //    {
161
        //        Base_TextBlock.TextDecorations = UnderLine;
162
        //    }
163
        //    if (this.Text != null)
164
        //    {
165
        //        Base_TextBox.Text = this.Text;
166
        //    }
167
        //    IsEditing = true;
168
        //}
169
        //void TextControl_LostFocus(object sender, RoutedEventArgs e)
170
        //{
171
        //    Base_TextBox.Visibility = Visibility.Collapsed;
172
        //    Base_TextBlock.Visibility = Visibility.Visible;
173
        //    this.Text = Base_TextBox.Text;
174
        //    if (UnderLine != null)
175
        //    {
176
        //        Base_TextBlock.TextDecorations = UnderLine;
177
        //    }
178
        //    Base_TextBlock.Margin =
179
        //       new Thickness(Base_TextBox.Margin.Left + 4, Base_TextBox.Margin.Top + 4, Base_TextBox.Margin.Right + 4, Base_TextBox.Margin.Bottom + 4);
180
        //    IsEditing = false;
181
        //}
182

    
183
        public void EditingMode()
184
        {
185
            //this.Base_TextBox.Focus();
186
            //System.Diagnostics.Debug.WriteLine(DateTime.Now.ToLongTimeString());
187
            TextBoxVisibility = Visibility.Visible;
188
            //Base_TextBox.Visibility = System.Windows.Visibility.Visible;
189

    
190
            TextBlockVisibility = Visibility.Collapsed;
191
            //Base_TextBlock.Visibility = System.Windows.Visibility.Collapsed;
192

    
193

    
194
            //this.Base_TextBox.BorderThickness = new Thickness(1);
195

    
196
            if (UnderLine != null)
197
                Base_TextBlock.TextDecorations = UnderLine;
198

    
199
            if (this.Text != null)
200
                Base_TextBox.Text = this.Text;
201

    
202
            //            Base_TextBox.Margin =
203
            //new Thickness(Base_TextBlock.Margin.Left + -2, Base_TextBlock.Margin.Top + 0,
204
            //Base_TextBlock.Margin.Right + 0, Base_TextBlock.Margin.Bottom + -2);
205
        }
206

    
207
        public void UnEditingMode()
208
        {
209
            if (EnableEditing)
210
                this.Text = Base_TextBox.Text;
211

    
212
            TextBoxVisibility = Visibility.Collapsed;
213
            //Base_TextBox.Visibility = System.Windows.Visibility.Collapsed;
214

    
215
            TextBlockVisibility = Visibility.Visible;
216
            //Base_TextBlock.Visibility = System.Windows.Visibility.Visible;
217

    
218
            if (UnderLine != null)
219
                Base_TextBlock.TextDecorations = UnderLine;
220

    
221
            //Base_TextBox.Focusable = false;
222

    
223
            //Base_TextBlock.Margin =
224
            //     new Thickness(Base_TextBox.Margin.Left + 4, Base_TextBox.Margin.Top + 4,
225
            //         Base_TextBox.Margin.Right + 4, Base_TextBox.Margin.Bottom + 4);
226

    
227
            //       Base_TextBlock.Margin =
228
            //new Thickness(Base_TextBox.Margin.Left + 2, Base_TextBox.Margin.Top + 2,
229
            //    Base_TextBox.Margin.Right + 2, Base_TextBox.Margin.Bottom + 2);
230

    
231
            //            Base_TextBlock.Margin =
232
            //new Thickness(Base_TextBox.Margin.Left + 5, Base_TextBox.Margin.Top + 0,
233
            //Base_TextBox.Margin.Right + 0, Base_TextBox.Margin.Bottom + 2);
234
        }
235

    
236
        public void SetText()
237
        {
238
            this.ApplyTemplate();
239
            if (IsHighLight)
240
            {
241
                this.BackInnerColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.6),
242
                    Colors.Yellow.R, Colors.Yellow.G, Colors.Yellow.B));
243
                this.BackColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.1),
244
                    Colors.Yellow.R, Colors.Yellow.G, Colors.Yellow.B));
245
            }
246
            else
247
            {
248
                this.BackInnerColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.6),
249
                    Colors.White.R, Colors.White.G, Colors.White.B));
250

    
251
                this.BackColor = new SolidColorBrush(Color.FromArgb(Convert.ToByte(255 * 0.1),
252
                    Colors.White.R, Colors.White.G, Colors.White.B));
253
            }
254
            if (Base_TextPath != null)
255
            {
256
                Base_TextPath.StrokeThickness = LineSize.Left;
257
            }
258
        }
259

    
260
        public void DrawingCloud()
261
        {
262
            this.ApplyTemplate();
263

    
264
            List<Point> pCloud = new List<Point>
265
            {
266
                new Point(0, 0),
267
                new Point(0, 0 + BoxHeight + 0),
268
                new Point(0 + BoxWidth + 2, 0 + BoxHeight + 0),
269
                new Point(0 + BoxWidth + 2 ,0),
270
            };
271

    
272
            if (Base_TextPath != null)
273
            {
274
                switch (ControlType_No)
275
                {
276
                    case 0:
277
                        {
278
                            PathData = new PathGeometry();
279
                            PathDataInner = (GenerateInner(pCloud));
280
                        }
281
                        break;
282
                    case 1:
283
                        {
284
                            PathData = (Generate_Rect(pCloud));
285
                            List<Point> pCloud2 = new List<Point>
286
                            {
287
                                new Point(0, 0),
288
                                new Point(0, 0 + BoxHeight + 0),
289
                                new Point(0 + BoxWidth + 10, 0 + BoxHeight + 0),
290
                                new Point(0 + BoxWidth + 10 ,0),
291
                            };
292
                            PathDataInner = (GenerateInner(pCloud));
293
                        }
294
                        break;
295
                    case 2:
296
                        {
297
                            PathData = (Generate(pCloud));
298
                            PathDataInner = (GenerateInner(pCloud));
299
                        }
300
                        break;
301
                }
302
            }
303

    
304
            //SetText();
305
        }
306
        #endregion Internal Method
307

    
308
        public void Dispose()
309
        {
310
            GC.Collect();
311
            GC.SuppressFinalize(this);
312
        }
313

    
314
        public override void UpdateControl()
315
        {
316
            if (this.PointSet.Count > 1)
317
            {
318
                this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
319
                this.EndPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
320
            }
321
        }
322

    
323
        #region Drawing Cloud Method
324
        public static PathGeometry Generate_Rect(List<Point> pData)
325
        {
326
            PathFigure pathFigure = new PathFigure();
327
            pathFigure.StartPoint = pData[0];
328

    
329
            PolyLineSegment polyline = new PolyLineSegment(pData, true);
330
            pathFigure.Segments.Add(polyline);
331

    
332
            PathGeometry rectPathGeometry = new PathGeometry();
333
            rectPathGeometry.Figures = new PathFigureCollection();
334
            pathFigure.IsClosed = true;
335
            pathFigure.IsFilled = false;
336
            rectPathGeometry.Figures.Add(pathFigure);
337

    
338

    
339
            return rectPathGeometry;
340
        }
341

    
342
        public static PathGeometry Generate(List<Point> pData)
343
        {
344
            var _pathGeometry = new PathGeometry();
345
            double area = MathSet.AreaOf(pData);
346
            bool reverse = (area > 0);
347
            int count = pData.Count;
348
            for (int i = 0; i < count; i++)
349
            {
350
                PathFigure pathFigure = GenerateLineWithCloud(pData[i % count], pData[(i + 1) % count], 20, reverse);
351
                pathFigure.IsClosed = false;
352
                pathFigure.IsFilled = true;
353
                _pathGeometry.Figures.Add(pathFigure);
354
            }
355

    
356
            return _pathGeometry;
357
        }
358

    
359

    
360
        public static PathGeometry GenerateInner(List<Point> pData)
361
        {
362
            var _pathGeometry = new PathGeometry();
363
            double area = MathSet.AreaOf(pData);
364
            bool reverse = (area > 0);
365
            int count = pData.Count;
366

    
367
            PathFigure pathFigur2 = new PathFigure();
368
            pathFigur2.StartPoint = pData[0];
369

    
370
            PolyLineSegment polyline = new PolyLineSegment(pData, true);
371
            pathFigur2.Segments.Add(polyline);
372

    
373
            pathFigur2.IsClosed = true;
374
            pathFigur2.IsFilled = true;
375
            _pathGeometry.Figures.Add(pathFigur2);
376

    
377
            return _pathGeometry;
378
        }
379

    
380
        public static PathFigure GenerateLineWithCloud(Point p1, Point p2, double _arcLength, bool reverse)
381
        {
382
            PathFigure pathFigure = new PathFigure();
383
            pathFigure.StartPoint = p1;
384

    
385
            double arcLength = _arcLength;
386
            double dx = p2.X - p1.X;
387
            double dy = p2.Y - p1.Y;
388
            double l = MathSet.DistanceTo(p1, p2);
389
            double theta = Math.Atan2(Math.Abs(dy), Math.Abs(dx)) * 180 / Math.PI;
390
            Point lastPt = new Point(p1.X, p1.Y);
391
            double count = l / _arcLength;
392

    
393
            dx /= l;
394
            dy /= l;
395

    
396
            Double j = 1;
397
            for (j = 1; j < (count - 1); j++)
398
            {
399
                ArcSegment arcSeg = new ArcSegment();
400
                arcSeg.Size = new Size(arcLength * TextControl._CloudArcDepth, arcLength * TextControl._CloudArcDepth);
401
                arcSeg.Point = new Point(p1.X + j * dx * arcLength, p1.Y + j * dy * arcLength);
402
                lastPt = arcSeg.Point;
403
                arcSeg.RotationAngle = theta + 90;
404
                if (true == reverse)
405
                    arcSeg.SweepDirection = SweepDirection.Clockwise;
406
                pathFigure.Segments.Add(arcSeg);
407
            }
408

    
409
            if ((count > j) || count > 0)
410
            {
411
                arcLength = MathSet.DistanceTo(lastPt, p2);
412
                ArcSegment arcSeg = new ArcSegment();
413
                arcSeg.Size = new Size(arcLength * TextControl._CloudArcDepth, arcLength * TextControl._CloudArcDepth);
414
                arcSeg.Point = new Point(p2.X, p2.Y);
415
                arcSeg.RotationAngle = theta;
416

    
417
                if (true == reverse)
418
                    arcSeg.SweepDirection = SweepDirection.Clockwise;
419

    
420
                pathFigure.Segments.Add(arcSeg);
421

    
422
            }
423
            return pathFigure;
424
        }
425
        #endregion
426

    
427
        #region Dependency Properties
428
        public static readonly DependencyProperty ControlTypeProperty =
429
        DependencyProperty.Register("ControlType", typeof(ControlType), typeof(TextControl), new FrameworkPropertyMetadata(ControlType.TextControl));
430

    
431
        public static readonly DependencyProperty ControlType_NoProperty =
432
        DependencyProperty.Register("ControlType_No", typeof(int), typeof(TextControl), new FrameworkPropertyMetadata(0));
433

    
434
        public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register(
435
            "IsSelected", typeof(bool), typeof(TextControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
436

    
437
        public static readonly DependencyProperty PathGeometryProperty = DependencyProperty.Register(
438
            "PathGeometry", typeof(PathGeometry), typeof(TextControl), new PropertyMetadata(null, SetPathGeometryChanged));
439

    
440
        public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
441
            "Text", typeof(string), typeof(TextControl), new PropertyMetadata(null));
442

    
443
        public static readonly DependencyProperty OverViewTextProperty = DependencyProperty.Register(
444
            "OverViewText", typeof(string), typeof(TextControl), new PropertyMetadata(null));
445

    
446
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
447
            "UserID", typeof(string), typeof(TextControl), new PropertyMetadata(null));
448

    
449
        /*public static readonly DependencyProperty FontColorProperty = DependencyProperty.Register(
450
            "FontColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));*/
451

    
452
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
453
            "StrokeColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
454

    
455
        //강인구 추가
456
        public static readonly DependencyProperty IsHighlightProperty = DependencyProperty.Register(
457
            "IsHighLight", typeof(bool), typeof(TextControl), new PropertyMetadata(false, PointValueChanged));
458

    
459
        public static readonly DependencyProperty BackColorProperty = DependencyProperty.Register(
460
            "BackColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.White)));
461

    
462
        public static readonly DependencyProperty BackInnerColorProperty = DependencyProperty.Register(
463
            "BackInnerColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.White)));
464

    
465
        public static readonly DependencyProperty UnderLineProperty = DependencyProperty.Register(
466
            "UnderLine", typeof(TextDecorationCollection), typeof(TextControl), new PropertyMetadata(null));
467

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

    
471
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
472
            "PointSet", typeof(List<Point>), typeof(TextControl), new PropertyMetadata(new List<Point>()));
473

    
474
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
475
            "PathData", typeof(Geometry), typeof(TextControl), null);
476

    
477

    
478

    
479
        public static readonly DependencyProperty PathDataInnerProperty = DependencyProperty.Register(
480
    "PathDataInner", typeof(Geometry), typeof(TextControl), null);
481

    
482
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
483
            "OverViewPathDataProperty", typeof(Geometry), typeof(TextControl), null);
484

    
485
        public static readonly DependencyProperty TextStyleProperty = DependencyProperty.Register(
486
            "TextStyle", typeof(FontStyle), typeof(TextControl), new PropertyMetadata(FontStyles.Normal));
487

    
488
        public static readonly DependencyProperty TextFamilyProperty = DependencyProperty.Register(
489
            "TextFamily", typeof(FontFamily), typeof(TextControl), new PropertyMetadata(new FontFamily("Arial")));
490

    
491
        public static readonly DependencyProperty TextWeightProperty = DependencyProperty.Register(
492
            "TextWeight", typeof(FontWeight), typeof(TextControl), new PropertyMetadata(FontWeights.Normal));
493

    
494
        public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register(
495
            "CenterX", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnCenterXYChanged));
496

    
497
        public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register(
498
            "CenterY", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnCenterXYChanged));
499

    
500
        public static readonly DependencyProperty CanvasXProperty = DependencyProperty.Register(
501
           "CanvasX", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
502

    
503
        public static readonly DependencyProperty CanvasYProperty = DependencyProperty.Register(
504
            "CanvasY", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
505

    
506
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
507
              "StartPoint", typeof(Point), typeof(TextControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
508

    
509
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
510
             "EndPoint", typeof(Point), typeof(TextControl), new PropertyMetadata(new Point(100, 100), PointValueChanged));
511

    
512
        public static readonly DependencyProperty TextSizeProperty = DependencyProperty.Register(
513
               "TextSize", typeof(Double), typeof(TextControl), new PropertyMetadata((Double)30, PointValueChanged));
514

    
515
        public static readonly DependencyProperty PaintProperty = DependencyProperty.Register(
516
                "Paint", typeof(PaintSet), typeof(TextControl), new PropertyMetadata((PaintSet.None), PointValueChanged));
517

    
518
        public static readonly DependencyProperty OverViewPaintProperty = DependencyProperty.Register(
519
                "OverViewPaint", typeof(PaintSet), typeof(TextControl), new PropertyMetadata((PaintSet.None), PointValueChanged));
520

    
521
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register(
522
            "Angle", typeof(double), typeof(TextControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
523

    
524
        public static readonly DependencyProperty EnableEditingProperty = DependencyProperty.Register(
525
           "EnableEditing", typeof(bool), typeof(TextControl), new PropertyMetadata((true), new PropertyChangedCallback(OnIsEditingChanged)));
526

    
527
        public static readonly DependencyProperty TextBoxVisibilityProperty = DependencyProperty.Register(
528
        "TextBoxVisibility", typeof(Visibility), typeof(TextControl), new PropertyMetadata((Visibility.Visible), OnTextBoxVisibilityChanged));
529

    
530
        public static readonly DependencyProperty TextBlockVisibilityProperty = DependencyProperty.Register(
531
        "TextBlockVisibility", typeof(Visibility), typeof(TextControl), new PropertyMetadata((Visibility.Collapsed), OnTextBlockVisibilityChanged));
532

    
533
        #endregion Dependency Properties
534

    
535
        #region dp Properties
536

    
537

    
538
        public override SolidColorBrush StrokeColor
539
        {
540
            get { return (SolidColorBrush)GetValue(StrokeColorProperty); }
541
            set
542
            {
543
                if (this.StrokeColor != value)
544
                {
545
                    SetValue(StrokeColorProperty, value);
546
                }
547
            }
548
        }
549

    
550

    
551

    
552
        public bool EnableEditing
553
        {
554
            get { return (bool)GetValue(EnableEditingProperty); }
555
            set
556
            {
557
                if (this.EnableEditing != value)
558
                {
559
                    SetValue(EnableEditingProperty, value);
560
                    OnPropertyChanged("EnableEditing");
561
                }
562
            }
563
        }
564

    
565
        public Thickness LineSize
566
        {
567
            get
568
            {
569
                return (Thickness)GetValue(LineSizeProperty);
570
            }
571
            set
572
            {
573
                if (this.LineSize != value)
574
                {
575
                    SetValue(LineSizeProperty, value);
576
                    OnPropertyChanged("LineSize");
577
                }
578
            }
579
        }
580

    
581
        public override ControlType ControlType
582
        {
583
            get
584
            {
585
                return (ControlType)GetValue(ControlTypeProperty);
586
            }
587
            set
588
            {
589
                SetValue(ControlTypeProperty, value);
590
            }
591
        }
592
        public int ControlType_No
593
        {
594
            get
595
            {
596
                return (int)GetValue(ControlType_NoProperty);
597
            }
598
            set
599
            {
600
                SetValue(ControlType_NoProperty, value);
601
            }
602
        }
603

    
604
        public string UserID
605
        {
606
            get { return (string)GetValue(UserIDProperty); }
607
            set
608
            {
609
                if (this.UserID != value)
610
                {
611
                    SetValue(UserIDProperty, value);
612
                    OnPropertyChanged("UserID");
613
                }
614
            }
615
        }
616

    
617
        public double CenterX
618
        {
619
            get { return (double)GetValue(CenterXProperty); }
620
            set
621
            {
622
                SetValue(CenterXProperty, value);
623
                OnPropertyChanged("CenterX");
624

    
625
            }
626
        }
627

    
628
        public double CenterY
629
        {
630
            get { return (double)GetValue(CenterYProperty); }
631
            set
632
            {
633
                SetValue(CenterYProperty, value);
634
                OnPropertyChanged("CenterY");
635
            }
636
        }
637

    
638
        public string Text
639
        {
640
            get { return (string)GetValue(TextProperty); }
641
            set
642
            {
643
                if (this.Text != value)
644
                {
645
                    SetValue(TextProperty, value);
646
                    OnPropertyChanged("Text");
647
                }
648
            }
649
        }
650

    
651
        public string OverViewText
652
        {
653
            get { return (string)GetValue(OverViewTextProperty); }
654
            set
655
            {
656
                if (this.OverViewText != value)
657
                {
658
                    SetValue(OverViewTextProperty, value);
659
                    OnPropertyChanged("OverViewText");
660
                }
661
            }
662
        }
663

    
664
        public Geometry OverViewPathData
665
        {
666
            get { return (Geometry)GetValue(OverViewPathDataProperty); }
667
            set
668
            {
669
                if (this.OverViewPathData != value)
670
                {
671
                    SetValue(OverViewPathDataProperty, value);
672
                    OnPropertyChanged("OverViewPathData");
673
                }
674
            }
675
        }
676

    
677
        public Visibility TextBoxVisibility
678
        {
679
            get { return (Visibility)GetValue(TextBoxVisibilityProperty); }
680
            set
681
            {
682
                if (this.TextBoxVisibility != value)
683
                {
684
                    SetValue(TextBoxVisibilityProperty, value);
685
                    OnPropertyChanged("TextBoxVisibility");
686
                }
687
            }
688
        }
689

    
690

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

    
704

    
705

    
706
        public Double TextSize
707
        {
708
            get { return (Double)GetValue(TextSizeProperty); }
709
            set
710
            {
711
                if (this.TextSize != value)
712
                {
713
                    SetValue(TextSizeProperty, value);
714
                    OnPropertyChanged("TextSize");
715
                }
716
            }
717
        }
718
        /*
719
        public SolidColorBrush FontColor
720
        {
721
            get { return (SolidColorBrush)GetValue(FontColorProperty); }
722
            set
723
            {
724
                if (this.FontColor != value)
725
                {
726
                    SetValue(FontColorProperty, value);
727
                    OnPropertyChanged("FontColor");
728
                }
729
            }
730
        }*/
731

    
732
        public SolidColorBrush BackColor
733
        {
734
            get { return (SolidColorBrush)GetValue(BackColorProperty); }
735
            set
736
            {
737
                if (this.BackColor != value)
738
                {
739
                    SetValue(BackColorProperty, value);
740
                    OnPropertyChanged("BackColor");
741
                }
742
            }
743
        }
744

    
745
        public SolidColorBrush BackInnerColor
746
        {
747
            get { return (SolidColorBrush)GetValue(BackInnerColorProperty); }
748
            set
749
            {
750
                if (this.BackInnerColor != value)
751
                {
752
                    SetValue(BackInnerColorProperty, value);
753
                    OnPropertyChanged("BackInnerColor");
754
                }
755
            }
756
        }
757

    
758

    
759

    
760
        public TextDecorationCollection UnderLine
761
        {
762
            get
763
            {
764
                return (TextDecorationCollection)GetValue(UnderLineProperty);
765
            }
766
            set
767
            {
768
                if (this.UnderLine != value)
769
                {
770
                    SetValue(UnderLineProperty, value);
771
                    OnPropertyChanged("UnderLine");
772
                }
773
            }
774
        }
775

    
776
        public double CanvasX
777
        {
778
            get { return (double)GetValue(CanvasXProperty); }
779
            set
780
            {
781
                if (this.CanvasX != value)
782
                {
783
                    SetValue(CanvasXProperty, value);
784
                    OnPropertyChanged("CanvasX");
785
                }
786
            }
787
        }
788

    
789
        public double CanvasY
790
        {
791
            get { return (double)GetValue(CanvasYProperty); }
792
            set
793
            {
794
                if (this.CanvasY != value)
795
                {
796
                    SetValue(CanvasYProperty, value);
797
                    OnPropertyChanged("CanvasY");
798
                }
799
            }
800
        }
801

    
802
        public Point EndPoint
803
        {
804
            get { return (Point)GetValue(EndPointProperty); }
805
            set
806
            {
807
                if (this.EndPoint != value)
808
                {
809
                    SetValue(EndPointProperty, value);
810
                    OnPropertyChanged("EndPoint");
811
                }
812
            }
813
        }
814

    
815
        public Point StartPoint
816
        {
817
            get { return (Point)GetValue(StartPointProperty); }
818
            set
819
            {
820
                if (this.StartPoint != value)
821
                {
822
                    SetValue(StartPointProperty, value);
823
                    OnPropertyChanged("StartPoint");
824
                }
825
            }
826
        }
827

    
828
        public FontStyle TextStyle
829
        {
830
            get { return (FontStyle)GetValue(TextStyleProperty); }
831
            set
832
            {
833
                if (this.TextStyle != value)
834
                {
835
                    SetValue(TextStyleProperty, value);
836
                    OnPropertyChanged("TextStyle");
837
                }
838
            }
839
        }
840

    
841
        public FontFamily TextFamily
842
        {
843
            get { return (FontFamily)GetValue(TextFamilyProperty); }
844
            set
845
            {
846
                if (this.TextFamily != value)
847
                {
848
                    SetValue(TextFamilyProperty, value);
849
                    OnPropertyChanged("TextFamily");
850
                }
851
            }
852
        }
853

    
854
        public FontWeight TextWeight
855
        {
856
            get { return (FontWeight)GetValue(TextWeightProperty); }
857
            set
858
            {
859
                if (this.TextWeight != value)
860
                {
861
                    SetValue(TextWeightProperty, value);
862
                    OnPropertyChanged("TextWeight");
863
                }
864
            }
865
        }
866

    
867
        public PaintSet Paint
868
        {
869
            get { return (PaintSet)GetValue(PaintProperty); }
870
            set
871
            {
872
                if (this.Paint != value)
873
                {
874
                    SetValue(PaintProperty, value);
875
                    OnPropertyChanged("Paint");
876
                }
877
            }
878
        }
879

    
880
        public PaintSet OverViewPaint
881
        {
882
            get { return (PaintSet)GetValue(OverViewPaintProperty); }
883
            set
884
            {
885
                if (this.OverViewPaint != value)
886
                {
887
                    SetValue(OverViewPaintProperty, value);
888
                    OnPropertyChanged("OverViewPaint");
889
                }
890
            }
891
        }
892

    
893
        double IPath.LineSize
894
        {
895
            get
896
            {
897
                return this.LineSize.Left;
898
            }
899
            set
900
            {
901
                this.LineSize = new Thickness(value);
902
                OnPropertyChanged("LineSize");
903
            }
904
        }
905

    
906

    
907
        public Geometry PathData
908
        {
909
            get { return (Geometry)GetValue(PathDataProperty); }
910
            set
911
            {
912
                SetValue(PathDataProperty, value);
913
                OnPropertyChanged("PathData");
914
            }
915
        }
916

    
917
        public Geometry PathDataInner
918
        {
919
            get { return (Geometry)GetValue(PathDataInnerProperty); }
920
            set
921
            {
922
                SetValue(PathDataInnerProperty, value);
923
                OnPropertyChanged("PathDataInner");
924
            }
925
        }
926

    
927
        public override double Angle
928
        {
929
            get { return (double)GetValue(AngleProperty); }
930
            set
931
            {
932
                if (this.Angle != value)
933
                {
934
                    SetValue(AngleProperty, value);
935

    
936
                    OnPropertyChanged("Angle");
937
                    UpdateLayout();
938
                }
939
            }
940
        }
941

    
942
        public bool IsHighLight
943
        {
944
            get { return (bool)GetValue(IsHighlightProperty); }
945
            set
946
            {
947
                if (this.IsHighLight != value)
948
                {
949
                    SetValue(IsHighlightProperty, value);
950
                    OnPropertyChanged("IsHighLight");
951
                }
952
            }
953
        }
954

    
955
        public List<Point> PointSet
956
        {
957
            get { return (List<Point>)GetValue(PointSetProperty); }
958
            set
959
            {
960
                SetValue(PointSetProperty, value);
961
                OnPropertyChanged("PointSet");
962
            }
963
        }
964

    
965
        #endregion Properties
966

    
967
        #region Properties
968

    
969

    
970

    
971
        public PathGeometry PathGeometry
972
        {
973
            get { return (PathGeometry)GetValue(PathGeometryProperty); }
974
            set
975
            {
976
                SetValue(PathGeometryProperty, value);
977
                OnPropertyChanged("PathGeometry");
978
            }
979
        }
980

    
981
        private double _BoxWidth;
982
        public double BoxWidth
983
        {
984
            get
985
            {
986
                return _BoxWidth;
987
            }
988
            set
989
            {
990
                _BoxWidth = value;
991
                OnPropertyChanged("BoxWidth");
992
            }
993
        }
994

    
995
        private double _BoxHeight;
996
        public double BoxHeight
997
        {
998
            get
999
            {
1000
                return _BoxHeight;
1001
            }
1002
            set
1003
            {
1004
                _BoxHeight = value;
1005
                OnPropertyChanged("BoxHeight");
1006
            }
1007
        }
1008

    
1009
        #endregion
1010

    
1011
        #region CallBack Method
1012
        public static void SetPathGeometryChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1013
        {
1014
            var instance = (TextControl)sender;
1015

    
1016
            if (e.OldValue != e.NewValue && instance.Base_TextPath != null)
1017
            {
1018
                instance.SetValue(e.Property, e.NewValue);
1019
            }
1020
        }
1021

    
1022

    
1023
        public static void OnTextBoxVisibilityChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1024
        {
1025
            var instance = (TextControl)sender;
1026

    
1027
            if (e.OldValue != e.NewValue && instance.Base_TextPath != null)
1028
            {
1029
                instance.SetValue(e.Property, e.NewValue);
1030
            }
1031
        }
1032

    
1033
        public static void OnTextBlockVisibilityChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1034
        {
1035
            var instance = (TextControl)sender;
1036

    
1037
            if (e.OldValue != e.NewValue && instance.Base_TextPath != null)
1038
            {
1039
                instance.SetValue(e.Property, e.NewValue);
1040
            }
1041
        }
1042

    
1043
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1044
        {
1045
            var instance = (TextControl)sender;
1046

    
1047
            if (e.OldValue != e.NewValue && instance.Base_Border != null)
1048
            {
1049
                instance.SetValue(e.Property, e.NewValue);
1050

    
1051
                if (instance.IsSelected)
1052
                {
1053
                    instance.StrokeColor = new SolidColorBrush(Colors.Blue);
1054
                    //instance.Base_Border.BorderBrush = new SolidColorBrush(Colors.Blue);
1055
                }
1056
                else
1057
                {
1058
                    instance.StrokeColor = new SolidColorBrush(Colors.Red);
1059
                    //instance.Base_Border.BorderBrush = new SolidColorBrush(Colors.Red);
1060
                    //instance.FontColor = new SolidColorBrush(Colors.Transparent);
1061
                    //instance.Base_Border.BorderBrush = new SolidColorBrush(Colors.Transparent);
1062
                }
1063

    
1064
            }
1065
        }
1066

    
1067
        public static void OnSetCansvasChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1068
        {
1069
            var instance = (TextControl)sender;
1070

    
1071
            if (e.OldValue != e.NewValue && instance != null)
1072
            {
1073
                instance.SetValue(e.Property, e.NewValue);
1074

    
1075
                Canvas.SetLeft(instance, instance.CanvasX);
1076
                Canvas.SetTop(instance, instance.CanvasY);
1077
            }
1078
        }
1079

    
1080
        public static void OnIsEditingChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1081
        {
1082
            var instance = (TextControl)sender;
1083

    
1084
            if (e.OldValue != e.NewValue && instance.Base_TextBlock != null)
1085
            {
1086
                instance.SetValue(e.Property, e.NewValue);
1087

    
1088
                //if (instance.EnableEditing)
1089
                //{
1090
                //    instance.EditingMode();
1091
                //}
1092
                //else
1093
                //{
1094
                //    instance.UnEditingMode();
1095
                //}
1096
            }
1097
        }
1098

    
1099
        public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1100
        {
1101
            var instance = (TextControl)sender;
1102

    
1103
            if (e.OldValue != e.NewValue && instance.Base_TextBlock != null)
1104
            {
1105
                instance.SetValue(e.Property, e.NewValue);
1106
                //instance.DrawingCloud();
1107
            }
1108
        }
1109

    
1110
        public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1111
        {
1112
            var instance = (TextControl)sender;
1113
            if (e.OldValue != e.NewValue && instance.Base_TextBlock != null)
1114
            {
1115
                instance.SetValue(e.Property, e.NewValue);
1116
                //instance.DrawingCloud();
1117
            }
1118
        }
1119

    
1120
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1121
        {
1122
            var instance = (TextControl)sender;
1123
            if (e.OldValue != e.NewValue && instance != null)
1124
            {
1125
                instance.SetValue(e.Property, e.NewValue);
1126
                //instance.DrawingCloud();
1127
            }
1128
        }
1129

    
1130
        #endregion CallBack Method
1131

    
1132
        protected void OnPropertyChanged(string propName)
1133
        {
1134
            if (PropertyChanged != null)
1135
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
1136
        }
1137

    
1138
        /// <summary>
1139
        /// return textcontrols' area
1140
        /// </summary>
1141
        public override Rect ItemRect
1142
        {
1143
            get
1144
            {
1145
                Point start = new Point(this.CanvasX, this.CanvasY);
1146

    
1147
                Point length = new Point();
1148
                double angle = this.Angle * Math.PI / 180;
1149

    
1150
                length.X = this.BoxWidth * Math.Cos(angle) - this.BoxHeight * Math.Sin(angle);
1151
                length.Y = this.BoxWidth * Math.Sin(angle) + this.BoxHeight * Math.Cos(angle);
1152

    
1153
                Point end = new Point(start.X + length.X, start.Y + length.Y);
1154
                return new Rect(start, end);
1155
            }
1156
        }
1157

    
1158
        /// <summary>
1159
        /// translate control along given dx,dy
1160
        /// </summary>
1161
        /// <param name="dx"></param>
1162
        /// <param name="dy"></param>
1163
        public override void OnTranslate(double dx, double dy)
1164
        {
1165
            //this.CanvasX = Canvas.GetLeft(this) + dx;
1166
            //this.CanvasY = Canvas.GetTop(this) + dy;
1167
            this.StartPoint = new Point(this.StartPoint.X + dx, this.StartPoint.Y + dy);
1168
            this.EndPoint = new Point(this.EndPoint.X + dx, this.EndPoint.Y + dy);
1169

    
1170
            this.SetValue(TextControl.CanvasXProperty, Canvas.GetLeft(this) + dx);
1171
            this.SetValue(TextControl.CanvasYProperty, Canvas.GetTop(this) + dy);
1172

    
1173

    
1174

    
1175

    
1176
            //Canvas.SetLeft(this, Canvas.GetLeft(this) + dx);
1177
            //Canvas.SetTop(this, Canvas.GetTop(this) + dy);
1178
        }
1179

    
1180
        /// <summary>
1181
        /// Serialize this
1182
        /// </summary>
1183
        /// <param name="sUserId"></param>
1184
        /// <returns></returns>
1185
        public override string Serialize()
1186
        {
1187
            using (S_TextControl STemp = new S_TextControl())
1188
            {
1189
                STemp.TransformPoint = "0|0";
1190
                STemp.SizeSet = String.Format("{0}|{1}", this.LineSize.Left.ToString(), this.TextSize.ToString());
1191
                STemp.Text = this.Text;
1192
                STemp.UserID = this.UserID;
1193
                STemp.FontColor = this.StrokeColor.Color.ToString();
1194
                //STemp.FontColor = "#FFFFFF00";
1195

    
1196
                if (this.StartPoint == new Point())
1197
                    STemp.StartPoint = new Point(this.CanvasX, this.CanvasY);
1198
                else
1199
                    STemp.StartPoint = this.StartPoint;
1200

    
1201
                STemp.EndPoint = this.EndPoint;
1202
                STemp.Opac = this.Opacity;
1203
                STemp.PointSet = this.PointSet;
1204
                STemp.Angle = this.Angle;
1205
                STemp.paintMethod = this.ControlType_No;
1206
                STemp.BoxW = this.BoxWidth;
1207
                STemp.BoxH = this.BoxHeight;
1208
                STemp.isHighLight = this.IsHighLight;
1209
                STemp.Name = this.GetType().Name.ToString();
1210
                STemp.fontConfig = new List<string>()
1211
                            {
1212
                                this.TextFamily.ToString(),
1213
                                this.TextStyle.ToString(),
1214
                                this.TextWeight.ToString(),
1215
                            };
1216

    
1217

    
1218

    
1219
                if (this.UnderLine != null)
1220
                {
1221
                    STemp.fontConfig.Add("true");
1222
                }
1223

    
1224
                ///강인구 추가(2017.11.02)
1225
                ///Memo 추가
1226
                STemp.Memo = this.Memo;
1227

    
1228
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
1229
            }
1230
        }
1231

    
1232
        /// <summary>
1233
        /// create a textcontrol from given string
1234
        /// </summary>
1235
        /// <param name="str"></param>
1236
        /// <returns></returns>
1237
        public static TextControl FromString(string str, SolidColorBrush brush, string sProjectNo)
1238
        {
1239
            using (S_TextControl s = JsonSerializerHelper.JsonDeserialize<S_TextControl>(str))
1240
            {
1241
                string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1242
                TextControl instance = new TextControl()
1243
                {
1244
                    Text = s.Text,
1245
                    StartPoint = s.StartPoint,
1246
                    EndPoint = s.EndPoint,
1247
                    CanvasX = s.StartPoint.X,
1248
                    CanvasY = s.StartPoint.Y,
1249
                    BoxWidth = s.BoxW,
1250
                    BoxHeight = s.BoxH,
1251
                    ControlType_No = s.paintMethod,
1252
                    LineSize = new Thickness(Convert.ToDouble(data2.First())),
1253
                    TextSize = Convert.ToDouble(data2[1]),
1254
                    StrokeColor = brush,
1255
                    FontSize = 10,
1256
                    UserID = s.UserID,
1257
                    IsHighLight = s.isHighLight,
1258
                    Angle = s.Angle,
1259
                    PointSet = s.PointSet,
1260
                    Opacity = s.Opac,
1261
                    TextFamily = new FontFamily(s.fontConfig[0]),
1262
                    //인구 추가(2018.04.17)
1263
                    TextStyle = StringToFont.ConFontStyle(s.fontConfig[1]),
1264
                    TextWeight = StringToFont.ConFontWeight(s.fontConfig[2]),
1265
                };
1266

    
1267
                if (s.fontConfig.Count() == 4)
1268
                {
1269
                    instance.UnderLine = TextDecorations.Underline;
1270
                }
1271

    
1272
                return instance;
1273
            }
1274
        }
1275
    }
1276
}
클립보드 이미지 추가 (최대 크기: 500 MB)