2 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com
3 * Copyright (C) 2007 Holger Hans Peter Freyther
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "FrameView.h"
33 #include "GraphicsContext.h"
34 #include "HostWindow.h"
36 #include "NotImplemented.h"
37 #include "RenderObject.h"
44 static GdkCursor* lastSetCursor;
46 Widget::Widget(PlatformWidget widget)
54 releasePlatformWidget();
57 void Widget::setFocus()
59 gtk_widget_grab_focus(platformWidget() ? platformWidget() : GTK_WIDGET(root()->hostWindow()->platformWindow()));
62 static GdkDrawable* gdkDrawable(PlatformWidget widget)
64 return widget ? widget->window : 0;
67 void Widget::setCursor(const Cursor& cursor)
69 GdkCursor* platformCursor = cursor.impl();
71 // http://bugs.webkit.org/show_bug.cgi?id=16388
72 // [GTK] Widget::setCursor() gets called frequently
74 // gdk_window_set_cursor() in certain GDK backends seems to be an
75 // expensive operation, so avoid it if possible.
77 if (platformCursor == lastSetCursor)
80 gdk_window_set_cursor(gdkDrawable(platformWidget()) ? GDK_WINDOW(gdkDrawable(platformWidget())) : GTK_WIDGET(root()->hostWindow()->platformWindow())->window, platformCursor);
81 lastSetCursor = platformCursor;
86 if (!platformWidget())
88 gtk_widget_show(platformWidget());
93 if (!platformWidget())
95 gtk_widget_hide(platformWidget());
99 * Strategy to painting a Widget:
100 * 1.) do not paint if there is no GtkWidget set
101 * 2.) We assume that GTK_NO_WINDOW is set and that frameRectsChanged positioned
102 * the widget correctly. ATM we do not honor the GraphicsContext translation.
104 void Widget::paint(GraphicsContext* context, const IntRect&)
106 if (!platformWidget())
109 if (!context->gdkExposeEvent())
112 GtkWidget* widget = platformWidget();
113 ASSERT(GTK_WIDGET_NO_WINDOW(widget));
115 GdkEvent* event = gdk_event_new(GDK_EXPOSE);
116 event->expose = *context->gdkExposeEvent();
117 event->expose.region = gtk_widget_region_intersect(widget, event->expose.region);
120 * This will be unref'ed by gdk_event_free.
122 g_object_ref(event->expose.window);
125 * If we are going to paint do the translation and GtkAllocation manipulation.
127 if (!gdk_region_empty(event->expose.region)) {
128 gdk_region_get_clipbox(event->expose.region, &event->expose.area);
129 gtk_widget_send_expose(widget, event);
132 gdk_event_free(event);
135 void Widget::setIsSelected(bool)
140 IntRect Widget::frameRect() const
145 void Widget::setFrameRect(const IntRect& rect)
150 void Widget::releasePlatformWidget()
152 if (!platformWidget())
154 g_object_unref(platformWidget());
157 void Widget::retainPlatformWidget()
159 if (!platformWidget())
161 #if GLIB_CHECK_VERSION(2,10,0)
162 g_object_ref_sink(platformWidget());
164 g_object_ref(platformWidget());
165 gtk_object_sink(GTK_OBJECT(platformWidget()));