| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/fonts_languages_window.h" | |
| 6 | |
| 7 #include <gtk/gtk.h> | |
| 8 | |
| 9 #include "base/message_loop.h" | |
| 10 #include "chrome/browser/profiles/profile.h" | |
| 11 #include "chrome/browser/ui/gtk/gtk_util.h" | |
| 12 #include "chrome/browser/ui/gtk/options/fonts_page_gtk.h" | |
| 13 #include "chrome/browser/ui/gtk/options/languages_page_gtk.h" | |
| 14 #include "grit/chromium_strings.h" | |
| 15 #include "grit/generated_resources.h" | |
| 16 #include "ui/base/l10n/l10n_util.h" | |
| 17 | |
| 18 /////////////////////////////////////////////////////////////////////////////// | |
| 19 // FontsLanguagesWindowGtk | |
| 20 // | |
| 21 // The contents of the Options dialog window. | |
| 22 | |
| 23 class FontsLanguagesWindowGtk { | |
| 24 public: | |
| 25 explicit FontsLanguagesWindowGtk(Profile* profile); | |
| 26 ~FontsLanguagesWindowGtk(); | |
| 27 | |
| 28 // Shows the tab corresponding to the specified |page|. | |
| 29 void ShowTabPage(gfx::NativeWindow window, FontsLanguagesPage page); | |
| 30 | |
| 31 private: | |
| 32 static void OnWindowDestroy(GtkWidget* widget, | |
| 33 FontsLanguagesWindowGtk* window); | |
| 34 | |
| 35 // The fonts and languages dialog. | |
| 36 GtkWidget *dialog_; | |
| 37 | |
| 38 // The container of the option pages. | |
| 39 GtkWidget *notebook_; | |
| 40 | |
| 41 // The Profile associated with these options. | |
| 42 Profile* profile_; | |
| 43 | |
| 44 // The fonts page. | |
| 45 FontsPageGtk fonts_page_; | |
| 46 | |
| 47 // The languages page. | |
| 48 LanguagesPageGtk languages_page_; | |
| 49 | |
| 50 DISALLOW_COPY_AND_ASSIGN(FontsLanguagesWindowGtk); | |
| 51 }; | |
| 52 | |
| 53 static FontsLanguagesWindowGtk* instance_ = NULL; | |
| 54 | |
| 55 /////////////////////////////////////////////////////////////////////////////// | |
| 56 // FontsLanguagesWindowGtk, public: | |
| 57 | |
| 58 FontsLanguagesWindowGtk::FontsLanguagesWindowGtk(Profile* profile) | |
| 59 // Always show preferences for the original profile. Most state when off | |
| 60 // the record comes from the original profile, but we explicitly use | |
| 61 // the original profile to avoid potential problems. | |
| 62 : profile_(profile->GetOriginalProfile()), | |
| 63 fonts_page_(profile_), | |
| 64 languages_page_(profile_) { | |
| 65 dialog_ = gtk_dialog_new_with_buttons( | |
| 66 l10n_util::GetStringUTF8(IDS_FONT_LANGUAGE_SETTING_WINDOWS_TITLE).c_str(), | |
| 67 // Prefs window is shared between all browser windows. | |
| 68 NULL, | |
| 69 // Non-modal. | |
| 70 GTK_DIALOG_NO_SEPARATOR, | |
| 71 GTK_STOCK_CLOSE, | |
| 72 GTK_RESPONSE_CLOSE, | |
| 73 NULL); | |
| 74 | |
| 75 gtk_window_set_default_size(GTK_WINDOW(dialog_), 500, -1); | |
| 76 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox), | |
| 77 gtk_util::kContentAreaSpacing); | |
| 78 | |
| 79 notebook_ = gtk_notebook_new(); | |
| 80 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog_)->vbox), notebook_); | |
| 81 | |
| 82 // Fonts and Encoding tab. | |
| 83 gtk_notebook_append_page( | |
| 84 GTK_NOTEBOOK(notebook_), | |
| 85 fonts_page_.get_page_widget(), | |
| 86 gtk_label_new( | |
| 87 l10n_util::GetStringUTF8( | |
| 88 IDS_FONT_LANGUAGE_SETTING_FONT_TAB_TITLE).c_str())); | |
| 89 | |
| 90 // Langauges tab. | |
| 91 gtk_notebook_append_page( | |
| 92 GTK_NOTEBOOK(notebook_), | |
| 93 languages_page_.get_page_widget(), | |
| 94 gtk_label_new( | |
| 95 l10n_util::GetStringUTF8( | |
| 96 IDS_FONT_LANGUAGE_SETTING_LANGUAGES_TAB_TITLE).c_str())); | |
| 97 | |
| 98 // Show the notebook. | |
| 99 gtk_util::ShowDialogWithLocalizedSize(dialog_, -1, -1, false); | |
| 100 | |
| 101 // We only have one button and don't do any special handling, so just hook it | |
| 102 // directly to gtk_widget_destroy. | |
| 103 g_signal_connect_swapped(dialog_, "response", G_CALLBACK(gtk_widget_destroy), | |
| 104 dialog_); | |
| 105 | |
| 106 g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroy), this); | |
| 107 } | |
| 108 | |
| 109 FontsLanguagesWindowGtk::~FontsLanguagesWindowGtk() { | |
| 110 } | |
| 111 | |
| 112 void FontsLanguagesWindowGtk::ShowTabPage(gfx::NativeWindow window, | |
| 113 FontsLanguagesPage page) { | |
| 114 // Center our dialog over whoever displayed us. | |
| 115 gtk_util::CenterOverWindow(GTK_WINDOW(dialog_), window); | |
| 116 | |
| 117 // Bring options window to front if it already existed and isn't already | |
| 118 // in front. | |
| 119 gtk_util::PresentWindow(dialog_, 0); | |
| 120 | |
| 121 // If the page is out of bounds, reset to the first tab. | |
| 122 if (page < 0 || page >= gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook_))) | |
| 123 page = FONTS_ENCODING_PAGE; | |
| 124 | |
| 125 // Switch the tab to the selected |page|. | |
| 126 gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook_), page); | |
| 127 } | |
| 128 | |
| 129 /////////////////////////////////////////////////////////////////////////////// | |
| 130 // FontsLanguagesWindowGtk, private: | |
| 131 | |
| 132 // static | |
| 133 void FontsLanguagesWindowGtk::OnWindowDestroy(GtkWidget* widget, | |
| 134 FontsLanguagesWindowGtk* window) { | |
| 135 instance_ = NULL; | |
| 136 MessageLoop::current()->DeleteSoon(FROM_HERE, window); | |
| 137 } | |
| 138 | |
| 139 void ShowFontsLanguagesWindow(gfx::NativeWindow window, | |
| 140 FontsLanguagesPage page, | |
| 141 Profile* profile) { | |
| 142 DCHECK(profile); | |
| 143 // If there's already an existing fonts and language window, activate it and | |
| 144 // switch to the specified page. | |
| 145 if (!instance_) | |
| 146 instance_ = new FontsLanguagesWindowGtk(profile); | |
| 147 | |
| 148 instance_->ShowTabPage(window, page); | |
| 149 } | |
| OLD | NEW |