Exemple #1
0
static void
button_callback(GtkWidget *widget, const char *data)
{
    GCALCTRACE();
    if (verbose) g_print("button_callback: %s was pressed\n", data);

    if (strcmp(data, "EE") != 0 )
        gtk_entry_append_text(GTK_ENTRY(text_entry), data);
    else
        gtk_entry_append_text(GTK_ENTRY(text_entry), "E");
}
Exemple #2
0
void getDigit(GtkButton *button, gpointer data) {
	const char *op = gtk_button_get_label(button);
	GtkEntry *display = data;
	const char *text = gtk_entry_get_text(GTK_ENTRY(data));

	//currentVal = atoi(text);
	printf("Stored val = %d\n", currentVal);

	switch (*op) {
		case '=':
			printf("OP = Equals\n");
		break;

		case '+':
			printf("OP = Addition");
			currentVal = currentVal + atoi(text);
			
		break;

		default:
			if (strcmp(text, "0") == 0) {
				gtk_entry_set_text(GTK_ENTRY(data), "");
			}

			gtk_entry_append_text(GTK_ENTRY(data), op);
			printf("DISPLAY = %s\n", text);
		break;
	}
}
Exemple #3
0
void inserir( GtkButton *button,Calc_win *calc) {
    if(calc->operacao.igual){
     gtk_entry_set_text(GTK_ENTRY(calc->painel_resultado),"");
     calc->operacao.igual=FALSE;
    }
    if(!g_strcmp0(gtk_button_get_label(button),",")&&
            !g_strcmp0(gtk_entry_get_text(GTK_ENTRY(calc->painel_resultado)),"0")) {
        gtk_entry_append_text(GTK_ENTRY(calc->painel_resultado),gtk_button_get_label(button));
        return TRUE;

    } else if( !g_strcmp0(gtk_entry_get_text(GTK_ENTRY(calc->painel_resultado)),"0")) {
        gtk_entry_set_text(GTK_ENTRY(calc->painel_resultado),"");
    }
    gtk_entry_append_text(GTK_ENTRY(calc->painel_resultado),gtk_button_get_label(button));
    calc->operacao.calculo = atof(gtk_entry_get_text(GTK_ENTRY(calc->painel_resultado)));
}
Exemple #4
0
Fichier : gtk.c Projet : foo/ii
static void dodaj_do_text(GtkWidget *widget, gpointer data) {
  if(strcmp((gchar*)data, "\n") == 0)
  {
        gtk_entry_append_text(GTK_ENTRY(text), (gchar*)"=");
        char* wejscie = gtk_entry_get_text (GTK_ENTRY (text));;
        int len = strlen(wejscie);
        char* wynik = oblicz(wejscie, len);
        gtk_entry_set_text(GTK_ENTRY(text), wynik);
    }
  if(strcmp((gchar*)data, "") == 0)
  {
        gtk_entry_set_text(GTK_ENTRY(text), "");
    }
  else 
    gtk_entry_append_text(GTK_ENTRY(text), (gchar*)data);
}
Exemple #5
0
void hasxsd(GtkWidget *widget,gpointer data)    //如果没有小数点,则加入一个小数点
{
    if(xsd==0)
    {
        gtk_entry_append_text(GTK_ENTRY(entry),gtk_button_get_label(widget));  //往文本框添加字符串(从后面添加)
        xsd=1;
    }
}
Exemple #6
0
void input(GtkWidget *widget,gpointer data)
{
    if(flag==1) 
    {
        gtk_entry_set_text(GTK_ENTRY(entry1),"");
        gtk_entry_set_text(GTK_ENTRY(entry),"");
        flag=0;
    }
    gtk_entry_append_text(GTK_ENTRY(entry),gtk_button_get_label(widget));
}
Exemple #7
0
void formatPainelParcial(Calc_win *calc) {
    char str[256];
    if(calc->operacao.calculo!=0 ) {
        sprintf(str, "%s",formataResultado(calc->operacao.calculo)) ;
        gtk_entry_set_text(GTK_ENTRY(calc->painel_parcial),"");
        gtk_entry_append_text(GTK_ENTRY(calc->painel_parcial),str);
        mudarSinal(calc,calc->operacao.tipo_opr);
        calc->operacao.v_parcial = calc->operacao.calculo;
    }

}
Exemple #8
0
static void
number_button_callback(GtkWidget *widget, const char *data)
{
    GCALCTRACE();
    if (verbose) g_print("number_button_callback: %s was pressed\n", data);

    if (reset_input)
    {
        GCALCTRACE();
        gtk_entry_set_text(GTK_ENTRY(text_entry), "");
    }
    reset_input = false;

    GCALCTRACE();
    gtk_entry_append_text(GTK_ENTRY(text_entry), data);
}
Exemple #9
0
void mul(GtkWidget *widget,gpointer data)  //乘法函数
{
    method=2;
    bin_operation();
    gtk_entry_append_text(GTK_ENTRY(entry1),"X");
}
Exemple #10
0
void Div(GtkWidget *widget,gpointer data)  //除法函数
{
    method=3;
    bin_operation();
    gtk_entry_append_text(GTK_ENTRY(entry1),"/");
}
Exemple #11
0
void on_button_clear_clicked() {
	/*ptempchar = gtk_entry_get_text(entry_calc);
	ptempchar[strlen(ptempchar)-1] = '\x00';
	gtk_entry_set_text(entry_calc, ptempchar);*/
	gtk_entry_append_text(entry_calc, "\r");
}
Exemple #12
0
void and(GtkWidget *widget,gpointer data)  //与函数
{
    method=5;
    bin_operation();
    gtk_entry_append_text(GTK_ENTRY(entry1),"&");
}
Exemple #13
0
void on_button_no_clicked(GtkWidget *widget, gpointer user_data) {
	gtk_entry_append_text(entry_calc, gtk_button_get_label(widget));
}
Exemple #14
0
void sub(GtkWidget *widget,gpointer data)  //减法函数
{
    method=1;
    bin_operation();
    gtk_entry_append_text(GTK_ENTRY(entry1),"-");
}
Exemple #15
0
gboolean
keyboard_press(GtkWidget   *widget,
               GdkEventKey *event,
               gpointer     disable_frequency_entry)
{
    guint current = gdk_keyval_to_upper(event->keyval);
    gboolean shift_pressed = (event->state & GDK_SHIFT_MASK);

    // tuning
    if(current == conf.key_tune_down)
    {
        tuner_modify_frequency(TUNER_FREQ_MODIFY_DOWN);
        return TRUE;
    }

    if(current == conf.key_tune_up)
    {
        tuner_modify_frequency(TUNER_FREQ_MODIFY_UP);
        return TRUE;
    }

    if(current == conf.key_tune_fine_up)
    {
        if(tuner_get_freq() < 1900)
            tuner_set_frequency(tuner_get_freq()+1);
        else
            tuner_set_frequency(tuner_get_freq()+5);
        return TRUE;
    }

    if(current == conf.key_tune_fine_down)
    {
        if(tuner_get_freq() <= 1900)
            tuner_set_frequency(tuner_get_freq()-1);
        else
            tuner_set_frequency(tuner_get_freq()-5);
        return TRUE;
    }

    if(current == conf.key_tune_jump_down)
    {
        tuner_set_frequency(tuner_get_freq()-1000);
        return TRUE;
    }

    if(current == conf.key_tune_jump_up)
    {
        tuner_set_frequency(tuner_get_freq()+1000);
        return TRUE;
    }

    if(current == conf.key_tune_back)
    {
        gtk_button_clicked(GTK_BUTTON(ui.b_tune_back));
        return TRUE;
    }

    if(current == conf.key_tune_reset)
    {
        gtk_button_clicked(GTK_BUTTON(ui.b_tune_reset));
        return TRUE;
    }

    if(current == conf.key_screenshot)
    {
        ui_screenshot();
        return TRUE;
    }

    if(current == conf.key_rotate_cw)
    {
        rotation_shift_pressed = shift_pressed;
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ui.b_cw), TRUE);
        return TRUE;
    }

    if(current == conf.key_rotate_ccw)
    {
        rotation_shift_pressed = shift_pressed;
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ui.b_ccw), TRUE);
        return TRUE;
    }

    if(current == conf.key_switch_antenna)
    {
        gint current = gtk_combo_box_get_active(GTK_COMBO_BOX(ui.c_ant));
        gtk_combo_box_set_active(GTK_COMBO_BOX(ui.c_ant), ((current < conf.ant_count-1) ? current+1 : 0));
        return TRUE;
    }

    if(current == conf.key_rds_ps_mode)
    {
        ui_toggle_ps_mode();
        return TRUE;
    }

    if(current == conf.key_scan_toggle)
    {
        scan_try_toggle(shift_pressed);
        return TRUE;
    }

    if(current == conf.key_scan_prev)
    {
        scan_try_prev();
        return TRUE;
    }

    if(current == conf.key_scan_next)
    {
        scan_try_next();
        return TRUE;
    }

    // presets
    if(event->keyval >= GDK_F1 && event->keyval <= GDK_F12)
    {
        gint id = event->keyval-GDK_F1;
        if(shift_pressed)
        {
            conf.presets[id] = tuner_get_freq();
            ui_status(1500, "Preset <b>F%d</b> has been stored.", id+1);
        }
        else
        {
            tuner_set_frequency(conf.presets[id]);
        }
        return TRUE;
    }

    // decrease filter bandwidth
    if(current == conf.key_bw_down)
    {
        gint current = gtk_combo_box_get_active(GTK_COMBO_BOX(ui.c_bw));
        gint offset = (gint)(tuner.mode == MODE_AM); /* don't set the 'default' option in AM mode */
        if(current != gtk_tree_model_iter_n_children(GTK_TREE_MODEL(gtk_combo_box_get_model(GTK_COMBO_BOX(ui.c_bw))), NULL)-1-offset)
        {
            gtk_combo_box_set_active(GTK_COMBO_BOX(ui.c_bw), current+1);
        }
        return TRUE;
    }

    // increase filter bandwidth
    if(current == conf.key_bw_up)
    {
        gint current = gtk_combo_box_get_active(GTK_COMBO_BOX(ui.c_bw));
        if(current != 0)
        {
            gtk_combo_box_set_active(GTK_COMBO_BOX(ui.c_bw), current-1);
        }
        return TRUE;
    }

    // adaptive filter bandwidth
    if(current == conf.key_bw_auto)
    {
        if(tuner.mode == MODE_FM)
        {
            gtk_combo_box_set_active(GTK_COMBO_BOX(ui.c_bw),
                                     gtk_tree_model_iter_n_children(GTK_TREE_MODEL(gtk_combo_box_get_model(GTK_COMBO_BOX(ui.c_bw))), NULL) - 1);
        }
        return TRUE;
    }

    if(disable_frequency_entry)
    {
        return FALSE;
    }

    // freq entry
    gtk_widget_grab_focus(ui.e_freq);
    gtk_editable_set_position(GTK_EDITABLE(ui.e_freq), -1);

    gchar buff[10], buff2[10];
    gint i = 0, j = 0, k = 0;
    gboolean flag = FALSE;
    g_snprintf(buff, 10, "%s", gtk_entry_get_text(GTK_ENTRY(ui.e_freq)));
    if(event->keyval == GDK_Return)
    {
        for(i=0; i<strlen(buff); i++)
            if(buff[i]=='.')
                flag = TRUE;
        if(flag)
        {
            k=strlen(buff);
            for(i=0; i<k; i++)
            {
                if(buff[i] != '.')
                    buff2[j++] = buff[i];
                else
                {
                    buff2[j] = '0';
                    buff2[j+1] = '0';
                    buff2[j+2] = '0';
                    buff2[j+3] = 0x00;
                    if(k>(i+4))
                        k=i+4;
                }
            }
        }
        else
            g_snprintf(buff2, 10, "%s000", buff);

        gint i = atoi(buff2);
        if(i>=100)
            tuner_set_frequency(atoi(buff2));

        gtk_entry_set_text(GTK_ENTRY(ui.e_freq), "");
        gtk_editable_set_position(GTK_EDITABLE(ui.e_freq), 2);
        return TRUE;
    }
    else if(event->state & GDK_CONTROL_MASK)
    {
        return FALSE;
    }
    else if((event->keyval < GDK_KEY_0 || event->keyval > GDK_KEY_9) && (event->keyval < GDK_KEY_KP_0 || event->keyval > GDK_KEY_KP_9) && event->keyval != GDK_BackSpace && event->keyval != '.')
    {
        return TRUE;
    }
    else
    {
        for(i=0; i<strlen(buff); i++)
            if(buff[i]=='.')
                flag = TRUE;
        if(flag)
        {
            if(event->keyval == '.')
                return TRUE;
        }
        else
        {
            i=atoi(buff);
            if(i>=20 && i<=200 && event->keyval != GDK_BackSpace && event->keyval != '.')
            {
                switch(event->keyval)
                {
                case GDK_KEY_KP_0:
                    sprintf(buff2, ".0");
                    break;
                case GDK_KEY_KP_1:
                    sprintf(buff2, ".1");
                    break;
                case GDK_KEY_KP_2:
                    sprintf(buff2, ".2");
                    break;
                case GDK_KEY_KP_3:
                    sprintf(buff2, ".3");
                    break;
                case GDK_KEY_KP_4:
                    sprintf(buff2, ".4");
                    break;
                case GDK_KEY_KP_5:
                    sprintf(buff2, ".5");
                    break;
                case GDK_KEY_KP_6:
                    sprintf(buff2, ".6");
                    break;
                case GDK_KEY_KP_7:
                    sprintf(buff2, ".7");
                    break;
                case GDK_KEY_KP_8:
                    sprintf(buff2, ".8");
                    break;
                case GDK_KEY_KP_9:
                    sprintf(buff2, ".9");
                    break;
                default:
                    sprintf(buff2, ".%c", event->keyval);
                    break;
                }

                gtk_entry_append_text(GTK_ENTRY(ui.e_freq), buff2);
                gtk_editable_set_position(GTK_EDITABLE(ui.e_freq), -1);
                return TRUE;
            }
        }
    }
    return FALSE;
}
Exemple #16
0
void xor(GtkWidget *widget,gpointer data)  //异或函数
{
    method=7;
    bin_operation();
    gtk_entry_append_text(GTK_ENTRY(entry1),"^");
}
Exemple #17
0
void mod(GtkWidget *widget,gpointer data)  //取余函数,取模
{
    method=8;
    bin_operation();
    gtk_entry_append_text(GTK_ENTRY(entry1),"%");
}
Exemple #18
0
void output()
{
    char num[50]="0";
//    gtk_entry_set_text(GTK_ENTRY(entry),"");
        strcpy(num,gtk_entry_get_text(GTK_ENTRY(entry)));
        gtk_entry_append_text(GTK_ENTRY(entry1),num);
        if(flag==0) flag=1;
        if(principle==16)
        {
            conversion(num,16,10);
            b=p;
        }
        if(principle==10)
        {
            b=atof(num);
        }
        if(principle==8)
        {
            conversion(num,8,10);
            b=p;
        }
        if(principle==2)
        {
            conversion(num,2,10);
            b=p;
        }
        if(a==0&&b==0)
        {
            gtk_entry_set_text(GTK_ENTRY(entry1),"0=");
            gtk_entry_set_text(GTK_ENTRY(entry),"0");

        }
        else
        {
            switch(method)
            {
                case 0: a=a+b;
                        right_output();
                        break;
                case 1: a=a-b;
                        right_output();
                        break;
                case 2: a=a*b;
                        right_output();
                        break;
                case 3:
                        if(b==0)
                        {
                            a=0;
                            b=0;
                            method=0;
                            gtk_entry_set_text(GTK_ENTRY(entry),g_locale_to_utf8("除数不能为零",-1,NULL,NULL,NULL));
                        }
                        else
                        {
                            a=a/b;  //C语言规定两个整数相除只取商的部分,但一个整数除以浮点数结果仍是浮点数
                            right_output();
                        }
                        break;
                case 4:
                        a=pow(a,b);
                        right_output();
                        break;
                case 5:
                        a=((int)a)&((int)b);
                        right_output();
                        break;
                case 6:
                        a=((int)a)|((int)b);
                        right_output();
                        break;
                case 7:
                        a=((int)a)^((int)b);
                        right_output();
                        break;
                case 8:
                        if(b==0)
                        {
                            a=0;
                            b=0;
                            method=0;
                            gtk_entry_set_text(GTK_ENTRY(entry),g_locale_to_utf8("除数不能为零",-1,NULL,NULL,NULL));
                        }
                        else
                        {
                            a=((int)a)%((int)b);    //C语言规定取余只能用于两个整数之间
                            right_output();
                        }
                        break;
                case 9:
                        a=sin(b);
                        right_output();
                        break;
                case 10:
                        a=cos(b);
                        right_output();
                        break;
                case 11:
                        a=tan(b);
                        right_output();
                        break;
                case 12:
                        a=exp(b);
                        right_output();
                        break;
                case 13:
                        a=b*b*b;
                        gtk_entry_append_text(GTK_ENTRY(entry1),"^3");
                        right_output();
                        break;
                case 14:
                        a=b*b;
                        gtk_entry_append_text(GTK_ENTRY(entry1),"^2");
                        right_output();
                        break;
                case 15:
                        if(b<=0)
                        {
                            a=0;
                            b=0;
                            method=0;
                            gtk_entry_set_text(GTK_ENTRY(entry),g_locale_to_utf8("对数必须为正数",-1,NULL,NULL,NULL));
                        }
                        else
                        {
                            a=log(b);
                            right_output();
                        }
                        break;
                case 16:
                        if(b<=0)
                        {
                            a=0;
                            b=0;
                            method=0;
                            gtk_entry_set_text(GTK_ENTRY(entry),g_locale_to_utf8("对数必须为正数",-1,NULL,NULL,NULL));
                        }
                        else
                        {
                            a=log10(b);
                            right_output();
                        }
                        break;
                case 17:
                        if(b<0)
                        {
                            a=0;
                            b=0;
                            method=0;
                            gtk_entry_set_text(GTK_ENTRY(entry),g_locale_to_utf8("阶乘不能为负数",-1,NULL,NULL,NULL));
                        }
                        else
                        {
                            a=jiechen((int)b);
                            gtk_entry_append_text(GTK_ENTRY(entry1),"!");
                            right_output();
                        }
                        break;
                case 18:
                        if(b==0)
                        {
                            a=0;
                            b=0;
                            method=0;
                            gtk_entry_set_text(GTK_ENTRY(entry),g_locale_to_utf8("除数不能为零",-1,NULL,NULL,NULL));
                        }
                        else
                        {
                            a=1/b;
                            right_output();
                        }
                        break;
                case 19:
                        a=~((int)b);
                        right_output();
                        break;
                case 20:
                        a=floor(b);
                        right_output();
                        break;
            }
            gtk_entry_append_text(GTK_ENTRY(entry1),"=");
        }
    
}
Exemple #19
0
void add(GtkWidget *widget,gpointer data)  //加法函数
{
    method=0;
    bin_operation();
    gtk_entry_append_text(GTK_ENTRY(entry1),"+");
}