root/trunk/src/IMainView.h

Revision 277, 25.0 kB (checked in by jordi, 15 months ago)

Added a patch by Igor Vagulin which adds text selection and copy to clipboard features. This fixes bug #14.

Line 
1// ePDFView - A lightweight PDF Viewer.
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#if !defined (__IMAIN_VIEW_H__)
19#define __IMAIN_VIEW_H__
20
21
22namespace ePDFView
23{
24    // Forward declarations
25    class MainPter;
26    class DocumentPage;
27    class DocumentOutline;
28
29    ///
30    /// @brief Main view's cursor.
31    ///
32    enum ViewCursor
33    {
34        /// Normal cursor.
35        MAIN_VIEW_CURSOR_NORMAL,
36        /// Hour glass wait cursor.
37        MAIN_VIEW_CURSOR_WAIT,
38        /// Drag cursor.
39        MAIN_VIEW_CURSOR_DRAG
40    };
41
42    ///
43    /// @class IMainView
44    /// @brief Interface class for the main view.
45    ///
46    /// This is the base class for all toolkit dependent implementations
47    /// of the main view. This is the class responsible to get all user
48    /// events and pass them to the presenter.
49    ///
50    class IMainView
51    {
52        public:
53            ///
54            /// @brief Destroys the main window's dynamically allocated memory.
55            ///
56            virtual ~IMainView (void) {}
57
58            ///
59            /// @brief Actives or datives the zoom to fit.
60            ///
61            /// The view must change the state of the zoom to fit option
62            /// to @a active.
63            ///
64            /// @param active TRUE if the option must be activated, FALSE
65            ///               otherwise.
66            ///
67            virtual void activeZoomFit (gboolean active) = 0;
68
69            ///
70            /// @brief Actives or deactivates the zoom to width.
71            ///
72            /// The view must change the state of the zoom to width option
73            /// to @a active.
74            ///
75            /// @param active TRUE if the option must be activated, FALSE
76            ///               otherwise.
77            ///
78            virtual void activeZoomWidth (gboolean active) = 0;
79
80            ///
81            /// @brief Shows the open file dialog.
82            ///
83            /// The view must ask the user which file to open by using
84            /// the toolkit's specific open dialog.
85            ///
86            /// @param lastFolder The last folder used to open a file. This is
87            ///                   used to show this folder when the open dialog
88            ///                   appears.
89            ///
90            /// @return A copy of the file name that the user will try to open
91            ///         or NULL if the user cancelled the operation.
92            ///         This string will be freed by the presenter.
93            ///
94            virtual gchar *openFileDialog (const gchar *lastFolder) = 0;
95
96            ///
97            /// @brief Shows the password dialog.
98            ///
99            /// This is used when the user wants to open an encrypted file.
100            /// The view must ask the password to the user. It will be called
101            /// up to three times by the presenter.
102            ///
103            /// @return A copy of the password entered by the user or NULL
104            ///         if the user cancelled the operation.
105            ///         This string will be freed by the presenter.
106            ///
107            virtual gchar *promptPasswordDialog (void) = 0;
108
109            ///
110            /// @brief Shows the save file dialog.
111            ///
112            /// The view must ask the user which file name to use to
113            /// save using the toolkit's specific save dialog.
114            ///
115            /// @param lastFolder The last folder used to save a file. This is
116            ///                   used to show this folder when the save dialog
117            ///                   appears.
118            /// @param fileName The file name to set as the initial name to
119            ///                 the save dialog.
120            ///
121            /// @return A copy of the file name that the user will try to use
122            ///         to save or NULL if the user cancelled the operation.
123            ///         This string will be freed by the presenter.
124            ///
125            virtual gchar *saveFileDialog (const gchar *lastFolder,
126                                           const gchar *fileName) = 0;
127
128            ///
129            /// @brief Changes the sensitivity of the "Find" action.
130            ///
131            /// The view must change the sensitivity (it's called enabled or
132            /// disabled on some toolkits) of the "Find" action
133            /// (both on the menu and the toolbar or any other place).
134            ///
135            /// @param sensitive Set to TRUE if need to make sensitive (enable)
136            ///                  the action (enable) or FALSE to
137            ///                  insensitive (disable) it.
138            ///
139            virtual void sensitiveFind (gboolean sensitive) = 0;
140
141            ///
142            /// @brief Changes the sensitivity of the "Go To First Page" action.
143            ///
144            /// The view must change the sensitivity (it's called enabled or
145            /// disabled on some toolkits) of the "Go To First Page" action
146            /// (both on the menu and the toolbar or any other place).
147            ///
148            /// @param sensitive Set to TRUE if need to make sensitive (enable)
149            ///                  the action (enable) or FALSE to
150            ///                  insensitive (disable) it.
151            ///
152            virtual void sensitiveGoToFirstPage (gboolean sensitive) = 0;
153
154            ///
155            /// @brief Changes the sensitivity of the "Go To Last Page" action.
156            ///
157            /// The view must change the sensitivity (it's called enabled or
158            /// disabled on some toolkits) of the "Go To Last Page" action
159            /// (both on the menu and the toolbar or any other place).
160            ///
161            /// @param sensitive Set to TRUE if need to make sensitive (enable)
162            ///                  the action (enable) or FALSE to
163            ///                  insensitive (disable) it.
164            ///
165            virtual void sensitiveGoToLastPage (gboolean sensitive) = 0;
166
167            ///
168            /// @brief Changes the sensitivity of the "Go To Next Page" action.
169            ///
170            /// The view must change the sensitivity (it's called enabled or
171            /// disabled on some toolkits) of the "Go To Next Page" action
172            /// (both on the menu and the toolbar or any other place).
173            ///
174            /// @param sensitive Set to TRUE if need to make sensitive (enable)
175            ///                  the action (enable) or FALSE to
176            ///                  insensitive (disable) it.
177            ///
178            virtual void sensitiveGoToNextPage (gboolean sensitive) = 0;
179
180            ///
181            /// @brief Changes the sensitivity of the "Go To Page" action.
182            ///
183            /// The view must change the sensitivity (it's called enabled or
184            /// disabled on some toolkits) of the "Go To Page" action
185            /// (both on the menu and the toolbar or any other place).
186            ///
187            /// @param sensitive Set to TRUE if need to make sensitive (enable)
188            ///                  the action (enable) or FALSE to
189            ///                  insensitive (disable) it.
190            ///
191            virtual void sensitiveGoToPage (gboolean sensitive) = 0;
192
193            ///
194            /// @brief Changes the sensitivity of the "Go To Prev. Page" action.
195            ///
196            /// The view must change the sensitivity (it's called enabled or
197            /// disabled on some toolkits) of the "Go To Previous Page" action
198            /// (both on the menu and the toolbar or any other place).
199            ///
200            /// @param sensitive Set to TRUE if need to make sensitive (enable)
201            ///                  the action (enable) or FALSE to
202            ///                  insensitive (disable) it.
203            ///
204            virtual void sensitiveGoToPreviousPage (gboolean sensitive) = 0;
205
206#if defined (HAVE_CUPS)
207            ///
208            /// @brief Changes the sensitivity of the "Print" action.
209            ///
210            /// The view must change the sensitivity (it's called enabled or
211            /// disabled on some toolkits) of the "Print" action
212            /// (both on the menu and the toolbar or any other place).
213            ///
214            /// @param sensitive Set to TRUE if need to make the action
215            ///                  sensitive (enable) or FALSE to
216            ///                  insensitive (disable) it.
217            ///
218            virtual void sensitivePrint (gboolean sensitive) = 0;
219#endif // HAVE_CUPS
220
221            ///
222            /// @brief Changes the sensitivity of the "Open" action.
223            ///
224            /// The view must change the sensitivity (it's called enabled or
225            /// disabled on some toolkits) of the "Open" action
226            /// (both on the menu and the toolbar or any other place).
227            ///
228            /// @param sensitive Set to TRUE if need to make sensitive (enable)
229            ///                  the action (enable) or FALSE to
230            ///                  insensitive (disable) it.
231            ///
232            virtual void sensitiveOpen (gboolean sensitive) = 0;
233
234            ///
235            /// @brief Changes the sensitivity of the "Reload" action.
236            ///
237            /// The view must change the sensitivity (it's called enabled or
238            /// disabled on some toolkits) of the "Reload" action
239            /// (both on the menu and the toolbar or any other place).
240            ///
241            /// @param sensitive Set to TRUE if need to make sensitive (enable)
242            ///                  the action (enable) or FALSE to
243            ///                  insensitive (disable) it.
244            ///
245            virtual void sensitiveReload (gboolean sensitive) = 0;
246
247            ///
248            /// @brief Changes the sensitivity of the "Rotate Left" action.
249            ///
250            /// The view must change the sensitivity (it's called enabled or
251            /// disabled on some toolkits) of the "Rotate Left" action
252            /// (both on the menu and the toolbar or any other place).
253            ///
254            /// @param sensitive Set to TRUE if need to make sensitive (enable)
255            ///                  the action (enable) or FALSE to
256            ///                  insensitive (disable) it.
257            ///
258            virtual void sensitiveRotateLeft (gboolean sensitive) = 0;
259
260            ///
261            /// @brief Changes the sensitivity of the "Rotate Right" action.
262            ///
263            /// The view must change the sensitivity (it's called enabled or
264            /// disabled on some toolkits) of the "Rotate Right" action
265            /// (both on the menu and the toolbar or any other place).
266            ///
267            /// @param sensitive Set to TRUE if need to make sensitive (enable)
268            ///                  the action (enable) or FALSE to
269            ///                  insensitive (disable) it.
270            ///
271            virtual void sensitiveRotateRight (gboolean sensitive) = 0;
272
273            ///
274            /// @brief Changes the sensitivity of the "Save a Copy" action.
275            ///
276            /// The view must change the sensitivity (it's called enabled or
277            /// disabled on some toolkits) of the "Save a Copy" action
278            /// (both on the menu and the toolbar or any other place).
279            ///
280            /// @param sensitive Set to TRUE if need to make sensitive (enable)
281            ///                  the action or FALSE to insensitive (disable)
282            ///                  it.
283            ///
284            virtual void sensitiveSave (gboolean sensitive) = 0;
285
286            ///
287            /// @brief Changes the sensitivity of the "Zoom" entry.
288            ///
289            /// The view must change the sensitivity (it's called enabled or
290            /// disabled on some toolkits) of the "Zoom" entry
291            /// on the toolbar.
292            ///
293            /// @param sensitive Set to TRUE if need to make sensitive (enable)
294            ///                  the entry or FALSE to insensitive (disable) it.
295            ///
296            virtual void sensitiveZoom (gboolean sensitive) = 0;
297
298            ///
299            /// @brief Changes the sensitivity of the "Zoom In" action.
300            ///
301            /// The view must change the sensitivity (it's called enabled or
302            /// disabled on some toolkits) of the "Zoom In" action
303            /// (both on the menu and the toolbar or any other place).
304            ///
305            /// @param sensitive Set to TRUE if need to make sensitive (enable)
306            ///                  the action (enable) or FALSE to
307            ///                  insensitive (disable) it.
308            ///
309            virtual void sensitiveZoomIn (gboolean sensitive) = 0;
310
311            ///
312            /// @brief Changes the sensitivity of the "Zoom Out" action.
313            ///
314            /// The view must change the sensitivity (it's called enabled or
315            /// disabled on some toolkits) of the "Zoom Out" action
316            /// (both on the menu and the toolbar or any other place).
317            ///
318            /// @param sensitive Set to TRUE if need to make sensitive (enable)
319            ///                  the action (enable) or FALSE to
320            ///                  insensitive (disable) it.
321            ///
322            virtual void sensitiveZoomOut (gboolean sensitive) = 0;
323
324            ///
325            /// @brief Changes the sensitivity of the "Zoom to Fit" action.
326            ///
327            /// The view must change the sensitivity (it's called enabled or
328            /// disabled on some toolkits) of the "Zoom to Fit" action
329            /// (both on the menu and the toolbar or any other place).
330            ///
331            /// @param sensitive Set to TRUE if need to make sensitive (enable)
332            ///                  the action (enable) or FALSE to
333            ///                  insensitive (disable) it.
334            ///
335            virtual void sensitiveZoomFit (gboolean sensitive) = 0;
336
337            ///
338            /// @brief Changes the sensitivity of the "Zoom to Width" action.
339            ///
340            /// The view must change the sensitivity (it's called enabled or
341            /// disabled on some toolkits) of the "Zoom to Width" action
342            /// (both on the menu and the toolbar or any other place).
343            ///
344            /// @param sensitive Set to TRUE if need to make sensitive (enable)
345            ///                  the action (enable) or FALSE to
346            ///                  insensitive (disable) it.
347            ///
348            virtual void sensitiveZoomWidth (gboolean sensitive) = 0;
349
350            ///
351            /// @brief Sets the page view's cursor.
352            ///
353            /// The main view must show the cursor as given by @a cursorType
354            /// for the page's view.
355            ///
356            /// @param cursorType The type of cursor to show.
357            ///
358            virtual void setCursor (ViewCursor cursorType) = 0;
359
360            ///
361            /// @brief Sets the view to full screen.
362            ///
363            /// @param fullScreen @a TRUE if the view should go full screen,
364            ///                   @a FALSE otherwise.
365            ///
366            virtual void setFullScreen (gboolean fullScreen) = 0;
367
368            ///
369            /// @brief Sets the text for the number of pages.
370            ///
371            /// The view displays the number of pages separately
372            /// of the current page. This function should set the
373            /// text to display in this separate control.
374            ///
375            /// @param text The text to set as the number of pages.
376            ///
377            virtual void setNumberOfPagesText (const gchar *text) = 0;
378
379            ///
380            /// @brief Sets the text of the status bar.
381            ///
382            /// The view must show the text at @a text unless it's NULL,
383            /// which means show nothing.
384            ///
385            /// @param text The text to shown on the status bar or NULL if
386            ///             no text should be shown on the status bar.
387            ///
388            virtual void setStatusBarText (const gchar *text) = 0;
389
390            ///
391            /// @brief Sets the current zoom text.
392            ///
393            /// The current zoom text is displayed on the tool bar and
394            /// the user can change it in order to specify a concrete
395            /// zoom level.
396            ///
397            /// @param text The text to show in the current zoom entry.
398            ///
399            virtual void setZoomText (const gchar *text) = 0;
400
401            ///
402            /// @brief Makes the main view to show itself.
403            ///
404            /// From the main view's creation until the presenter calls
405            /// this function, the main view must remain hidden.
406            ///
407            virtual void show (void) = 0;
408
409            ///
410            /// @brief Shows an error message dialog.
411            ///
412            /// Shows to the user a dialog with an error message. Use
413            /// the toolkit's dialog feature to show it.
414            ///
415            /// Some environments uses the @a title and @a body as the
416            /// dialog's primary and secondary texts respectively. The
417            /// presenter doesn't care.
418            ///
419            /// @param title The error dialog's title.
420            /// @param body The error dialog's body (the error message.)
421            ///
422            virtual void showErrorMessage (const gchar *title,
423                                           const gchar *body) = 0;
424
425            ///
426            /// @brief Shows the document's index.
427            ///
428            /// The presenter will call it just before to show the main window,
429            /// to let the view know if it must show the index or not
430            /// when the main window will be displayed.
431            ///
432            /// After that, the presenter can call it to show or hide the
433            /// index when the user toggles the "Show Index" option.
434            ///
435            /// @param show Set to TRUE if the index should be shown. FALSE
436            ///             otherwise.
437            ///
438            virtual void showIndex (gboolean show) = 0;
439
440            ///
441            /// @brief Shows the status bar.
442            ///
443            /// The view must show the status bar or hide it depending
444            /// on the @a show parameter.
445            ///
446            /// @param show TRUE if the status bar must be shown,
447            ///             FALSE otherwise.
448            ///
449            virtual void showStatusbar (gboolean show) = 0;
450
451            ///
452            /// @brief Shows the tool bar.
453            ///
454            /// The view must show the toolbar or hide it depending
455            /// on the @a show parameter.
456            ///
457            /// @param show TRUE if the toolbar must be shown, FALSE otherwise.
458            ///
459            virtual void showToolbar (gboolean show) = 0;
460
461            ///
462            /// @brief Sets the "Go To Page" text.
463            ///
464            /// The view must keep a text entry (edit control) that has the
465            /// current shown page number. The presenter will update this
466            /// text every time the page changes by calling this function.
467            ///
468            /// @param text The text to set to the "Go To Page" entry.
469            ///
470            virtual void setGoToPageText (const gchar *text) = 0;
471
472            ///
473            /// @brief Gets the text at "Go To Page".
474            ///
475            /// Gets the text that is displayed on the "Go To Page" entry.
476            /// This is normally used when the user activated it (pressed
477            /// the Enter key) and the presenter must try to go to the page
478            /// the user entered.
479            ///
480            /// @return The text at "Go To Page". The presenter won't free
481            ///         this pointer.
482            ///
483            virtual const gchar *getGoToPageText (void) = 0;
484
485            ///
486            /// @brief Gets the find's view.
487            ///
488            /// When the main view is created it also creates the find
489            /// view, although hidden.
490            ///
491            /// This view is then retrieved by the MainPter when the
492            /// find bar must be shown, and is passed to the FindPter
493            /// that will control it.
494            ///
495            /// @return The find's view. The returned pointer will be
496            ///         freed by the main view.
497            virtual IFindView *getFindView (void) = 0;
498
499            ///
500            /// @brief Gets the page's view.
501            ///
502            /// When the main view is created besides creating all its
503            /// controls, it creates the page view because.
504            ///
505            /// This created view is then retrieved by the soon-to-be-presenter
506            /// class when it is created. This way the presenter knows nothing
507            /// about how to create the view (i.e., toolkit agnostic.)
508            ///
509            /// @return The page's view. The returned pointer will be freed
510            ///         by the main view.
511            ///
512            virtual IPageView *getPageView (void) = 0;
513
514            ///
515            /// @brief Gets the preferences' view.
516            ///
517            /// The preferences view is created each time the presenter
518            /// calls this function, with the main view as its parent window.
519            ///
520            /// @return The new preferences view. The returned pointer
521            ///         must be freed by the caller.
522            ///
523            virtual IPreferencesView *getPreferencesView (void) = 0;
524
525#if defined (HAVE_CUPS)
526            ///
527            /// @brief Gets the print's view.
528            ///
529            /// The print view is created each time the presenter
530            /// class this function, with the main view as its parent window.
531            ///
532            /// @return The new print view. The returned pointer must be
533            ///         freed by the caller.
534            ///
535            virtual IPrintView *getPrintView (void) = 0;
536#endif // HAVE_CUPS
537
538            ///
539            /// @brief Gets the text from the zoom entry.
540            ///
541            /// Gets the text inside the "Current Zoom" entry on the
542            /// tool bar.
543            ///
544            /// @return The text inside the "Current Zoom" entry.
545            ///
546            virtual const gchar *getZoomText (void) = 0;
547
548            ///
549            /// @brief Sets the main view's title.
550            ///
551            /// This is called by the presenter when a new document has been
552            /// loaded. Normally it will put the document's file name or the
553            /// document's title (if it has).
554            ///
555            /// The view just has to set the window's title to @a title.
556            ///
557            /// @param title The title to set to the main window.
558            ///
559            virtual void setTitle (const gchar *title) = 0;
560
561            ///
562            /// @brief Sets the document's outline.
563            ///
564            /// The presenter will call this function regardless if the
565            /// sidebar is shown or not.
566            ///
567            /// The view must make a tree view from the document's outline
568            /// and show it when the sidebar is shown.
569            ///
570            /// Also, when one of these outlines is activated (the user
571            /// clicks on one of them) the view must pass the pointer to the
572            /// activated outline when calling MainPter::outlineActivated().
573            ///
574            /// @param outline The root outline to set. It can have no
575            ///                children.
576            ///
577            virtual void setOutline (DocumentOutline *outline) = 0;
578
579            virtual void copyTextToClibboard(const gchar* text) = 0;
580            virtual void activePageModeScroll (gboolean active) = 0;
581            virtual void activePageModeText (gboolean active) = 0;
582
583        protected:
584            ///
585            /// @brief Constructs a new main view.
586            ///
587            /// This constructor is keep protected because this class is an
588            /// interface (abstract class) that can't be instantiated.
589            ///
590            /// @param pter The main presenter that will drive the view.
591            ///
592            IMainView (MainPter *pter)
593            {
594                g_assert ( NULL != pter && "Tried to set a NULL presenter." );
595                m_Pter = pter;
596            }
597
598            /// The view's presenter.
599            MainPter *m_Pter;
600    };
601}
602
603#endif // !__IMAIN_VIEW_H__
Note: See TracBrowser for help on using the browser.