• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ap_RDFSemanticItemGTKInjected.h

Go to the documentation of this file.
00001 /* AbiWord
00002  * Copyright (C) Ben Martin 2012.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301 USA.
00018  */
00019 
00020 #ifndef AP_RDFSEMANTICITEMGTKINJECTED_H
00021 #define AP_RDFSEMANTICITEMGTKINJECTED_H
00022 
00023 #include "pd_DocumentRDF.h"
00024 #include "ut_std_string.h"
00025 #include "xap_Dialog_Id.h"
00026 #include "xap_App.h"
00027 
00028 #define G_OBJECT_SEMITEM "G_OBJECT_SEMITEM"
00029 #define G_OBJECT_SEMITEM_LIST "G_OBJECT_SEMITEM_LIST"
00030 #define G_OBJECT_WINDOW  "G_OBJECT_WINDOW"
00031 #define G_OBJECT_TREEVIEW "G_OBJECT_TREEVIEW"
00032 
00033 class ap_GObjectSemItem
00034 {
00035 public:
00036     PD_RDFSemanticItemHandle h;
00037     ap_GObjectSemItem( PD_RDFSemanticItemHandle _h )
00038         : h(_h)
00039     {
00040     }
00041 };
00042 
00043 class ap_GObjectSemItem_List
00044 {
00045 public:
00046     PD_RDFSemanticItems cl;
00047     ap_GObjectSemItem_List( PD_RDFSemanticItems _cl )
00048         : cl(_cl)
00049     {
00050     }
00051 };
00052 
00053 void GDestroyNotify_GObjectSemItem(gpointer data);
00054 PD_RDFSemanticItemHandle getHandle(GtkDialog* d);
00055 void OnSemItemEdited ( GtkDialog* d, gint /*response_id*/,
00056                        gpointer /*user_data*/);
00057 
00058 void GDestroyNotify_GObjectSemItem_List(gpointer data);
00059 PD_RDFSemanticItems getSemItemListHandle(GtkDialog* d);
00060 void OnSemItemListEdited ( GtkDialog* d, gint response_id,
00061                            gpointer /*user_data*/);
00062 
00063 
00064 
00065 
00066 template < class ParentClass >
00067 class ABI_EXPORT AP_RDFSemanticItemGTKInjected : public ParentClass
00068 {
00069   public:
00070     typedef std::list< std::map< std::string, std::string > > PD_ResultBindings_t;
00071     AP_RDFSemanticItemGTKInjected( PD_DocumentRDFHandle rdf, PD_ResultBindings_t::iterator& it )
00072       : ParentClass( rdf, it )
00073     {
00074     }
00075     AP_RDFSemanticItemGTKInjected( PD_DocumentRDFHandle rdf, PD_ResultBindings_t::iterator& it, bool v )
00076       : ParentClass( rdf, it, v )
00077     {
00078     }
00079 
00080     void showEditorWindow( PD_RDFSemanticItemHandle c )
00081     {
00082         UT_DEBUGMSG(("showEditorWindow(INJECTED) name:%s linksubj:%s\n",
00083                      c->name().c_str(), c->linkingSubject().toString().c_str() ));
00084         GtkWidget* d = gtk_dialog_new_with_buttons ("Message",
00085                                                     0,
00086                                                     GTK_DIALOG_DESTROY_WITH_PARENT,
00087                                                     GTK_STOCK_OK,
00088                                                     GTK_RESPONSE_NONE,
00089                                                     NULL);
00090         GtkWidget* w = GTK_WIDGET(c->createEditor());
00091         g_object_set_data_full( G_OBJECT(w),
00092                                 G_OBJECT_SEMITEM,
00093                                 new ap_GObjectSemItem( c ),
00094                                 GDestroyNotify_GObjectSemItem );
00095         /* g_object_set_data_full( G_OBJECT(d), */
00096         /*                         G_OBJECT_SEMITEM, */
00097         /*                         new struct G_OBJECT_SEMITEM( c ), */
00098         /*                         GDestroyNotify_G_OBJECT_SEMITEM ); */
00099         gtk_widget_reparent( w, GTK_WIDGET( gtk_dialog_get_content_area( GTK_DIALOG (d))));
00100 
00101         g_signal_connect (G_OBJECT(d), "response",  G_CALLBACK(OnSemItemEdited), c.get() );
00102         gtk_widget_show_all (d);
00103     }
00104 
00105     void showEditorWindow( PD_RDFSemanticItems cl )
00106     {
00107         UT_DEBUGMSG(("showEditorWindow() list... sz:%ld\n", cl.size() ));
00108 
00109         GtkWidget* d = gtk_dialog_new_with_buttons ("Message",
00110                                                     0,
00111                                                     GTK_DIALOG_DESTROY_WITH_PARENT,
00112                                                     GTK_STOCK_OK,
00113                                                     GTK_RESPONSE_NONE,
00114                                                     NULL);
00115         GtkNotebook* notebook = GTK_NOTEBOOK(gtk_notebook_new());
00116         gtk_container_add( GTK_CONTAINER(gtk_dialog_get_content_area( GTK_DIALOG (d))),
00117                            GTK_WIDGET(notebook) );
00118         for( PD_RDFSemanticItems::iterator ci = cl.begin(); ci != cl.end(); ++ci )
00119         {
00120             PD_RDFSemanticItemHandle c = *ci;
00121             GtkWidget* w = GTK_WIDGET(c->createEditor());
00122             g_object_set_data_full( G_OBJECT(w),
00123                                     G_OBJECT_SEMITEM,
00124                                     new ap_GObjectSemItem( c ),
00125                                     GDestroyNotify_GObjectSemItem );
00126             g_object_set_data_full( G_OBJECT(d),
00127                                     G_OBJECT_SEMITEM,
00128                                     new ap_GObjectSemItem( c ),
00129                                     GDestroyNotify_GObjectSemItem );
00130 
00131             std::string label = c->getDisplayLabel();
00132             GtkWidget* container = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
00133             gtk_notebook_append_page( notebook, container, gtk_label_new( label.c_str() ));
00134             gtk_widget_reparent( w, GTK_WIDGET( container));
00135         }
00136         g_object_set_data_full( G_OBJECT(d),
00137                                 G_OBJECT_SEMITEM_LIST,
00138                                 new ap_GObjectSemItem_List( cl ),
00139                                 GDestroyNotify_GObjectSemItem_List );
00140         g_signal_connect (G_OBJECT(d), "response",  G_CALLBACK(OnSemItemListEdited), 0 );
00141         gtk_widget_show_all (d);
00142     }
00143 
00144     void importFromDataComplete( std::istream& /*iss*/,
00145                                 PD_DocumentRDFHandle rdf,
00146                                 PD_DocumentRDFMutationHandle m,
00147                                 PD_DocumentRange * pDocRange = 0 )
00148     {
00149         // Create and populate and editor with the current data,
00150         // then update the Rdf from that editor.
00151         GtkWidget* objectEditor = (GtkWidget*)this->createEditor();
00152         this->updateFromEditorData( m );
00153         gtk_widget_destroy( GTK_WIDGET(objectEditor) );
00154 
00155         if (pDocRange)
00156         {
00157 //        insert(host);
00158         }
00159 
00160         if (rdf)
00161         {
00162 //        rdf->emitSemanticObjectAdded(this);
00163         }
00164     }
00165 
00166     std::string getImportFromFileName( const std::string& filename_const,
00167                                        std::list< std::pair< std::string, std::string> > types ) const
00168     {
00169         std::string ret = filename_const;
00170 
00171         UT_runDialog_AskForPathname afp( XAP_DIALOG_ID_FILE_IMPORT );
00172         if( !types.empty() )
00173         {
00174             std::list< std::pair< std::string, std::string> >::iterator iter = types.begin();
00175             afp.setDefaultFiletype( iter->first, iter->second );
00176         }
00177         for( std::list< std::pair< std::string, std::string> >::iterator iter = types.begin();
00178              iter != types.end(); ++iter )
00179         {
00180             afp.appendFiletype(    iter->first, iter->second );
00181         }
00182 
00183         if( afp.run( XAP_App::getApp()->getLastFocussedFrame() ) )
00184         {
00185             ret = afp.getPath();
00186             if( starts_with( ret, "file:" ))
00187                 ret = ret.substr( strlen("file:") );
00188         }
00189         return ret;
00190     }
00191 
00192     std::string
00193         getExportToFileName( const std::string& filename_const,
00194                              std::string defaultExtension,
00195                              std::list< std::pair< std::string, std::string> > types ) const
00196     {
00197         std::string filename = filename_const;
00198 
00199         if( filename.empty() )
00200         {
00201             UT_runDialog_AskForPathname afp( XAP_DIALOG_ID_FILE_EXPORT );
00202             if( !types.empty() )
00203             {
00204                 std::list< std::pair< std::string, std::string> >::iterator iter = types.begin();
00205                 afp.setDefaultFiletype( iter->first, iter->second );
00206             }
00207             for( std::list< std::pair< std::string, std::string> >::iterator iter = types.begin();
00208                  iter != types.end(); ++iter )
00209             {
00210                 afp.appendFiletype(    iter->first, iter->second );
00211             }
00212 
00213             if( afp.run( XAP_App::getApp()->getLastFocussedFrame() ) )
00214             {
00215                 filename = afp.getPath();
00216                 if( starts_with( filename, "file:" ))
00217                     filename = filename.substr( strlen("file:") );
00218                 if( !ends_with( filename, defaultExtension ))
00219                     filename += defaultExtension;
00220             }
00221         }
00222 
00223         return filename;
00224     }
00225 
00226 
00227 };
00228 #endif

Generated on Sun May 19 2013 for AbiWord by  doxygen 1.7.1