"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/lcd.c" between
grpn-1.5.1.tar.gz and grpn-1.5.2.tar.gz

About: grpn is a RPN calcuator for real and complex numbers (requires GTK).

lcd.c  (grpn-1.5.1):lcd.c  (grpn-1.5.2)
skipping to change at line 122 skipping to change at line 122
void lcdGetSelection(int time); void lcdGetSelection(int time);
void lcdStartHighlight(int x, int y, int time); void lcdStartHighlight(int x, int y, int time);
void lcdStopHighlight(int x, int y, int time); void lcdStopHighlight(int x, int y, int time);
void lcdContinueHighlight(int x, int y); void lcdContinueHighlight(int x, int y);
#define TARGET_STRING 0x1 #define TARGET_STRING 0x1
#define TARGET_TEXT 0x2 #define TARGET_TEXT 0x2
#define TARGET_COMPOUND_TEXT 0x4 #define TARGET_COMPOUND_TEXT 0x4
GtkWidget *setupLCD(GtkWidget *parent, int rows, int cols, char *font){ GtkWidget *setupLCD(GtkWidget *parent, int rows, int cols, char *font){
int i;
int width;
int wid, hgt; int wid, hgt;
#ifdef GTK_VER_1_1 #ifdef GTK_VER_1_1
static GtkTargetEntry targetlist[] = { static GtkTargetEntry targetlist[] = {
/* Target Flags Info */ /* Target Flags Info */
{ "STRING", 0, TARGET_STRING }, { "STRING", 0, TARGET_STRING },
{ "TEXT", 0, TARGET_TEXT }, { "TEXT", 0, TARGET_TEXT },
{ "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT } { "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT }
}; };
static gint ntargets = sizeof(targetlist) / sizeof(targetlist[0]); static gint ntargets = sizeof(targetlist) / sizeof(targetlist[0]);
#endif #endif
skipping to change at line 177 skipping to change at line 175
NULL == (lcdFont = gdk_font_load(FONT3)) && NULL == (lcdFont = gdk_font_load(FONT3)) &&
NULL == (lcdFont = gdk_font_load(FONT4)) && NULL == (lcdFont = gdk_font_load(FONT4)) &&
NULL == (lcdFont = gdk_font_load(FONT5)) && NULL == (lcdFont = gdk_font_load(FONT5)) &&
NULL == (lcdFont = gdk_font_load(FONT6))){ NULL == (lcdFont = gdk_font_load(FONT6))){
fprintf(stderr, "Unable to load a font.\n"); fprintf(stderr, "Unable to load a font.\n");
exit(0); exit(0);
} }
/* find max font width */ /* find max font width */
for(i=0; i<256; i++){ for(int i=0; i<256; i++){
width = gdk_char_width(lcdFont, (gchar)i); int width = gdk_char_width(lcdFont, (gchar)i);
if(width < 50 && width > fontW) fontW = width; if (width < 50 && width > fontW) fontW = width;
} }
/* globals we use all over the place */ /* globals we use all over the place */
fontH = lcdFont->ascent + lcdFont->descent; fontH = lcdFont->ascent + lcdFont->descent;
fontD = lcdFont->descent; fontD = lcdFont->descent;
#endif #endif
if(fontW == 0 || fontH == 0){ if(fontW == 0 || fontH == 0){
fprintf(stderr, "Error: can not determine font dimentions.\n"); fprintf(stderr, "Error: can not determine font dimentions.\n");
exit(0); exit(0);
skipping to change at line 280 skipping to change at line 278
} }
void clearLCDwindow(){ void clearLCDwindow(){
gdk_window_clear(lcdDA->window); gdk_window_clear(lcdDA->window);
} }
/* Recalculate the contents of the lcd display. /* Recalculate the contents of the lcd display.
* note: we don't redraw the lcd here, that is done by drawStackLCD(). * note: we don't redraw the lcd here, that is done by drawStackLCD().
*/ */
void calcStackLCD(){ void calcStackLCD(){
int i, j; int i, j, pLen, curPos;
int strLen, pLen, curPos; size_t strLen;
char *c, *p; char *c, *p;
char *txt; /* the number */ char *txt; /* the number */
char label[16]; /* the stack number label */ char label[16]; /* the stack number label */
int height; int height;
int indx; int indx;
int row; /* the row to start print the current number */ int row; /* the row to start print the current number */
int txtPos; /* which col do we start printing in */ int txtPos; /* which col do we start printing in */
int lines; /* the number of lines this number has */ int lines; /* the number of lines this number has */
int top; /* which row is the top for drawing the stack */ int top; /* which row is the top for drawing the stack */
int bottom; /* which row is the current bottom for drawing the stack */ int bottom; /* which row is the current bottom for drawing the stack */
skipping to change at line 311 skipping to change at line 309
if(height <= 0) return; if(height <= 0) return;
/* clear the old display */ /* clear the old display */
for(i=0; i<lcdHeight; i++){ for(i=0; i<lcdHeight; i++){
for(j=0; j<lcdWidth; j++){ for(j=0; j<lcdWidth; j++){
lcdText[i][j] = ' '; lcdText[i][j] = ' ';
} }
} }
/* check for an error */ /* check for an error */
if(isError()){ if (isError()) {
top = 1; top = 1;
c = getStringError(); c = getStringError();
strLen = strlen(c); strLen = strnlen(c, lcdWidth);
if(strLen > lcdWidth) strLen = lcdWidth;
strncpy(lcdText[0], c, strLen); strncpy(lcdText[0], c, strLen);
} else { } else {
top = 0; top = 0;
} }
bottom = height; bottom = height;
/* print all of the numbers */ /* print all of the numbers */
for(indx=0; indx<stackLen(); indx++){ for(indx=0; indx<stackLen(); indx++){
/* get the number to print */ /* get the number to print */
skipping to change at line 345 skipping to change at line 342
/* how many lines is this number? */ /* how many lines is this number? */
lines = 1; lines = 1;
for(p=txt; *p!='\0'; p++) if(*p=='\n'){ lines++; *p='\0'; } for(p=txt; *p!='\0'; p++) if(*p=='\n'){ lines++; *p='\0'; }
/* find the starting line of the number */ /* find the starting line of the number */
row = bottom - lines; row = bottom - lines;
if(row < top) row = top; if(row < top) row = top;
/* print the stack number label */ /* print the stack number label */
sprintf(label, "%d: ", indx+1); sprintf(label, "%d: ", indx+1);
labelLen = strlen(label); labelLen = strnlen(label, lcdWidth);
if(labelLen > lcdWidth) labelLen = lcdWidth;
strncpy(lcdText[row], label, labelLen); strncpy(lcdText[row], label, labelLen);
/* print the number */ /* print the number */
p = txt; p = txt;
for(j=0, i=row; i<bottom && j<lines; i++, j++){ for(j=0, i=row; i<bottom && j<lines; i++, j++){
pLen = strlen(p); pLen = strlen(p);
txtPos = lcdWidth - pLen; txtPos = lcdWidth - pLen;
if(txtPos < labelLen) txtPos = labelLen; if(txtPos < labelLen) txtPos = labelLen;
if(txtPos > lcdWidth) break; if(txtPos > lcdWidth) break;
skipping to change at line 373 skipping to change at line 369
bottom = bottom - j; bottom = bottom - j;
if(bottom == top) break; if(bottom == top) break;
} }
/* fill in the rest of the indexes */ /* fill in the rest of the indexes */
for(i=indx, j=bottom; j>top; i++, j--){ for(i=indx, j=bottom; j>top; i++, j--){
sprintf(label, "%d: ", i+1); sprintf(label, "%d: ", i+1);
labelLen = strlen(label); labelLen = strnlen(label, lcdWidth);
if(labelLen > lcdWidth) labelLen = lcdWidth;
strncpy(lcdText[j-1], label, labelLen); strncpy(lcdText[j-1], label, labelLen);
} }
if(isEditingEditor()){ if(isEditingEditor()){
txt = getLineEditor(); txt = getLineEditor();
curPos = cursorPosEditor(); curPos = cursorPosEditor();
if(curPos > lcdWidth){ if(curPos > lcdWidth){
txt += (curPos - lcdWidth); txt += (curPos - lcdWidth);
} }
strLen = strlen(txt); strLen = strnlen(txt, lcdWidth);
if(strLen > lcdWidth) strLen = lcdWidth;
strncpy(lcdText[lcdHeight-1], txt, strLen); strncpy(lcdText[lcdHeight-1], txt, strLen);
} }
} }
/* Redraw the contents of the lcd display. /* Redraw the contents of the lcd display.
* note: start BORDER pixels down and to the right. * note: start BORDER pixels down and to the right.
* TODO: we could be smart and only redraw what has changed. * TODO: we could be smart and only redraw what has changed.
* This does this work correctly with varriable sized fonts. * This does this work correctly with varriable sized fonts.
*/ */
void drawStackLCD(){ void drawStackLCD(){
int i; int i;
int curPos; int curPos;
int strt, stop; int strt = 0, stop;
GdkGC *drawgc; GdkGC *drawgc;
#ifdef USE_PANGO #ifdef USE_PANGO
PangoRectangle rect; PangoRectangle rect;
int pango_pos; int pango_pos;
#endif #endif
/* draw the stack */ /* draw the stack */
for(i=0; i<lcdHeight; i++){ for(i=0; i<lcdHeight; i++){
/* draw the first unhighlighted section of the line */ /* draw the first unhighlighted section of the line */
skipping to change at line 671 skipping to change at line 664
} }
static gint lcdKeyReleaseEvnt(GtkWidget *widget, GdkEventKey *event){ static gint lcdKeyReleaseEvnt(GtkWidget *widget, GdkEventKey *event){
return TRUE; return TRUE;
} }
static gint lcdButtonPressEvnt(GtkWidget *widget, GdkEventButton *event) { static gint lcdButtonPressEvnt(GtkWidget *widget, GdkEventButton *event) {
gtk_widget_grab_focus(lcdDA); gtk_widget_grab_focus(lcdDA);
if(event->button == 1){ if(event->button == 1){
lcdStartHighlight(event->x, event->y, event->time); lcdStartHighlight(event->x, event->y, event->time);
} }
return TRUE;
} }
static gint lcdButtonReleaseEvnt(GtkWidget *widget, GdkEventButton *event) { static gint lcdButtonReleaseEvnt(GtkWidget *widget, GdkEventButton *event) {
switch(event->button){ switch(event->button){
case 1: /* stop highlighting an area */ case 1: /* stop highlighting an area */
lcdStopHighlight(event->x, event->y, event->time); lcdStopHighlight(event->x, event->y, event->time);
break; break;
case 2: /* paste data */ case 2: /* paste data */
lcdGetSelection(event->time); lcdGetSelection(event->time);
break; break;
case 3: /* might be used to continue highlighting */ case 3: /* might be used to continue highlighting */
if(dataSelected == DATA_SELECTED){ if(dataSelected == DATA_SELECTED){
lcdContinueHighlight(event->x, event->y); lcdContinueHighlight(event->x, event->y);
lcdStopHighlight(event->x, event->y, event->time); lcdStopHighlight(event->x, event->y, event->time);
} }
break; break;
} }
return TRUE;
} }
static gint lcdMotionEvnt(GtkWidget *widget, GdkEventMotion *event) static gint lcdMotionEvnt(GtkWidget *widget, GdkEventMotion *event)
{ {
int x, y; int x, y;
GdkModifierType state; GdkModifierType state;
if(event->is_hint){ if(event->is_hint){
gdk_window_get_pointer(event->window, &x, &y, &state); gdk_window_get_pointer(event->window, &x, &y, &state);
} else { } else {
skipping to change at line 716 skipping to change at line 711
lcdContinueHighlight(x, y); lcdContinueHighlight(x, y);
} else if(state & GDK_BUTTON3_MASK && } else if(state & GDK_BUTTON3_MASK &&
dataSelected == DATA_SELECTED){ dataSelected == DATA_SELECTED){
/* continuing a highlight with button 3 */ /* continuing a highlight with button 3 */
lcdContinueHighlight(x, y); lcdContinueHighlight(x, y);
} }
return TRUE; return TRUE;
} }
#ifdef GTK_VER_1_1 #ifdef GTK_VER_1_1
void convertSelection( void convertSelection(
GtkWidget *widget, GtkWidget *widget,
GtkSelectionData *selection, GtkSelectionData *selection,
guint info, guint info,
guint time, guint time,
gpointer data) gpointer data)
#else #else
skipping to change at line 752 skipping to change at line 746
if(dataSelected != DATA_SELECTED){ if(dataSelected != DATA_SELECTED){
printf("convertSelection called, but no selection.\n"); printf("convertSelection called, but no selection.\n");
} else { } else {
width = hiX2 - hiX1 + 1; width = hiX2 - hiX1 + 1;
height = hiY2 - hiY1 + 1; height = hiY2 - hiY1 + 1;
len = (width + 1) * height; len = (width + 1) * height;
str = (char *)malloc(len * sizeof(char)); str = malloc(len * sizeof(*str));
for(i=0; i<height; i++){ for(i=0; i<height; i++){
strncpy(str+(i*(width+1)), &(lcdText[i+hiY1][hiX1]), width); strncpy(str+(i*(width+1)), &(lcdText[i+hiY1][hiX1]), width);
*(str+(i*(width+1))+width) = '\n'; *(str+(i*(width+1))+width) = '\n';
} }
str[len-1] = '\0'; str[len-1] = '\0';
#ifdef GTK_VER_1_1 #ifdef GTK_VER_1_1
switch(info){ switch(info){
#else #else
switch(selection->target){ switch(selection->target){
#endif #endif
/* case GDK_TARGET_STRING: */ /* case GDK_TARGET_STRING: */
case TARGET_STRING: case TARGET_STRING:
gtk_selection_data_set( gtk_selection_data_set(
selection, selection,
GDK_SELECTION_TYPE_STRING, GDK_SELECTION_TYPE_STRING,
8, 8,
str, (guchar*)str,
len-1); len-1);
break; break;
case TARGET_TEXT: case TARGET_TEXT:
case TARGET_COMPOUND_TEXT: case TARGET_COMPOUND_TEXT:
gdk_string_to_compound_text(str, gdk_string_to_compound_text(str,
&type, &format, &text, &len); &type, &format, &text, &len);
gtk_selection_data_set( gtk_selection_data_set(
selection, selection,
type, type,
format, format,
 End of changes. 15 change blocks. 
22 lines changed or deleted 16 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)