root/trunk/tests/DumbDocumentObserver.cxx

Revision 156, 4.5 kB (checked in by jordi, 2 years ago)

The FindPter? can now search new matches in forward directions (i.e., Find Next.)

Line 
1// ePDFView - Dumb Test Document Observer.
2// Copyright (C) 2006 Emma's Software.
3//
4// This program is free software; you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation; either version 2 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18#include <epdfview.h>
19#include "DumbDocumentObserver.h"
20
21G_LOCK_DEFINE_STATIC (Searching);
22
23using namespace ePDFView;
24
25DumbDocumentObserver::DumbDocumentObserver ():
26    IDocumentObserver ()
27{
28    m_CurrentPage = 0;
29    m_Error = NULL;
30    m_FindMatchRect = NULL;
31    m_NotifiedError = FALSE;
32    m_NotifiedPassword = FALSE;
33    m_NotifiedLoad = FALSE;
34    m_NotifiedPageRotated = FALSE;
35    m_NotifiedPageZoomed = FALSE;
36    m_NotifiedReload = FALSE;
37    G_LOCK (Searching);
38    m_Searching = FALSE;
39    G_UNLOCK (Searching);
40    m_Zoom = 0.0;
41}
42
43DumbDocumentObserver::~DumbDocumentObserver ()
44{
45    setLoadError (NULL);
46}
47
48void
49DumbDocumentObserver::notifyFindChanged (DocumentRectangle *matchRect)
50{
51    m_FindMatchRect = matchRect;
52    G_LOCK (Searching);
53    m_Searching = FALSE;
54    G_UNLOCK (Searching);
55}
56
57void
58DumbDocumentObserver::notifyFindFinished ()
59{
60    G_LOCK (Searching);
61    m_Searching = FALSE;
62    G_UNLOCK (Searching);
63}
64
65void
66DumbDocumentObserver::notifyFindStarted ()
67{
68    G_LOCK (Searching);
69    m_Searching = TRUE;
70    G_UNLOCK (Searching);
71}
72
73void
74DumbDocumentObserver::notifyLoad ()
75{
76    m_NotifiedLoad = TRUE;
77    m_CurrentPage = 1;
78    m_Zoom = 1.0;
79}
80
81void
82DumbDocumentObserver::notifyLoadError (const GError *error)
83{
84    setLoadError (error);
85    m_NotifiedError = TRUE;
86}
87
88void
89DumbDocumentObserver::notifyLoadPassword (const gchar *fileName,
90                                          gboolean reload,
91                                          const GError *error)
92{
93    setLoadError (error);
94    m_NotifiedPassword = TRUE;
95}
96
97void
98DumbDocumentObserver::notifyPageChanged (gint pageNum)
99{
100    m_CurrentPage = pageNum;
101}
102
103void
104DumbDocumentObserver::notifyPageRotated (gint rotation)
105{
106    m_NotifiedPageRotated = TRUE;
107}
108
109void
110DumbDocumentObserver::notifyPageZoomed (gdouble zoom)
111{
112    m_NotifiedPageZoomed = TRUE;
113    m_Zoom = zoom;
114}
115
116void
117DumbDocumentObserver::notifyReload (void)
118{
119    m_NotifiedReload = TRUE;
120}
121
122////////////////////////////////////////////////////////////////
123// Test purposes methods.
124////////////////////////////////////////////////////////////////
125
126DocumentRectangle *
127DumbDocumentObserver::getFindMatchRect ()
128{
129    return m_FindMatchRect;
130}
131
132gint
133DumbDocumentObserver::getCurrentPage (void)
134{
135    return m_CurrentPage;
136}
137
138const GError *
139DumbDocumentObserver::getLoadError (void)
140{
141    return m_Error;
142}
143
144gdouble
145DumbDocumentObserver::getZoom (void)
146{
147    return m_Zoom;
148}
149
150gboolean
151DumbDocumentObserver::isStillSearching (void)
152{
153    G_LOCK (Searching);
154    gboolean searching = m_Searching;
155    G_UNLOCK (Searching);
156    return searching;
157}
158
159gboolean
160DumbDocumentObserver::loadFinished (void)
161{
162    return m_NotifiedError || m_NotifiedPassword || m_NotifiedLoad ||
163           m_NotifiedReload;
164}
165
166gboolean
167DumbDocumentObserver::notifiedError (void)
168{
169    gboolean notified = m_NotifiedError;
170    m_NotifiedError = FALSE;
171    return notified;
172}
173
174gboolean
175DumbDocumentObserver::notifiedLoaded (void)
176{
177    gboolean notified = m_NotifiedLoad;
178    m_NotifiedLoad = FALSE;
179    return notified;
180}
181
182gboolean
183DumbDocumentObserver::notifiedPassword (void)
184{
185    gboolean notified = m_NotifiedPassword;
186    m_NotifiedPassword = FALSE;
187    return notified;
188}
189
190gboolean
191DumbDocumentObserver::notifiedRotation (void)
192{
193    gboolean notified = m_NotifiedPageRotated;
194    m_NotifiedPageRotated = FALSE;
195    return notified;
196}
197
198gboolean
199DumbDocumentObserver::notifiedZoom (void)
200{
201    gboolean notified = m_NotifiedPageZoomed;
202    m_NotifiedPageZoomed = FALSE;
203    return notified;
204}
205
206void
207DumbDocumentObserver::setLoadError (const GError *error)
208{
209    if ( NULL != m_Error )
210    {
211        g_error_free (m_Error);
212    }
213    if ( NULL != error )
214    {       
215        m_Error = g_error_copy (error);
216    }   
217}
Note: See TracBrowser for help on using the browser.