Show
Ignore:
Timestamp:
08/15/08 13:25:16 (5 months ago)
Author:
mbensi
Message:

merge with webkit revision 35774

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/BAL/WKAL/Concretizations/Widgets/Gtk/BCPlatformScreenGtk.cpp

    r243 r437  
    22 * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved. 
    33 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com 
     4 * Copyright (C) 2008 Christian Dywan <christian@imendio.com> 
     5 * Copyright (C) 2008 Collabora Ltd. 
    46 * All rights reserved. 
    57 * 
     
    3436#include <gtk/gtk.h> 
    3537 
     38#if defined(GDK_WINDOWING_X11) 
     39#include <gdk/gdkx.h> 
     40#include <X11/Xatom.h> 
     41#endif 
     42 
    3643namespace WKAL { 
    3744 
    3845int screenDepth(Widget* widget) 
    3946{ 
    40     ASSERT(widget->containingWindow() && GTK_WIDGET(widget->containingWindow())->window); 
     47    GtkWidget* container = GTK_WIDGET(widget->containingWindow()); 
     48    if (!container) 
     49        return 24; 
    4150 
    42     gint depth; 
    43     gdk_window_get_geometry(GTK_WIDGET(widget->containingWindow())->window, 0, 0, 0, 0, &depth); 
    44     return depth; 
     51    GdkVisual* visual = gdk_drawable_get_visual(GDK_DRAWABLE(GTK_WIDGET(widget->containingWindow())->window)); 
     52    return visual->depth; 
    4553} 
    4654 
    47 int screenDepthPerComponent(Widget*
     55int screenDepthPerComponent(Widget* widget
    4856{ 
    49     notImplemented(); 
    50     return 8; 
     57    GtkWidget* container = GTK_WIDGET(widget->containingWindow()); 
     58    if (!container) 
     59        return 8; 
     60 
     61    GdkVisual* visual = gdk_drawable_get_visual(GDK_DRAWABLE(GTK_WIDGET(widget->containingWindow())->window)); 
     62    return visual->bits_per_rgb; 
    5163} 
    5264 
    5365bool screenIsMonochrome(Widget* widget) 
    5466{ 
     67    GtkWidget* container = GTK_WIDGET(widget->containingWindow()); 
     68    if (!container) 
     69        return false; 
     70 
    5571    return screenDepth(widget) < 2; 
    5672} 
     
    5874FloatRect screenRect(Widget* widget) 
    5975{ 
    60     ASSERT(widget->containingWindow() && GTK_WIDGET(widget->containingWindow())->window); 
     76    GtkWidget* container = GTK_WIDGET(widget->containingWindow()); 
     77    if (!container) 
     78        return FloatRect(); 
    6179 
    62     GdkScreen* screen = gtk_widget_get_screen(GTK_WIDGET(widget->containingWindow())); 
    63     gint monitor = gdk_screen_get_monitor_at_window(screen, GTK_WIDGET(widget->containingWindow())->window); 
     80    GdkScreen* screen = gtk_widget_has_screen(container) ? gtk_widget_get_screen(container) : gdk_screen_get_default(); 
     81    if (!screen) 
     82        return FloatRect(); 
     83 
     84    gint monitor = gdk_screen_get_monitor_at_window(screen, GTK_WIDGET(container)->window); 
    6485    GdkRectangle geometry; 
    65  
    6686    gdk_screen_get_monitor_geometry(screen, monitor, &geometry); 
    6787     
     
    6989} 
    7090 
    71 FloatRect screenAvailableRect(Widget*
     91FloatRect screenAvailableRect(Widget* widget
    7292{ 
    73     notImplemented(); 
    74     return FloatRect(); 
     93#if defined(GDK_WINDOWING_X11) 
     94    GtkWidget* container = GTK_WIDGET(widget->containingWindow()); 
     95    if (!container) 
     96        return FloatRect(); 
     97 
     98    if (!GTK_WIDGET_REALIZED(container)) 
     99        return screenRect(widget); 
     100 
     101    GdkDrawable* rootWindow = GDK_DRAWABLE(gtk_widget_get_root_window(container)); 
     102    GdkDisplay* display = gdk_drawable_get_display(rootWindow); 
     103    Atom xproperty = gdk_x11_get_xatom_by_name_for_display(display, "_NET_WORKAREA"); 
     104 
     105    Atom retType; 
     106    int retFormat; 
     107    long *workAreaPos = NULL; 
     108    unsigned long retNItems; 
     109    unsigned long retAfter; 
     110    int xRes = XGetWindowProperty(GDK_DISPLAY_XDISPLAY(display), GDK_WINDOW_XWINDOW(rootWindow), xproperty, 
     111        0, 4, FALSE, XA_CARDINAL, &retType, &retFormat, &retNItems, &retAfter, (guchar**)&workAreaPos); 
     112 
     113    FloatRect rect; 
     114    if (xRes == Success && workAreaPos != NULL && retType == XA_CARDINAL && retNItems == 4 && retFormat == 32) { 
     115        rect = FloatRect(workAreaPos[0], workAreaPos[1], workAreaPos[2], workAreaPos[3]); 
     116        // rect contains the available space in the whole screen not just in the monitor 
     117        // containing the widget, so we intersect it with the monitor rectangle. 
     118        rect.intersect(screenRect(widget)); 
     119    } else 
     120        rect = screenRect(widget); 
     121 
     122    if (workAreaPos) 
     123        XFree(workAreaPos); 
     124 
     125    return rect; 
     126#else 
     127    return screenRect(widget); 
     128#endif 
    75129} 
    76130