프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Text / TextControl.cs @ 661b7416

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

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