Re: Sample bonobo2 container.



First, thanks a million for the container. Simple and interesting to
play with. I offer some modifications of the container (support for
png,pdf,ps and initial work for non-bonobowindow-based test app).

I played with 4 kinds of servers: ggf, gpdf, gtkhtml3, eog and found
them very different in terms of bonobization quality level. gtkhtml is
really nice. And probably best working of 4. 

ggv, gpdf, eog declare themselves as zoomable. But only eog really zooms
from popup menu and toolbar. Both ggv and gpdf show menu items and
buttons - but do not zoom.

Also, I started to modify (#ifdef GTKWIN) the application to see how
these controls embed themselves into usual gtk widgets. They work not
that bad - but only popup menus are available. If I could get at least
toolbars... Well, gtkhtml really goes crazy in this mode. It shows
formatting toolbar. Twice - on top and bottom:)

Versions:

ggv 1.99.98
gpdf 0.100
gtkhtml3 3.0.1
eog 2.2.1

GNOME 2.2.1 taken from NyQuist by apt-get on RH8.0

In a word: I think this test app would be a really nice thing to have in
GNOME CVS. Even with simplest makefile. Just as a bench for bonobo
control developers - at least we could compare different controls on
their bonobo quality level.

Michal, what do you think on this?

-- 
Sergey
#define BONOBO_UI_INTERNAL
#include <bonobo.h>
#include <glib.h>

#define GTKWIN

BonoboControlFrame *ctrl_frame;
BonoboUIComponent *ui_comp;

/* vbox */
GtkWidget *box;
GtkWidget *ctrl_widget;

char *image_file;

#ifdef GTKWIN
static Bonobo_Control instantiate_control( const char *fileMoniker )
{
  GtkWidget *bo = bonobo_widget_new_control( fileMoniker, CORBA_OBJECT_NIL );
  return ( Bonobo_Control )
    Bonobo_Unknown_queryInterface( bonobo_widget_get_objref
                                   ( BONOBO_WIDGET( bo ) ),
                                   "IDL:Bonobo/Control:1.0", NULL );

}

#else
static Bonobo_Control instantiate_control( const char *fileMoniker )
{
  Bonobo_Control control;
  Bonobo_PersistFile pfile;
  CORBA_Environment ev;

  const char *iid = strstr( fileMoniker,
                            ".png" ) ? "OAFIID:GNOME_EOG_Control" :
    strstr( fileMoniker,
            ".ps" ) ? "OAFIID:GNOME_GGV_Control" : 
    strstr( fileMoniker,
            ".pdf" ) ? "OAFIID:GNOME_PDF_Control" : 
    strstr( fileMoniker,
            ".html" ) ? "OAFIID:GNOME_GtkHTML_Editor:3.0" : "WTF?";

  CORBA_exception_init( &ev );

  /* get control component */
  control = bonobo_get_object( iid, "Bonobo/Control", &ev );
  if( BONOBO_EX( &ev ) || ( control == CORBA_OBJECT_NIL ) )
    exit( 1 );

  /* get PersistFile interface */
  pfile =
    Bonobo_Unknown_queryInterface( control, "IDL:Bonobo/PersistFile:1.0",
                                   &ev );
  if( BONOBO_EX( &ev ) || ( pfile == CORBA_OBJECT_NIL ) )
    exit( 1 );

  /* load the file */
  Bonobo_PersistFile_load( pfile, image_file, &ev );
  bonobo_object_release_unref( pfile, NULL );
  return control;
}

static void
verb_DoNothing( BonoboUIComponent * uic, gpointer user_data,
                const char *cname )
{
}

static BonoboUIVerb app_verbs[] = {
  BONOBO_UI_VERB( "FileNewWindow", verb_DoNothing ),
  BONOBO_UI_VERB( "FileOpen", verb_DoNothing ),
  BONOBO_UI_VERB( "FileCloseWindow", verb_DoNothing ),
  BONOBO_UI_VERB( "FileExit", verb_DoNothing ),
  BONOBO_UI_VERB( "Preferences", verb_DoNothing ),
  BONOBO_UI_VERB( "HelpAbout", verb_DoNothing ),
  BONOBO_UI_VERB( "Help", verb_DoNothing ),
  BONOBO_UI_VERB( "DnDNewWindow", verb_DoNothing ),
  BONOBO_UI_VERB( "DnDSameWindow", verb_DoNothing ),
  BONOBO_UI_VERB( "DnDCancel", verb_DoNothing ),
  BONOBO_UI_VERB_END
};
#endif

static void add_control_to_ui( GtkWidget * window, Bonobo_Control control )
{
  CORBA_Environment ev;
  Bonobo_PropertyControl prop_control;
  BonoboUIContainer *ui_container;
  char *curdir;

  g_return_if_fail( window != NULL );
#ifndef GTKWIN
  g_return_if_fail( BONOBO_IS_WINDOW( window ) );
#endif

  CORBA_exception_init( &ev );
#ifdef GTKWIN
  ui_container = bonobo_ui_container_new(  );
  BonoboUIEngine *bue = bonobo_ui_engine_new( G_OBJECT( window ) );
  bonobo_ui_engine_set_ui_container( bue, ui_container );
#else
  ui_container = bonobo_window_get_ui_container( BONOBO_WINDOW( window ) );
#endif

  ctrl_frame = bonobo_control_frame_new( BONOBO_OBJREF( ui_container ) );

  /* bind and view new control widget */
  bonobo_control_frame_bind_to_control( ctrl_frame, control, &ev );
  bonobo_control_frame_control_activate( ctrl_frame );
  if( control != CORBA_OBJECT_NIL && ctrl_widget == NULL )
  {
    ctrl_widget = bonobo_control_frame_get_widget( ctrl_frame );
    if( !ctrl_widget )
      g_assert_not_reached(  );

#ifdef GTKWIN
    gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( ctrl_widget ) );
#else
    bonobo_window_set_contents( BONOBO_WINDOW( window ),
                                GTK_WIDGET( ctrl_widget ) );
#endif
    gtk_widget_show( ctrl_widget );
  }

  ui_comp = bonobo_ui_component_new( "eog" );
  bonobo_ui_component_set_container( ui_comp, BONOBO_OBJREF( ui_container ),
                                     NULL );

#ifndef GTKWIN
  curdir = ( char * ) getcwd( NULL, 0 );
  printf( "curdir = %s\n", curdir );
  bonobo_ui_util_set_ui( ui_comp, curdir, "container-ui.xml", "Container",
                         NULL );
  free( curdir );
  bonobo_ui_component_add_verb_list_with_data( ui_comp, app_verbs, window );

  /* update sensitivity of the properties menu item */
  prop_control = Bonobo_Unknown_queryInterface( control,
                                                "IDL:Bonobo/PropertyControl:1.0",
                                                &ev );
  bonobo_ui_component_set_prop( ui_comp, "/commands/Preferences", "sensitive",
                                prop_control == CORBA_OBJECT_NIL ? "0" : "1",
                                &ev );

  bonobo_object_release_unref( prop_control, &ev );
#endif

  /* enable view menu */
  /* FIXME: We should check if the component adds anything to 
   *        the menu, so that we don't view an empty menu.
   */

  CORBA_exception_free( &ev );

  /* retrieve control properties and install listeners */
  //check_for_control_properties (window);
}

static void window_destroyed( GtkWindow * window, char *data )
{
  Bonobo_Control control;
  bonobo_control_frame_control_deactivate( ctrl_frame );
  control = bonobo_control_frame_get_control( ctrl_frame );
  bonobo_object_release_unref( control, NULL );
  bonobo_main_quit(  );
}

int main( int argc, char *argv[] )
{
  BonoboWidget *bw;
  gchar filename[100];
  GtkWindow *window;
  BonoboUIEngine *engine;
  BonoboUIContainer *container;
  Bonobo_Control control;

  bindtextdomain( "container", GNOMELOCALEDIR );
  bind_textdomain_codeset( "container", "UTF-8" );
  textdomain( "container" );

  if( argc <= 1 )
  {
    fprintf( stderr, "%s: not enough args\n", argv[0] );
    fprintf( stderr, "Usage: %s <image file>\n", argv[0] );
    exit( 1 );
  }
  image_file = argv[1];

  bonobo_ui_init( "container", "1.0", &argc, argv );

  if( gnome_vfs_init(  ) == FALSE )
    g_error( _( "Could not initialize GnomeVFS!\n" ) );

#ifdef GTKWIN
  window = GTK_WINDOW( gtk_window_new( GTK_WINDOW_TOPLEVEL ) );
  GtkWidget *nb = gtk_notebook_new(  );
  gtk_container_add( GTK_CONTAINER( window ), nb );

  GtkWidget *page1 = gtk_alignment_new( 12, 12, 1, 1 );
  gtk_notebook_append_page( GTK_NOTEBOOK( nb ), page1,
                            gtk_label_new( "bonobo control" ) );
  GtkWidget *page2 = gtk_label_new( "Just for fun..." );
  gtk_notebook_append_page( GTK_NOTEBOOK( nb ), page2,
                            gtk_label_new( "gtk label" ) );
#else
  window = GTK_WINDOW( bonobo_window_new( "Window", "Test Container" ) );
#endif

  // instantiate a control
  g_snprintf( filename, sizeof( filename ), "file:/%s", image_file );

  control = instantiate_control( filename );

  // put it into our window
#ifdef GTKWIN
  add_control_to_ui( page1, control );
#else
  add_control_to_ui( GTK_WIDGET( window ), control );
#endif

  g_signal_connect( window, "destroy",
                    G_CALLBACK( window_destroyed ), &window );

  gtk_widget_show_all( GTK_WIDGET( window ) );

  bonobo_main(  );

  return 0;
}

Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]