프로젝트

일반

사용자정보

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

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

이력 | 보기 | 이력해설 | 다운로드 (44.1 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
            Base_TextBox.Text = this.Text;
95
            this.Base_TextBox.TextChanged += Base_TextBox_TextChanged;
96
            
97
            DrawingCloud();
98
            SetText();
99
        }
100

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

    
110
            DrawingCloud();
111
        }
112

    
113
        public override void ApplyOverViewData()
114
        {
115
            this.OverViewPathData = this.PathData;
116
            this.OverViewText = this.Text;
117
            this.OverViewPaint = this.Paint;
118

    
119
        }
120

    
121
        void Base_TextBlock_SizeChanged(object sender, SizeChangedEventArgs e)
122
        {
123
            BoxWidth = e.NewSize.Width;
124
            BoxHeight = e.NewSize.Height;
125
            DrawingCloud();
126
        }
127

    
128
        void Base_TextBox_SizeChanged(object sender, SizeChangedEventArgs e)
129
        {
130
            if (Base_TextBox.Text.Contains("|OR||DZ|")) {
131
                Base_TextBox.Text = this.Text;
132
            }
133

    
134
            this.Text = Base_TextBox.Text;
135
            BoxWidth = e.NewSize.Width;
136
            BoxHeight = e.NewSize.Height;
137
            DrawingCloud();
138
        }
139

    
140
        void TextControl_GotFocus(object sender, RoutedEventArgs e)
141
        {
142
            if (EnableEditing)
143
            {
144
                EditingMode();
145
            }
146
            else
147
            {
148
                UnEditingMode();
149
            }
150
        }
151

    
152
        void TextControl_LostFocus(object sender, RoutedEventArgs e)
153
        {
154
            UnEditingMode();
155
            ApplyOverViewData();
156
        }
157

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

    
187
        public void EditingMode()
188
        {
189
            //this.Base_TextBox.Focus();
190
            //System.Diagnostics.Debug.WriteLine(DateTime.Now.ToLongTimeString());
191
            TextBoxVisibility = Visibility.Visible;
192
            //Base_TextBox.Visibility = System.Windows.Visibility.Visible;
193

    
194
            TextBlockVisibility = Visibility.Collapsed;
195
            //Base_TextBlock.Visibility = System.Windows.Visibility.Collapsed;
196

    
197

    
198
            //this.Base_TextBox.BorderThickness = new Thickness(1);
199

    
200
            if (UnderLine != null)
201
                Base_TextBlock.TextDecorations = UnderLine;
202

    
203
            if (this.Text != null)
204
                Base_TextBox.Text = this.Text;
205

    
206
            //            Base_TextBox.Margin =
207
            //new Thickness(Base_TextBlock.Margin.Left + -2, Base_TextBlock.Margin.Top + 0,
208
            //Base_TextBlock.Margin.Right + 0, Base_TextBlock.Margin.Bottom + -2);
209
        }
210

    
211
        public void UnEditingMode()
212
        {
213
            if (EnableEditing)
214
                this.Text = Base_TextBox.Text;
215

    
216
            TextBoxVisibility = Visibility.Collapsed;
217
            //Base_TextBox.Visibility = System.Windows.Visibility.Collapsed;
218

    
219
            TextBlockVisibility = Visibility.Visible;
220
            //Base_TextBlock.Visibility = System.Windows.Visibility.Visible;
221

    
222
            if (UnderLine != null)
223
                Base_TextBlock.TextDecorations = UnderLine;
224

    
225
            //Base_TextBox.Focusable = false;
226

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

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

    
235
            //            Base_TextBlock.Margin =
236
            //new Thickness(Base_TextBox.Margin.Left + 5, Base_TextBox.Margin.Top + 0,
237
            //Base_TextBox.Margin.Right + 0, Base_TextBox.Margin.Bottom + 2);
238
        }
239

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

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

    
264
        public void DrawingCloud()
265
        {
266
            this.ApplyTemplate();
267

    
268
            List<Point> pCloud = new List<Point>
269
            {
270
                new Point(0, 0),
271
                new Point(0, 0 + BoxHeight + 0),
272
                new Point(0 + BoxWidth + 2, 0 + BoxHeight + 0),
273
                new Point(0 + BoxWidth + 2 ,0),
274
            };
275

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

    
308
            //SetText();
309
        }
310
        #endregion Internal Method
311

    
312
        public void Dispose()
313
        {
314
            GC.Collect();
315
            GC.SuppressFinalize(this);
316
        }
317

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

    
327
        #region Drawing Cloud Method
328
        public static PathGeometry Generate_Rect(List<Point> pData)
329
        {
330
            PathFigure pathFigure = new PathFigure();
331
            pathFigure.StartPoint = pData[0];
332

    
333
            PolyLineSegment polyline = new PolyLineSegment(pData, true);
334
            pathFigure.Segments.Add(polyline);
335

    
336
            PathGeometry rectPathGeometry = new PathGeometry();
337
            rectPathGeometry.Figures = new PathFigureCollection();
338
            pathFigure.IsClosed = true;
339
            pathFigure.IsFilled = false;
340
            rectPathGeometry.Figures.Add(pathFigure);
341

    
342

    
343
            return rectPathGeometry;
344
        }
345

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

    
360
            return _pathGeometry;
361
        }
362

    
363

    
364
        public static PathGeometry GenerateInner(List<Point> pData)
365
        {
366
            var _pathGeometry = new PathGeometry();
367
            double area = MathSet.AreaOf(pData);
368
            bool reverse = (area > 0);
369
            int count = pData.Count;
370

    
371
            PathFigure pathFigur2 = new PathFigure();
372
            pathFigur2.StartPoint = pData[0];
373

    
374
            PolyLineSegment polyline = new PolyLineSegment(pData, true);
375
            pathFigur2.Segments.Add(polyline);
376

    
377
            pathFigur2.IsClosed = true;
378
            pathFigur2.IsFilled = true;
379
            _pathGeometry.Figures.Add(pathFigur2);
380

    
381
            return _pathGeometry;
382
        }
383

    
384
        public static PathFigure GenerateLineWithCloud(Point p1, Point p2, double _arcLength, bool reverse)
385
        {
386
            PathFigure pathFigure = new PathFigure();
387
            pathFigure.StartPoint = p1;
388

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

    
397
            dx /= l;
398
            dy /= l;
399

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

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

    
421
                if (true == reverse)
422
                    arcSeg.SweepDirection = SweepDirection.Clockwise;
423

    
424
                pathFigure.Segments.Add(arcSeg);
425

    
426
            }
427
            return pathFigure;
428
        }
429
        #endregion
430

    
431
        #region Dependency Properties
432
        public static readonly DependencyProperty ControlTypeProperty =
433
        DependencyProperty.Register("ControlType", typeof(ControlType), typeof(TextControl), new FrameworkPropertyMetadata(ControlType.TextControl));
434

    
435
        public static readonly DependencyProperty ControlType_NoProperty =
436
        DependencyProperty.Register("ControlType_No", typeof(int), typeof(TextControl), new FrameworkPropertyMetadata(0));
437

    
438
        public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register(
439
            "IsSelected", typeof(bool), typeof(TextControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
440

    
441
        public static readonly DependencyProperty PathGeometryProperty = DependencyProperty.Register(
442
            "PathGeometry", typeof(PathGeometry), typeof(TextControl), new PropertyMetadata(null, SetPathGeometryChanged));
443

    
444
        public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
445
            "Text", typeof(string), typeof(TextControl), new PropertyMetadata(null));
446

    
447
        public static readonly DependencyProperty OverViewTextProperty = DependencyProperty.Register(
448
            "OverViewText", typeof(string), typeof(TextControl), new PropertyMetadata(null));
449

    
450
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
451
            "UserID", typeof(string), typeof(TextControl), new PropertyMetadata(null));
452

    
453
        /*public static readonly DependencyProperty FontColorProperty = DependencyProperty.Register(
454
            "FontColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));*/
455

    
456
        public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register(
457
            "StrokeColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.Red)));
458

    
459
        //강인구 추가
460
        public static readonly DependencyProperty IsHighlightProperty = DependencyProperty.Register(
461
            "IsHighLight", typeof(bool), typeof(TextControl), new PropertyMetadata(false, PointValueChanged));
462

    
463
        public static readonly DependencyProperty BackColorProperty = DependencyProperty.Register(
464
            "BackColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.White)));
465

    
466
        public static readonly DependencyProperty BackInnerColorProperty = DependencyProperty.Register(
467
            "BackInnerColor", typeof(SolidColorBrush), typeof(TextControl), new PropertyMetadata(new SolidColorBrush(Colors.White)));
468

    
469
        public static readonly DependencyProperty UnderLineProperty = DependencyProperty.Register(
470
            "UnderLine", typeof(TextDecorationCollection), typeof(TextControl), new PropertyMetadata(null));
471

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

    
475
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
476
            "PointSet", typeof(List<Point>), typeof(TextControl), new PropertyMetadata(new List<Point>()));
477

    
478
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
479
            "PathData", typeof(Geometry), typeof(TextControl), null);
480

    
481

    
482

    
483
        public static readonly DependencyProperty PathDataInnerProperty = DependencyProperty.Register(
484
    "PathDataInner", typeof(Geometry), typeof(TextControl), null);
485

    
486
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
487
            "OverViewPathDataProperty", typeof(Geometry), typeof(TextControl), null);
488

    
489
        public static readonly DependencyProperty TextStyleProperty = DependencyProperty.Register(
490
            "TextStyle", typeof(FontStyle), typeof(TextControl), new PropertyMetadata(FontStyles.Normal));
491

    
492
        public static readonly DependencyProperty TextFamilyProperty = DependencyProperty.Register(
493
            "TextFamily", typeof(FontFamily), typeof(TextControl), new PropertyMetadata(new FontFamily("Arial")));
494

    
495
        public static readonly DependencyProperty TextWeightProperty = DependencyProperty.Register(
496
            "TextWeight", typeof(FontWeight), typeof(TextControl), new PropertyMetadata(FontWeights.Normal));
497

    
498
        public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register(
499
            "CenterX", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnCenterXYChanged));
500

    
501
        public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register(
502
            "CenterY", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnCenterXYChanged));
503

    
504
        public static readonly DependencyProperty CanvasXProperty = DependencyProperty.Register(
505
           "CanvasX", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
506

    
507
        public static readonly DependencyProperty CanvasYProperty = DependencyProperty.Register(
508
            "CanvasY", typeof(double), typeof(TextControl), new PropertyMetadata((double)0, OnSetCansvasChanged));
509

    
510
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
511
              "StartPoint", typeof(Point), typeof(TextControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
512

    
513
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
514
             "EndPoint", typeof(Point), typeof(TextControl), new PropertyMetadata(new Point(100, 100), PointValueChanged));
515

    
516
        public static readonly DependencyProperty TextSizeProperty = DependencyProperty.Register(
517
               "TextSize", typeof(Double), typeof(TextControl), new PropertyMetadata((Double)30, PointValueChanged));
518

    
519
        public static readonly DependencyProperty PaintProperty = DependencyProperty.Register(
520
                "Paint", typeof(PaintSet), typeof(TextControl), new PropertyMetadata((PaintSet.None), PointValueChanged));
521

    
522
        public static readonly DependencyProperty OverViewPaintProperty = DependencyProperty.Register(
523
                "OverViewPaint", typeof(PaintSet), typeof(TextControl), new PropertyMetadata((PaintSet.None), PointValueChanged));
524

    
525
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register(
526
            "Angle", typeof(double), typeof(TextControl), new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
527

    
528
        public static readonly DependencyProperty EnableEditingProperty = DependencyProperty.Register(
529
           "EnableEditing", typeof(bool), typeof(TextControl), new PropertyMetadata((true), new PropertyChangedCallback(OnIsEditingChanged)));
530

    
531
        public static readonly DependencyProperty TextBoxVisibilityProperty = DependencyProperty.Register(
532
        "TextBoxVisibility", typeof(Visibility), typeof(TextControl), new PropertyMetadata((Visibility.Visible), OnTextBoxVisibilityChanged));
533

    
534
        public static readonly DependencyProperty TextBlockVisibilityProperty = DependencyProperty.Register(
535
        "TextBlockVisibility", typeof(Visibility), typeof(TextControl), new PropertyMetadata((Visibility.Collapsed), OnTextBlockVisibilityChanged));
536

    
537
        #endregion Dependency Properties
538

    
539
        #region dp Properties
540

    
541

    
542
        public override SolidColorBrush StrokeColor
543
        {
544
            get { return (SolidColorBrush)GetValue(StrokeColorProperty); }
545
            set
546
            {
547
                if (this.StrokeColor != value)
548
                {
549
                    SetValue(StrokeColorProperty, value);
550
                }
551
            }
552
        }
553

    
554

    
555

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

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

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

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

    
621
        public double CenterX
622
        {
623
            get { return (double)GetValue(CenterXProperty); }
624
            set
625
            {
626
                SetValue(CenterXProperty, value);
627
                OnPropertyChanged("CenterX");
628

    
629
            }
630
        }
631

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

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

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

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

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

    
694

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

    
708

    
709

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

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

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

    
762

    
763

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

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

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

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

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

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

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

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

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

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

    
897
        double IPath.LineSize
898
        {
899
            get
900
            {
901
                return this.LineSize.Left;
902
            }
903
            set
904
            {
905
                this.LineSize = new Thickness(value);
906
                OnPropertyChanged("LineSize");
907
            }
908
        }
909

    
910

    
911
        public Geometry PathData
912
        {
913
            get { return (Geometry)GetValue(PathDataProperty); }
914
            set
915
            {
916
                SetValue(PathDataProperty, value);
917
                OnPropertyChanged("PathData");
918
            }
919
        }
920

    
921
        public Geometry PathDataInner
922
        {
923
            get { return (Geometry)GetValue(PathDataInnerProperty); }
924
            set
925
            {
926
                SetValue(PathDataInnerProperty, value);
927
                OnPropertyChanged("PathDataInner");
928
            }
929
        }
930

    
931
        public override double Angle
932
        {
933
            get { return (double)GetValue(AngleProperty); }
934
            set
935
            {
936
                if (this.Angle != value)
937
                {
938
                    SetValue(AngleProperty, value);
939

    
940
                    OnPropertyChanged("Angle");
941
                    UpdateLayout();
942
                }
943
            }
944
        }
945

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

    
959
        public List<Point> PointSet
960
        {
961
            get { return (List<Point>)GetValue(PointSetProperty); }
962
            set
963
            {
964
                SetValue(PointSetProperty, value);
965
                OnPropertyChanged("PointSet");
966
            }
967
        }
968

    
969
        #endregion Properties
970

    
971
        #region Properties
972

    
973

    
974

    
975
        public PathGeometry PathGeometry
976
        {
977
            get { return (PathGeometry)GetValue(PathGeometryProperty); }
978
            set
979
            {
980
                SetValue(PathGeometryProperty, value);
981
                OnPropertyChanged("PathGeometry");
982
            }
983
        }
984

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

    
999
        private double _BoxHeight;
1000
        public double BoxHeight
1001
        {
1002
            get
1003
            {
1004
                return _BoxHeight;
1005
            }
1006
            set
1007
            {
1008
                _BoxHeight = value;
1009
                OnPropertyChanged("BoxHeight");
1010
            }
1011
        }
1012

    
1013
        #endregion
1014

    
1015
        #region CallBack Method
1016
        public static void SetPathGeometryChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1017
        {
1018
            var instance = (TextControl)sender;
1019

    
1020
            if (e.OldValue != e.NewValue && instance.Base_TextPath != null)
1021
            {
1022
                instance.SetValue(e.Property, e.NewValue);
1023
            }
1024
        }
1025

    
1026

    
1027
        public static void OnTextBoxVisibilityChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1028
        {
1029
            var instance = (TextControl)sender;
1030

    
1031
            if (e.OldValue != e.NewValue && instance.Base_TextPath != null)
1032
            {
1033
                instance.SetValue(e.Property, e.NewValue);
1034
            }
1035
        }
1036

    
1037
        public static void OnTextBlockVisibilityChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1038
        {
1039
            var instance = (TextControl)sender;
1040

    
1041
            if (e.OldValue != e.NewValue && instance.Base_TextPath != null)
1042
            {
1043
                instance.SetValue(e.Property, e.NewValue);
1044
            }
1045
        }
1046

    
1047
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1048
        {
1049
            var instance = (TextControl)sender;
1050

    
1051
            if (e.OldValue != e.NewValue && instance.Base_Border != null)
1052
            {
1053
                instance.SetValue(e.Property, e.NewValue);
1054

    
1055
                if (instance.IsSelected)
1056
                {
1057
                    instance.StrokeColor = new SolidColorBrush(Colors.Blue);
1058
                    //instance.Base_Border.BorderBrush = new SolidColorBrush(Colors.Blue);
1059
                }
1060
                else
1061
                {
1062
                    instance.StrokeColor = new SolidColorBrush(Colors.Red);
1063
                    //instance.Base_Border.BorderBrush = new SolidColorBrush(Colors.Red);
1064
                    //instance.FontColor = new SolidColorBrush(Colors.Transparent);
1065
                    //instance.Base_Border.BorderBrush = new SolidColorBrush(Colors.Transparent);
1066
                }
1067

    
1068
            }
1069
        }
1070

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

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

    
1079
                Canvas.SetLeft(instance, instance.CanvasX);
1080
                Canvas.SetTop(instance, instance.CanvasY);
1081
            }
1082
        }
1083

    
1084
        public static void OnIsEditingChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1085
        {
1086
            var instance = (TextControl)sender;
1087

    
1088
            if (e.OldValue != e.NewValue && instance.Base_TextBlock != null)
1089
            {
1090
                instance.SetValue(e.Property, e.NewValue);
1091

    
1092
                //if (instance.EnableEditing)
1093
                //{
1094
                //    instance.EditingMode();
1095
                //}
1096
                //else
1097
                //{
1098
                //    instance.UnEditingMode();
1099
                //}
1100
            }
1101
        }
1102

    
1103
        public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1104
        {
1105
            var instance = (TextControl)sender;
1106

    
1107
            if (e.OldValue != e.NewValue && instance.Base_TextBlock != null)
1108
            {
1109
                instance.SetValue(e.Property, e.NewValue);
1110
                //instance.DrawingCloud();
1111
            }
1112
        }
1113

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

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

    
1134
        #endregion CallBack Method
1135

    
1136
        protected void OnPropertyChanged(string propName)
1137
        {
1138
            if (PropertyChanged != null)
1139
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
1140
        }
1141

    
1142
        /// <summary>
1143
        /// return textcontrols' area
1144
        /// </summary>
1145
        public override Rect ItemRect
1146
        {
1147
            get
1148
            {
1149
                Point start = new Point(this.CanvasX, this.CanvasY);
1150

    
1151
                Point length = new Point();
1152
                double angle = this.Angle * Math.PI / 180;
1153

    
1154
                length.X = this.BoxWidth * Math.Cos(angle) - this.BoxHeight * Math.Sin(angle);
1155
                length.Y = this.BoxWidth * Math.Sin(angle) + this.BoxHeight * Math.Cos(angle);
1156

    
1157
                Point end = new Point(start.X + length.X, start.Y + length.Y);
1158
                return new Rect(start, end);
1159
            }
1160
        }
1161

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

    
1174
            this.SetValue(TextControl.CanvasXProperty, Canvas.GetLeft(this) + dx);
1175
            this.SetValue(TextControl.CanvasYProperty, Canvas.GetTop(this) + dy);
1176

    
1177

    
1178

    
1179

    
1180
            //Canvas.SetLeft(this, Canvas.GetLeft(this) + dx);
1181
            //Canvas.SetTop(this, Canvas.GetTop(this) + dy);
1182
        }
1183

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

    
1200
                if (this.StartPoint == new Point())
1201
                    STemp.StartPoint = new Point(this.CanvasX, this.CanvasY);
1202
                else
1203
                    STemp.StartPoint = this.StartPoint;
1204

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

    
1221

    
1222

    
1223
                if (this.UnderLine != null)
1224
                {
1225
                    STemp.fontConfig.Add("true");
1226
                }
1227

    
1228
                ///강인구 추가(2017.11.02)
1229
                ///Memo 추가
1230
                STemp.Memo = this.Memo;
1231

    
1232
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
1233
            }
1234
        }
1235

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

    
1271
                if (s.fontConfig.Count() == 4)
1272
                {
1273
                    instance.UnderLine = TextDecorations.Underline;
1274
                }
1275

    
1276
                return instance;
1277
            }
1278
        }
1279
    }
1280
}
클립보드 이미지 추가 (최대 크기: 500 MB)