Changeset 201

Show
Ignore:
Timestamp:
06/05/06 11:16:50 (2 years ago)
Author:
jordi
Message:

The main window now shows the current zoom level on the tool bar and is manipulable, so a custom zoom level can be specified (inside the 400%-5.12% margins.)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/IDocument.cxx

    r200 r201  
    12451245IDocument::setZoom (gdouble zoom) 
    12461246{ 
    1247     if ( ABS (zoom - m_Scale) > 0.00001 )     
     1247    if ( ABS (zoom - m_Scale) > 0.00001 ) 
    12481248    { 
    12491249        G_LOCK (JobRender); 
    1250         m_Scale = zoom
     1250        m_Scale = CLAMP (zoom, ZOOM_OUT_MAX, ZOOM_IN_MAX)
    12511251        refreshCache (); 
    12521252        G_UNLOCK (JobRender); 
  • trunk/src/IMainView.h

    r200 r201  
    267267 
    268268            /// 
     269            /// @brief Changes the sensitivity of the "Zoom" entry. 
     270            /// 
     271            /// The view must change the sensitivity (it's called enabled or 
     272            /// disabled on some toolkits) of the "Zoom" entry 
     273            /// on the toolbar. 
     274            /// 
     275            /// @param sensitive Set to TRUE if need to make sensitive (enable) 
     276            ///                  the entry or FALSE to insensitive (disable) it. 
     277            /// 
     278            virtual void sensitiveZoom (gboolean sensitive) = 0; 
     279 
     280            /// 
    269281            /// @brief Changes the sensitivity of the "Zoom In" action. 
    270282            /// 
     
    338350            /// 
    339351            virtual void setStatusBarText (const gchar *text) = 0; 
     352 
     353            /// 
     354            /// @brief Sets the current zoom text. 
     355            /// 
     356            /// The current zoom text is displayed on the tool bar and 
     357            /// the user can change it in order to specify a concrete 
     358            /// zoom level. 
     359            /// 
     360            /// @param text The text to show in the current zoom entry. 
     361            /// 
     362            virtual void setZoomText (const gchar *text) = 0; 
    340363 
    341364            /// 
     
    472495            /// 
    473496            virtual IPreferencesView *getPreferencesView (void) = 0; 
     497 
     498            /// 
     499            /// @brief Gets the text from the zoom entry. 
     500            /// 
     501            /// Gets the text inside the "Current Zoom" entry on the 
     502            /// tool bar. 
     503            /// 
     504            /// @return The text inside the "Current Zoom" entry. 
     505            /// 
     506            virtual const gchar *getZoomText (void) = 0; 
    474507 
    475508            /// 
  • trunk/src/MainPter.cxx

    r200 r201  
    118118            view.setTitle (m_Document->getTitle ()); 
    119119        } 
     120        setZoomText (m_Document->getZoom ()); 
    120121        view.sensitiveFind (TRUE); 
    121122        view.sensitiveGoToPage (TRUE); 
     
    124125        view.sensitiveRotateLeft (TRUE); 
    125126        view.sensitiveSave (TRUE); 
     127        view.sensitiveZoom (TRUE); 
    126128        view.sensitiveZoomIn (TRUE); 
    127129        view.sensitiveZoomOut (TRUE); 
     
    142144    { 
    143145        view.setTitle (_("PDF Viewer")); 
     146        setZoomText (1.0); 
    144147        view.sensitiveFind (FALSE); 
    145148        view.sensitiveGoToFirstPage (FALSE); 
     
    152155        view.sensitiveRotateLeft (FALSE); 
    153156        view.sensitiveSave (FALSE); 
     157        view.sensitiveZoom (FALSE); 
    154158        view.sensitiveZoomIn (FALSE); 
    155159        view.sensitiveZoomOut (FALSE); 
     
    191195{ 
    192196    // Insensitive the open, reload, page navigation, zoom and rotate. 
     197    setZoomText (1.0); 
    193198    IMainView &view = getView (); 
    194199    view.sensitiveFind (FALSE); 
     
    202207    view.sensitiveRotateLeft (FALSE); 
    203208    view.sensitiveSave (FALSE); 
     209    view.sensitiveZoom (FALSE); 
    204210    view.sensitiveZoomIn (FALSE); 
    205211    view.sensitiveZoomOut (FALSE); 
     
    223229    // Set the number of times we can try the password. 
    224230    m_PasswordTries = 3; 
     231} 
     232 
     233/// 
     234/// @brief Tells the view which text to show in the zoom entry. 
     235/// 
     236/// @param zoom The current document's zoom value. 
     237/// 
     238void 
     239MainPter::setZoomText (gdouble zoom) 
     240{ 
     241    gchar *zoomText = g_strdup_printf ("%.3g%%", zoom * 100.0); 
     242    getView ().setZoomText (zoomText); 
     243    g_free (zoomText); 
    225244} 
    226245 
     
    541560 
    542561/// 
     562/// @brief The user entered a zoom value. 
     563/// 
     564void 
     565MainPter::zoomActivated () 
     566{ 
     567    IMainView &view = getView (); 
     568    const gchar *zoomText = view.getZoomText (); 
     569    if ( NULL != zoomText ) 
     570    { 
     571        Config &config = Config::getConfig (); 
     572        config.setZoomToFit (FALSE); 
     573        config.setZoomToWidth (FALSE); 
     574 
     575        view.activeZoomFit (FALSE); 
     576        view.activeZoomWidth (FALSE); 
     577 
     578        gdouble zoom = atof (zoomText); 
     579        m_Document->setZoom (zoom / 100.0); 
     580    } 
     581} 
     582 
     583/// 
    543584/// @brief Performs the "Zoom Fit Best". 
    544585/// 
     
    591632    view.activeZoomFit (FALSE); 
    592633    view.activeZoomWidth (FALSE); 
    593      
     634 
    594635    m_Document->zoomIn (); 
    595636} 
     
    784825{ 
    785826    IMainView &view = getView (); 
     827    // Show the new zoom. 
     828    setZoomText (zoom); 
    786829    // Set the zoom sensitivity. 
    787830    view.sensitiveZoomIn (m_Document->canZoomIn ()); 
  • trunk/src/MainPter.h

    r200 r201  
    6464            void showStatusbarActivated (gboolean show); 
    6565            void showToolbarActivated (gboolean show); 
     66            void zoomActivated (void); 
    6667            void zoomFitActivated (gboolean active); 
    6768            void zoomInActivated (void); 
     
    9798 
    9899            void checkZoomSettings (void); 
     100            void setZoomText (gdouble zoom); 
    99101            void zoomFit (void); 
    100102            void zoomWidth (void); 
  • trunk/src/gtk/MainView.cxx

    r200 r201  
    3232// Constants. 
    3333static gint CURRENT_PAGE_POS = 5; 
     34static gint CURRENT_PAGE_WIDTH = 14; 
     35static gint CURRENT_ZOOM_POS = 8; 
     36static gint CURRENT_ZOOM_WIDTH = 7; 
    3437 
    3538// Enumerations. 
     
    6366static void main_window_show_statusbar_cb (GtkToggleAction *, gpointer); 
    6467static void main_window_show_toolbar_cb (GtkToggleAction *, gpointer); 
     68static void main_window_zoom_cb (GtkWidget *, gpointer); 
    6569static void main_window_zoom_fit_cb (GtkToggleAction *, gpointer); 
    6670static void main_window_zoom_in_cb (GtkWidget *, gpointer); 
     
    201205                        CURRENT_PAGE_POS); 
    202206    gtk_widget_show_all (GTK_WIDGET (m_CurrentPageToolItem)); 
    203     gtk_toolbar_insert (GTK_TOOLBAR (toolBar), gtk_separator_tool_item_new (), 
    204                         CURRENT_PAGE_POS + 1); 
     207    GtkToolItem *separator = gtk_separator_tool_item_new (); 
     208    gtk_toolbar_insert (GTK_TOOLBAR (toolBar), separator, CURRENT_PAGE_POS + 1); 
     209    gtk_widget_show_all (GTK_WIDGET (separator)); 
     210    // Add the current zoom item. 
     211    createCurrentZoom (); 
     212    gtk_toolbar_insert (GTK_TOOLBAR (toolBar), m_CurrentZoomToolItem, 
     213                        CURRENT_ZOOM_POS); 
     214    gtk_widget_show_all (GTK_WIDGET (m_CurrentZoomToolItem)); 
    205215    // Create the page view 
    206216    GtkWidget *pageViewPaned = createPageView (); 
     
    484494 
    485495void 
     496MainView::sensitiveZoom (gboolean sensitive) 
     497{ 
     498    gtk_widget_set_sensitive (m_CurrentZoom, sensitive); 
     499} 
     500 
     501void 
    486502MainView::sensitiveZoomIn (gboolean sensitive) 
    487503{ 
     
    604620} 
    605621 
     622const gchar * 
     623MainView::getZoomText (void) 
     624{ 
     625    return gtk_entry_get_text (GTK_ENTRY (m_CurrentZoom)); 
     626} 
     627 
    606628void 
    607629MainView::setStatusBarText (const gchar *text) 
     
    614636        gtk_statusbar_push (GTK_STATUSBAR (m_StatusBar), contextId, text); 
    615637    } 
     638} 
     639 
     640void 
     641MainView::setZoomText (const gchar *text) 
     642{ 
     643    gtk_entry_set_text (GTK_ENTRY (m_CurrentZoom), text); 
    616644} 
    617645 
     
    692720/// @brief Creates the "Current Page" widget that will be displayed on toolbar. 
    693721/// 
    694 /// @return The tool item to add to the toolbar. 
    695 /// 
    696722void 
    697723MainView::createCurrentPage () 
     
    705731    gtk_entry_set_text (GTK_ENTRY (m_CurrentPage), _("0 of 0")); 
    706732    gtk_entry_set_alignment (GTK_ENTRY (m_CurrentPage), 1.0f); 
     733    gtk_entry_set_width_chars (GTK_ENTRY (m_CurrentPage), CURRENT_PAGE_WIDTH); 
    707734    g_signal_connect (G_OBJECT (m_CurrentPage), "activate", 
    708735                      G_CALLBACK (main_window_go_to_page_cb), m_Pter); 
     
    711738    m_CurrentPageToolItem = gtk_tool_item_new (); 
    712739    gtk_container_add (GTK_CONTAINER (m_CurrentPageToolItem), hbox); 
     740} 
     741 
     742 
     743/// 
     744/// @brief Creates the "Current Zoom" widget that will be displayed on toolbar. 
     745/// 
     746void 
     747MainView::createCurrentZoom () 
     748{ 
     749    m_CurrentZoom = gtk_entry_new (); 
     750    gtk_entry_set_alignment (GTK_ENTRY (m_CurrentZoom), 1.0f); 
     751    gtk_entry_set_width_chars (GTK_ENTRY (m_CurrentZoom), CURRENT_ZOOM_WIDTH); 
     752    g_signal_connect (G_OBJECT (m_CurrentZoom), "activate", 
     753                      G_CALLBACK (main_window_zoom_cb), m_Pter); 
     754 
     755    m_CurrentZoomToolItem = gtk_tool_item_new (); 
     756    gtk_container_add (GTK_CONTAINER (m_CurrentZoomToolItem), m_CurrentZoom); 
    713757} 
    714758 
     
    800844 
    801845    GError *error = NULL; 
    802     if ( !gtk_ui_manager_add_ui_from_file (m_UIManager,  
    803                                            DATADIR"/ui/epdfview-ui.xml",  
     846    if ( !gtk_ui_manager_add_ui_from_file (m_UIManager, 
     847                                           DATADIR"/ui/epdfview-ui.xml", 
    804848                                           &error) ) 
    805849    { 
     
    11691213 
    11701214/// 
     1215/// @brief The user tries to set a zoom. 
     1216/// 
     1217void 
     1218main_window_zoom_cb (GtkWidget *widget, gpointer data) 
     1219{ 
     1220    g_assert ( NULL != data && "The data parameter is NULL."); 
     1221 
     1222    MainPter *pter = (MainPter *)data; 
     1223    pter->zoomActivated (); 
     1224} 
     1225 
     1226/// 
    11711227/// @brief The user tries to fit the document into the window. 
    11721228/// 
  • trunk/src/gtk/MainView.h

    r200 r201  
    5050            void sensitiveRotateRight (gboolean sensitive); 
    5151            void sensitiveSave (gboolean sensitive); 
     52            void sensitiveZoom (gboolean sensitive); 
    5253            void sensitiveZoomIn (gboolean sensitive); 
    5354            void sensitiveZoomOut (gboolean sensitive); 
     
    6162            void setGoToPageText (const gchar *text); 
    6263            void setStatusBarText (const gchar *text); 
     64            void setZoomText (const gchar *text); 
    6365            const gchar *getGoToPageText (void); 
    6466            IFindView *getFindView (void); 
    6567            IPageView *getPageView (void); 
    6668            IPreferencesView *getPreferencesView (void); 
     69            const gchar *getZoomText (void); 
    6770            void setTitle (const gchar *title); 
    6871            void setOutline (DocumentOutline *outline); 
     
    7376            GtkWidget *m_CurrentPage; 
    7477            GtkToolItem *m_CurrentPageToolItem; 
     78            GtkWidget *m_CurrentZoom; 
     79            GtkToolItem *m_CurrentZoomToolItem; 
    7580            FindView *m_FindView; 
    76             GtkWidget *m_MainWindow;  
     81            GtkWidget *m_MainWindow; 
    7782            GtkWidget *m_MainBox; 
    7883            GtkTreeStore *m_Outline; 
     
    8590 
    8691            void createCurrentPage (void); 
     92            void createCurrentZoom (void); 
    8793            GtkWidget *createPageView (void); 
    8894            void createUIManager (void);