void event_editor::OnInsert() { int i; if (m_num_events == MAX_MISSION_EVENTS) { MessageBox("You have reached the limit on mission events.\n" "Can't add any more."); return; } if(cur_event < 0 || m_num_events == 0) { //There are no events yet, so just create one reset_event(m_num_events++, TVI_LAST); } else { for (i=m_num_events; i>cur_event; i--) { m_events[i] = m_events[i - 1]; m_sig[i] = m_sig[i - 1]; } if (cur_event){ reset_event(cur_event, get_event_handle(cur_event - 1)); } else { reset_event(cur_event, TVI_FIRST); } m_num_events++; } }
CP_HIDDEN void cpi_wait_mutex(cpi_mutex_t *mutex) { DWORD self = GetCurrentThreadId(); assert(mutex != NULL); lock_mutex(mutex->os_mutex); if (mutex->lock_count > 0 && self == mutex->os_thread) { int lc = mutex->lock_count; // Release mutex mutex->lock_count = 0; mutex->num_wait_threads++; set_event(mutex->os_cond_lock); unlock_mutex(mutex->os_mutex); // Wait for signal wait_for_event(mutex->os_cond_wake); // Reset wake signal if last one waking up lock_mutex(mutex->os_mutex); if (--mutex->num_wait_threads == 0) { reset_event(mutex->os_cond_wake); } // Re-acquire mutex and restore lock count for this thread lock_mutex_holding(mutex); mutex->lock_count = lc; } else { cpi_fatalf(_("Internal C-Pluff error: Unauthorized attempt at waiting on a mutex.")); } unlock_mutex(mutex->os_mutex); }
void event_editor::OnButtonNewEvent() { if (m_num_events == MAX_MISSION_EVENTS) { MessageBox("You have reached the limit on mission events.\n" "Can't add any more."); return; } reset_event(m_num_events++, TVI_LAST); }
int DialogInput(GtkWidget * parent, const char *title, const char *mes, const char *init_str, char **s, int *x, int *y) { GtkWidget *dlg, *text; GtkBox *vbox; int data; gint res_id; dlg = gtk_dialog_new_with_buttons(title, GTK_WINDOW(parent), #if GTK_CHECK_VERSION(3, 12, 0) && USE_HEADER_BAR GTK_DIALOG_USE_HEADER_BAR | #endif GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, _("_Cancel"), GTK_RESPONSE_CANCEL, _("_OK"), GTK_RESPONSE_OK, NULL); gtk_dialog_set_default_response(GTK_DIALOG(dlg), GTK_RESPONSE_OK); gtk_window_set_resizable(GTK_WINDOW(dlg), FALSE); vbox = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dlg))); if (mes) { GtkWidget *label; label = gtk_label_new(mes); gtk_box_pack_start(vbox, label, FALSE, FALSE, 5); } text = create_text_entry(FALSE, TRUE); if (init_str) { gtk_entry_set_text(GTK_ENTRY(text), init_str); } gtk_box_pack_start(vbox, text, FALSE, FALSE, 5); set_dialog_position(dlg, x, y); gtk_widget_show_all(dlg); res_id = ndialog_run(dlg); switch (res_id) { case GTK_RESPONSE_OK: *s = g_strdup(gtk_entry_get_text(GTK_ENTRY(text))); data = IDOK; break; default: data = IDCANCEL; break; } get_dialog_position(dlg, x, y); gtk_widget_destroy(dlg); reset_event(); return data; }
void event_editor::OnButtonNewEvent() { if (m_num_events == MAX_MISSION_EVENTS) { MessageBox("You have reached the limit on mission events.\n" "Can't add any more."); return; } // before we do anything, we must check and save off any data from the current event (e.g // the repeat count and interval count) save(); reset_event(m_num_events++, TVI_LAST); }
void event_editor::OnInsert() { int i; if (m_num_events == MAX_MISSION_EVENTS) { MessageBox("You have reached the limit on mission events.\n" "Can't add any more."); return; } // before we do anything, we must check and save off any data from the current event (e.g // the repeat count and interval count) save(); if(cur_event < 0 || m_num_events == 0) { //There are no events yet, so just create one reset_event(m_num_events++, TVI_LAST); } else { for (i=m_num_events; i>cur_event; i--) { m_events[i] = m_events[i - 1]; m_sig[i] = m_sig[i - 1]; } if (cur_event){ reset_event(cur_event, get_event_handle(cur_event - 1)); } else { reset_event(cur_event, TVI_FIRST); } m_num_events++; } }
int DialogButton(GtkWidget *parent, const char *title, const char *caption, struct narray *array, int *x, int *y) { GtkWidget *dlg; gint res_id; char **d; int i, anum; d = arraydata(array); anum = arraynum(array); if (anum < 1) { return -1; } dlg = gtk_dialog_new(); for (i = 0; i < anum; i++) { if (d[i] && g_utf8_validate(d[i], -1, NULL)) { gtk_dialog_add_button(GTK_DIALOG(dlg), d[i], i); } } if (title && g_utf8_validate(title, -1, NULL)) { gtk_window_set_title(GTK_WINDOW(dlg), title); } if (caption && g_utf8_validate(caption, -1, NULL)) { GtkWidget *box, *label; box = gtk_dialog_get_content_area(GTK_DIALOG(dlg)); label = gtk_label_new(caption); gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 4); } gtk_window_set_resizable(GTK_WINDOW(dlg), FALSE); set_dialog_position(dlg, x, y); gtk_widget_show_all(dlg); res_id = ndialog_run(dlg); get_dialog_position(dlg, x, y); gtk_widget_destroy(dlg); reset_event(); return res_id; }
static BOOL winpr_StartThread(WINPR_THREAD* thread) { pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); if (thread->dwStackSize > 0) pthread_attr_setstacksize(&attr, (size_t) thread->dwStackSize); thread->started = TRUE; reset_event(thread); if (pthread_create(&thread->thread, &attr, thread_launcher, thread)) goto error; if (pthread_mutex_lock(&thread->threadIsReadyMutex)) goto error; if (!ListDictionary_Add(thread_list, &thread->thread, thread)) { WLog_ERR(TAG, "failed to add the thread to the thread list"); pthread_mutex_unlock(&thread->threadIsReadyMutex); goto error; } if (pthread_cond_signal(&thread->threadIsReady) != 0) { WLog_ERR(TAG, "failed to signal the thread was ready"); pthread_mutex_unlock(&thread->threadIsReadyMutex); goto error; } if (pthread_mutex_unlock(&thread->threadIsReadyMutex)) goto error; pthread_attr_destroy(&attr); dump_thread(thread); return TRUE; error: pthread_attr_destroy(&attr); return FALSE; }
static BOOL winpr_StartThread(WINPR_THREAD *thread) { pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); if (thread->dwStackSize > 0) pthread_attr_setstacksize(&attr, (size_t) thread->dwStackSize); thread->started = TRUE; reset_event(thread); if (pthread_create(&thread->thread, &attr, thread_launcher, thread)) goto error; if (!ListDictionary_Add(thread_list, &thread->thread, thread)) goto error; pthread_attr_destroy(&attr); dump_thread(thread); return TRUE; error: pthread_attr_destroy(&attr); return FALSE; }
int DialogSpinEntry(GtkWidget *parent, const char *title, const char *caption, double min, double max, double inc, double *r, int *x, int *y) { GtkWidget *dlg, *spin; GtkBox *vbox; int data, n; gint res_id; double prec; dlg = gtk_dialog_new_with_buttons(title, GTK_WINDOW(parent), #if GTK_CHECK_VERSION(3, 12, 0) && USE_HEADER_BAR GTK_DIALOG_USE_HEADER_BAR | #endif GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, _("_Cancel"), GTK_RESPONSE_CANCEL, _("_OK"), GTK_RESPONSE_OK, NULL); gtk_dialog_set_default_response(GTK_DIALOG(dlg), GTK_RESPONSE_OK); gtk_window_set_resizable(GTK_WINDOW(dlg), FALSE); vbox = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dlg))); if (caption) { GtkWidget *label; label = gtk_label_new(caption); gtk_box_pack_start(vbox, label, FALSE, FALSE, 5); } if (inc == 0) inc = 1; spin = gtk_spin_button_new_with_range(min, max, inc); gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(spin), TRUE); gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), *r); gtk_box_pack_start(vbox, spin, FALSE, FALSE, 2); gtk_entry_set_activates_default(GTK_ENTRY(spin), TRUE); prec = log10(fabs(inc)); if (prec < 0) { n = ceil(- prec); } else { n = 0; } gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spin), n); set_dialog_position(dlg, x, y); gtk_widget_show_all(dlg); res_id = ndialog_run(dlg); switch (res_id) { case GTK_RESPONSE_OK: *r = gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin)); data = IDOK; break; default: data = IDCANCEL; break; } get_dialog_position(dlg, x, y); gtk_widget_destroy(dlg); reset_event(); return data; }
/** * @fn HRESULT receive_execute(struct CONN_BCAP_SERVER *bcap_param) * @brief Receives the b-CAP packet and executes callback functions. * @param[in,out] bcap_param b-CAP communication object. */ static HRESULT receive_execute(struct CONN_BCAP_SERVER *bcap_param) { int index; int32_t relation_id; uint16_t i, clear_flag = 1; uint32_t cur, start, diff; HRESULT hr; struct CONN_BCAP_SERVER *tmp_param = bcap_param; struct CONN_PARAM_COMMON *device = &bcap_param->device; struct BCAP_PACKET tmp_send_packet, tmp_recv_packet, *send_packet = &bcap_param->last_send, *recv_packet = &bcap_param->last_recv; struct VEC_OBJECT *pObj = NULL; BSTR bstrOpt = NULL; VARIANT vntTmp, vntOpt; VariantInit(&vntTmp); VariantInit(&vntOpt); /* Initializes temporary packet */ tmp_recv_packet.argc = (uint16_t) -1; tmp_recv_packet.args = NULL; /* Receives b-CAP packet */ hr = bcap_recv(device, &tmp_recv_packet, 0); if(SUCCEEDED(hr)) { /* Sets S_EXECUTING packet */ memset(&tmp_send_packet, 0, sizeof(struct BCAP_PACKET)); tmp_send_packet.serial = tmp_recv_packet.serial; tmp_send_packet.id = S_EXECUTING; /* Checks retry packet */ switch(device->type) { case CONN_UDP: tmp_param = search_node(bcap_param, device->arg, sizeof(struct sockaddr_in)); if(tmp_param == NULL) { /* Checks life limit */ if((bcap_param->num_child >= BCAP_CLIENT_MAX) && (check_lifelimit(bcap_param) >= BCAP_CLIENT_MAX)) { tmp_send_packet.id = E_MAX_CONNECT; bcap_send(device, &tmp_send_packet); hr = S_FALSE; goto exit_proc; } /* Adds child */ change_relation(bcap_param, ADD_CHILD, &device->sock); tmp_param = bcap_param->node1; } send_packet = &tmp_param->last_send; //break; case CONN_COM: /* Sets retry count */ tmp_recv_packet.reserv = (tmp_recv_packet.reserv == 0) ? tmp_recv_packet.serial : tmp_recv_packet.reserv; /* If already responded, then does not execute */ if(send_packet->serial == tmp_recv_packet.reserv) { /* Copies last send packet */ tmp_send_packet = *send_packet; /* Sets new serial number */ tmp_send_packet.serial = tmp_recv_packet.serial; /* Sends temporary send packet */ bcap_send(device, &tmp_send_packet); hr = S_FALSE; goto exit_proc; } break; default: break; } /* Checks execute thread */ hr = wait_event(&bcap_param->comp_evt, 0); if(hr == E_TIMEOUT) { /* Sends result busy process */ tmp_send_packet.id = E_BUSY_PROC; bcap_send(device, &tmp_send_packet); goto exit_proc; } switch(tmp_recv_packet.id) { case ID_SERVICE_START: case ID_CONTROLLER_CONNECT: case ID_CONTROLLER_GETEXTENSION: case ID_CONTROLLER_GETFILE: case ID_FILE_GETFILE: case ID_CONTROLLER_GETROBOT: case ID_CONTROLLER_GETTASK: case ID_CONTROLLER_GETVARIABLE: case ID_EXTENSION_GETVARIABLE: case ID_FILE_GETVARIABLE: case ID_ROBOT_GETVARIABLE: case ID_TASK_GETVARIABLE: case ID_CONTROLLER_GETCOMMAND: case ID_CONTROLLER_GETMESSAGE: if(bcap_param->num_object >= BCAP_OBJECT_MAX) { tmp_send_packet.id = E_MAX_OBJECT; bcap_send(device, &tmp_send_packet); hr = S_FALSE; goto exit_proc; } if(tmp_recv_packet.id == ID_SERVICE_START) { if((tmp_recv_packet.argc >= 1) && (tmp_recv_packet.args != NULL)) { VariantCopy(&vntTmp, &tmp_recv_packet.args[0]); hr = VariantChangeType(&vntTmp, &vntTmp, 0, VT_BSTR); if(FAILED(hr)) { tmp_send_packet.id = hr; bcap_send(device, &tmp_send_packet); hr = S_FALSE; goto exit_proc; } } else { vntTmp.vt = VT_BSTR; vntTmp.bstrVal = SysAllocString(L""); } bstrOpt = SysAllocString(L"WDT"); hr = GetOptionValue(vntTmp.bstrVal, bstrOpt, VT_UI4, &vntOpt); vntOpt.ulVal = (vntOpt.vt == VT_UI4) ? vntOpt.ulVal : INIT_WDT_INTERVAL; if(vntOpt.ulVal < MIN_WDT_INTERVAL) { tmp_send_packet.id = E_INVALIDARG; bcap_send(device, &tmp_send_packet); hr = S_FALSE; goto exit_proc; } else { tmp_param->wdt_interval = vntOpt.ulVal; } SysFreeString(bstrOpt); VariantClear(&vntOpt); bstrOpt = SysAllocString(L"InvokeTimeout"); hr = GetOptionValue(vntTmp.bstrVal, bstrOpt, VT_UI4, &vntOpt); vntOpt.ulVal = (vntOpt.vt == VT_UI4) ? vntOpt.ulVal : INIT_EXEC_TIMEOUT; if(vntOpt.ulVal < MIN_WDT_INTERVAL) { tmp_send_packet.id = E_INVALIDARG; bcap_send(device, &tmp_send_packet); hr = S_FALSE; goto exit_proc; } else { tmp_param->exec_timeout = vntOpt.ulVal; } SysFreeString(bstrOpt); VariantClear(&vntOpt); VariantClear(&vntTmp); bstrOpt = NULL; } break; default: break; } /* Resets last received packet */ if(recv_packet->args != NULL) { for(i = 0; i < recv_packet->argc; i++) { VariantClear(&recv_packet->args[i]); } free(recv_packet->args); } /* Copies to last receive packet */ clear_flag = 0; *recv_packet = tmp_recv_packet; /* Runs execute thread */ reset_event(&bcap_param->comp_evt); set_event(&bcap_param->exec_evt); if(SUCCEEDED(hr)) { start = gettimeofday_msec(); while(1) { hr = wait_event(&bcap_param->comp_evt, tmp_param->wdt_interval); if(SUCCEEDED(hr)) { break; } else { /* Sends S_EXECUTING packet */ hr = bcap_send(device, &tmp_send_packet); if(FAILED(hr)) { break; } } /* Checks executing timeout */ cur = gettimeofday_msec(); diff = calc_time_diff(start, cur); if(diff > tmp_param->exec_timeout) { hr = E_TIMEOUT; break; } } } } exit_proc: if(hr == S_OK) { if(bcap_param->last_send.id == S_OK) { /* Changes the vector of created objects */ relation_id = m_map_id[recv_packet->id].relation_id; if(relation_id > 0) { // Push pObj = (struct VEC_OBJECT *) malloc(sizeof(struct VEC_OBJECT)); if(pObj != NULL) { memset(pObj, 0, sizeof(struct VEC_OBJECT)); pObj->id = relation_id; pObj->hObj = (recv_packet->id == ID_SERVICE_START) ? 0 : bcap_param->last_send.args[0].lVal; push_vector(bcap_param, pObj); } } else if(relation_id < 0) { // Pop index = search_vector(bcap_param, recv_packet->id, (recv_packet->id == ID_SERVICE_STOP) ? 0 : recv_packet->args[0].lVal); if(index >= 0) { pop_vector(bcap_param, &pObj, index); free(pObj); } if((device->type == CONN_UDP) && (recv_packet->id == ID_SERVICE_STOP)) { change_relation(tmp_param, DESTROY_SELF, NULL); change_relation(bcap_param, DELETE_CHILD, NULL); tmp_param = NULL; } } } /* Responds the result message */ hr = bcap_send(device, &bcap_param->last_send); if(SUCCEEDED(hr) && (tmp_param != NULL)) { tmp_param->last_send.serial = bcap_param->last_send.serial; tmp_param->last_send.reserv = bcap_param->last_send.reserv; tmp_param->last_send.id = bcap_param->last_send.id; tmp_param->last_send.argc = bcap_param->last_send.argc; VariantCopy(tmp_param->last_send.args, bcap_param->last_send.args); tmp_param->last_modified = gettimeofday_msec(); } } /* Clears temporary packet */ if(clear_flag) { if(tmp_recv_packet.args != NULL) { for(i = 0; i < tmp_recv_packet.argc; i++) { VariantClear(&tmp_recv_packet.args[i]); } free(tmp_recv_packet.args); } } VariantClear(&vntTmp); VariantClear(&vntOpt); if(bstrOpt) { SysFreeString(bstrOpt); } return hr; }
void main() { disable_interrupts(GLOBAL); setup_spi(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_16 ); setup_spi2(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_16 ); setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4|VSS_4V096); setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0); // TIMER 0 is being used to service the WTD setup_timer_0(T0_INTERNAL|T0_DIV_256); /* sets the internal clock as source and prescale 256. At 10 Mhz timer0 will increment every 0.4us (Fosc*4) in this setup and overflows every 6.71 seconds. Timer0 defaults to 16-bit if RTCC_8_BIT is not used. Fosc = 10 MHz, Fosc/4 = 2.5 Mhz, div 256 = 0.0001024 s, 65536 increments = 6.71 sec Fosc = 64 MHz, Fosc/4 = 16 Mhz, div 256 = 0.000016 s, 65536 increments = 1.05 sec .. pre-load with 3036 to get exact 1.0000 sec value */ // TIMER 1 is used to extinguish the LED setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); /* sets the internal clock as source and prescale 4. At 10Mhz timer0 will increment every 0.4us in this setup and overflows every 104.8 ms. Timer1 is 16-bit. Fosc = 10 Mhz ... 2.5 MHz / div 4 = 0.00000160 s * 65536 = 0.104858 sec Fosc = 64 Mhz ... 16 MHz / div 4 = 0.00000025 s * 65536 = 0.016384 sec Fosc = 64 Mhz ... 16 MHz / div 8 = 0.00000200 s * 65536 = 0.032768 sec */ setup_stepper_pwm(); // Uses TIMER 2 // TIMER 3 is used for stepper motor intervals setup_timer_3(T3_INTERNAL | T3_DIV_BY_1); // 16 bit timer // TIMER 4 is use for serial time-outs. 8-bit timer. setup_timer_4(T4_DIV_BY_4, 127, 1); setup_comparator(NC_NC_NC_NC); setup_oscillator(OSC_16MHZ | OSC_PLL_ON); // Fosc = 64 MHz ext_int_edge(0, H_TO_L); // Set up PIC18 EXT0 enable_interrupts(INT_EXT); start_heartbeat(); enable_interrupts(GLOBAL); init_hardware(); motor_sleep_rdy(); sleep_mode = FALSE; busy_set(); init_nv_vars(); get_step_vars(); init_aws(); blink(); //Add for TCP/IP interface //delay_ms(15000); signon(); RTC_read(); RTC_last_power(); RTC_reset_HT(); RTC_read(); RTC_read_flags(); if(nv_sd_status>0) fprintf(COM_A,"@SD=%Lu\r\n", nv_sd_status); init_rtc(); // This is the FAT RTC sd_status = init_sdcard(); if(sd_status>0) msg_card_fail(); reset_event(); if(m_error[0] > 0 || m_error[1] > 0) msg_mer(); if (m_comp[0]==FALSE) { e_port[0]=0; write16(ADDR_E1_PORT,0); fprintf(COM_A, "@MC1,%Lu,%Ld\r\n", m_comp[0],e_port[0]); } if (m_comp[1]==FALSE) { m_lin_pos[1]=-1; write16(ADDR_M2_LIN_POS, -1); fprintf(COM_A, "@MC2,%Lu,%Ld\r\n", m_comp[1],m_lin_pos[1]); } if (nv_cmd_mode == FALSE){ for(dt=0; dt<100; ++dt){ blip(); if (nv_cmd_mode == TRUE) { busy_clear(); fputs("@OK!", COM_A); command_prompt(); dt = 100; } } } else command_prompt(); user_quit = auto_sample_ready(); reset_cpu(); }
static int FileSelectionDialog(GtkWidget *parent, int type, char *stock) { struct nGetOpenFileData *data; GtkWidget *dlg, *rc; GtkFileFilter *filter; char *fname; data = &FileSelection; data->parent = (parent) ? parent : TopLevel; dlg = gtk_file_chooser_dialog_new(data->title, GTK_WINDOW(data->parent), type, _("_Cancel"), GTK_RESPONSE_CANCEL, stock, GTK_RESPONSE_ACCEPT, NULL); gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(dlg), TRUE); rc = gtk_check_button_new_with_mnemonic(_("_Change current directory")); gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dlg))), rc, FALSE, FALSE, 5); data->chdir_cb = rc; gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dlg), data->multi); data->widget = dlg; if (data->ext) { char *filter_str, *filter_name, *ext_name; filter_str = g_strdup_printf("*.%s", data->ext); ext_name = g_ascii_strup(data->ext, -1); filter_name = g_strdup_printf(_("%s file (*.%s)"), ext_name, data->ext); g_free(ext_name); filter = gtk_file_filter_new(); gtk_file_filter_add_pattern(filter, filter_str); gtk_file_filter_set_name(filter, filter_name); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dlg), filter); g_free(filter_str); g_free(filter_name); filter = gtk_file_filter_new(); gtk_file_filter_add_pattern(filter, "*"); gtk_file_filter_set_name(filter, _("All")); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dlg), filter); } if (data->init_dir && *(data->init_dir)) { gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dlg), *(data->init_dir)); } gtk_widget_show_all(dlg); if (data->changedir && data->init_dir) { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->chdir_cb), data->chdir); } else { gtk_widget_hide(data->chdir_cb); } fname = get_filename_with_ext(data->init_file, data->ext); if (fname) { if (type == GTK_FILE_CHOOSER_ACTION_SAVE) { #ifdef WINDOWS char *tmp; tmp = g_locale_from_utf8(fname, -1, NULL, NULL, NULL); if (tmp) { file_dialog_set_current_neme(dlg, tmp); g_free(tmp); } #else /* WINDOWS */ file_dialog_set_current_neme(dlg, fname); #endif /* WINDOWS */ } else { gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dlg), fname); } g_free(fname); } data->ret = IDCANCEL; while (1) { if (ndialog_run(dlg) != GTK_RESPONSE_ACCEPT) break; fsok(dlg); if (data->ret == IDOK && type == GTK_FILE_CHOOSER_ACTION_SAVE) { file_dialog_set_current_neme(dlg, FileSelection.file[0]); if (! data->overwrite && check_overwrite(dlg, FileSelection.file[0])) { data->ret = IDCANCEL; continue; } } break; } gtk_widget_destroy(dlg); reset_event(); data->widget = NULL; return data->ret; }
int DialogCheck(GtkWidget *parent, const char *title, const char *caption, struct narray *array, int *r, int *x, int *y) { GtkWidget *dlg, *btn, **btn_ary; GtkBox *vbox; int data; gint res_id; char **d; int i, anum; d = arraydata(array); anum = arraynum(array); btn_ary = g_malloc(anum * sizeof(*btn_ary)); if (btn_ary == NULL) return IDCANCEL; dlg = gtk_dialog_new_with_buttons(title, GTK_WINDOW(parent), #if GTK_CHECK_VERSION(3, 12, 0) && USE_HEADER_BAR GTK_DIALOG_USE_HEADER_BAR | #endif GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, _("_Cancel"), GTK_RESPONSE_CANCEL, _("_OK"), GTK_RESPONSE_OK, NULL); gtk_dialog_set_default_response(GTK_DIALOG(dlg), GTK_RESPONSE_OK); gtk_window_set_resizable(GTK_WINDOW(dlg), FALSE); vbox = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dlg))); if (caption) { GtkWidget *label; label = gtk_label_new(caption); gtk_box_pack_start(vbox, label, FALSE, FALSE, 5); } btn = NULL; for (i = 0; i < anum; i++) { btn = gtk_check_button_new_with_mnemonic(d[i]); gtk_box_pack_start(vbox, btn, FALSE, FALSE, 2); btn_ary[i] = btn; } for (i = 0; i < anum; i++) { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(btn_ary[i]), r[i]); } set_dialog_position(dlg, x, y); gtk_widget_show_all(dlg); res_id = ndialog_run(dlg); switch (res_id) { case GTK_RESPONSE_OK: for (i = 0; i < anum; i++) { r[i] = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(btn_ary[i])); } data = IDOK; break; default: data = IDCANCEL; break; } g_free(btn_ary); get_dialog_position(dlg, x, y); gtk_widget_destroy(dlg); reset_event(); return data; }
int DialogComboEntry(GtkWidget *parent, const char *title, const char *caption, struct narray *array, int sel, char **r, int *x, int *y) { GtkWidget *dlg, *combo; GtkBox *vbox; int data; gint res_id; char **d; const char *s; int i, anum; d = arraydata(array); anum = arraynum(array); *r = NULL; dlg = gtk_dialog_new_with_buttons(title, GTK_WINDOW(parent), #if GTK_CHECK_VERSION(3, 12, 0) && USE_HEADER_BAR GTK_DIALOG_USE_HEADER_BAR | #endif GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, _("_Cancel"), GTK_RESPONSE_CANCEL, _("_OK"), GTK_RESPONSE_OK, NULL); gtk_dialog_set_default_response(GTK_DIALOG(dlg), GTK_RESPONSE_OK); gtk_window_set_resizable(GTK_WINDOW(dlg), FALSE); vbox = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dlg))); if (caption) { GtkWidget *label; label = gtk_label_new(caption); gtk_box_pack_start(vbox, label, FALSE, FALSE, 5); } combo = combo_box_entry_create(); for (i = 0; i < anum; i++) { combo_box_append_text(combo, d[i]); } if (sel >= 0 && sel < anum) { combo_box_set_active(combo, sel); } gtk_box_pack_start(vbox, combo, FALSE, FALSE, 2); set_dialog_position(dlg, x, y); gtk_widget_show_all(dlg); res_id = ndialog_run(dlg); switch (res_id) { case GTK_RESPONSE_OK: s = combo_box_entry_get_text(combo); if (s) { *r = g_strdup(s); } else { *r = NULL; } data = IDOK; break; default: data = IDCANCEL; break; } get_dialog_position(dlg, x, y); gtk_widget_destroy(dlg); reset_event(); return data; }
int message_box(GtkWidget * parent, const char *message, const char *title, int mode) { GtkWidget *dlg; int data; GtkMessageType dlg_type; GtkButtonsType dlg_button; gint res_id; if (title == NULL) { title = _("Error"); } switch (mode) { case RESPONS_YESNOCANCEL: dlg_button = GTK_BUTTONS_CANCEL; dlg_type = GTK_MESSAGE_QUESTION; break; case RESPONS_YESNO: dlg_button = GTK_BUTTONS_YES_NO; dlg_type = GTK_MESSAGE_QUESTION; break; case RESPONS_ERROR: dlg_button = GTK_BUTTONS_OK; dlg_type = GTK_MESSAGE_ERROR; break; default: dlg_button = GTK_BUTTONS_OK; dlg_type = GTK_MESSAGE_INFO; } if (parent == NULL) parent = get_current_window(); dlg = gtk_message_dialog_new(GTK_WINDOW(parent), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, dlg_type, dlg_button, "%.256s", message); switch (mode) { case RESPONS_YESNOCANCEL: gtk_dialog_add_button(GTK_DIALOG(dlg), _("_No"), GTK_RESPONSE_NO); gtk_dialog_add_button(GTK_DIALOG(dlg), _("_Yes"), GTK_RESPONSE_YES); case RESPONS_YESNO: /* fall-through */ gtk_dialog_set_default_response(GTK_DIALOG(dlg), GTK_RESPONSE_YES); break; } gtk_window_set_title(GTK_WINDOW(dlg), title); gtk_window_set_resizable(GTK_WINDOW(dlg), FALSE); gtk_widget_show_all(dlg); res_id = ndialog_run(dlg); switch (res_id) { case GTK_RESPONSE_OK: data = IDYES; break; case GTK_RESPONSE_YES: data = IDYES; break; case GTK_RESPONSE_NO: data = IDNO; break; case GTK_RESPONSE_CANCEL: data = IDCANCEL; break; default: if ((mode == RESPONS_OK) || (mode == RESPONS_ERROR)) { data = IDOK; } else if (mode == RESPONS_YESNO) { data = IDNO; } else { data = IDCANCEL; } } gtk_widget_destroy(dlg); reset_event(); return data; }
void message_beep(GtkWidget * parent) { gdk_beep(); reset_event(); }
int DialogExecute(GtkWidget *parent, void *dialog) { GtkWidget *dlg, *win_ptr, *btn; struct DialogType *data; gint res_id, lockstate; lockstate = DnDLock; DnDLock = TRUE; data = (struct DialogType *) dialog; if (data->widget && (data->parent != parent)) { #if 1 gtk_window_set_transient_for(GTK_WINDOW(data->widget), GTK_WINDOW(parent)); data->parent = parent; #else gtk_widget_destroy(data->widget); reset_event(); data->widget = NULL; #endif } if (data->widget == NULL) { dlg = gtk_dialog_new_with_buttons(_(data->resource), GTK_WINDOW(parent), #if GTK_CHECK_VERSION(3, 12, 0) && USE_HEADER_BAR GTK_DIALOG_USE_HEADER_BAR | #endif GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, _("_Cancel"), GTK_RESPONSE_CANCEL, NULL); gtk_window_set_resizable(GTK_WINDOW(dlg), TRUE); g_signal_connect(dlg, "delete-event", G_CALLBACK(dialog_delete_cb), data); g_signal_connect(dlg, "destroy", G_CALLBACK(dialog_destroyed_cb), data); g_signal_connect(dlg, "key-press-event", G_CALLBACK(dialog_key_down_cb), NULL); data->parent = parent; data->widget = dlg; data->vbox = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dlg))); data->show_cancel = TRUE; data->ok_button = _("_OK"); gtk_window_set_title(GTK_WINDOW(dlg), _(data->resource)); data->SetupWindow(dlg, data, TRUE); gtk_dialog_add_button(GTK_DIALOG(dlg), data->ok_button, GTK_RESPONSE_OK); if (! data->show_cancel) { btn = gtk_dialog_get_widget_for_response(GTK_DIALOG(dlg), GTK_RESPONSE_CANCEL); gtk_widget_hide(btn); } gtk_dialog_set_default_response(GTK_DIALOG(dlg), GTK_RESPONSE_OK); } else { dlg = data->widget; data->SetupWindow(dlg, data, FALSE); } gtk_widget_hide(dlg); gtk_dialog_set_default_response(GTK_DIALOG(dlg), GTK_RESPONSE_OK); data->widget = dlg; data->ret = IDLOOP; gtk_widget_show(dlg); win_ptr = get_current_window(); set_current_window(dlg); if (data->focus) gtk_widget_grab_focus(data->focus); while (data->ret == IDLOOP) { res_id = ndialog_run(dlg); if (res_id < 0) { switch (res_id) { case GTK_RESPONSE_OK: data->ret = IDOK; break; default: data->ret = IDCANCEL; break; } } else { data->ret = res_id; } if (data->CloseWindow) { data->CloseWindow(dlg, data); } } // gtk_widget_destroy(dlg); // data->widget = NULL; set_current_window(win_ptr); gtk_widget_hide(dlg); reset_event(); DnDLock = lockstate; return data->ret; }