00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef AP_RDFSEMANTICITEMGTKINJECTED_H
00021 #define AP_RDFSEMANTICITEMGTKINJECTED_H
00022
00023 #include <gtk/gtk.h>
00024
00025 #include "pd_DocumentRDF.h"
00026 #include "ut_std_string.h"
00027 #include "xap_Dialog_Id.h"
00028 #include "xap_App.h"
00029 #include "xap_UnixDialogHelper.h"
00030 #include "xap_Strings.h"
00031
00032 #define G_OBJECT_SEMITEM "G_OBJECT_SEMITEM"
00033 #define G_OBJECT_SEMITEM_LIST "G_OBJECT_SEMITEM_LIST"
00034 #define G_OBJECT_WINDOW "G_OBJECT_WINDOW"
00035 #define G_OBJECT_TREEVIEW "G_OBJECT_TREEVIEW"
00036
00037 class ap_GObjectSemItem
00038 {
00039 public:
00040 PD_RDFSemanticItemHandle h;
00041 ap_GObjectSemItem( PD_RDFSemanticItemHandle _h )
00042 : h(_h)
00043 {
00044 }
00045 };
00046
00047 class ap_GObjectSemItem_List
00048 {
00049 public:
00050 PD_RDFSemanticItems cl;
00051 ap_GObjectSemItem_List( PD_RDFSemanticItems _cl )
00052 : cl(_cl)
00053 {
00054 }
00055 };
00056
00057 void GDestroyNotify_GObjectSemItem(gpointer data);
00058 PD_RDFSemanticItemHandle getHandle(GtkDialog* d);
00059 void OnSemItemEdited ( GtkDialog* d, gint ,
00060 gpointer );
00061
00062 void GDestroyNotify_GObjectSemItem_List(gpointer data);
00063 PD_RDFSemanticItems getSemItemListHandle(GtkDialog* d);
00064 void OnSemItemListEdited ( GtkDialog* d, gint response_id,
00065 gpointer );
00066
00067
00068
00069
00070 template < class ParentClass >
00071 class ABI_EXPORT AP_RDFSemanticItemGTKInjected : public ParentClass
00072 {
00073 public:
00074 typedef std::list< std::map< std::string, std::string > > PD_ResultBindings_t;
00075 AP_RDFSemanticItemGTKInjected( PD_DocumentRDFHandle rdf, PD_ResultBindings_t::iterator& it )
00076 : ParentClass( rdf, it )
00077 {
00078 }
00079 AP_RDFSemanticItemGTKInjected( PD_DocumentRDFHandle rdf, PD_ResultBindings_t::iterator& it, bool v )
00080 : ParentClass( rdf, it, v )
00081 {
00082 }
00083
00084 void showEditorWindow( PD_RDFSemanticItemHandle c )
00085 {
00086 UT_DEBUGMSG(("showEditorWindow(INJECTED) name:%s linksubj:%s\n",
00087 c->name().c_str(), c->linkingSubject().toString().c_str() ));
00088 const XAP_StringSet* pSS = XAP_App::getApp()->getStringSet();
00089 std::string s;
00090 pSS->getValueUTF8(XAP_STRING_ID_DLG_OK, s);
00091 GtkWidget* d = gtk_dialog_new_with_buttons ("Message",
00092 0,
00093 GTK_DIALOG_DESTROY_WITH_PARENT,
00094 convertMnemonics(s).c_str(),
00095 GTK_RESPONSE_NONE,
00096 NULL);
00097 GtkWidget* w = GTK_WIDGET(c->createEditor());
00098 g_object_set_data_full( G_OBJECT(w),
00099 G_OBJECT_SEMITEM,
00100 new ap_GObjectSemItem( c ),
00101 GDestroyNotify_GObjectSemItem );
00102
00103
00104
00105
00106
00107 g_object_ref(w);
00108 GtkWidget* container = gtk_widget_get_parent(w);
00109 gtk_container_remove(GTK_CONTAINER(container), w);
00110 gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area( GTK_DIALOG (d))), w);
00111 g_object_unref(w);
00112
00113 g_signal_connect (G_OBJECT(d), "response", G_CALLBACK(OnSemItemEdited), c.get() );
00114 gtk_widget_show_all (d);
00115 }
00116
00117 void showEditorWindow( PD_RDFSemanticItems cl )
00118 {
00119 UT_DEBUGMSG(("showEditorWindow() list... sz:%ld\n", cl.size() ));
00120
00121 const XAP_StringSet* pSS = XAP_App::getApp()->getStringSet();
00122 std::string s;
00123 pSS->getValueUTF8(XAP_STRING_ID_DLG_OK, s);
00124 GtkWidget* d = gtk_dialog_new_with_buttons ("Message",
00125 0,
00126 GTK_DIALOG_DESTROY_WITH_PARENT,
00127 convertMnemonics(s).c_str(),
00128 GTK_RESPONSE_NONE,
00129 NULL);
00130 GtkNotebook* notebook = GTK_NOTEBOOK(gtk_notebook_new());
00131 gtk_container_add( GTK_CONTAINER(gtk_dialog_get_content_area( GTK_DIALOG (d))),
00132 GTK_WIDGET(notebook) );
00133 for( PD_RDFSemanticItems::iterator ci = cl.begin(); ci != cl.end(); ++ci )
00134 {
00135 PD_RDFSemanticItemHandle c = *ci;
00136 GtkWidget* w = GTK_WIDGET(c->createEditor());
00137 g_object_set_data_full( G_OBJECT(w),
00138 G_OBJECT_SEMITEM,
00139 new ap_GObjectSemItem( c ),
00140 GDestroyNotify_GObjectSemItem );
00141 g_object_set_data_full( G_OBJECT(d),
00142 G_OBJECT_SEMITEM,
00143 new ap_GObjectSemItem( c ),
00144 GDestroyNotify_GObjectSemItem );
00145
00146 std::string label = c->getDisplayLabel();
00147 GtkWidget* container = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
00148 gtk_notebook_append_page( notebook, container, gtk_label_new( label.c_str() ));
00149 GtkWidget *oldContainer = gtk_widget_get_parent(w);
00150 g_object_ref(w);
00151 gtk_container_remove(GTK_CONTAINER(oldContainer), w);
00152 gtk_container_add(GTK_CONTAINER(container), w);
00153 g_object_unref(w);
00154 }
00155 g_object_set_data_full( G_OBJECT(d),
00156 G_OBJECT_SEMITEM_LIST,
00157 new ap_GObjectSemItem_List( cl ),
00158 GDestroyNotify_GObjectSemItem_List );
00159 g_signal_connect (G_OBJECT(d), "response", G_CALLBACK(OnSemItemListEdited), 0 );
00160 gtk_widget_show_all (d);
00161 }
00162
00163 void importFromDataComplete( std::istream& ,
00164 PD_DocumentRDFHandle rdf,
00165 PD_DocumentRDFMutationHandle m,
00166 PD_DocumentRange * pDocRange = 0 )
00167 {
00168
00169
00170 GtkWidget* objectEditor = (GtkWidget*)this->createEditor();
00171 this->updateFromEditorData( m );
00172 gtk_widget_destroy( GTK_WIDGET(objectEditor) );
00173
00174 if (pDocRange)
00175 {
00176
00177 }
00178
00179 if (rdf)
00180 {
00181
00182 }
00183 }
00184
00185 std::string getImportFromFileName( const std::string& filename_const,
00186 std::list< std::pair< std::string, std::string> > types ) const
00187 {
00188 std::string ret = filename_const;
00189
00190 UT_runDialog_AskForPathname afp( XAP_DIALOG_ID_FILE_IMPORT );
00191 if( !types.empty() )
00192 {
00193 std::list< std::pair< std::string, std::string> >::iterator iter = types.begin();
00194 afp.setDefaultFiletype( iter->first, iter->second );
00195 }
00196 for( std::list< std::pair< std::string, std::string> >::iterator iter = types.begin();
00197 iter != types.end(); ++iter )
00198 {
00199 afp.appendFiletype( iter->first, iter->second );
00200 }
00201
00202 if( afp.run( XAP_App::getApp()->getLastFocussedFrame() ) )
00203 {
00204 ret = afp.getPath();
00205 if( starts_with( ret, "file:" ))
00206 ret = ret.substr( strlen("file:") );
00207 }
00208 return ret;
00209 }
00210
00211 std::string
00212 getExportToFileName( const std::string& filename_const,
00213 std::string defaultExtension,
00214 std::list< std::pair< std::string, std::string> > types ) const
00215 {
00216 std::string filename = filename_const;
00217
00218 if( filename.empty() )
00219 {
00220 UT_runDialog_AskForPathname afp( XAP_DIALOG_ID_FILE_EXPORT );
00221 if( !types.empty() )
00222 {
00223 std::list< std::pair< std::string, std::string> >::iterator iter = types.begin();
00224 afp.setDefaultFiletype( iter->first, iter->second );
00225 }
00226 for( std::list< std::pair< std::string, std::string> >::iterator iter = types.begin();
00227 iter != types.end(); ++iter )
00228 {
00229 afp.appendFiletype( iter->first, iter->second );
00230 }
00231
00232 if( afp.run( XAP_App::getApp()->getLastFocussedFrame() ) )
00233 {
00234 filename = afp.getPath();
00235 if( starts_with( filename, "file:" ))
00236 filename = filename.substr( strlen("file:") );
00237 if( !ends_with( filename, defaultExtension ))
00238 filename += defaultExtension;
00239 }
00240 }
00241
00242 return filename;
00243 }
00244
00245
00246 };
00247 #endif