summaryrefslogtreecommitdiff
path: root/winrt/mupdf_cpp/DocumentPage.h
blob: a75854103f343752731ff192a1cd8abc4e5ffd94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#pragma once

#include "RectList.h"
#include <collection.h>


/* Used for binding to the xaml in the scroll view. */
using namespace Windows::UI::Xaml::Media::Imaging;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Xaml::Data;

typedef enum {
    FULL_RESOLUTION = 0,
    THUMBNAIL,
    DUMMY,
    NOTSET
} Page_Content_t;

        
namespace mupdf_cpp
{
    // enables data binding with this class
    [Windows::UI::Xaml::Data::Bindable] 
    public ref class DocumentPage sealed : Windows::UI::Xaml::Data::INotifyPropertyChanged
    {
    private:
        int height;
        int width;
        double zoom;
        WriteableBitmap^ image;
        Page_Content_t content;
        IVector<RectList^>^ textbox;
        IVector<RectList^>^ linkbox;
    public:
        DocumentPage(void);

        /* Note IVector needed for WinRT interface */
        property IVector<RectList^>^ TextBox
        {
            IVector<RectList^>^ get() { return (textbox); }
            void set(IVector<RectList^>^ value)
            {
                textbox = value;
                DocumentPage::OnPropertyChanged("TextBox");
            }
        }

        property IVector<RectList^>^ LinkBox
        {
            IVector<RectList^>^ get() { return (linkbox); }
            void set(IVector<RectList^>^ value)
            {
                linkbox = value;
                DocumentPage::OnPropertyChanged("LinkBox");
            }
        }

        property int Content
        {
            int get() { return ((int) content); }
            void set(int value)
            {
                if (value > NOTSET)
                { 
                    throw ref new Platform::InvalidArgumentException(); 
                }
                content = (Page_Content_t) value;
            }
        }

        property int Height
        {
            int get() { return height; }
            void set(int value)
            {
                if (value < 0) 
                { 
                    throw ref new Platform::InvalidArgumentException(); 
                }
                height = value;
            }
        }

        property int Width
        {
            int get() { return width; }
            void set(int value)
            {
                if (value < 0) 
                { 
                    throw ref new Platform::InvalidArgumentException(); 
                }
                width = value;
            }
        }

        property double Zoom
        {
            double get() { return zoom; }
            void set(double value)
            {
                if (value < 0) 
                { 
                    throw ref new Platform::InvalidArgumentException(); 
                }
                zoom = value;
            }
        }

        property WriteableBitmap^ Image
        {
            WriteableBitmap^ get() { return image; }
            void set(WriteableBitmap^ value)
            {
                image = value;
                DocumentPage::OnPropertyChanged("Image");
            }
        }

        private:
            bool _isPropertyChangedObserved;
            event Windows::UI::Xaml::Data::PropertyChangedEventHandler^ _privatePropertyChanged;


        protected:
            /// <summary>
            /// Notifies listeners that a property value has changed.
            /// </summary>
            /// <param name="propertyName">Name of the property used to notify listeners.</param>
            void OnPropertyChanged(String^ propertyName)
            {
                if (_isPropertyChangedObserved)
                {
                    PropertyChanged(this, ref new PropertyChangedEventArgs(propertyName));
                }
            }

        public:

            // in c++, it is not neccessary to include definitions of add, remove, and raise.
            //  these definitions have been made explicitly here so that we can check if the 
            //  event has listeners before firing the event
            virtual event Windows::UI::Xaml::Data::PropertyChangedEventHandler^ PropertyChanged
            {
                virtual Windows::Foundation::EventRegistrationToken add(Windows::UI::Xaml::Data::PropertyChangedEventHandler^ e)
                {
                    _isPropertyChangedObserved = true;
                    return _privatePropertyChanged += e;
                }
                virtual void remove(Windows::Foundation::EventRegistrationToken t)
                {
                    _privatePropertyChanged -= t;
                }

        protected:
                virtual void raise(Object^ sender, Windows::UI::Xaml::Data::PropertyChangedEventArgs^ e)
                {
                    if (_isPropertyChangedObserved)
                    {
                        _privatePropertyChanged(sender, e);
                    }
                }
            }
#pragma endregion




    };
}