openbsd-ports/cad/xtrkcad/patches/patch-app_wlib_gtklib_gtkhelp_c
sebastia af01d17e82 Import xtrkcad: CAD program for designing model railroad layouts
pkg/DESCR:
XTrackCAD is a CAD program for designing model railroad layouts. You can
easily create layout of any scale or size. Libraries for many brands of
track and turnouts are included. Adding new components is easy with the
built-in editor.
2010-10-24 20:07:54 +00:00

698 lines
23 KiB
Plaintext

$OpenBSD: patch-app_wlib_gtklib_gtkhelp_c,v 1.1.1.1 2010/10/24 20:07:55 sebastia Exp $
switch from old gtkhtml to webkit, patch based on patch for Debian
against older version:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=549039
--- app/wlib/gtklib/gtkhelp.c.orig Mon Jul 6 20:22:42 2009
+++ app/wlib/gtklib/gtkhelp.c Sun Oct 24 11:18:31 2010
@@ -37,7 +37,7 @@
#include <gtk/gtk.h>
#include <gdk/gdk.h>
-#include <libgtkhtml/gtkhtml.h>
+#include <webkit/webkit.h>
#include "gtkint.h"
#include "i18n.h"
@@ -62,12 +62,16 @@
#define BACKBUTTON "back"
#define FORWARDBUTTON "forward"
+#define HOMEBUTTON "home"
+#define CONTENTBUTTON "contents"
#define TOCDOC "tocDoc"
#define CONTENTSDOC "contentsDoc"
#define TOCVIEW "viewLeft"
#define CONTENTSVIEW "viewRight"
#define PANED "hpane"
+enum pane_views { MAIN_VIEW, CONTENTS_VIEW };
+
#define MAXHISTORYSIZE 20
/** \struct htmlHistory
@@ -89,6 +93,8 @@ static struct htmlHistory sHtmlHistory;
static char *directory; /**< base directory for HTML files */
static GtkWidget *wHelpWindow; /**< handle for the help window */
+static GtkWidget *main_view; /** handle for the help main data pane */
+static GtkWidget *contents_view; /** handle for the help contents pane */
#define GLADE_HOOKUP_OBJECT(component,widget,name) \
g_object_set_data_full (G_OBJECT (component), name, \
@@ -427,351 +433,7 @@ CreateHPaned( GtkBox *container, char *property )
return( hpaned );
}
-/**
- * load a HTML file into the specified doc.The base directory will be prepended before
- * the file is opmned for reading. In case the file can't be opened, a static error
- * page is output to teh document.
- *
- * \PARAM view IN HTML view to display in
- * \PARAM doc IN document into which the file will be loaded.
- * \PARAM file IN filename to load.
- */
-
-static void
-LoadHtml( GtkWidget *view, HtmlDocument *doc, const char *file )
-{
- char *filename;
- char *copyOfUrl;
- char *htmlFile;
- char *buffer;
- char *errtext;
- int handle;
- int len;
-
- /* create a working copy of the filename, as this will be modified */
- copyOfUrl = strdup( file );
- assert( copyOfUrl != NULL );
-
- /* separate an anchor from the rest */
- filename = strtok( copyOfUrl, "#" );
-
- /* make sure that the filename as a file part and is not only an anchor */
- if( file[ 0 ] != '#' ) {
- html_view_set_document( HTML_VIEW(view), NULL );
-
- /* assemble the full filename for the HTML file */
- htmlFile = malloc( strlen( directory ) + strlen( filename ) + 1 );
- assert( htmlFile != NULL );
-
- strcpy( htmlFile, directory );
- strcat( htmlFile, filename );
-
- /* open the output stream */
- html_document_open_stream (doc, "text/html");
-
- /* open the file */
- handle = open( htmlFile, O_RDONLY );
- if( handle != -1 )
- {
- /* if successful, read the file and output it to the document */
- buffer = malloc( 8192 );
- assert( buffer != NULL );
-
- while((len = read( handle, buffer, 8192 )) > 0 ) {
- html_document_write_stream( doc, buffer, len );
- }
-
- /* clean up */
- free( buffer );
- close( handle );
-
- } else {
- /* file could not be opened, display the error page instead */
- errtext = strerror( errno );
- buffer = malloc( strlen( HTMLERRORTEXT ) + strlen( errtext ) + strlen ( htmlFile ));
- assert( buffer != NULL );
- if( buffer ) {
- sprintf( buffer, HTMLERRORTEXT, htmlFile, errtext );
- html_document_write_stream( doc, buffer, strlen( buffer ));
- free( buffer );
- }
- }
-
-
- html_view_set_document(HTML_VIEW( view ), doc);
-
- /* clean up */
- html_document_close_stream (doc);
- free( htmlFile );
-
- filename = strtok( NULL, "#" );
- }
-
- if( filename ) {
- /* jump to anchor */
- html_view_jump_to_anchor( HTML_VIEW(view), filename );
- }
-
- free( copyOfUrl );
-
-
-}
-
/**
- * handles clicks on the forward / backward buttons.
- *
- * \PARAM widget IN button pressed
- * \PARAM data IN dialog window handle
- */
-
-static void
-DoHistory( GtkWidget *widget, void *data )
-{
- GtkWidget *parent = (GtkWidget *)data;
- GtkWidget *back = lookup_widget( parent, BACKBUTTON );
- GtkWidget *forw = lookup_widget( parent, FORWARDBUTTON);
- HtmlDocument *doc = (HtmlDocument *)lookup_widget( parent, CONTENTSDOC );
- GtkWidget *view = lookup_widget( parent, CONTENTSVIEW );
-
- if( widget == back ) {
- sHtmlHistory.curShownPage = DECBUFFERINDEX( sHtmlHistory.curShownPage );
-
- /* enable forward button */
- gtk_widget_set_sensitive( forw, TRUE );
-
- /* if oldest page is shown, disable back button */
- if( sHtmlHistory.curShownPage == sHtmlHistory.oldestPage )
- gtk_widget_set_sensitive( widget, FALSE );
- } else {
- if( widget == forw ) {
- sHtmlHistory.curShownPage = INCBUFFERINDEX( sHtmlHistory.curShownPage );
-
- /* enable back button */
- gtk_widget_set_sensitive( back, TRUE );
- /* if newest page is shown, disable forward button */
- if( sHtmlHistory.curShownPage == sHtmlHistory.newestPage )
- gtk_widget_set_sensitive( widget, FALSE );
- } else {
- assert(( widget == forw || widget == back ));
- }
- }
-
- LoadHtml( view, doc, sHtmlHistory.url[ sHtmlHistory.curShownPage ]);
-}
-
-
-/**
- * Put the filename into the history stack.
- *
- * \PARAM helpWin IN handle of help window
- * \PARAM filename IN relative filename to put onto the stack
- */
-
-static void
-AddToHistory( GtkWidget *helpWin, char *filename )
-{
- /* this handles the start case when the buffer is still empty */
- if( sHtmlHistory.bInUse )
- {
- /* starting from the second page added, curShownPage is always advanced */
- sHtmlHistory.curShownPage = INCBUFFERINDEX( sHtmlHistory.curShownPage );
- gtk_widget_set_sensitive( lookup_widget( helpWin, BACKBUTTON ), TRUE );
- }
-
- gtk_widget_set_sensitive( lookup_widget( helpWin, FORWARDBUTTON ), FALSE );
-
-
- sHtmlHistory.newestPage = sHtmlHistory.curShownPage;
-
- if( sHtmlHistory.url[ sHtmlHistory.newestPage ] )
- free( sHtmlHistory.url[ sHtmlHistory.newestPage ] );
-
- /* put the filaname into the buffer */
- sHtmlHistory.url[ sHtmlHistory.newestPage ] = strdup( filename );
-
- if( sHtmlHistory.newestPage == sHtmlHistory.oldestPage && sHtmlHistory.bInUse )
- /* the buffer pointer wrapped around, so the oldest entry will be overwritten next.
- The relevant index now points to the second oldest entry */
- sHtmlHistory.oldestPage = INCBUFFERINDEX( sHtmlHistory.oldestPage );
-
- sHtmlHistory.bInUse = TRUE;
-
- return;
-}
-
-/**
- * handles the clicked event for the Home button. Single action is to load
- * the homepage into the contents window.
- * \PARAM widget IN ignored
- * \PARAM data IN handle for the help dialog window
- *
- */
-
-static void
-LoadHomepage( GtkWidget *widget, void *data )
-{
- GtkWidget *parent = (GtkWidget *)data;
- HtmlDocument *doc = (HtmlDocument *)lookup_widget( parent, CONTENTSDOC );
- GtkWidget *view = lookup_widget( parent, CONTENTSVIEW );
-
-
- AddToHistory( (GtkWidget *)data, "index.html" );
-
- LoadHtml( view, doc, "index.html" );
-}
-
-/**
- * Create all the widgets for decorating and scrolling an HTML view
- *
- * \PARAM paned IN the pane container holding the view
- * \PARAM PackFunc IN pointer to function for adding the widget to the pane
- * \PARAM htmlView IN the HTML view widget to add
- *
- * \RETURN the scroll widget
- */
-
-static GtkWidget*
-CreateHtmlViewScrollable( GtkWidget *paned, void PackFunc( GtkPaned *, GtkWidget *), GtkWidget *htmlView )
-{
- GtkWidget *frame;
- GtkWidget *scroll;
-
- /* a frame */
- frame = gtk_frame_new( NULL );
- PackFunc( (GtkPaned *)paned, frame );
-
- /* and a scroll window holding the HTML view */
- scroll = gtk_scrolled_window_new( NULL, NULL );
- gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
- gtk_container_add( GTK_CONTAINER( scroll ), htmlView );
-
- /* put the scroll window into the frame */
- gtk_container_add( GTK_CONTAINER(frame), GTK_WIDGET(scroll));
-
- return scroll;
-}
-
-/**
- * Create a new stock button. The button is created, made visible, disabled and stuffed into a container.
- * Additionally a click handler is registered.
- *
- * \PARAM name IN Stock name of the button
- * \PARAM container IN Container into which the button is stuffed
- * \PARAM clickHandler IN handler to be called on button click
- * \PARAM userData IN data to be passed to this handler
- *
- * \RETURN button handle
- */
-
-static GtkWidget *
-CreateButton( char *name, GtkWidget *container, GCallback clickHandler, void *userData )
-{
- GtkWidget *button;
-
- button = gtk_button_new_from_stock( name );
- gtk_widget_set_sensitive( button, FALSE );
- gtk_widget_show( button );
- gtk_container_add( GTK_CONTAINER( container ), button );
- GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
-
- g_signal_connect( button, "clicked", clickHandler, userData );
-
- return( button );
-}
-
-/**
- * Create a HTML document object.
- *
- * \PARAM UrlReq IN callback for requesting URLs
- * \PARAM LinkClick IN callback for 'link clicked' events
- * \PARAM userData IN additional data to be passed with events
- *
- * \RETURN doc created document object
- */
-
-static HtmlDocument *
-CreateHtmlDoc( GCallback UrlReq, GCallback LinkClick, void *userData )
-{
- HtmlDocument *doc;
-
- doc = html_document_new();
-
- g_signal_connect (G_OBJECT( doc ), "request_url", UrlReq, userData );
-
- /* whenever the user selects a link here, the contents area has to be updated */
- g_signal_connect(G_OBJECT (doc), "link_clicked", LinkClick, userData);
-
- return doc;
-}
-
-/**
- * Event handler for clicks onto links.
- *
- * \PARAM doc IN affected HTML document
- * \PARAM uri IN selected resource
- * \PARAM ptr IN pointer to user data ( help window handle )
- */
-
-void
-LinkClicked(HtmlDocument *doc, const gchar *uri, void *ptr )
-{
- GtkWidget *outView = lookup_widget( ptr, CONTENTSVIEW);
- HtmlDocument *docCont = (HtmlDocument *)lookup_widget( ptr, CONTENTSDOC );
-
- AddToHistory((GtkWidget *)ptr, (char *)uri );
-
- LoadHtml( outView, docCont, uri );
-
- return;
-}
-
-/**
- * Event handler for URL requests. This handler is called for all inline URLs eg. images.
- * The files are read and the contents is dumped into the supplied stream.
- *
- * \PARAM doc IN affected HTML document
- * \PARAM uri IN requested url
- * \PARAM stream IN stream into which the data should be written
- * \PARAM data IN unused
- */
-
-
-void
-UrlRequested(HtmlDocument *doc, const gchar *uri, HtmlStream *stream, gpointer data)
-{
- char *filename;
- char *buffer;
- int handle;
- int len;
-
- filename = malloc( strlen( directory ) + strlen( uri ) + 1 );
- assert( filename != NULL );
-
- strcpy( filename, directory );
- strcat( filename, uri );
-
- handle = open( filename, O_RDONLY );
- if( handle )
- {
- buffer = malloc( 8192 );
- assert( buffer != NULL );
-
- while((len = read( handle, buffer, 8192 )) > 0 ) {
- html_stream_write( stream, buffer, len );
- }
- close( handle );
-
- free( buffer );
- }
-
- free( filename );
-
- html_stream_close(stream);
-
- return;
-}
-
-/**
* Handler for the delete-event issued on the help window.We are saving window
* information (eg. position) and are hiding the window instead of closing it.
*
@@ -810,7 +472,82 @@ DestroyHelpWindow( GtkWidget *win, GdkEvent *event, vo
return TRUE;
}
+void back_button_clicked(GtkWidget *widget, gpointer data) {
+ webkit_web_view_go_back(WEBKIT_WEB_VIEW(data));
+}
+
+void forward_button_clicked(GtkWidget *widget, gpointer data) {
+ webkit_web_view_go_forward(WEBKIT_WEB_VIEW(data));
+}
+
+void home_button_clicked(GtkWidget *widget, gpointer data) {
+ load_into_view("index.html", MAIN_VIEW);
+}
+
+/* Toggles the contents pane */
+void contents_button_clicked(GtkWidget *widget, gpointer data) {
+ if (gtk_paned_get_position(GTK_PANED(data)) < 50) {
+ gtk_paned_set_position(GTK_PANED(data), 370);
+ }
+ else {
+ gtk_paned_set_position(GTK_PANED(data), 0);
+ }
+}
+
+gboolean contents_click_handler(
+ WebKitWebView *web_view,
+ WebKitWebFrame *frame,
+ WebKitNetworkRequest *request,
+ WebKitWebNavigationAction *navigation_action,
+ WebKitWebPolicyDecision *policy_decision,
+ gpointer data) {
+
+ webkit_web_view_load_uri(WEBKIT_WEB_VIEW(data), webkit_network_request_get_uri(request));
+
+ return TRUE;
+}
+
/**
+ * Initialize the buttons for the help window
+ */
+void initialize_buttons (GtkWidget *main_vbox, GtkWidget *content_hpane) {
+ GtkWidget *buttons_hbuttonbox;
+ GtkWidget *back_button;
+ GtkWidget *forward_button;
+ GtkWidget *home_button;
+ GtkWidget *contents_button;
+
+ // define and attach signals to buttons
+ back_button = gtk_button_new_with_label("Back");
+ g_signal_connect(back_button, "clicked", G_CALLBACK(back_button_clicked), G_OBJECT(main_view));
+
+ forward_button = gtk_button_new_with_label("Forward");
+ g_signal_connect(forward_button, "clicked", G_CALLBACK(forward_button_clicked), G_OBJECT(main_view));
+
+ home_button = gtk_button_new_with_label("Home");
+ g_signal_connect(home_button, "clicked", G_CALLBACK(home_button_clicked), G_OBJECT(main_view));
+
+ contents_button = gtk_button_new_with_label("Contents");
+ g_signal_connect(contents_button, "clicked", G_CALLBACK(contents_button_clicked), G_OBJECT(content_hpane));
+
+ // button layout
+ buttons_hbuttonbox = gtk_hbutton_box_new();
+ gtk_container_add(GTK_CONTAINER(buttons_hbuttonbox), back_button);
+ gtk_container_add(GTK_CONTAINER(buttons_hbuttonbox), forward_button);
+ gtk_container_add(GTK_CONTAINER(buttons_hbuttonbox), home_button);
+ gtk_container_add(GTK_CONTAINER(buttons_hbuttonbox), contents_button);
+ gtk_box_pack_start(GTK_BOX(main_vbox), buttons_hbuttonbox, FALSE, TRUE, 0);
+ gtk_box_set_spacing(GTK_BOX(buttons_hbuttonbox), 6);
+ gtk_button_box_set_layout(GTK_BUTTON_BOX(buttons_hbuttonbox), GTK_BUTTONBOX_START);
+
+ /* Store pointers to all widgets, for use by lookup_widget(). */
+ GLADE_HOOKUP_OBJECT (main_view, back_button, BACKBUTTON);
+ GLADE_HOOKUP_OBJECT (main_view, forward_button, FORWARDBUTTON);
+ GLADE_HOOKUP_OBJECT (main_view, home_button, HOMEBUTTON);
+ GLADE_HOOKUP_OBJECT (main_view, contents_button, CONTENTBUTTON);
+}
+
+/**
* Create the help windows including all contained widgets and the needed HTML documents.
*
* \RETURN handle of the created window.
@@ -819,20 +556,10 @@ DestroyHelpWindow( GtkWidget *win, GdkEvent *event, vo
GtkWidget*
CreateHelpWindow (void)
{
- GtkWidget *wHelpWindow;
- GtkWidget *vbox2;
- GtkWidget *hbuttonbox1;
- GtkWidget *back;
- GtkWidget *forw;
- GtkWidget *button3;
- GtkWidget *hbox1;
- GtkWidget *image2;
- GtkWidget *label18;
- GtkWidget *hpaned;
- GtkWidget *viewLeft;
- GtkWidget *viewRight;
- HtmlDocument *doc1;
- HtmlDocument *doc2;
+ GtkWidget *main_vbox;
+ GtkWidget *main_view_scroller;
+ GtkWidget *contents_view_scroller;
+ GtkWidget *content_hpane;
int width;
int height;
@@ -841,7 +568,7 @@ CreateHelpWindow (void)
const char *pref;
char title[100];
- wHelpWindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ wHelpWindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
width = gdk_screen_get_width( gtk_window_get_screen( (GtkWindow *)wHelpWindow ));
height = gdk_screen_get_height( gtk_window_get_screen( (GtkWindow *)wHelpWindow ));
@@ -872,93 +599,68 @@ CreateHelpWindow (void)
x = ( width * 3 ) / 5 - 10;
y = 70;
}
-
gtk_window_resize( (GtkWindow *)wHelpWindow, w, h );
gtk_window_move( (GtkWindow *)wHelpWindow, x, y );
- gtk_window_set_title (GTK_WINDOW (wHelpWindow), _("XTrackCAD Help"));
+ gtk_window_set_title (GTK_WINDOW (wHelpWindow), _("XTrackCAD Help"));
g_signal_connect( G_OBJECT( wHelpWindow ), "delete-event", G_CALLBACK( DestroyHelpWindow ), NULL );
- vbox2 = gtk_vbox_new (FALSE, 0);
- gtk_widget_show (vbox2);
+ main_view_scroller = gtk_scrolled_window_new(NULL, NULL);
+ contents_view_scroller = gtk_scrolled_window_new(NULL, NULL);
+ main_view = webkit_web_view_new();
+ contents_view = webkit_web_view_new();
+ // must be done here as it gets locked down later
+ load_into_view ("contents.html", CONTENTS_VIEW);
+ gtk_widget_set_size_request(GTK_WIDGET(wHelpWindow), x, y);
- gtk_container_add (GTK_CONTAINER (wHelpWindow), vbox2);
+ main_vbox = gtk_vbox_new(FALSE, 5);
+ gtk_container_add(GTK_CONTAINER(wHelpWindow), main_vbox);
- hbuttonbox1 = gtk_hbutton_box_new ();
- gtk_widget_show (hbuttonbox1);
- gtk_box_pack_start (GTK_BOX (vbox2), hbuttonbox1, FALSE, TRUE, 0);
- gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox1), GTK_BUTTONBOX_START);
- gtk_container_set_border_width (GTK_CONTAINER (hbuttonbox1), 6);
- gtk_box_set_spacing (GTK_BOX (hbuttonbox1), 6);
+ gtk_container_add(GTK_CONTAINER(main_view_scroller), main_view);
+ gtk_container_add(GTK_CONTAINER(contents_view_scroller), contents_view);
- /* the two navigation buttons */
- back = CreateButton( "gtk-go-back", hbuttonbox1, (GCallback)DoHistory, wHelpWindow );
+ content_hpane = gtk_hpaned_new();
+ initialize_buttons(main_vbox, content_hpane);
+ gtk_container_add(GTK_CONTAINER(content_hpane), contents_view_scroller);
+ gtk_container_add(GTK_CONTAINER(content_hpane), main_view_scroller);
+ gtk_box_pack_start(GTK_BOX(main_vbox), content_hpane, TRUE, TRUE, 0);
- forw = CreateButton( "gtk-go-forward", hbuttonbox1, (GCallback)DoHistory, wHelpWindow );
+ gtk_paned_set_position(GTK_PANED(content_hpane), 370);
- /* as we want to set the text shown, the GTK_STOCK_HOME can't be used here */
- button3 = gtk_button_new ();
- gtk_widget_show (button3);
- gtk_container_add (GTK_CONTAINER (hbuttonbox1), button3);
- GTK_WIDGET_SET_FLAGS (button3, GTK_CAN_DEFAULT);
-
- hbox1 = gtk_hbox_new (FALSE, 0);
- gtk_widget_show (hbox1);
- gtk_container_add (GTK_CONTAINER (button3), hbox1);
-
- image2 = gtk_image_new_from_stock ("gtk-home", GTK_ICON_SIZE_BUTTON);
- gtk_widget_show (image2);
- gtk_box_pack_start (GTK_BOX (hbox1), image2, TRUE, FALSE, 0);
- gtk_misc_set_alignment (GTK_MISC (image2), 0, 0);
-
- label18 = gtk_label_new (_("Home"));
- gtk_widget_show (label18);
- gtk_box_pack_end (GTK_BOX (hbox1), label18, TRUE, TRUE, 0);
- gtk_misc_set_alignment (GTK_MISC (label18), 0, 0.5);
-
- g_signal_connect( GTK_WIDGET( button3 ), "clicked", (GCallback)LoadHomepage, wHelpWindow );
-
- /*
- * create the browser windows
- */
-
- /* the horizontal slider */
- hpaned = CreateHPaned( GTK_BOX (vbox2), "property" );
-
- /* the left side of the slider */
- viewLeft = html_view_new ();
- html_view_set_magnification (HTML_VIEW (viewLeft), 1 );
-
- CreateHtmlViewScrollable( hpaned, gtk_paned_add1, viewLeft );
-
- doc1 = CreateHtmlDoc( (GCallback)UrlRequested, (GCallback)LinkClicked, wHelpWindow );
-
- /* the right side of the slider */
- viewRight = html_view_new ();
- html_view_set_magnification (HTML_VIEW (viewRight), 1 );
-
- CreateHtmlViewScrollable( hpaned, gtk_paned_add2, viewRight );
-
- doc2 = CreateHtmlDoc( (GCallback)UrlRequested, (GCallback)LinkClicked, wHelpWindow );
+ g_signal_connect(contents_view, "navigation-policy-decision-requested", G_CALLBACK(contents_click_handler), G_OBJECT(main_view));
- /* Store pointers to all widgets, for use by lookup_widget(). */
- GLADE_HOOKUP_OBJECT_NO_REF (wHelpWindow, wHelpWindow, "wHelpWindow");
- GLADE_HOOKUP_OBJECT (wHelpWindow, back, BACKBUTTON);
- GLADE_HOOKUP_OBJECT (wHelpWindow, forw, FORWARDBUTTON);
- GLADE_HOOKUP_OBJECT (wHelpWindow, button3, "button3");
- GLADE_HOOKUP_OBJECT (wHelpWindow, hpaned, PANED );
- GLADE_HOOKUP_OBJECT (wHelpWindow, viewLeft, TOCVIEW );
- GLADE_HOOKUP_OBJECT (wHelpWindow, viewRight, CONTENTSVIEW );
- GLADE_HOOKUP_OBJECT_NO_REF (wHelpWindow, (GtkWidget *)doc1, TOCDOC );
- GLADE_HOOKUP_OBJECT_NO_REF (wHelpWindow, (GtkWidget *)doc2, CONTENTSDOC );
-
+ /* Store pointers to all widgets, for use by lookup_widget(). */
+ GLADE_HOOKUP_OBJECT_NO_REF (wHelpWindow, wHelpWindow, "wHelpWindow");
+ GLADE_HOOKUP_OBJECT (wHelpWindow, content_hpane, PANED );
+ GLADE_HOOKUP_OBJECT (wHelpWindow, contents_view, TOCVIEW );
+ GLADE_HOOKUP_OBJECT (wHelpWindow, main_view, CONTENTSVIEW );
- return wHelpWindow;
+ return wHelpWindow;
}
+void load_into_view (char *file, int requested_view) {
+ GtkWidget *view;
+ switch (requested_view) {
+ case MAIN_VIEW:
+ view = main_view;
+ break;
+ case CONTENTS_VIEW:
+ view = contents_view;
+ break;
+ default:
+ printf("*** error, could not find view");
+ break;
+ }
+ char fileToLoad[100] = "file://";
+ strcat(fileToLoad,directory);
+ strcat(fileToLoad,file);
+ //debug printf("*** loading %s into pane %d.\n", fileToLoad, requested_view);
+ webkit_web_view_load_uri(WEBKIT_WEB_VIEW(view), fileToLoad);
+}
+
/**
* Invoke the help system to display help for <topic>.
*
@@ -967,41 +669,28 @@ CreateHelpWindow (void)
EXPORT void wHelp( const char * topic )
{
- HtmlDocument *docToc;
- HtmlDocument *docContents;
- GtkWidget *view;
- GtkWidget *viewToc;
char *htmlFile;
-
if( !wHelpWindow )
{
- wHelpWindow = CreateHelpWindow();
directory = malloc( BUFSIZ );
assert( directory != NULL );
sprintf( directory, "%s/html/", wGetAppLibDir());
- /* initialize the left pane of the window */
- viewToc = lookup_widget( wHelpWindow, TOCVIEW);
- docToc = (HtmlDocument *)lookup_widget( wHelpWindow, TOCDOC );
+ wHelpWindow = CreateHelpWindow();
+ /* load the default content */
+ load_into_view ("index.html", MAIN_VIEW);
- /* load and show the table of contents */
- LoadHtml( viewToc, docToc, "contents.html" );
}
- /* display the requested page in the main pane */
- view = lookup_widget( wHelpWindow, CONTENTSVIEW);
- docContents = (HtmlDocument *)lookup_widget( wHelpWindow, CONTENTSDOC );
-
/* need space for the 'html' extension plus dot plus \0 */
htmlFile = malloc( strlen( topic ) + 6 );
assert( htmlFile != NULL );
sprintf( htmlFile, "%s.html", topic );
- AddToHistory( wHelpWindow, htmlFile );
- LoadHtml( view, docContents, htmlFile );
+ load_into_view (htmlFile, MAIN_VIEW);
gtk_widget_show_all(wHelpWindow);
gtk_window_present(GTK_WINDOW(wHelpWindow));