Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

sxy_task_edtext.cpp

Go to the documentation of this file.
00001 // =======================================================================
00002 
00003 char *task_edtext_cpp = "$Id: sxy_task_edtext.cpp,v 1.2 2003/01/07 16:19:22 clinio Exp $";
00004 
00005 // =======================================================================
00006 
00007 #include <assert.h>
00008 #include <xy.h>
00009 
00010 extern "C" {
00011 #include <iup.h>
00012 #include <iupgc.h>
00013 #include <cd.h>
00014 }
00015 
00016 #include "sxy_chart.h"
00017 #include "sxy_graph.h"
00018 #include "sxy_task.h"
00019 #include "sxy_task_edtext.h"
00020 
00021 #define HIDDEN_TEXT "HIDDEN_TEXT_ATTRIBUTE_AT_TASK"
00022 
00023 // =======================================================================
00024 
00025 static int cb_edttext_text( Ihandle* h );
00026 static int cb_edttext_font( Ihandle* h );
00027 static int cb_edttext_color( Ihandle* h );
00028 static int cb_edttext_size( Ihandle* h );
00029    
00030 // =======================================================================
00031 
00032 SXYTaskReturn SXYTaskEditText::mouseClick(SXYGraph* graph, int b, int x, int y, 
00033 int sft, int ctr) {
00034    if (b != 3) return CALLBACK_NOT_TREATED;
00035    int cht = graph->getChartOfEvent(x, y);
00036    if (cht < 0) return CALLBACK_NOT_TREATED;
00037 
00038    SXYChart* chart = graph->getChart(cht);
00039    XYRasterText* text = chart->getXyTitle();
00040    if ( text && text->pick(x, y) ) {
00041         popupActions( text );
00042         graph->redrawGraph();
00043         return CALLBACK_TREATED;
00044    }
00045    text = chart->getXySubTitle();
00046    if ( text && text->pick(x, y) ) {
00047         popupActions( text );
00048         graph->redrawGraph();
00049         return CALLBACK_TREATED;
00050    }
00051 
00052    return CALLBACK_NOT_TREATED;
00053 }
00054 
00055 // ......................................................................
00056 //
00057 SXYTaskReturn SXYTaskEditText::mouseUnclick(SXYGraph* graph, int b, int x, int y, 
00058 int sft, int ctr) {
00059    return CALLBACK_NOT_TREATED;
00060 }
00061 
00062 // ......................................................................
00063 
00064 SXYTaskReturn SXYTaskEditText::mouseMotion(SXYGraph* graph, int x, int y, 
00065 int sft, int ctr) {
00066    return CALLBACK_NOT_TREATED;
00067 }
00068 
00069 // ......................................................................
00070 
00071 SXYTaskReturn SXYTaskEditText::mouseEnter(SXYGraph* graph) {
00072    return CALLBACK_NOT_TREATED;
00073 }
00074 
00075 // ......................................................................
00076 
00077 SXYTaskReturn SXYTaskEditText::mouseLeave(SXYGraph* graph) {
00078    return CALLBACK_NOT_TREATED;
00079 }
00080 
00081 // ......................................................................
00082 
00083 Ihandle* SXYTaskEditText::createMenu(XYRasterText* txt) {
00084    char* strings[][64] = {
00085       { "Editar texto", "Editar cor", "Editar tamanho", "Editar fonte" },
00086       { "Edit text", "Edit color", "Edit size", "Edit font" }
00087    };
00088    char* callbacks[] = {
00089       "cb_edttext_text", "cb_edttext_color" 
00090       /* "cb_edttext_size" , "cb_edttext_font" */
00091    };
00092 
00093    int nitens = sizeof(callbacks) / sizeof(char*);
00094    int language = ( !strcmp( IupGetLanguage(), IUP_ENGLISH ) ) ? 1 : 0;
00095    
00096    Ihandle *iup_menu = IupMenu(NULL);
00097    IupSetAttribute(iup_menu, HIDDEN_TEXT, (char*)txt);
00098    for (int i = 0; i < nitens; i++) {
00099      Ihandle* iup_item = IupItem( strings[language][i], callbacks[i]);
00100      IupSetAttribute(iup_item, HIDDEN_TEXT, (char*)txt);
00101      IupAppend(iup_menu, iup_item);
00102    }
00103   
00104    IupSetFunction("cb_edttext_text",  (Icallback) cb_edttext_text);
00105    IupSetFunction("cb_edttext_color", (Icallback) cb_edttext_color);
00106    IupSetFunction("cb_edttext_font",  (Icallback) cb_edttext_font);
00107    IupSetFunction("cb_edttext_size",  (Icallback) cb_edttext_size);
00108 
00109    return iup_menu;
00110 }
00111 
00112 // ......................................................................
00113 
00114 void SXYTaskEditText::popupActions(XYRasterText* txt) {
00115    Ihandle* iup_menu = createMenu(txt);
00116    IupPopup(iup_menu, IUP_MOUSEPOS, IUP_MOUSEPOS);
00117    IupDestroy(iup_menu);
00118 }
00119 
00120 // ......................................................................
00121 
00122 SXYTaskEditText::SXYTaskEditText(void) {
00123 }
00124 
00125 // ......................................................................
00126 
00127 SXYTaskEditText::~SXYTaskEditText() {
00128 };
00129 
00130 // ......................................................................
00131 
00132 static int cb_edttext_text( Ihandle* h ) {
00133    XYRasterText* txt = (XYRasterText*) IupGetAttribute( h, HIDDEN_TEXT );
00134    assert(txt);
00135 
00136    static char buffer[128];
00137    sprintf( buffer, "%s", txt->text() );
00138    char* fmt = NULL;
00139    if (!strcmp( IupGetLanguage(), IUP_ENGLISH ))
00140       fmt = "String data entry\n string: %128.64%s\n";
00141    else
00142       fmt = "Entrada de texto\n texto: %128.64%s\n";
00143 
00144    int answer = IupScanf( fmt, buffer );
00145    if ( answer == 1 ) txt->text(buffer);
00146 
00147    return IUP_DEFAULT;
00148 }
00149 
00150 // ......................................................................
00151 
00152 static int cb_edttext_size( Ihandle* h ) {
00153    XYRasterText* txt = (XYRasterText*) IupGetAttribute( h, HIDDEN_TEXT );
00154    assert(txt);
00155 
00156    int  dlg_size = 8 ;
00157    char *options[] = {
00158        "8", "10", "12", "14", "16", "18", "20", "22", "24", "26" } ;
00159                                             
00160    
00161    int opt = ( txt->size() - atoi(options[0]) ) / 2;
00162    int answer = IupListDialog( 1, "Escolha de tamanho", 
00163          dlg_size, options, opt, 32, 5, NULL);
00164    if (answer == -1) return IUP_DEFAULT;
00165 
00166    txt->size( atoi(options[answer]) );
00167 
00168    return IUP_DEFAULT;
00169 }
00170 
00171 // ......................................................................
00172 
00173 static int cb_edttext_font( Ihandle* h ) {
00174    XYRasterText* txt = (XYRasterText*) IupGetAttribute( h, HIDDEN_TEXT );
00175    assert(txt);
00176 
00177    int opt;
00178    enum XYText::Typeface font = (XYText::Typeface)txt->font();
00179    if ( font == XYText::common ) opt = 0;
00180    else if ( font == XYText::helvetica ) opt = 1;
00181    else if ( font == XYText::courier ) opt = 2;
00182    else if ( font == XYText::timesRoman ) opt = 3;
00183    else assert(0);
00184 
00185    int  dlg_size = 4 ;
00186    char *options[] = { 
00187       "Standart (sistema)", "Helvética", 
00188       "Courier (monoespaçado)", "Times New Roman" 
00189    };
00190    
00191    int answer = IupListDialog( 1, "Escolha de fonte", 
00192          dlg_size, options, opt, 32, 4, NULL);
00193    if (answer == -1) return IUP_DEFAULT;
00194 
00195    if ( answer == 0 ) font = XYText::common;
00196    else if ( answer == 1 ) font = XYText::helvetica;
00197    else if ( answer == 2 ) font = XYText::courier;
00198    else if ( answer == 3 ) font = XYText::timesRoman;
00199    else assert(0);
00200 
00201    txt->font( (XYText::Typeface)font );
00202 
00203    return IUP_DEFAULT;
00204 }
00205 
00206 // ......................................................................
00207 
00208 static int cb_edttext_color( Ihandle* h ) {
00209    XYRasterText* txt = (XYRasterText*) IupGetAttribute( h, HIDDEN_TEXT );
00210    assert(txt);
00211    long int color = txt->color();
00212    unsigned char r, g, b;
00213    r = (color & 0xFF0000) >> 16;
00214    g = (color & 0x00FF00) >> 8;
00215    b = (color & 0x0000FF);
00216    int answer = IupGetColor (IUP_CENTER, IUP_CENTER, &r, &g, &b);
00217    if ( answer == 1 ) {
00218       color = r << 16 | g << 8 | b;
00219       txt->color(color);
00220    }
00221 
00222    return IUP_DEFAULT;
00223 }
00224 
00225 // ......................................................................
00226 

SXY
Tecgraf / PUC-Rio - Computer Graphics Technology Group