COOPY » Guide  version 0.6.5
/home/paulfitz/cvs/coopy_scm/coopy/src/libgnumeric/gnumeric_link.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 //#include <gnumeric-config.h>
00003 #include <glib/gi18n.h>
00004 #include "gnumeric.h"
00005 #include "position.h"
00006 #include "parse-util.h"
00007 #include "workbook.h"
00008 #include "workbook-priv.h"
00009 #include "workbook-control.h"
00010 #include "sheet.h"
00011 #include "dependent.h"
00012 #include "expr-name.h"
00013 #include "libgnumeric.h"
00014 #include "gutils.h"
00015 //#include "gnumeric-paths.h"
00016 #include "gnm-plugin.h"
00017 #include "command-context.h"
00018 #include "command-context-stderr.h"
00019 #include "workbook-view.h"
00020 #include "cell.h"
00021 #include "value.h"
00022 //#include <dialogs/dialogs.h>
00023 #include <goffice/goffice.h>
00024 #include <goffice/utils/go-file.h>
00025 #include <goffice/app/io-context.h>
00026 #include <gsf/gsf-utils.h>
00027 #include <string.h>
00028 #include "stf-parse.h"
00029 #include "clipboard.h"
00030 
00031 #include "mstyle.h"
00032 #include "style.h"
00033 #include "sheet-style.h"
00034 #include "style-color.h"
00035 
00036 #include "hlink.h"
00037 #include "func.h"
00038 #include "expr.h"
00039 #include "expr-impl.h"
00040 
00041 #include "coopy/gnumeric_link.h"
00042 
00043 #ifndef GNM_VERSION_FULL
00044 #define OLD_GNUMERIC
00045 #endif
00046 
00047 #ifdef OLD_GNUMERIC
00048 #define GOIOContext IOContext
00049 #define GO_FILE_SAVE_WORKBOOK FILE_SAVE_WORKBOOK
00050 #define GOErrorInfo ErrorInfo
00051 #define GNM_VERSION_FULL GNUMERIC_VERSION
00052 #define go_get_file_savers get_file_savers
00053 #define go_get_file_openers get_file_openers
00054 #define go_io_context_new gnumeric_io_context_new
00055 #define wb_view_get_workbook wb_view_workbook
00056 #define sheet_cell_create sheet_cell_new
00057 #define PASTE_CONTENTS PASTE_CONTENT
00058 #define DO_UNDO NULL, &tmp
00059 #define BEGIN_UNDO GnmRelocUndo tmp;
00060 #define END_UNDO dependents_unrelocate_free (tmp.exprs);
00061 #else
00062 #define DO_UNDO NULL
00063 #define BEGIN_UNDO
00064 #define END_UNDO
00065 #endif
00066 
00067 static GOErrorInfo      *plugin_errs = NULL;
00068 static GOCmdContext     *cc = NULL;
00069 static int gnumeric_init_ct = 0;
00070 static int gnumeric_inited = 0;
00071 
00072 static void gnumeric_atexit(void) {
00073   if (gnumeric_inited) {
00074     g_object_unref (cc);
00075     gnm_shutdown ();
00076     gnumeric_inited = 0;
00077   }
00078 }
00079 
00080 int gnumeric_init() {
00081   gnumeric_init_ct++;
00082   if (gnumeric_init_ct>1) return 0;
00083   int            res = 0;
00084   int argc = 1;
00085   char const *argv[] = { "gnumeric", NULL };
00086 #ifdef OLD_GNUMERIC
00087         gchar const **args = go_shell_argv_to_glib_encoding (argc, argv);
00088         gnm_pre_parse_init (args[0]);
00089         gnm_common_init (FALSE);
00090 #else
00091         gnm_pre_parse_init (argc, argv);
00092         gnm_init ();
00093 #endif
00094   
00095   cc = cmd_context_stderr_new ();
00096   gnm_plugins_init (GO_CMD_CONTEXT (cc));
00097   go_plugin_db_activate_plugin_list (
00098                                      go_plugins_get_available_plugins (), &plugin_errs);
00099   atexit(gnumeric_atexit);
00100   return 0;
00101 }
00102 
00103 //static WorkbookView *wbv = NULL;
00104 
00105 int gnumeric_fini() {
00106   // moved to atexit()
00107 
00108   //gnumeric_init_ct--;
00109   //if (gnumeric_init_ct>0) return 0;
00110 }
00111 
00112 int gnumeric_free(GnumericWorkbookPtr workbook) {
00113   WorkbookView *wbv = (WorkbookView *)workbook;
00114   if (wbv!=NULL) {
00115     g_object_unref (wb_view_get_workbook (wbv));
00116   }
00117   return 0;
00118 }
00119 
00120 
00121 GnumericWorkbookPtr gnumeric_load(const char *fname) {
00122   GOIOContext *io_context = go_io_context_new (cc);
00123   char *uri = go_filename_to_uri (fname);
00124   //printf("Have uri %s\n", uri);
00125 
00126   WorkbookView *wbv = wb_view_new_from_uri (uri, NULL,
00127                                             io_context, NULL);
00128   g_free (uri);
00129   //printf("Have workbook view\n");
00130   g_object_unref (io_context);
00131   return wbv;
00132 }
00133 
00134 GnumericWorkbookPtr gnumeric_create() {
00135   return workbook_view_new(NULL);
00136 
00137 }
00138 
00139 
00140 int gnumeric_save(GnumericWorkbookPtr workbook, const char *fname,
00141                   const char *format) {
00142   WorkbookView *wbv = (WorkbookView *)workbook;
00143   int res = 0;
00144   GOFileSaver *fs = NULL;
00145 
00146   if (format!=NULL) {
00147     fs = go_file_saver_for_id(format);
00148     if (fs == NULL) {
00149       fs = go_file_saver_for_file_name (format);
00150       if (fs == NULL) {
00151         res = 1;
00152         g_printerr (_("Unknown exporter '%s'.\n"), format);
00153         return 1;
00154       }
00155     }
00156   }
00157   if (fs==NULL) {
00158     fs = go_file_saver_for_file_name (fname);
00159     if (fs == NULL) {
00160       res = 2;
00161       g_printerr (_("Unable to guess exporter to use for '%s'.\n"
00162                     "Try --list-exporters to see a list of possibilities.\n"),
00163                   fname);
00164       return 1;
00165     }
00166   }
00167   //g_print ("Using exporter %s\n",
00168   //go_file_saver_get_id (fs));
00169   if (go_file_saver_get_save_scope (fs) !=
00170       GO_FILE_SAVE_WORKBOOK) {
00171     g_printerr (_("Selected exporter (%s) does not support saving multiple sheets in one file.\n"
00172                   "Only the current sheet will be saved.\n"),
00173                 go_file_saver_get_id (fs));
00174   }
00175   char *outfile = go_filename_to_uri (fname);
00176   if (fname[0]=='-') {
00177     res = !wb_view_save_as (wbv, fs, "fd://1", cc);
00178   } else {
00179     res = !wb_view_save_as (wbv, fs, outfile, cc);
00180   }
00181   g_free (outfile);
00182   return 0;
00183 }
00184 
00185 int gnumeric_overlay_csv(GnumericWorkbookPtr workbook,
00186                          const char *start, const char *stop) {
00187   WorkbookView *wbv = (WorkbookView *)workbook;
00188   printf("For testing, try pasting some data into workbook\n");
00189   //Workbook *wb = wb_view_get_workbook (wbv);
00190   Sheet *sheet = wb_view_cur_sheet (wbv);
00191   if (sheet==NULL) { printf("no sheet!\n"); return 1; }
00192   StfParseOptions_t *options = stf_parse_options_guess(start);
00193   stf_parse_sheet(options,start,stop,sheet,0,0);
00194   stf_parse_options_free(options);
00195   options = NULL;
00196   return 0;
00197 }
00198 
00199 int gnumeric_get_sheet_count(GnumericWorkbookPtr workbook) {
00200   WorkbookView *wbv = (WorkbookView *)workbook;
00201   return workbook_sheet_count(wb_view_get_workbook(wbv));
00202 }
00203 
00204 GnumericSheetPtr gnumeric_get_sheet(GnumericWorkbookPtr workbook, int index) {
00205   WorkbookView *wbv = (WorkbookView *)workbook;
00206   Sheet *sheet = workbook_sheet_by_index (wb_view_get_workbook (wbv), index);
00207   return (GnumericSheetPtr*)sheet;
00208 }
00209 
00210 GnumericSheetPtr gnumeric_get_sheet_by_name(GnumericWorkbookPtr workbook, 
00211                                             const char *name) {
00212   WorkbookView *wbv = (WorkbookView *)workbook;
00213   Sheet *sheet = workbook_sheet_by_name (wb_view_get_workbook (wbv), name);
00214   return (GnumericSheetPtr*)sheet;
00215 }
00216 
00217 GnumericSheetPtr gnumeric_add_sheet(GnumericWorkbookPtr workbook,
00218                                     const char *name) {
00219   WorkbookView *wbv = (WorkbookView *)workbook;
00220 
00221 #ifndef OLD_GNUMERIC
00222   int cols = gnm_conf_get_core_workbook_n_cols ();
00223   int rows = gnm_conf_get_core_workbook_n_rows ();
00224   if (!gnm_sheet_valid_size (cols, rows)) {
00225     gnm_sheet_suggest_size (&cols, &rows);
00226   }
00227   Sheet *sheet = workbook_sheet_add (wb_view_get_workbook (wbv), 
00228                                      -1, cols, rows);
00229 #else
00230   Sheet *sheet = workbook_sheet_add (wb_view_get_workbook (wbv), 
00231                                      -1, TRUE);
00232 #endif
00233   if (name!=NULL) {
00234     int idx = gnumeric_get_sheet_count(workbook)-1;
00235     GSList *idxs = NULL;
00236     GSList *names = NULL;
00237     idxs = g_slist_append(idxs, GINT_TO_POINTER(idx));
00238     names = g_slist_append(names, (gpointer)name);
00239     workbook_sheet_rename(wb_view_get_workbook (wbv),
00240                           idxs,
00241                           names,
00242                           cc);
00243     g_slist_free(idxs);
00244     g_slist_free(names);
00245   }
00246   return (GnumericSheetPtr*)sheet;
00247 }
00248 
00249 int gnumeric_sheet_get_size(GnumericSheetPtr sheet, int *w, int *h) {
00250   Sheet *s = (Sheet *)sheet;
00251   //GnmSheetSize const *size = gnm_sheet_get_size(sheet);
00252   GnmRange range = sheet_get_extent(s,FALSE);
00253   if (w!=NULL) *w = range.end.col+1;
00254   if (h!=NULL) *h = range.end.row+1;
00255 }
00256 
00257 char *gnumeric_sheet_get_cell_as_string(GnumericSheetPtr sheet, int x, int y) {
00258   GnmValue const *value = sheet_cell_get_value((Sheet*)sheet,x,y);
00259   if (value==NULL) return NULL;
00260   if (value->type == VALUE_EMPTY) return NULL;
00261   return value_get_as_string(value);
00262 }
00263 
00264 int gnumeric_sheet_get_cell(GnumericSheetPtr sheet, int x, int y,
00265                             GSheetCellPtr cell) {
00266   gsheetcell_zero(cell);
00267   GnmValue const *value = sheet_cell_get_value((Sheet*)sheet,x,y);
00268   if (value==NULL) return 0;
00269   if (value->type == VALUE_EMPTY) return 0;
00270 
00271   GnmCell const *gcell = sheet_cell_get((Sheet*)sheet,x,y);
00272   if (gcell) {
00273     if (gnm_cell_has_expr (gcell)) {
00274       if (gcell->base.texpr->expr) {
00275         const GnmExpr *expr = gcell->base.texpr->expr;
00276         if (expr) {
00277           if (expr->oper==GNM_EXPR_OP_FUNCALL) {
00278             if (expr->func.func) {
00279               const char *name = expr->func.func->name;
00280               if (name) {
00281                 if (strcasecmp(name,"hyperlink")==0) {
00282                   // Hyperlink. Take url part.
00283                   char *url = NULL;
00284                   char *txt = NULL;
00285                   if (expr->func.argc==2) {
00286                     const GnmExpr *expr0 = expr->func.argv[0];
00287                     if (expr0) {
00288                       if (expr0->oper == GNM_EXPR_OP_CONSTANT) {
00289                         url = value_get_as_string(expr0->constant.value);
00290                       }
00291                     }
00292                     const GnmExpr *expr1 = expr->func.argv[1];
00293                     if (expr1) {
00294                       if (expr1->oper == GNM_EXPR_OP_CONSTANT) {
00295                         txt = value_get_as_string(expr1->constant.value);
00296                       }
00297                     }
00298                   }
00299                   if (url&&txt) {
00300                     if (strcasecmp(url,txt)==0) {
00301                       cell->all = url;
00302                       cell->url = g_strdup(url);
00303                       cell->txt = g_strdup(url);
00304                       cell->is_url = 1;
00305                       return 0;
00306                     }
00307                     cell->all = g_strconcat("[",url,"|",txt,"]",NULL);
00308                     cell->url = url;
00309                     cell->txt = txt;
00310                     cell->is_url = 1;
00311                     return 0;
00312                   } else {
00313                     if (url) g_free(url);
00314                     if (txt) g_free(txt);
00315                   }
00316                 }
00317               }
00318             }
00319           }
00320         }
00321       }
00322       //return gnm_cell_get_entered_text(cell);
00323     }
00324   }
00325 
00326   GnmStyle const *style = sheet_style_get((Sheet*)sheet,x,y);
00327   GnmHLink* hlink = gnm_style_get_hlink (style);
00328   const guchar* hlink_target = NULL;
00329   if (hlink && IS_GNM_HLINK_URL (hlink)) {
00330     hlink_target = gnm_hlink_get_target (hlink);
00331     if (hlink_target) {
00332       //char *str = value_get_as_string(value);
00333       //if (!str) return str;
00334       //const char *str2 = " ";
00335       //char *result = g_strconcat(str,str2,hlink_target);
00336       //g_free(str);
00337       //return result;
00338       cell->is_url = 1;
00339       cell->all = g_strdup(hlink_target);
00340       cell->url = g_strdup(hlink_target);
00341       cell->txt = g_strdup(hlink_target);
00342       return 0;
00343     }
00344   }
00345 
00346   cell->all = value_get_as_string(value);
00347   return 0;
00348 }
00349 
00350 int gnumeric_sheet_set_cell(GnumericSheetPtr sheet, int x, int y,
00351                             GSheetCellPtr cell) {
00352   if (!cell->is_url) {
00353     if (cell->all) {
00354       gnumeric_sheet_set_cell_as_string(sheet,x,y,cell->all);
00355       return 0;
00356     }
00357     gnumeric_sheet_remove_cell(sheet,x,y);
00358     return 0;
00359   }
00360 
00361   if (cell->url&&cell->txt) {
00362     GnmFunc *func = gnm_func_lookup("hyperlink",((Sheet *)sheet)->workbook);
00363     if (!func) {
00364       fprintf(stderr,"hyperlink unknown\n");
00365       exit(1);
00366     }
00367     GnmExpr const *expr = 
00368       gnm_expr_new_funcall2(func,
00369                             gnm_expr_new_constant(value_new_string(cell->url)),
00370                             gnm_expr_new_constant(value_new_string(cell->txt)));
00371     GnmExprTop const *texpr = gnm_expr_top_new(expr);
00372     GnmCell *cell2 = sheet_cell_get((Sheet*)sheet,x,y);
00373     if (cell2==NULL) {
00374       cell2 = sheet_cell_create((Sheet*)sheet,x,y);
00375     }
00376     GnmValue *val = value_new_string(cell->txt);
00377     //sheet_cell_set_value(cell2,val);
00378     gnm_cell_set_expr_and_value(cell2,texpr,val,0);
00379   }
00380 
00381   return 0;
00382 }
00383 
00384 
00385 //char *gnumeric_sheet_get_cell_as_string(GnumericSheetPtr sheet, int x, int y) {
00386 //}
00387 
00388 static void
00389 coopy_add_attr (PangoAttrList *attrs, PangoAttribute *attr)
00390 {
00391         attr->start_index = 0;
00392         attr->end_index = 2;
00393         pango_attr_list_insert (attrs, attr);
00394 }
00395 
00396 int gnumeric_sheet_set_cell_as_string(GnumericSheetPtr sheet, int x, int y,
00397                                       const char *str) {
00398   GnmCell *cell = sheet_cell_get((Sheet*)sheet,x,y);
00399   if (cell==NULL) {
00400     cell = sheet_cell_create((Sheet*)sheet,x,y);
00401   }
00402 
00403   // When we have set up cell types better, we can try this:
00404   //   sheet_cell_set_text(cell,str,NULL);
00405 
00406   // For now we quote everything as strings:
00407   GnmValue *val = value_new_string(str);
00408 
00409   sheet_cell_set_value(cell,val);
00410 
00411 
00412   /*
00413   GnmStyle *mstyle;
00414   
00415   mstyle = gnm_style_new ();
00416   //gnm_style_set_format_text (mstyle, format);
00417   //gnm_style_get_pango_attrs(mstyle,NULL,1.0)
00418   printf("Setting WEIGHT\n");
00419   gnm_style_set_font_strike (mstyle, TRUE);
00420   //gnm_style_set_font_bold (mstyle, TRUE);
00421   printf("Done.\n");
00422   
00423   GnmRange r;
00424   r.start = r.end = cell->pos;
00425   sheet_style_apply_range (cell->base.sheet, &r, mstyle);
00426   */
00427 
00428   return 0;
00429 }
00430 
00431 int gnumeric_sheet_remove_cell(GnumericSheetPtr sheet, int x, int y) {
00432   GnmCell *cell = sheet_cell_get((Sheet*)sheet,x,y);
00433   if (cell==NULL) {
00434     return 0;
00435   }
00436   sheet_cell_remove((Sheet*)sheet,cell,FALSE,FALSE);
00437   return 0;
00438 }
00439 
00440 
00441 const char *gnumeric_sheet_get_name(GnumericSheetPtr sheet) {
00442   Sheet *s = (Sheet *)sheet;
00443   return s->name_unquoted;
00444 }
00445 
00446 void gnumeric_free_string(char *str) {
00447   g_free(str);
00448 }
00449 
00450 
00451 int gnumeric_move_column(GnumericSheetPtr sheet, int src, int dest) {
00452   int w, h;
00453   gnumeric_sheet_get_size(sheet,&w,&h);
00454 
00455   /*
00456     If dest<src:
00457        copy the src column
00458        copy from dest to src-1
00459          paste that offset to right by 1
00460        paste to dest column
00461 
00462     If dest>src:
00463        copy the src column
00464        copy from src+1 to dest
00465          paste that offset to left by 1
00466        paste to dest column
00467    */
00468 
00469   GnmPasteTarget pt;
00470   pt.sheet = sheet;
00471   pt.paste_flags = PASTE_CONTENTS | PASTE_COMMENTS | PASTE_NO_RECALC;
00472   pt.paste_flags = pt.paste_flags | PASTE_FORMATS;
00473 
00474   GnmRange range1, range2;
00475   GnmCellRegion *rcopy1, *rcopy2 = NULL;
00476   if (src==dest) return 0;
00477 
00478   // copy src column
00479   range1.start.row = 0;
00480   range1.end.row = h-1;
00481   range1.start.col = src;
00482   range1.end.col = src;
00483   rcopy1 = clipboard_copy_range(sheet,&range1);
00484 
00485   // copy src-dest range
00486   range2.start.row = 0;
00487   range2.end.row = h-1;
00488   if (dest<src) {
00489     range2.start.col = dest;
00490     range2.end.col = src-1;
00491   } else {
00492     range2.start.col = src+1;
00493     range2.end.col = dest;
00494   }
00495   rcopy2 = clipboard_copy_range(sheet,&range2);
00496   if (dest<src) {
00497     range2.start.col++;
00498     range2.end.col++;
00499   } else {
00500     range2.start.col--;
00501     range2.end.col--;
00502   }
00503   pt.range = range2;
00504   clipboard_paste_region(rcopy2, &pt, cc);
00505   cellregion_unref(rcopy2);
00506 
00507   range1.start.col = dest;
00508   range1.end.col = dest;
00509   pt.range = range1;
00510   clipboard_paste_region(rcopy1, &pt, cc);
00511   cellregion_unref(rcopy1);
00512   return 0;
00513 }
00514 
00515 
00516 int gnumeric_move_row(GnumericSheetPtr sheet, int src, int dest) {
00517   int w, h;
00518   gnumeric_sheet_get_size(sheet,&w,&h);
00519 
00520   GnmPasteTarget pt;
00521   pt.sheet = sheet;
00522   pt.paste_flags = PASTE_CONTENTS | PASTE_COMMENTS | PASTE_NO_RECALC;
00523   pt.paste_flags = pt.paste_flags | PASTE_FORMATS;
00524 
00525   GnmRange range1, range2;
00526   GnmCellRegion *rcopy1, *rcopy2 = NULL;
00527   if (src==dest) return 0;
00528 
00529   // copy src column
00530   range1.start.col = 0;
00531   range1.end.col = w-1;
00532   range1.start.row = src;
00533   range1.end.row = src;
00534   rcopy1 = clipboard_copy_range(sheet,&range1);
00535 
00536   // copy src-dest range
00537   range2.start.col = 0;
00538   range2.end.col = w-1;
00539   if (dest<src) {
00540     range2.start.row = dest;
00541     range2.end.row = src-1;
00542   } else {
00543     range2.start.row = src+1;
00544     range2.end.row = dest;
00545   }
00546   rcopy2 = clipboard_copy_range(sheet,&range2);
00547   if (dest<src) {
00548     range2.start.row++;
00549     range2.end.row++;
00550   } else {
00551     range2.start.row--;
00552     range2.end.row--;
00553   }
00554   pt.range = range2;
00555   clipboard_paste_region(rcopy2, &pt, cc);
00556   cellregion_unref(rcopy2);
00557 
00558   range1.start.row = dest;
00559   range1.end.row = dest;
00560   pt.range = range1;
00561   clipboard_paste_region(rcopy1, &pt, cc);
00562   cellregion_unref(rcopy1);
00563   return 0;
00564 }
00565 
00566 
00567 
00568 int gnumeric_insert_column(GnumericSheetPtr sheet, int before) {
00569   BEGIN_UNDO;
00570   sheet_insert_cols(sheet,before,1,DO_UNDO,cc);
00571   //gnumeric_sheet_get_size(sheet, &w, &h);
00572   END_UNDO;
00573   return 0;
00574 }
00575 
00576 int gnumeric_delete_column(GnumericSheetPtr sheet, int at) {
00577   BEGIN_UNDO;
00578   sheet_delete_cols(sheet,at,1,DO_UNDO,cc);
00579   END_UNDO;
00580   return 0;
00581 }
00582 
00583 int gnumeric_insert_row(GnumericSheetPtr sheet, int before) {
00584   BEGIN_UNDO;
00585   sheet_insert_rows(sheet,before,1,DO_UNDO,cc);
00586   END_UNDO;
00587   return 0;
00588 }
00589 
00590 int gnumeric_delete_row(GnumericSheetPtr sheet, int at) {
00591   //printf("deleting %d\n", at);
00592   BEGIN_UNDO;
00593   sheet_delete_rows(sheet,at,1,DO_UNDO,cc);
00594   END_UNDO;
00595   //sheet_row_destroy(sheet,at,TRUE);
00596   return 0;
00597 }
00598 
00599 int gnumeric_delete_rows(GnumericSheetPtr sheet, int first, int last) {
00600   //printf("delete from %d to %d\n", first, last);
00601   BEGIN_UNDO;
00602   sheet_delete_rows(sheet,first,last-first+1,DO_UNDO,cc);
00603   END_UNDO;
00604   return last-first+1;
00605 }
00606 
00607 
00608 int gnumeric_delete_data(GnumericSheetPtr sheet) {
00609   printf("delete all\n");
00610   //sheet_destroy_contents(sheet);
00611   BEGIN_UNDO;
00612   int w, h;
00613   gnumeric_sheet_get_size(sheet, &w, &h);
00614   sheet_delete_rows(sheet,0,h+1,DO_UNDO,cc);
00615   END_UNDO;
00616   return 0;
00617 }
00618 
00619 
00620 GnumericStylePtr gnumeric_sheet_get_style(GnumericSheetPtr sheet, 
00621                                           int x, int y) {
00622   GnmStyle const *r = sheet_style_get((Sheet*)sheet,x,y);
00623   if (r==NULL) return NULL;
00624   return gnm_style_dup(r);
00625 }
00626 
00627 int gnumeric_sheet_set_style(GnumericSheetPtr sheet, 
00628                              GnumericStylePtr style,
00629                              int x, int y) {
00630   GnmRange r;
00631   r.start.col = x;
00632   r.start.row = y;
00633   r.end.col = x;
00634   r.end.row = y;
00635   sheet_style_apply_range ((Sheet*)sheet, &r, (GnmStyle*)style);
00636   return 0;
00637 }
00638 
00639 int gnumeric_sheet_set_row_style(GnumericSheetPtr sheet, 
00640                                  GnumericStylePtr style,
00641                                  int y) {
00642   sheet_style_apply_row ((Sheet*)sheet, y, (GnmStyle*)style);
00643   return 0;
00644 }
00645 
00646 int gnumeric_sheet_set_col_style(GnumericSheetPtr sheet, 
00647                                  GnumericStylePtr style,
00648                                  int x) {
00649   sheet_style_apply_col ((Sheet*)sheet, x, (GnmStyle*)style);
00650   return 0;
00651 }
00652 
00653 //gnumeric_style_set_font_strike(GnumericStylePtr style, int flag);
00654 
00655 int gnumeric_style_set_font_strike(GnumericStylePtr style, int flag) {
00656   gnm_style_set_font_strike ((GnmStyle*)style, flag?TRUE:FALSE);
00657   return 0;
00658 }
00659 
00660 int gnumeric_style_set_font_bold(GnumericStylePtr style, int flag) {
00661   gnm_style_set_font_bold ((GnmStyle*)style, flag?TRUE:FALSE);
00662   return 0;
00663 }
00664 
00665 int gnumeric_style_set_font_color(GnumericStylePtr style, 
00666                                   int r16, int g16, int b16) {
00667   GnmColor *color = style_color_new_i16(r16,g16,b16);
00668   gnm_style_set_font_color((GnmStyle*)style,color);
00669   return 0;
00670 }
00671 
00672 int gnumeric_style_set_back_color(GnumericStylePtr style, 
00673                                   int r16, int g16, int b16) {
00674   GnmColor *color = style_color_new_i16(r16,g16,b16);
00675   gnm_style_set_back_color((GnmStyle*)style,color);
00676   gnm_style_set_pattern((GnmStyle*)style,1);
00677   return 0;
00678 }
00679 
00680 
00681 void gnumeric_free_style(GnumericStylePtr style) {
00682   gnm_style_unref((GnmStyle*)style);
00683 }
00684 
00685 int gnumeric_sheet_get_cell_font_color(GnumericSheetPtr sheet, int x, int y,
00686                                        int *r16, int *g16, int *b16) {
00687   GnmCell *cell = sheet_cell_get((Sheet*)sheet,x,y);
00688   if (cell==NULL) {
00689     return 1;
00690   }
00691   GOColor c = gnm_cell_get_render_color(cell);
00692   if (!c) {
00693     *r16 = *g16 = *b16 = 0;
00694   } else {
00695       *r16 = GO_COLOR_UINT_R(c);
00696       *g16 = GO_COLOR_UINT_G(c);
00697       *b16 = GO_COLOR_UINT_B(c);
00698   }
00699   return 0;
00700 }
00701 
00702 
00703 void gsheetcell_zero(GSheetCellPtr cell) {
00704   if (!cell) return;
00705   cell->all = cell->url = cell->txt = NULL;
00706   cell->is_url = 0;
00707 }
00708 
00709 
00710 void gsheetcell_free(GSheetCellPtr cell) {
00711   if (!cell) return;
00712   if (cell->all) g_free(cell->all);
00713   if (cell->url) g_free(cell->url);
00714   if (cell->txt) g_free(cell->txt);
00715   gsheetcell_zero(cell);
00716 }
00717 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines