* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Cody Russell <crussell@canonical.com>
* Alexander Larsson <alexl@redhat.com>
#include "config.h"
#include "gtkoffscreenwindow.h"
-
-#include "gtksizerequest.h"
+#include "gtkwidgetprivate.h"
+#include "gtkcontainerprivate.h"
+#include "gtkprivate.h"
/**
* SECTION:gtkoffscreenwindow
G_DEFINE_TYPE (GtkOffscreenWindow, gtk_offscreen_window, GTK_TYPE_WINDOW);
static void
-gtk_offscreen_window_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
+gtk_offscreen_window_get_preferred_width (GtkWidget *widget,
+ gint *minimum,
+ gint *natural)
{
GtkBin *bin = GTK_BIN (widget);
GtkWidget *child;
gint border_width;
- gint default_width, default_height;
+ gint default_width;
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
- requisition->width = border_width * 2;
- requisition->height = border_width * 2;
+ *minimum = border_width * 2;
+ *natural = border_width * 2;
child = gtk_bin_get_child (bin);
if (child != NULL && gtk_widget_get_visible (child))
{
- GtkRequisition child_req;
+ gint child_min, child_nat;
- gtk_size_request_get_size (GTK_SIZE_REQUEST (child),
- &child_req, NULL);
+ gtk_widget_get_preferred_width (child, &child_min, &child_nat);
- requisition->width += child_req.width;
- requisition->height += child_req.height;
+ *minimum += child_min;
+ *natural += child_nat;
}
gtk_window_get_default_size (GTK_WINDOW (widget),
- &default_width, &default_height);
- if (default_width > 0)
- requisition->width = default_width;
+ &default_width, NULL);
- if (default_height > 0)
- requisition->height = default_height;
+ *minimum = MAX (*minimum, default_width);
+ *natural = MAX (*natural, default_width);
+}
+
+static void
+gtk_offscreen_window_get_preferred_height (GtkWidget *widget,
+ gint *minimum,
+ gint *natural)
+{
+ GtkBin *bin = GTK_BIN (widget);
+ GtkWidget *child;
+ gint border_width;
+ gint default_height;
+
+ border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
+
+ *minimum = border_width * 2;
+ *natural = border_width * 2;
+
+ child = gtk_bin_get_child (bin);
+
+ if (child != NULL && gtk_widget_get_visible (child))
+ {
+ gint child_min, child_nat;
+
+ gtk_widget_get_preferred_height (child, &child_min, &child_nat);
+
+ *minimum += child_min;
+ *natural += child_nat;
+ }
+
+ gtk_window_get_default_size (GTK_WINDOW (widget),
+ NULL, &default_height);
+
+ *minimum = MAX (*minimum, default_height);
+ *natural = MAX (*natural, default_height);
}
static void
GdkWindow *window;
GdkWindowAttr attributes;
gint attributes_mask;
- gint border_width;
bin = GTK_BIN (widget);
gtk_widget_set_realized (widget, TRUE);
- border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
-
gtk_widget_get_allocation (widget, &allocation);
attributes.x = allocation.x;
window = gdk_window_new (gtk_widget_get_parent_window (widget),
&attributes, attributes_mask);
gtk_widget_set_window (widget, window);
- gdk_window_set_user_data (window, widget);
+ gtk_widget_register_window (widget, window);
child = gtk_bin_get_child (bin);
if (child)
gtk_widget_set_parent_window (child, window);
- gtk_widget_style_attach (widget);
- gtk_style_set_background (gtk_widget_get_style (widget),
- window, GTK_STATE_NORMAL);
+ gtk_style_context_set_background (gtk_widget_get_style_context (widget),
+ window);
}
static void
GtkAllocation allocation = { 0, 0 };
GtkRequisition requisition;
- gtk_size_request_get_size (GTK_SIZE_REQUEST (widget),
- &requisition, NULL);
+ gtk_widget_get_preferred_size (widget, &requisition, NULL);
allocation.width = requisition.width;
allocation.height = requisition.height;
gtk_offscreen_window_show (GtkWidget *widget)
{
gboolean need_resize;
- GtkContainer *container;
- GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
+ _gtk_widget_set_visible_flag (widget, TRUE);
- container = GTK_CONTAINER (widget);
- need_resize = _gtk_container_get_need_resize (container) || !gtk_widget_get_realized (widget);
- _gtk_container_set_need_resize (container, FALSE);
+ need_resize = _gtk_widget_get_alloc_needed (widget) || !gtk_widget_get_realized (widget);
if (need_resize)
gtk_offscreen_window_resize (widget);
static void
gtk_offscreen_window_hide (GtkWidget *widget)
{
- GTK_WIDGET_UNSET_FLAGS (widget, GTK_VISIBLE);
+ _gtk_widget_set_visible_flag (widget, FALSE);
gtk_widget_unmap (widget);
}
widget_class->realize = gtk_offscreen_window_realize;
widget_class->show = gtk_offscreen_window_show;
widget_class->hide = gtk_offscreen_window_hide;
- widget_class->size_request = gtk_offscreen_window_size_request;
+ widget_class->get_preferred_width = gtk_offscreen_window_get_preferred_width;
+ widget_class->get_preferred_height = gtk_offscreen_window_get_preferred_height;
widget_class->size_allocate = gtk_offscreen_window_size_allocate;
container_class->check_resize = gtk_offscreen_window_check_resize;
if (surface != NULL)
{
- pixbuf = gdk_pixbuf_get_from_surface (NULL, surface,
- 0, 0, 0, 0,
+ pixbuf = gdk_pixbuf_get_from_surface (surface,
+ 0, 0,
gdk_window_get_width (window),
gdk_window_get_height (window));
}