* make maemo work even with the new libhildon (1.1)
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Fri, 27 Apr 2007 15:23:09 +0000 (15:23 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Fri, 27 Apr 2007 15:23:09 +0000 (15:23 +0000)
pmo-trunk-r1699

src/maemo/Makefile.am
src/maemo/modest-msg-edit-window.c
src/maemo/modest-scroll-area.c [new file with mode: 0644]
src/maemo/modest-scroll-area.h [new file with mode: 0644]

index 50c1bc4..d645887 100644 (file)
@@ -53,6 +53,8 @@ libmodest_ui_la_SOURCES=              \
        modest-platform.c             \
        modest-signature-editor-dialog.c         \
        modest-signature-editor-dialog.h         \
+       modest-scroll-area.h          \
+       modest-scroll-area.c          \
        modest-store-widget.c         \
        modest-store-widget.h         \
        modest-transport-widget.c     \
index d4b4adb..70d6325 100644 (file)
 #include <tny-simple-list.h>
 #include <wptextview.h>
 #include <wptextbuffer.h>
+#include "modest-scroll-area.h"
+
+#ifdef MODEST_HILDON_VERSION_0
 #include <hildon-widgets/hildon-color-selector.h>
 #include <hildon-widgets/hildon-color-button.h>
 #include <hildon-widgets/hildon-banner.h>
 #include <hildon-widgets/hildon-caption.h>
 #include <hildon-widgets/hildon-note.h>
-#include <hildon-widgets/hildon-scroll-area.h>
+#include <hildon-widgets/hildon-file-chooser-dialog.h>
 #include <hildon-widgets/hildon-font-selection-dialog.h>
+#else
+#include <hildon/hildon-file-chooser-dialog.h>
+#include <hildon/hildon-color-chooser.h>
+#include <hildon/hildon-banner.h>
+#include <hildon/hildon-color-button.h>
+#include <hildon/hildon-note.h>
+#include <hildon/hildon-color-button.h>
+#include <hildon/hildon-font-selection-dialog.h>
+#include <hildon/hildon-caption.h>
+#endif /* MODEST_HILDON_VERSION_0*/
+
+
 #include "widgets/modest-msg-edit-window-ui.h"
 
 #ifdef MODEST_HILDON_VERSION_0
-#include <hildon-widgets/hildon-file-chooser-dialog.h>
 #else
-#include <hildon/hildon-file-chooser-dialog.h>
 
 #endif /*MODEST_HILDON_VERSION_0 */
 
@@ -431,7 +444,7 @@ init_window (ModestMsgEditWindow *obj)
                gtk_widget_hide (priv->bcc_field);
 
        gtk_container_add (GTK_CONTAINER(obj), priv->scroll);
-       scroll_area = hildon_scroll_area_new (priv->scroll, priv->msg_body);
+       scroll_area = modest_scroll_area_new (priv->scroll, priv->msg_body);
        gtk_container_add (GTK_CONTAINER (frame), scroll_area);
        gtk_container_set_focus_vadjustment (GTK_CONTAINER (scroll_area), 
                                             gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->scroll)));
@@ -1136,6 +1149,7 @@ text_buffer_refresh_attributes (WPTextBuffer *buffer, ModestMsgEditWindow *windo
 
 }
 
+
 void
 modest_msg_edit_window_select_color (ModestMsgEditWindow *window)
 {
@@ -1144,20 +1158,32 @@ modest_msg_edit_window_select_color (ModestMsgEditWindow *window)
        ModestMsgEditWindowPrivate *priv;
        GtkWidget *dialog = NULL;
        gint response;
-       const GdkColor *new_color = NULL;
+       GdkColor *new_color = NULL;
        
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
        wp_text_buffer_get_attributes (WP_TEXT_BUFFER (priv->text_buffer), buffer_format, FALSE);
        
+#ifdef MODEST_HILDON_VERSION_0 
        dialog = hildon_color_selector_new (GTK_WINDOW (window));
-       hildon_color_selector_set_color (HILDON_COLOR_SELECTOR (dialog), & (buffer_format->color));
+       hildon_color_selector_set_color (HILDON_COLOR_SELECTOR (dialog), &(buffer_format->color));
+#else
+       dialog = hildon_color_chooser_new ();
+       hildon_color_chooser_set_color (HILDON_COLOR_CHOOSER (dialog), &(buffer_format->color));
+#endif /*MODEST_HILDON_VERSION_9*/             
        g_free (buffer_format);
 
        response = gtk_dialog_run (GTK_DIALOG (dialog));
        switch (response) {
-       case GTK_RESPONSE_OK:
+       case GTK_RESPONSE_OK: {
+#ifdef MODEST_HILDON_VERSION_0
                new_color = hildon_color_selector_get_color (HILDON_COLOR_SELECTOR (dialog));
-               break;
+#else
+               GdkColor col;
+               hildon_color_chooser_get_color (HILDON_COLOR_CHOOSER(dialog), &col);
+               new_color = &col;
+       }
+#endif /*MODEST_HILDON_VERSION_0*/
+       break;
        default:
                break;
        }
@@ -1175,19 +1201,31 @@ modest_msg_edit_window_select_background_color (ModestMsgEditWindow *window)
        ModestMsgEditWindowPrivate *priv;
        GtkWidget *dialog = NULL;
        gint response;
-       const GdkColor *old_color = NULL;
-       const GdkColor *new_color = NULL;
+       GdkColor *old_color = NULL;
+       GdkColor *new_color = NULL;
        
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
-       old_color = wp_text_buffer_get_background_color (WP_TEXT_BUFFER (priv->text_buffer));
+       old_color = (GdkColor*)wp_text_buffer_get_background_color (WP_TEXT_BUFFER (priv->text_buffer));
        
+#ifdef MODEST_HILDON_VERSION_0 
        dialog = hildon_color_selector_new (GTK_WINDOW (window));
-       hildon_color_selector_set_color (HILDON_COLOR_SELECTOR (dialog), (GdkColor *) old_color);
+       hildon_color_selector_set_color (HILDON_COLOR_SELECTOR (dialog),(GdkColor*)old_color);
+#else
+       dialog = hildon_color_chooser_new ();
+       hildon_color_chooser_set_color (HILDON_COLOR_CHOOSER (dialog),(GdkColor*)old_color);
+#endif /*MODEST_HILDON_VERSION_9*/             
 
        response = gtk_dialog_run (GTK_DIALOG (dialog));
        switch (response) {
-       case GTK_RESPONSE_OK:
+       case GTK_RESPONSE_OK: {
+#ifdef MODEST_HILDON_VERSION_0
                new_color = hildon_color_selector_get_color (HILDON_COLOR_SELECTOR (dialog));
+#else
+               GdkColor col;
+               hildon_color_chooser_get_color (HILDON_COLOR_CHOOSER(dialog), &col);
+               new_color = &col;
+          }
+#endif /*MODEST_HILDON_VERSION_0*/
                break;
        default:
                break;
@@ -1287,11 +1325,18 @@ modest_msg_edit_window_color_button_change (ModestMsgEditWindow *window,
 {
        ModestMsgEditWindowPrivate *priv;
        GdkColor *new_color;
-
        priv = MODEST_MSG_EDIT_WINDOW_GET_PRIVATE (window);
+       
+#ifdef MODEST_HILDON_VERSION_0 
        new_color = hildon_color_button_get_color (HILDON_COLOR_BUTTON (priv->font_color_button));
+#else 
+       GdkColor col;
+       hildon_color_button_get_color (HILDON_COLOR_BUTTON(priv->font_color_button), &col);
+       new_color = &col;
+#endif /*MODEST_HILDON_VERSION_0*/
 
        wp_text_buffer_set_attribute (WP_TEXT_BUFFER (priv->text_buffer), WPT_FORECOLOR, (gpointer) new_color);
+       
        gtk_window_set_focus (GTK_WINDOW (window), priv->msg_body);
 
 }
diff --git a/src/maemo/modest-scroll-area.c b/src/maemo/modest-scroll-area.c
new file mode 100644 (file)
index 0000000..c63106d
--- /dev/null
@@ -0,0 +1,245 @@
+/* Copyright (c) 2007, Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Nokia Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+/**
+ * SECTION:modest-scroll-area
+ * @short_description: A helper to create Maemo specific views,
+ * which are using scrollable area
+ *
+ * #GtkScrollArea combines a large widget that needs scrolling (like a
+ * text editor or a tree view) and other widgets that wouldn't fit one
+ * the screen normally without scrolling (like entries, toolbars etc.)
+ * into one scrollable area.
+ */
+
+#include "modest-scroll-area.h"
+#include <gtk/gtkscrolledwindow.h>
+#include <gtk/gtkfixed.h>
+#include <gtk/gtkadjustment.h>
+#include <gtk/gtkwidget.h>
+#include <string.h>
+
+typedef struct
+  {
+    GtkWidget *fixed;
+
+    /* Scrolled windows */
+    GtkWidget *swouter;
+    GtkWidget *swinner;
+
+    /* Widget that's being contained */
+    GtkWidget *child;
+
+    /* Vertical adjustment for scrolled windows */
+    GtkAdjustment *outadj;
+    GtkAdjustment *inadj;
+
+  } HildonScrollArea;
+
+
+static void modest_scroll_area_outer_value_changed (GtkAdjustment *adjustment,
+                                                   HildonScrollArea *sc);
+static void modest_scroll_area_inner_value_changed (GtkAdjustment *adjustment,
+                                                   HildonScrollArea *sc);
+static void modest_scroll_area_size_allocate (GtkWidget *widget,
+                                             GtkAllocation *allocation,
+                                             HildonScrollArea *sc);
+static void modest_scroll_area_child_requisition (GtkWidget *widget,
+                                                 GtkRequisition *req,
+                                                 HildonScrollArea *sc);
+static void modest_scroll_area_fixed_allocate (GtkWidget *widget,
+                                              GtkAllocation *allocation,
+                                              HildonScrollArea *sc);
+
+static int calculate_size (GtkWidget *widget);
+
+/**
+ * modest_scroll_area_new:
+ * @sw: #GtkWidget - #GtkScrolledWindow
+ * @child: #GtkWidget - child to be place inside the sw
+ *
+ * This is not a widget. It's a helper function to create
+ * hildon-specific scrolling methods.
+ * A common situation where the scroll area should be used
+ * might be following.  A view containing @GtkTreeView based widget,
+ * (or any similar widget which has built-in @GtkScrolledWindow support)
+ * and eg. couple buttons.  Normaly @GtkScrolledWindow can not handle
+ * the situation so that the @GtkTreeView built-in support
+ * would work.  The scroll area is connecting this built-in system to
+ * the scrolled window and also noticing the buttons.  To use, one should
+ * create a box to which pack the buttons and the scroll area.
+ * The scroll area then contains the problematic widget eg. the @GtkTreeView.
+ * Then the box should be placed in the @GtkScrolledWindow.
+ * The function is currently assuming that the newly created scroll area
+ * hierarchy is not modified in anyway.  Or if it is, it may lead to
+ * unwanted problems.  Also assumed, that the @child will be packed
+ * to the @sw.
+ *
+ * Returns: a @GtkFixed
+ */
+GtkWidget *modest_scroll_area_new (GtkWidget *sw, GtkWidget *child)
+{
+  GtkWidget *swi;
+  GtkWidget *fixed;
+  HildonScrollArea *sc;
+
+  g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (sw)
+                       && GTK_IS_WIDGET (child), NULL);
+
+  swi = gtk_scrolled_window_new (NULL, NULL);
+  fixed = gtk_fixed_new ();
+  sc = g_malloc (sizeof (HildonScrollArea));
+  memset (sc, 0, sizeof (HildonScrollArea));
+
+  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swi),
+                                 GTK_POLICY_NEVER, GTK_POLICY_NEVER);
+
+  gtk_container_add (GTK_CONTAINER (swi), child);
+  gtk_fixed_put (GTK_FIXED (fixed), swi, 0, 0);
+
+  sc->fixed = fixed;
+  sc->swouter = sw;
+  sc->swinner = swi;
+  sc->child = child;
+  sc->outadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (sw));
+  sc->inadj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (swi));
+
+  g_signal_connect_after (G_OBJECT (child), "size-request",
+                         G_CALLBACK (modest_scroll_area_child_requisition), sc);
+
+  g_signal_connect_after (G_OBJECT (sc->outadj), "value_changed",
+                         G_CALLBACK (modest_scroll_area_outer_value_changed), sc);
+  g_signal_connect_after (G_OBJECT (sc->inadj), "value_changed",
+                         G_CALLBACK (modest_scroll_area_inner_value_changed), sc);
+
+  g_signal_connect_after (G_OBJECT (sw), "size-allocate",
+                         G_CALLBACK (modest_scroll_area_size_allocate), sc);
+  g_signal_connect (G_OBJECT (sc->fixed), "size-allocate",
+                   G_CALLBACK (modest_scroll_area_fixed_allocate), sc);
+  g_signal_connect_swapped (G_OBJECT (sw), "destroy",
+                   G_CALLBACK (g_free), sc);
+
+  gtk_widget_show_all (sw);
+  return fixed;
+}
+
+static void modest_scroll_area_fixed_allocate (GtkWidget *widget,
+                                              GtkAllocation *allocation,
+                                              HildonScrollArea *sc)
+{
+  gtk_widget_set_size_request (sc->swinner, -1,
+                              MIN (sc->outadj->page_size, allocation->height));
+}
+
+
+static int calculate_size (GtkWidget *widget)
+{
+  int size = 0;
+
+  if (GTK_IS_TEXT_VIEW (widget))
+    return 0;
+
+  if (GTK_IS_CONTAINER (widget)) {
+    GList *children = gtk_container_get_children (GTK_CONTAINER (widget));
+    while (children != NULL) {
+      GtkWidget *wid = GTK_WIDGET (children->data);
+      gint sz = calculate_size (wid);
+      if ((GTK_WIDGET_VISIBLE (wid))) {
+        size += sz;
+      }
+
+      children = g_list_next (children);
+    }
+  } else { 
+    size = widget->allocation.height;
+  }
+
+  return size;
+}
+
+static void modest_scroll_area_child_requisition (GtkWidget *widget,
+                                                 GtkRequisition *req,
+                                                 HildonScrollArea *sc)
+{
+  /* Limit height to fixed height */
+  gint new_req = MAX (req->height, sc->fixed->allocation.height);
+  gint adjust_factor = calculate_size (sc->swouter) * 0.7;
+  
+  adjust_factor = MAX (0, adjust_factor - sc->outadj->value);
+  new_req = MIN (sc->outadj->page_size - adjust_factor, new_req);
+
+  gtk_widget_set_size_request (sc->fixed, -1, req->height);
+  /* Request inner scrolled window at most page size */
+  gtk_widget_set_size_request (sc->swinner, -1, new_req);
+}
+
+static void modest_scroll_area_outer_value_changed (GtkAdjustment *adjustment,
+                                                    HildonScrollArea *sc)
+{
+  GtkRequisition req;
+  gtk_widget_size_request (sc->child, &req);
+
+  /* Update inner adjustment position based on outer one, update fixed position */
+  if ((sc->outadj->value + sc->outadj->page_size) > sc->fixed->allocation.y
+      && sc->outadj->value < (sc->fixed->allocation.y + req.height))
+    {
+      gdouble new_pos = 0;
+
+      new_pos = MAX (sc->outadj->value - sc->fixed->allocation.y, 0);
+      new_pos = MIN (new_pos, req.height - sc->inadj->page_size);
+      new_pos = MAX (new_pos, 0);
+
+      gtk_fixed_move (GTK_FIXED (sc->fixed), sc->swinner, 0, new_pos);
+      gtk_adjustment_set_value (sc->inadj, new_pos);
+    }
+}
+
+static void modest_scroll_area_inner_value_changed (GtkAdjustment *adjustment,
+                                                   HildonScrollArea *sc)
+{
+  /* Update outer adjustment based on inner adjustment position */
+  if (sc->outadj->value != sc->fixed->allocation.y + adjustment->value)
+    gtk_adjustment_set_value (sc->outadj,
+                             sc->fixed->allocation.y + adjustment->value);
+}
+
+__inline__ static gint calculate_width (HildonScrollArea *sc)
+{
+  GtkScrolledWindow *scwin = GTK_SCROLLED_WINDOW (sc->swouter);
+  return (scwin->hscrollbar_visible * scwin->hscrollbar->allocation.width);
+}
+
+static void modest_scroll_area_size_allocate (GtkWidget *widget,
+                                             GtkAllocation *allocation,
+                                             HildonScrollArea *sc)
+{
+  gtk_widget_set_size_request (sc->fixed, calculate_width (sc), sc->fixed->allocation.height);
+  gtk_widget_set_size_request (sc->child, sc->fixed->allocation.width, -1);
+}
diff --git a/src/maemo/modest-scroll-area.h b/src/maemo/modest-scroll-area.h
new file mode 100644 (file)
index 0000000..8fb044a
--- /dev/null
@@ -0,0 +1,45 @@
+/* Copyright (c) 2007, Nokia Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Nokia Corporation nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * The reason why this is not made as a widget:
+ *  We can not create a widget which could return the correct child.
+ *  (ie. by gtk_bin_get_child)
+ */
+
+#ifndef __MODEST_SCROLL_AREA_H__
+#define __MODEST_SCROLL_AREA_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+    GtkWidget * modest_scroll_area_new(GtkWidget * sw, GtkWidget * child);
+
+G_END_DECLS
+#endif /* __MODEST_SCROLL_AREA_H__ */