static gint button_release_event(GtkWidget *widget, GdkEventButton *event) { int which; if(event->button==1) { if(dnd_state==0) cachedwhich=-1; gdk_pointer_ungrab(event->time); DEBUG(printf("Button 1 released\n")); } /********************* button 3 *********************/ if((event->button==3)&&(signalpixmap)) { cachedwhich=-1; gdk_pointer_ungrab(event->time); DEBUG(printf("Button 3 released\n")); if(dnd_state==1) { if(cachedtrace) { cachedtrace->flags|=TR_HIGHLIGHT; } which=(int)(event->y); which=(which/fontheight)-1; if( ((which<0) && (topmost_trace==traces.first) && PrependBuffer()) || (PasteBuffer()) ) /* short circuit on special which<0 case */ { status_text("Drop completed.\n"); MaxSignalLength(); signalarea_configure_event(signalarea, NULL); wavearea_configure_event(wavearea, NULL); } dnd_state=0; } } /********************* button 3 *********************/ return(TRUE); }
/* * Insert a blank [or comment] trace into the display... */ int InsertBlankTrace(char *comment) { TempBuffer tb; char *comm; Trptr t; if( (t = (Trptr) calloc_2( 1, sizeof( TraceEnt ))) == NULL ) { fprintf( stderr, "Out of memory, can't insert blank trace to analyzer\n"); return( 0 ); } t->flags=TR_BLANK; if((comm=precondition_string(comment))) { t->name=comm; t->is_alias=1; } if(!traces.first) { traces.first=traces.last=t; traces.total=1; return(1); } else { tb.buffer=traces.buffer; tb.bufferlast=traces.bufferlast; tb.buffercount=traces.buffercount; traces.buffer=traces.bufferlast=t; traces.buffercount=1; PasteBuffer(); traces.buffer=tb.buffer; traces.bufferlast=tb.bufferlast; traces.buffercount=tb.buffercount; return(1); } }
static void replace_callback(GtkWidget *widget, GtkWidget *nothing) { Traces tcache; int i; Trptr tfirst=NULL, tlast=NULL; if(!selectedtree) return; memcpy(&tcache,&traces,sizeof(Traces)); traces.total=0; traces.first=traces.last=NULL; for(i=fetchlow(selectedtree)->which;i<=fetchhigh(selectedtree)->which;i++) { struct symbol *s; s=facs[i]; if(s->vec_root) { s->vec_root->selected=autocoalesce; } } for(i=fetchlow(selectedtree)->which;i<=fetchhigh(selectedtree)->which;i++) { int len; struct symbol *s, *t; s=facs[i]; t=s->vec_root; if((t)&&(autocoalesce)) { if(t->selected) { t->selected=0; len=0; while(t) { len++; t=t->vec_chain; } if(len) add_vector_chain(s->vec_root, len); } } else { AddNode(s->n, NULL); } } tfirst=traces.first; tlast=traces.last; /* cache for highlighting */ traces.buffercount=traces.total; traces.buffer=traces.first; traces.bufferlast=traces.last; traces.first=tcache.first; traces.last=tcache.last; traces.total=tcache.total; PasteBuffer(); traces.buffercount=tcache.buffercount; traces.buffer=tcache.buffer; traces.bufferlast=tcache.bufferlast; CutBuffer(); while(tfirst) { tfirst->flags |= TR_HIGHLIGHT; if(tfirst==tlast) break; tfirst=tfirst->next; } MaxSignalLength(); signalarea_configure_event(signalarea, NULL); wavearea_configure_event(wavearea, NULL); }
void g2LabelEdit::KeyEvent(unsigned char key, bool IsSpecial) { // In OSX the backspace maps to DEL while DEL maps to backspace, need to swap #if __APPLE__ if(key == 127) key = 8; else if(key == 8) key = 127; #endif // Ignore all inputs if disabled if(GetDisabled()) return; /*** User Movement / Editing ***/ // If system key (i.e. left/right) else if(IsSpecial) { // Move far left/right if(key == GLUT_KEY_LEFT && glutGetModifiers() == GLUT_ACTIVE_CTRL) { CursorIndex = 0; ViewIndex = 0; } else if(key == GLUT_KEY_RIGHT && glutGetModifiers() == GLUT_ACTIVE_CTRL) { // Move the cursor to the far right and calculate // what is the best position for the view buffer to be moved to CursorIndex = (int)strlen(TextBuffer); // When something is written on-screen, check to see where our // left-view limit should be ViewIndex = (int)strlen(TextBuffer) - RenderableLeftChars(CursorIndex); } // If left/right, move the cursor if(key == GLUT_KEY_LEFT && CursorIndex > 0) { // Move cursor to left CursorIndex--; // Move view left if we can if(CursorIndex < ViewIndex) ViewIndex--; } else if(key == GLUT_KEY_RIGHT && CursorIndex < (int)strlen(TextBuffer)) { // Move cursor to right CursorIndex++; // If the movement will cause us to be offsreen.. while(LengthToCursor() > Width) ViewIndex++; } } // Backspace else if(key == 8) { // Is there anything to delete? if(strlen(TextBuffer) <= 0) return; // Ignore if we are at the 0 position else if(CursorIndex <= 0) return; else { // Delete this character by shifting everything from right to left by 1 // Note that this copies the null terminator for(size_t i = CursorIndex; i <= strlen(TextBuffer); i++) TextBuffer[i - 1] = TextBuffer[i]; // Decrease the cursor position CursorIndex--; // Is the cursor now smaller than the current view index // Move view left if we can while(CursorIndex < ViewIndex) { ViewIndex -= 5; if(ViewIndex < 0) ViewIndex = 0; } } } // Delete else if(key == 127) { // Is there anything to delete? if(CursorIndex >= (int)strlen(TextBuffer)) return; else { // Delete this character by shifting everything from right to left by 1 // Note that this copies the null terminator for(size_t i = CursorIndex; i < strlen(TextBuffer); i++) TextBuffer[i] = TextBuffer[i + 1]; // Cursor does not move } } // Commit / enter else if(key == '\r') { DidUserReturn = true; } /*** Cut, Copy, or Paste ***/ // Note that when doing a ctrl+key event, the given number // is offset from 'a', meaning true ascii = 'a' - key + 1 // Cut text else if(key == ('x' - 'a' + 1) && glutGetModifiers() == GLUT_ACTIVE_CTRL) { // Copy into buffer, then set text to empty CopyBuffer(); SetText(""); } // Copy text else if(key == ('c' - 'a' + 1) && glutGetModifiers() == GLUT_ACTIVE_CTRL) { // Direct copy CopyBuffer(); } // Paste text else if(key == ('v' - 'a' + 1) && glutGetModifiers() == GLUT_ACTIVE_CTRL) { // Direct paste PasteBuffer(); } /*** Regular User Input ***/ // Standard keyboard input; add character else if(isprint(key) != 0) { // Can we actually add anything? if(strlen(TextBuffer) < g2LabelEdit_TextBufferLength - 1 && !IsSpecial) { // Ignore if it isn't a valid character if(!InFilter(key)) return; // If we are writing to the end, make sure to string-cap if(CursorIndex == (int)strlen(TextBuffer)) { // Write to the old string-end and move the terminator a little further TextBuffer[CursorIndex + 0] = key; TextBuffer[CursorIndex + 1] = '\0'; } // Offset one char to the right, then set else { // Null-terminate the end of the string int Length = (int)strlen(TextBuffer); for(int i = Length; i > CursorIndex; i--) TextBuffer[i] = TextBuffer[i - 1]; TextBuffer[CursorIndex] = key; TextBuffer[Length + 1] = '\0'; } // Grow cursor position to be after the current char CursorIndex++; } // If the movement will cause us to be offsreen.. while(LengthToCursor() > Width) ViewIndex++; } // All done for each type of event }
static void replace_callback(GtkWidget *widget, GtkWidget *nothing) { Traces tcache; int i; Trptr tfirst, tlast; struct symchain *symc, *symc_current; gfloat interval; if(is_replace_running) return; is_replace_running = ~0; gtk_grab_add(widget); tfirst=NULL; tlast=NULL; symc=NULL; memcpy(&tcache,&traces,sizeof(Traces)); traces.total=0; traces.first=traces.last=NULL; GTK_ADJUSTMENT(pdata->adj)->upper = (gfloat)((num_rows>1)?num_rows-1:1); interval = (gfloat)(num_rows/100.0); pdata->oldvalue = -1.0; for(i=0;i<num_rows;i++) { int len; struct symbol *s, *t; s=(struct symbol *)gtk_clist_get_row_data(GTK_CLIST(clist), i); if(s->selected) { pdata->value = i; if(((int)(pdata->value/interval))!=((int)(pdata->oldvalue/interval))) { gtk_progress_set_value (GTK_PROGRESS (pdata->pbar), i); while (gtk_events_pending()) gtk_main_iteration(); } pdata->oldvalue = i; if((!s->vec_root)||(!autocoalesce)) { AddNode(s->n, NULL); } else { len=0; t=s->vec_root; while(t) { if(t->selected) { if(len) t->selected=0; symc_current=(struct symchain *)calloc_2(1,sizeof(struct symchain)); symc_current->next=symc; symc_current->symbol=t; symc=symc_current; } len++; t=t->vec_chain; } if(len)add_vector_chain(s->vec_root, len); } } } while(symc) { symc->symbol->selected=1; symc_current=symc; symc=symc->next; free_2(symc_current); } tfirst=traces.first; tlast=traces.last; /* cache for highlighting */ traces.buffercount=traces.total; traces.buffer=traces.first; traces.bufferlast=traces.last; traces.first=tcache.first; traces.last=tcache.last; traces.total=tcache.total; PasteBuffer(); traces.buffercount=tcache.buffercount; traces.buffer=tcache.buffer; traces.bufferlast=tcache.bufferlast; CutBuffer(); while(tfirst) { tfirst->flags |= TR_HIGHLIGHT; if(tfirst==tlast) break; tfirst=tfirst->next; } MaxSignalLength(); signalarea_configure_event(signalarea, NULL); wavearea_configure_event(wavearea, NULL); gtk_progress_set_value (GTK_PROGRESS (pdata->pbar), 0.0); pdata->oldvalue = -1.0; gtk_grab_remove(widget); is_replace_running=0; }