Re: [libcroco-list] sewfox minimal application
- From: Dodji Seketeli <dodji seketeli org>
- To: Stephane Bonhomme <s bonhomme wanadoo fr>
- Cc: libcroco-list gnome org
- Subject: Re: [libcroco-list] sewfox minimal application
- Date: Sat, 28 Feb 2004 13:41:14 +0100
Hi Stephane,
I have modified minifox a bit to provide it with a contextual menu from
which we can dump the box model along with all the style and layouting
information it has, on stdout.
This is commited into CVS HEAD, and I have attached it to this mail so
that you don't have to wait for the anoncvs lag period.
Regards,
Dodji.
On Thu, 2004-02-19 at 10:53, Stephane Bonhomme wrote:
> Hi
>
> Here is a new version that dumps the box model tree on stdout
>
> Le mar 17/02/2004 à 17:04, Stephane Bonhomme a écrit :
> > Hi all
> >
> > Here is a minimal gtk application that displays a xml file using a css
> > stylesheet with sewfox.
> >
> > It only depends on libsewfox and I hope it will be useful for debugging
> > purpose
> >
> > It could be great if it were included in the test dir of the sewfox
> > source tree.
> >
> >
> > Stephane
/* -*- Mode: C; indent-tabs-mode:nil; c-basic-offset: 8-*- */
/*
* This file is part of the SEWFOX project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of
* the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the
* GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
*Initial Author: Stephane Bonhomme
*/
#include <stdio.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <sx-box-view.h>
static void usage (void) ;
static GtkWidget * get_contextual_menu (SXBoxView *a_viewport) ;
static gboolean delete_event_cb ( GtkWidget *widget,
GdkEvent *event,
gpointer data ) ;
static gboolean
delete_event_cb ( GtkWidget *widget,
GdkEvent *event,
gpointer data )
{
gtk_main_quit () ;
return FALSE;
}
static void
dump_box_model_menuitem_activate_cb (GtkWidget *a_menuitem,
gpointer a_user_data)
{
SXBoxModel *box_model = NULL ;
SXBoxView *viewport = a_user_data ;
g_return_if_fail (a_menuitem
&& GTK_IS_WIDGET (a_menuitem)
&& SX_IS_BOX_VIEW (viewport)) ;
sx_box_view_get_box_model (viewport, &box_model) ;
if (box_model)
{
sx_box_dump_to_file ((SXBox*)box_model,
0, stdout) ;
}
else
{
cr_utils_trace_info ("Got NULL box_model") ;
}
}
static gboolean
button_press_event_cb (GtkWidget *a_viewport,
GdkEvent *a_event,
gpointer *a_user_data)
{
GtkWidget * menu = NULL, *window = NULL;
GdkEventButton *button_event = NULL ;
g_return_val_if_fail (a_event && a_viewport
&& SX_BOX_VIEW (a_viewport),
FALSE) ;
window = GTK_WIDGET (a_user_data) ;
g_return_val_if_fail (window && GTK_IS_WINDOW (window),
FALSE) ;
switch (a_event->type)
{
case GDK_BUTTON_PRESS:
if (a_event->button.button == 3)
{
menu = get_contextual_menu
(SX_BOX_VIEW (a_viewport)) ;
if (!menu)
break ;
button_event = (GdkEventButton*)a_event ;
gtk_menu_popup (GTK_MENU (menu),
NULL, NULL, NULL,
window, button_event->button,
button_event->time) ;
return TRUE ;
}
break ;
default:
break ;
}
return FALSE ;
}
static void
usage (void)
{
g_print ("usage : minifox <xmlfile> <cssfile>\n");
}
static GtkWidget *
get_contextual_menu (SXBoxView *a_viewport)
{
static GtkWidget * menu = NULL;
GtkWidget *menuitem= NULL ;
g_return_val_if_fail (a_viewport
&& SX_IS_BOX_VIEW (a_viewport),
NULL) ;
if (!menu)
{
menu = gtk_menu_new () ;
menuitem = gtk_menu_item_new_with_label ("Dump Box model") ;
gtk_widget_show (menuitem) ;
g_signal_connect (G_OBJECT (menuitem),
"activate",
G_CALLBACK (dump_box_model_menuitem_activate_cb),
a_viewport) ;
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem) ;
}
return menu ;
}
int
main (int argc, char **argv)
{
GtkWidget *window = NULL;
GtkWidget *scroll = NULL;
SXBoxView * viewport = NULL;
gtk_init (&argc, &argv);
if (argc != 3) {
usage ();
return 1;
}
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (GTK_WINDOW (window),
500, 300) ;
gtk_window_set_resizable (GTK_WINDOW (window),
TRUE) ;
g_signal_connect (G_OBJECT (window), "delete-event",
G_CALLBACK (delete_event_cb), NULL);
scroll = gtk_scrolled_window_new (NULL, NULL) ;
gtk_container_add (GTK_CONTAINER (window), scroll) ;
g_print ("Rendering xml: %s - css: %s \n",argv[1],argv[2]);
viewport = sx_box_view_new_from_xml_css_paths(argv[1], argv[2]);
if (!viewport)
{
cr_utils_trace_info ("Could not instanciate the viewport") ;
return -1 ;
}
gtk_container_add (GTK_CONTAINER (scroll), GTK_WIDGET (viewport)) ;
g_signal_connect (G_OBJECT (viewport),
"button-press-event",
G_CALLBACK (button_press_event_cb),
window) ;
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]