changeset 1354:1f22addc2722

Changed the behavior of dw_html_new() to return NULL on failure like the documentation indicates... Instead of creating a text widget with an error message. This error message is now sent to the console. This allows programs to be able to gracefully handle the failure to create the HTML widget. Also updated the dwtest program to create a text widget in a similar fashion on failure. Also updated the dw_calendar_* comments to no longer be unsupported on OS/2.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 18 Nov 2011 13:34:36 +0000
parents f4ad4ba39b61
children dd252596227b
files dwtest.c gtk/dw.c gtk3/dw.c os2/dw.c win/dw.c
diffstat 5 files changed, 48 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/dwtest.c	Wed Nov 16 20:31:35 2011 +0000
+++ b/dwtest.c	Fri Nov 18 13:34:36 2011 +0000
@@ -1655,11 +1655,19 @@
     dw_notebook_page_set_text( notebook, notebookpage7, "html");
 
     rawhtml = dw_html_new(1001);
-    dw_box_pack_start( notebookbox7, rawhtml, 0, 100, TRUE, FALSE, 0);
-    dw_html_raw(rawhtml, "<html><body><center><h1>dwtest</h1></center></body></html>");
-    html = dw_html_new(1002);
-    dw_box_pack_start( notebookbox7, html, 0, 100, TRUE, TRUE, 0);
-    dw_html_url(html, "http://dwindows.netlabs.org");
+    if(rawhtml)
+    {
+        dw_box_pack_start( notebookbox7, rawhtml, 0, 100, TRUE, FALSE, 0);
+        dw_html_raw(rawhtml, "<html><body><center><h1>dwtest</h1></center></body></html>");
+        html = dw_html_new(1002);
+        dw_box_pack_start( notebookbox7, html, 0, 100, TRUE, TRUE, 0);
+        dw_html_url(html, "http://dwindows.netlabs.org");
+    }
+    else
+    {
+        html = dw_text_new("HTML widget not available.", 0);
+        dw_box_pack_start( notebookbox7, html, 0, 100, TRUE, TRUE, 0);
+    }
 
     notebookbox8 = dw_box_new( BOXVERT, 7 );
     notebookpage8 = dw_notebook_page_new( notebook, 1, FALSE );
--- a/gtk/dw.c	Wed Nov 16 20:31:35 2011 +0000
+++ b/gtk/dw.c	Fri Nov 18 13:34:36 2011 +0000
@@ -12271,16 +12271,14 @@
  */
 HWND dw_html_new(unsigned long id)
 {
-   GtkWidget *widget,*stext;
+   GtkWidget *widget = NULL,*stext;
    int _locked_by_me = FALSE;
 
    DW_MUTEX_LOCK;
 #ifdef USE_GTKMOZEMBED
    if (!_gtk_moz_embed_new)
    {
-      widget = dw_box_new(DW_HORZ, 0);
-      stext = dw_text_new( "HTML widget not available; you do not have access to gtkmozembed.", 0);
-      dw_box_pack_start(widget, stext, 0, 0, TRUE, TRUE, 10);
+      dw_debug( "HTML widget not available; you do not have access to gtkmozembed." );
    }
    else
    {
@@ -12290,13 +12288,12 @@
        */
       gtk_signal_connect( GTK_OBJECT(widget), "net-stop", GTK_SIGNAL_FUNC(_dw_html_net_stop_cb), widget );
       gtk_signal_connect( GTK_OBJECT(widget), "dom_mouse_click", GTK_SIGNAL_FUNC(_dw_dom_mouse_click_cb), widget );
+      gtk_widget_show(widget);
    }
 #elif defined(USE_LIBGTKHTML2)
    if ( !_html_document_new )
    {
-      widget = dw_box_new(DW_HORZ, 0);
-      stext = dw_text_new( "HTML widget not available; you do not have access to libgtkhtml-2.", 0);
-      dw_box_pack_start(widget, stext, 0, 0, TRUE, TRUE, 10);
+      dw_debug( "HTML widget not available; you do not have access to libgtkhtml-2." );
    }
    else
    {
@@ -12309,13 +12306,12 @@
       g_signal_connect (G_OBJECT (document), "link_clicked", G_CALLBACK (link_clicked), NULL);
       widget = _html_view_new();
       gtk_object_set_data(GTK_OBJECT(widget), "_dw_html_document", (gpointer)document);
+      gtk_widget_show(widget);
    }
 #elif defined(USE_WEBKIT)
    if (!_webkit_web_view_open)
    {
-      widget = dw_box_new(DW_HORZ, 0);
-      stext = dw_text_new( "HTML widget not available; you do not have access to webkit.", 0);
-      dw_box_pack_start(widget, stext, 0, 0, TRUE, TRUE, 10);
+      dw_debug( "HTML widget not available; you do not have access to webkit." );
    }
    else
    {
@@ -12323,7 +12319,6 @@
       widget = gtk_scrolled_window_new (NULL, NULL);
       gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW (widget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
       web_view = (WebKitWebView *)_webkit_web_view_new();
-/*      web_view = WEBKIT_WEB_VIEW(_webkit_web_view_new() ); */
       gtk_container_add( GTK_CONTAINER (widget), GTK_WIDGET(web_view) );
       gtk_widget_show( GTK_WIDGET(web_view) );
       gtk_object_set_data( GTK_OBJECT(widget), "_dw_web_view", (gpointer)web_view );
@@ -12332,13 +12327,11 @@
       g_signal_connect( web_view, "populate-popup", G_CALLBACK(_dw_html_populate_popup_cb), NULL );
 #  endif
 # endif
-   }
-#else
-   widget = dw_box_new(DW_HORZ, 0);
-   stext = dw_text_new( "HTML widget not available; you do not have access to gtkmozembed.", 0);
-   dw_box_pack_start(widget, stext, 0, 0, TRUE, TRUE, 10);
-#endif
-   gtk_widget_show(widget);
+      gtk_widget_show(widget);
+   }
+#else
+   dw_debug( "HTML widget not available; you do not have access to gtkmozembed, webkit nor libgtkhtml-2.", 0);
+#endif
    DW_MUTEX_UNLOCK;
    return widget;
 }
--- a/gtk3/dw.c	Wed Nov 16 20:31:35 2011 +0000
+++ b/gtk3/dw.c	Fri Nov 18 13:34:36 2011 +0000
@@ -10129,16 +10129,14 @@
  */
 HWND dw_html_new(unsigned long id)
 {
-   GtkWidget *widget,*stext;
+   GtkWidget *widget = NULL,*stext;
    int _locked_by_me = FALSE;
 
    DW_MUTEX_LOCK;
 #ifdef USE_WEBKIT
    if (!_webkit_web_view_open)
    {
-      widget = dw_box_new(DW_HORZ, 0);
-      stext = dw_text_new( "HTML widget not available; you do not have access to webkit.", 0);
-      dw_box_pack_start(widget, stext, 0, 0, TRUE, TRUE, 10);
+      dw_debug( "HTML widget not available; you do not have access to webkit." );
    }
    else
    {
@@ -10152,12 +10150,10 @@
       g_object_set_data(G_OBJECT(widget), "_dw_web_view", (gpointer)web_view);
       g_signal_connect( web_view, "populate-popup", G_CALLBACK(_dw_html_populate_popup_cb), NULL );
    }
+   gtk_widget_show(widget);
 #else
-   widget = dw_box_new(DW_HORZ, 0);
-   stext = dw_text_new( "HTML widget not available; you do not have access to webkit.", 0);
-   dw_box_pack_start(widget, stext, 0, 0, TRUE, TRUE, 10);
+   dw_debug( "HTML widget not available; you do not have access to webkit." );
 #endif
-   gtk_widget_show(widget);
    DW_MUTEX_UNLOCK;
    return widget;
 }
--- a/os2/dw.c	Wed Nov 16 20:31:35 2011 +0000
+++ b/os2/dw.c	Fri Nov 18 13:34:36 2011 +0000
@@ -10733,7 +10733,8 @@
 HWND API dw_html_new(unsigned long id)
 {
    id = id;
-   return dw_box_new(DW_HORZ, 0);
+   dw_debug("HTML widget not available; OS/2 currently does not support it.");
+   return 0;
 }
 
 typedef struct _dwprint 
@@ -11471,14 +11472,12 @@
    }
 }
 
-
-
-/*
- * Create a new static text window (widget) to be packed.
- * Not available under OS/2, eCS
- * Parameters:
- *       text: The text to be display by the static text widget.
+/*
+ * Create a new calendar window (widget) to be packed.
+ * Parameters:
  *       id: An ID to be used with dw_window_from_id() or 0L.
+ * Returns:
+ *       Handle to the created calendar or NULL on error.
  */
 HWND API dw_calendar_new(ULONG id)
 {
@@ -11503,7 +11502,10 @@
 }
 
 /*
- * The following are stubs
+ * Sets the current date of a calendar.
+ * Parameters:
+ *       handle: The handle to the calendar returned by dw_calendar_new().
+ *       year, month, day: To set the calendar to display.
  */
 void API dw_calendar_set_date( HWND window, unsigned int year, unsigned int month, unsigned int day )
 {
@@ -11522,6 +11524,14 @@
     WinPostMsg(window, WM_PAINT, 0, 0);
 }
 
+/*
+ * Gets the year, month and day set in the calendar widget.
+ * Parameters:
+ *       handle: The handle to the calendar returned by dw_calendar_new().
+ *       year: Variable to store the year or NULL.
+ *       month: Variable to store the month or NULL.
+ *       day: Variable to store the day or NULL.
+ */
 void API dw_calendar_get_date( HWND window, unsigned int *year, unsigned int *month, unsigned int *day )
 {
     if(year)
--- a/win/dw.c	Wed Nov 16 20:31:35 2011 +0000
+++ b/win/dw.c	Fri Nov 18 13:34:36 2011 +0000
@@ -4737,6 +4737,7 @@
                   DWInstance,
                   NULL);
 #else
+   dw_debug("HTML widget not available; Support not enabled in this build.");
    return 0;
 #endif
 }