프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Text / TextControl.cs @ 0d00f9c8

이력 | 보기 | 이력해설 | 다운로드 (43.9 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 0d00f9c8 humkyung
        private const string PART_Canvas = "PART_TextControlCanvas";
33 787a4489 KangIngu
        //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 0d00f9c8 humkyung
        public Canvas Base_Canvas = null;
39 787a4489 KangIngu
        //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 53393bae KangIngu
        private const double _CloudArcDepth = 0.8;  /// 2018.05.14 added by humkyung
48 5a9353a9 humkyung
49 959b3ef2 humkyung
        public override bool IsSelected
50 787a4489 KangIngu
        {
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 6b5d33c6 djkim
            this.DefaultStyleKey = typeof(TextControl);           
67 787a4489 KangIngu
        }
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 6b5d33c6 djkim
            
76 787a4489 KangIngu
        }
77 6b5d33c6 djkim
        
78
        
79 787a4489 KangIngu
        public override void OnApplyTemplate()
80
        {
81 6b5d33c6 djkim
            base.OnApplyTemplate();            
82 787a4489 KangIngu
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 0d00f9c8 humkyung
            Base_Canvas = GetTemplateChild(PART_Canvas) as Canvas;
89
            
90 787a4489 KangIngu
            this.Base_TextBox.SizeChanged += new SizeChangedEventHandler(Base_TextBox_SizeChanged);
91 6b5d33c6 djkim
            this.Base_TextBlock.SizeChanged += new SizeChangedEventHandler(Base_TextBlock_SizeChanged);
92
            this.Base_TextBox.GotFocus += new RoutedEventHandler(TextControl_GotFocus);
93 819630e9 송근호
            this.Base_TextBox.LostFocus += new RoutedEventHandler(TextControl_LostFocus);
94
           
95 6b5d33c6 djkim
            DrawingCloud();
96 787a4489 KangIngu
            SetText();
97
        }
98
99 f513c215 humkyung
        public override void ApplyOverViewData()
100 787a4489 KangIngu
        {
101
            this.OverViewPathData = this.PathData;
102
            this.OverViewText = this.Text;
103
            this.OverViewPaint = this.Paint;
104
105
        }
106
107
        void Base_TextBlock_SizeChanged(object sender, SizeChangedEventArgs e)
108
        {
109 90e7968d ljiyeon
            
110
111 787a4489 KangIngu
            this.Text = Base_TextBox.Text;
112
113
            BoxWidth = e.NewSize.Width;
114
            BoxHeight = e.NewSize.Height;
115
116
            this.ApplyTemplate();
117
118
            DrawingCloud();
119
        }
120
121
        //void TextControl_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
122
        //{
123
        //    this.Focus();
124
        //}
125
126
        void Base_TextBox_SizeChanged(object sender, SizeChangedEventArgs e)
127
        {
128 b0fb3ad7 ljiyeon
            if (Base_TextBox.Text.Contains("|OR||DZ|"))
129
            {
130
                Base_TextBox.Text = this.Text;
131
            }
132
133 787a4489 KangIngu
            this.Text = Base_TextBox.Text;
134
            BoxWidth = e.NewSize.Width;
135
            BoxHeight = e.NewSize.Height;
136
            this.ApplyTemplate();
137 90e7968d ljiyeon
            DrawingCloud();
138 787a4489 KangIngu
        }
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 6b5d33c6 djkim
            //this.Base_TextBox.Focus();
190 2aac9b2b djkim
            //System.Diagnostics.Debug.WriteLine(DateTime.Now.ToLongTimeString());
191 787a4489 KangIngu
            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 6b5d33c6 djkim
            
268 787a4489 KangIngu
            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 6b5d33c6 djkim
            //SetText();
309 787a4489 KangIngu
        }
310
        #endregion Internal Method
311
312
        public void Dispose()
313
        {
314
            GC.Collect();
315
            GC.SuppressFinalize(this);
316
        }
317 0d00f9c8 humkyung
318
        public override void UpdateControl()
319 787a4489 KangIngu
        {
320 0d00f9c8 humkyung
            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 787a4489 KangIngu
        }
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 10df01b4 humkyung
            PolyLineSegment polyline = new PolyLineSegment(pData, true);
334
            pathFigure.Segments.Add(polyline);
335 787a4489 KangIngu
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 10df01b4 humkyung
            for (int i = 0; i < count; i++)
353 787a4489 KangIngu
            {
354 10df01b4 humkyung
                PathFigure pathFigure = GenerateLineWithCloud(pData[i%count], pData[(i + 1)%count], 20, reverse);
355 787a4489 KangIngu
                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 10df01b4 humkyung
            PolyLineSegment polyline = new PolyLineSegment(pData, true);
375
            pathFigur2.Segments.Add(polyline);
376 787a4489 KangIngu
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 5a9353a9 humkyung
                arcSeg.Size = new Size(arcLength * TextControl._CloudArcDepth, arcLength * TextControl._CloudArcDepth);
405 787a4489 KangIngu
                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 5a9353a9 humkyung
                arcSeg.Size = new Size(arcLength * TextControl._CloudArcDepth, arcLength * TextControl._CloudArcDepth);
418 787a4489 KangIngu
                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 05009a0e ljiyeon
        /*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 787a4489 KangIngu
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 f8769f8a ljiyeon
            "LineSize", typeof(Thickness), typeof(TextControl), new PropertyMetadata(new Thickness(4), PointValueChanged)); //여기만 4인지 모르겠지만 4 그대로 두겠음
474 787a4489 KangIngu
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 05009a0e ljiyeon
482
483 787a4489 KangIngu
        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 71d7e0bf 송근호
           "EnableEditing", typeof(bool), typeof(TextControl), new PropertyMetadata((true), new PropertyChangedCallback(OnIsEditingChanged)));
530 787a4489 KangIngu
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 05009a0e ljiyeon
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 71d7e0bf 송근호
      
555 787a4489 KangIngu
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 5529d2a2 humkyung
        public override ControlType ControlType
586 787a4489 KangIngu
        {
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 { SetValue(CenterXProperty, value);
625
            OnPropertyChanged("CenterX");
626
            
627
            }
628
        }
629
630
        public double CenterY
631
        {
632
            get { return (double)GetValue(CenterYProperty); }
633
            set { SetValue(CenterYProperty, value);
634
            OnPropertyChanged("CenterY");
635
            }
636
        }
637
638
        public string Text
639
        {
640
            get { return (string)GetValue(TextProperty); }
641
            set
642
            {
643
                if (this.Text != value)
644
                {
645
                    SetValue(TextProperty, value);
646
                    OnPropertyChanged("Text");
647
                }
648
            }
649
        }
650
651
        public string OverViewText
652
        {
653
            get { return (string)GetValue(OverViewTextProperty); }
654
            set
655
            {
656
                if (this.OverViewText != value)
657
                {
658
                    SetValue(OverViewTextProperty, value);
659
                    OnPropertyChanged("OverViewText");
660
                }
661
            }
662
        }
663
664
        public Geometry OverViewPathData
665
        {
666
            get { return (Geometry)GetValue(OverViewPathDataProperty); }
667
            set
668
            {
669
                if (this.OverViewPathData != value)
670
                {
671
                    SetValue(OverViewPathDataProperty, value);
672
                    OnPropertyChanged("OverViewPathData");
673
                }
674
            }
675
        }
676
677
        public Visibility TextBoxVisibility
678
        {
679
            get { return (Visibility)GetValue(TextBoxVisibilityProperty); }
680
            set
681
            {
682
                if (this.TextBoxVisibility != value)
683
                {
684
                    SetValue(TextBoxVisibilityProperty, value);
685
                    OnPropertyChanged("TextBoxVisibility");
686
                }
687
            }
688
        }
689
690
691
        public Visibility TextBlockVisibility
692
        {
693
            get { return (Visibility)GetValue(TextBlockVisibilityProperty); }
694
            set
695
            {
696
                if (this.TextBlockVisibility != value)
697
                {
698
                    SetValue(TextBlockVisibilityProperty, value);
699
                    OnPropertyChanged("TextBlockVisibility");
700
                }
701
            }
702
        }
703
704
705
706
        public Double TextSize
707
        {
708
            get { return (Double)GetValue(TextSizeProperty); }
709
            set
710
            {
711
                if (this.TextSize != value)
712
                {
713
                    SetValue(TextSizeProperty, value);
714
                    OnPropertyChanged("TextSize");
715
                }
716
            }
717
        }
718 05009a0e ljiyeon
        /*
719 787a4489 KangIngu
        public SolidColorBrush FontColor
720
        {
721
            get { return (SolidColorBrush)GetValue(FontColorProperty); }
722
            set
723
            {
724
                if (this.FontColor != value)
725
                {
726
                    SetValue(FontColorProperty, value);
727
                    OnPropertyChanged("FontColor");
728
                }
729
            }
730 05009a0e ljiyeon
        }*/
731 787a4489 KangIngu
732
        public SolidColorBrush BackColor
733
        {
734
            get { return (SolidColorBrush)GetValue(BackColorProperty); }
735
            set
736
            {
737
                if (this.BackColor != value)
738
                {
739
                    SetValue(BackColorProperty, value);
740
                    OnPropertyChanged("BackColor");
741
                }
742
            }
743
        }
744
745
        public SolidColorBrush BackInnerColor
746
        {
747
            get { return (SolidColorBrush)GetValue(BackInnerColorProperty); }
748
            set
749
            {
750
                if (this.BackInnerColor != value)
751
                {
752
                    SetValue(BackInnerColorProperty, value);
753
                    OnPropertyChanged("BackInnerColor");
754
                }
755
            }
756
        }
757
758
        
759
760
        public TextDecorationCollection UnderLine
761
        {
762
            get
763
            {
764
                return (TextDecorationCollection)GetValue(UnderLineProperty);
765
            }
766
            set
767
            {
768
                if (this.UnderLine != value)
769
                {
770
                    SetValue(UnderLineProperty, value);
771
                    OnPropertyChanged("UnderLine");
772
                }
773
            }
774
        }
775
776
        public double CanvasX
777
        {
778
            get { return (double)GetValue(CanvasXProperty); }
779
            set
780
            {
781
                if (this.CanvasX != value)
782
                {
783
                    SetValue(CanvasXProperty, value);
784
                    OnPropertyChanged("CanvasX");
785
                }
786
            }
787
        }
788
789
        public double CanvasY
790
        {
791
            get { return (double)GetValue(CanvasYProperty); }
792
            set
793
            {
794
                if (this.CanvasY != value)
795
                {
796
                    SetValue(CanvasYProperty, value);
797
                    OnPropertyChanged("CanvasY");
798
                }
799
            }
800
        }
801
802
        public Point EndPoint
803
        {
804
            get { return (Point)GetValue(EndPointProperty); }
805
            set
806
            {
807
                if (this.EndPoint != value)
808
                {
809
                    SetValue(EndPointProperty, value);
810
                    OnPropertyChanged("EndPoint");
811
                }
812
            }
813
        }
814
815
        public Point StartPoint
816
        {
817
            get { return (Point)GetValue(StartPointProperty); }
818
            set
819
            {
820
                if (this.StartPoint != value)
821
                {
822
                    SetValue(StartPointProperty, value);
823
                    OnPropertyChanged("StartPoint");
824
                }
825
            }
826
        }
827
828
        public FontStyle TextStyle
829
        {
830
            get { return (FontStyle)GetValue(TextStyleProperty); }
831
            set
832
            {
833
                if (this.TextStyle != value)
834
                {
835
                    SetValue(TextStyleProperty, value);
836
                    OnPropertyChanged("TextStyle");
837
                }
838
            }
839
        }
840
841
        public FontFamily TextFamily
842
        {
843
            get { return (FontFamily)GetValue(TextFamilyProperty); }
844
            set
845
            {
846
                if (this.TextFamily != value)
847
                {
848
                    SetValue(TextFamilyProperty, value);
849
                    OnPropertyChanged("TextFamily");
850
                }
851
            }
852
        }
853
854
        public FontWeight TextWeight
855
        {
856
            get { return (FontWeight)GetValue(TextWeightProperty); }
857
            set
858
            {
859
                if (this.TextWeight != value)
860
                {
861
                    SetValue(TextWeightProperty, value);
862
                    OnPropertyChanged("TextWeight");
863
                }
864
            }
865
        }
866
867
        public PaintSet Paint
868
        {
869
            get { return (PaintSet)GetValue(PaintProperty); }
870
            set
871
            {
872
                if (this.Paint != value)
873
                {
874
                    SetValue(PaintProperty, value);
875
                    OnPropertyChanged("Paint");
876
                }
877
            }
878
        }
879
880
        public PaintSet OverViewPaint
881
        {
882
            get { return (PaintSet)GetValue(OverViewPaintProperty); }
883
            set
884
            {
885
                if (this.OverViewPaint != value)
886
                {
887
                    SetValue(OverViewPaintProperty, value);
888
                    OnPropertyChanged("OverViewPaint");
889
                }
890
            }
891
        }
892
893
        double IPath.LineSize
894
        {
895
            get
896
            {
897
                return this.LineSize.Left;
898
            }
899
            set
900
            {
901
                this.LineSize = new Thickness(value);
902
                OnPropertyChanged("LineSize");
903
            }
904
        }
905
906
907
        public Geometry PathData
908
        {
909
            get { return (Geometry)GetValue(PathDataProperty); }
910
            set { SetValue(PathDataProperty, value);
911
            OnPropertyChanged("PathData");
912
            }
913
        }
914
915
        public Geometry PathDataInner
916
        {
917
            get { return (Geometry)GetValue(PathDataInnerProperty); }
918
            set
919
            {
920
                SetValue(PathDataInnerProperty, value);
921
                OnPropertyChanged("PathDataInner");
922
            }
923
        }
924
925
        public double Angle
926
        {
927
            get { return (double)GetValue(AngleProperty); }
928
            set
929
            {
930
                if (this.Angle != value)
931
                {
932
                    SetValue(AngleProperty, value);
933
934
                    OnPropertyChanged("Angle");
935
                    UpdateLayout();
936
                }
937
            }
938
        }
939
940
        public bool IsHighLight
941
        {
942
            get { return (bool)GetValue(IsHighlightProperty); }
943
            set
944
            {
945
                if (this.IsHighLight != value)
946
                {
947
                    SetValue(IsHighlightProperty, value);
948
                    OnPropertyChanged("IsHighLight");
949
                }
950
            }
951
        }
952
953
        public List<Point> PointSet
954
        {
955
            get { return (List<Point>)GetValue(PointSetProperty); }
956
            set { SetValue(PointSetProperty, value);
957
            OnPropertyChanged("PointSet");
958
            }
959
        }
960
961
        #endregion Properties
962
963
        #region Properties
964
965
966
967
        public PathGeometry PathGeometry 
968
        {
969
            get { return (PathGeometry)GetValue(PathGeometryProperty); }
970
            set
971
            {
972
                SetValue(PathGeometryProperty, value);
973
                OnPropertyChanged("PathGeometry");
974
            }
975
        }
976
977
        private double _BoxWidth;
978
        public double BoxWidth
979
        {
980
            get
981
            {
982
                return _BoxWidth;
983
            }
984
            set
985
            {
986
                _BoxWidth = value;
987
                OnPropertyChanged("BoxWidth");
988
            }
989
        }
990
991
        private double _BoxHeight;
992
        public double BoxHeight
993
        {
994
            get
995
            {
996
                return _BoxHeight;
997
            }
998
            set
999
            {
1000
                _BoxHeight = value;
1001
                OnPropertyChanged("BoxHeight");
1002
            }
1003
        }
1004
1005
        #endregion
1006
1007
        #region CallBack Method
1008
        public static void SetPathGeometryChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1009
        {
1010
            var instance = (TextControl)sender;
1011
1012
            if (e.OldValue != e.NewValue && instance.Base_TextPath != null)
1013
            {
1014
                instance.SetValue(e.Property, e.NewValue);
1015
            }
1016
        }
1017
1018
1019
        public static void OnTextBoxVisibilityChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1020
        {
1021
            var instance = (TextControl)sender;
1022
1023
            if (e.OldValue != e.NewValue && instance.Base_TextPath != null)
1024
            {
1025
                instance.SetValue(e.Property, e.NewValue);
1026
            }
1027
        }
1028
1029
        public static void OnTextBlockVisibilityChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1030
        {
1031
            var instance = (TextControl)sender;
1032
1033
            if (e.OldValue != e.NewValue && instance.Base_TextPath != null)
1034
            {
1035
                instance.SetValue(e.Property, e.NewValue);
1036
            }
1037
        }
1038
1039
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1040
        {
1041
            var instance = (TextControl)sender;
1042
1043
            if (e.OldValue != e.NewValue && instance.Base_Border != null)
1044
            {
1045
                instance.SetValue(e.Property, e.NewValue);
1046
1047
                if (instance.IsSelected)
1048
                {
1049 05009a0e ljiyeon
                    instance.StrokeColor = new SolidColorBrush(Colors.Blue);
1050 787a4489 KangIngu
                    //instance.Base_Border.BorderBrush = new SolidColorBrush(Colors.Blue);
1051
                }
1052
                else
1053
                {
1054 05009a0e ljiyeon
                    instance.StrokeColor = new SolidColorBrush(Colors.Red);
1055 787a4489 KangIngu
                    //instance.Base_Border.BorderBrush = new SolidColorBrush(Colors.Red);
1056
                    //instance.FontColor = new SolidColorBrush(Colors.Transparent);
1057
                    //instance.Base_Border.BorderBrush = new SolidColorBrush(Colors.Transparent);
1058
                }
1059
1060
            }
1061
        }
1062
1063
        public static void OnSetCansvasChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1064
        {
1065
            var instance = (TextControl)sender;
1066
1067
            if (e.OldValue != e.NewValue && instance != null)
1068
            {
1069
                instance.SetValue(e.Property, e.NewValue);
1070
1071
                Canvas.SetLeft(instance, instance.CanvasX);
1072
                Canvas.SetTop(instance, instance.CanvasY);
1073
            }
1074
        }
1075
1076
        public static void OnIsEditingChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1077
        {
1078
            var instance = (TextControl)sender;
1079
1080
            if (e.OldValue != e.NewValue && instance.Base_TextBlock != null)
1081
            {
1082
                instance.SetValue(e.Property, e.NewValue);
1083
1084 819630e9 송근호
                //if (instance.EnableEditing)
1085
                //{
1086
                //    instance.EditingMode();
1087
                //}
1088
                //else
1089
                //{
1090
                //    instance.UnEditingMode();
1091
                //}
1092 787a4489 KangIngu
            }
1093
        }
1094
1095
        public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1096
        {
1097
            var instance = (TextControl)sender;
1098
1099
            if (e.OldValue != e.NewValue && instance.Base_TextBlock != null)
1100
            {
1101
                instance.SetValue(e.Property, e.NewValue);
1102 6b5d33c6 djkim
                //instance.DrawingCloud();
1103 787a4489 KangIngu
            }
1104
        }
1105
1106
        public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1107
        {
1108
            var instance = (TextControl)sender;
1109
            if (e.OldValue != e.NewValue && instance.Base_TextBlock != null)
1110
            {
1111
                instance.SetValue(e.Property, e.NewValue);
1112 05009a0e ljiyeon
                //instance.DrawingCloud();
1113 787a4489 KangIngu
            }
1114
        }
1115
1116
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
1117
        {
1118
            var instance = (TextControl)sender;
1119
            if (e.OldValue != e.NewValue && instance!= null)
1120
            {
1121
                instance.SetValue(e.Property, e.NewValue);
1122 05009a0e ljiyeon
                //instance.DrawingCloud();
1123 787a4489 KangIngu
            }
1124
        }
1125
            
1126
        #endregion CallBack Method
1127
1128
        protected void OnPropertyChanged(string propName)
1129
        {
1130
            if (PropertyChanged != null)
1131
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
1132
        }
1133 036650a0 humkyung
1134
        /// <summary>
1135 91efe37a humkyung
        /// return textcontrols' area
1136 036650a0 humkyung
        /// </summary>
1137 91efe37a humkyung
        public override Rect ItemRect
1138
        {
1139
            get
1140
            {
1141 e6a9ddaf humkyung
                Point start = new Point(this.CanvasX, this.CanvasY);
1142 91efe37a humkyung
1143
                Point length = new Point();
1144
                double angle = this.Angle * Math.PI / 180;
1145
1146
                length.X = this.BoxWidth * Math.Cos(angle) - this.BoxHeight * Math.Sin(angle);
1147
                length.Y = this.BoxWidth * Math.Sin(angle) + this.BoxHeight * Math.Cos(angle);
1148
1149
                Point end = new Point(start.X + length.X, start.Y + length.Y);
1150
                return new Rect(start, end);
1151
            }
1152
        }
1153
1154 e6a9ddaf humkyung
        /// <summary>
1155 0d00f9c8 humkyung
        /// translate control along given dx,dy
1156 e6a9ddaf humkyung
        /// </summary>
1157
        /// <param name="dx"></param>
1158
        /// <param name="dy"></param>
1159 0d00f9c8 humkyung
        public override void OnTranslate(double dx, double dy)
1160 e6a9ddaf humkyung
        {
1161 0d00f9c8 humkyung
            //this.CanvasX = Canvas.GetLeft(this) + dx;
1162
            //this.CanvasY = Canvas.GetTop(this) + dy;
1163
1164
            //this.SetValue(TextControl.CanvasXProperty, Canvas.GetLeft(this) + dx);
1165
            //this.SetValue(TextControl.CanvasYProperty, Canvas.GetTop(this) + dy);
1166 e6a9ddaf humkyung
            this.StartPoint = new Point(this.StartPoint.X + dx, this.StartPoint.Y + dy);
1167
            this.EndPoint = new Point(this.EndPoint.X + dx, this.EndPoint.Y + dy);
1168 0d00f9c8 humkyung
1169
            Canvas.SetLeft(this, Canvas.GetLeft(this) + dx);
1170
            Canvas.SetTop(this, Canvas.GetTop(this) + dy);
1171 e6a9ddaf humkyung
        }
1172
1173
        /// <summary>
1174
        /// Serialize this
1175
        /// </summary>
1176
        /// <param name="sUserId"></param>
1177
        /// <returns></returns>
1178
        public override string Serialize()
1179 036650a0 humkyung
        {
1180
            using (S_TextControl STemp = new S_TextControl())
1181
            {
1182
                STemp.TransformPoint = "0|0";
1183
                STemp.SizeSet = String.Format("{0}|{1}", this.LineSize.Left.ToString(), this.TextSize.ToString());
1184
                STemp.Text = this.Text;
1185
                STemp.UserID = this.UserID;
1186 05009a0e ljiyeon
                STemp.FontColor = this.StrokeColor.Color.ToString();
1187 036650a0 humkyung
                //STemp.FontColor = "#FFFFFF00";
1188
1189
                if (this.StartPoint == new Point())
1190
                    STemp.StartPoint = new Point(this.CanvasX, this.CanvasY);
1191
                else
1192
                    STemp.StartPoint = this.StartPoint;
1193
1194
                STemp.EndPoint = this.EndPoint;
1195
                STemp.Opac = this.Opacity;
1196
                STemp.PointSet = this.PointSet;
1197
                STemp.Angle = this.Angle;
1198
                STemp.paintMethod = this.ControlType_No;
1199
                STemp.BoxW = this.BoxWidth;
1200
                STemp.BoxH = this.BoxHeight;
1201
                STemp.isHighLight = this.IsHighLight;
1202
                STemp.Name = this.GetType().Name.ToString();
1203
                STemp.fontConfig = new List<string>()
1204
                            {
1205
                                this.TextFamily.ToString(),
1206
                                this.TextStyle.ToString(),
1207
                                this.TextWeight.ToString(),
1208
                            };
1209
1210
1211
1212
                if (this.UnderLine != null)
1213
                {
1214
                    STemp.fontConfig.Add("true");
1215
                }
1216
1217
                ///강인구 추가(2017.11.02)
1218
                ///Memo 추가
1219
                STemp.Memo = this.Memo;
1220
1221
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
1222
            }
1223
        }
1224 661b7416 humkyung
1225
        /// <summary>
1226
        /// create a textcontrol from given string
1227
        /// </summary>
1228
        /// <param name="str"></param>
1229
        /// <returns></returns>
1230
        public static TextControl FromString(string str, SolidColorBrush brush, string sProjectNo)
1231
        {
1232
            using (S_TextControl s = JsonSerializerHelper.JsonDeserialize<S_TextControl>(str))
1233
            {
1234
                string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
1235
                TextControl instance = new TextControl()
1236
                {
1237
                    Text = s.Text,
1238
                    StartPoint = s.StartPoint,
1239
                    EndPoint = s.EndPoint,
1240
                    CanvasX = s.StartPoint.X,
1241
                    CanvasY = s.StartPoint.Y,
1242
                    BoxWidth = s.BoxW,
1243
                    BoxHeight = s.BoxH,
1244
                    ControlType_No = s.paintMethod,
1245
                    LineSize = new Thickness(Convert.ToDouble(data2.First())),
1246
                    TextSize = Convert.ToDouble(data2[1]),
1247 05009a0e ljiyeon
                    StrokeColor = brush,
1248 661b7416 humkyung
                    FontSize = 10,
1249
                    UserID = s.UserID,
1250
                    IsHighLight = s.isHighLight,
1251
                    Angle = s.Angle,
1252
                    PointSet = s.PointSet,
1253
                    Opacity = s.Opac,
1254
                    TextFamily = new FontFamily(s.fontConfig[0]),
1255
                    //인구 추가(2018.04.17)
1256
                    TextStyle = StringToFont.ConFontStyle(s.fontConfig[1]),
1257
                    TextWeight = StringToFont.ConFontWeight(s.fontConfig[2]),
1258
                };
1259
1260
                if (s.fontConfig.Count() == 4)
1261
                {
1262
                    instance.UnderLine = TextDecorations.Underline;
1263
                }
1264
1265
                return instance;
1266
            }
1267
        }
1268 787a4489 KangIngu
    }
1269
}
클립보드 이미지 추가 (최대 크기: 500 MB)