"SfR Fresh" - the SfR Freeware/Shareware Archive

Member "grpn-1.1.7.4/callback_buttons.c" of archive grpn-1.1.7.4.tar.gz:


As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
    1 /*
    2 
    3 Copyright (C) 2002  Paul Wilkins
    4 
    5 This program is free software; you can redistribute it and/or
    6 modify it under the terms of the GNU General Public License
    7 as published by the Free Software Foundation; either version 2
    8 of the License, or (at your option) any later version.
    9 
   10 This program is distributed in the hope that it will be useful,
   11 but WITHOUT ANY WARRANTY; without even the implied warranty of
   12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13 GNU General Public License for more details.
   14 
   15 You should have received a copy of the GNU General Public License
   16 along with this program; if not, write to the Free Software
   17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   18 
   19 */
   20 /* callback_buttons.c  by Paul Wilkins */
   21 
   22 #include <stdio.h>
   23 #include <gtk/gtk.h>
   24 
   25 #include "buttons.h"
   26 #include "funcs.h"
   27 #include "editor.h"
   28 #include "error.h"
   29 #include "lcd.h"
   30 
   31 
   32 /* the generic button callback function */
   33 void genericButtonCB(GtkWidget *w, gpointer clientData){
   34    FuncInfo *fi = (FuncInfo *)clientData;
   35    void (*func)();
   36 
   37    /* reset any error string */
   38    resetError();
   39 
   40    /* call the real work function */
   41    if(fi->data){
   42       func = fi->data;
   43       func();
   44       redrawLCD();
   45    }
   46 }
   47 
   48 /* the null button callback function */
   49 void nullButtonCB(GtkWidget *w, gpointer clientData){
   50    printf("Sorry: Unimpilmented feature\n");
   51 }
   52 
   53 /* inserts a char into the edit buffer */
   54 void enterNumCB(GtkWidget *w, gpointer clientData){
   55    int tmp;
   56    FuncInfo *fi = (FuncInfo *)clientData;
   57 
   58    /* reset any error string */
   59    resetError();
   60 
   61    tmp = (int)fi->data;
   62    insertEditor(tmp);
   63    redrawLCD();
   64 }
   65 
   66 
   67 /* the +/- key needs a special callback */
   68 /* this is unnessisarily complicated */
   69 void plusMinusCB(GtkWidget *w, gpointer clientData){
   70    char *p, *line;
   71    int i, pos, foundE;
   72 
   73    /* reset any error string */
   74    resetError();
   75 
   76    if(isEditingEditor()){
   77       line = getLineEditor();
   78 
   79       /* look for an 'e' or 'E' */
   80       foundE = 0;
   81       for(p=line; *p!='\0'; p++){
   82          if(*p == 'e' || *p == 'E'){
   83             foundE = 1;
   84             break;
   85          }
   86       }
   87 
   88       pos = cursorPosEditor();
   89 
   90       /* if we found an exponent */
   91       if(foundE){
   92          p++;
   93 
   94          /* put the cursor after the 'e' or 'E' */
   95          for(i=(p-line)-pos; i>0; i--) rightEditor();
   96          for(i=pos-(p-line); i>0; i--) leftEditor();
   97 
   98          if(*p == '+'){
   99             rightEditor();
  100             deleteEditor();
  101             insertEditor('-');
  102             if(pos-(p-line) > 0) pos--;
  103          } else if(*p == '-'){
  104             rightEditor();
  105             deleteEditor();
  106             insertEditor('+');
  107             if(pos-(p-line) > 0) pos--;
  108          } else {
  109             insertEditor('-');
  110             pos++;
  111          }
  112 
  113          /* restore the cursor to where it should be */
  114          for(i=(p-line)-pos+1; i>0; i--) leftEditor();
  115          for(i=pos-(p-line); i>0; i--) rightEditor();
  116 
  117       }
  118 
  119       /* we didn't find an exponent */
  120       else {
  121          homeEditor();
  122          if(*line == '+'){
  123             rightEditor();
  124             deleteEditor();
  125             insertEditor('-');
  126             pos--;
  127          } else if(*line == '-'){
  128             rightEditor();
  129             deleteEditor();
  130             insertEditor('+');
  131             pos--;
  132          } else {
  133             insertEditor('-');
  134          }
  135          for(i=0; i<pos; i++) rightEditor();
  136       }
  137    } else {
  138 
  139       NegStack();
  140    }
  141 
  142    redrawLCD();
  143 }
  144