summaryrefslogtreecommitdiffstats
path: root/app/gtk_util.cc
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-10 18:32:14 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-10 18:32:14 +0000
commit6e64343accab0d5b5436645e40a36f5ff20d17ec (patch)
treecbf33d783e15f8fcd27bd1c27b79046fac0fb4be /app/gtk_util.cc
parentede729d4d7a1e6a1dc07d58e0fff2ca5cc6e7131 (diff)
downloadchromium_src-6e64343accab0d5b5436645e40a36f5ff20d17ec.zip
chromium_src-6e64343accab0d5b5436645e40a36f5ff20d17ec.tar.gz
chromium_src-6e64343accab0d5b5436645e40a36f5ff20d17ec.tar.bz2
Final removal of the bad dependency of chrome/common on chrome/browser
Also convert app/gtk_dnd_util.h from a class to a namespace for consistency with added app/gtk_util.h. TEST=none BUG=none Review URL: http://codereview.chromium.org/669268 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41177 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/gtk_util.cc')
-rw-r--r--app/gtk_util.cc66
1 files changed, 66 insertions, 0 deletions
diff --git a/app/gtk_util.cc b/app/gtk_util.cc
new file mode 100644
index 0000000..b2aab1a
--- /dev/null
+++ b/app/gtk_util.cc
@@ -0,0 +1,66 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "app/gtk_util.h"
+
+#include <gtk/gtk.h>
+
+#include "app/l10n_util.h"
+#include "base/linux_util.h"
+#include "base/logging.h"
+#include "base/string_util.h"
+
+namespace gtk_util {
+
+void GetWidgetSizeFromResources(
+ GtkWidget* widget, int width_chars, int height_lines,
+ int* width, int* height) {
+ DCHECK(GTK_WIDGET_REALIZED(widget))
+ << " widget must be realized to compute font metrics correctly";
+
+ double chars = 0;
+ if (width)
+ StringToDouble(l10n_util::GetStringUTF8(width_chars), &chars);
+
+ double lines = 0;
+ if (height)
+ StringToDouble(l10n_util::GetStringUTF8(height_lines), &lines);
+
+ GetWidgetSizeFromCharacters(widget, chars, lines, width, height);
+}
+
+void GetWidgetSizeFromCharacters(
+ GtkWidget* widget, double width_chars, double height_lines,
+ int* width, int* height) {
+ DCHECK(GTK_WIDGET_REALIZED(widget))
+ << " widget must be realized to compute font metrics correctly";
+ PangoContext* context = gtk_widget_create_pango_context(widget);
+ PangoFontMetrics* metrics = pango_context_get_metrics(context,
+ widget->style->font_desc, pango_context_get_language(context));
+ if (width) {
+ *width = static_cast<int>(
+ pango_font_metrics_get_approximate_char_width(metrics) *
+ width_chars / PANGO_SCALE);
+ }
+ if (height) {
+ *height = static_cast<int>(
+ (pango_font_metrics_get_ascent(metrics) +
+ pango_font_metrics_get_descent(metrics)) *
+ height_lines / PANGO_SCALE);
+ }
+ pango_font_metrics_unref(metrics);
+ g_object_unref(context);
+}
+
+void ApplyMessageDialogQuirks(GtkWidget* dialog) {
+ if (gtk_window_get_modal(GTK_WINDOW(dialog))) {
+ // Work around a KDE 3 window manager bug.
+ scoped_ptr<base::EnvironmentVariableGetter> env(
+ base::EnvironmentVariableGetter::Create());
+ if (base::DESKTOP_ENVIRONMENT_KDE3 == GetDesktopEnvironment(env.get()))
+ gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), FALSE);
+ }
+}
+
+} // namespace gtk_util