static void questions_tree_view_row_activated (GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data) { GPInstructLessonTestMultiChoiceEditor *editor = GPINSTRUCT_LESSON_TEST_MULTI_CHOICE_EDITOR (user_data); GPInstructLessonTestMultiChoiceEditorPrivate *priv = editor->priv; GPInstructObject *object; GtkTreeIter iter; GtkWidget *scrolled_window, *text_view, *explanation_view, *answer_combobox; if (gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->questions_store), &iter, path)) { gtk_tree_model_get (GTK_TREE_MODEL (priv->questions_store), &iter, DATA_COLUMN, &object, -1); if (GPINSTRUCT_IS_LESSON_TEST_MULTI_CHOICE_QUESTION (object)) { GPInstructLessonTestMultiChoiceQuestion *question = GPINSTRUCT_LESSON_TEST_MULTI_CHOICE_QUESTION (object); guint choices_num = gpinstruct_lesson_test_multi_choice_question_get_choices_length (question); GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Question Properties"), GTK_WINDOW (priv->window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL); GtkWidget *content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); gtk_window_set_default_size (GTK_WINDOW (dialog), 400, 300); scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); text_view = gtk_text_view_new (); gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_WORD_CHAR); gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view)), gpinstruct_lesson_test_multi_choice_question_get_text (question), -1); gtk_container_add (GTK_CONTAINER (scrolled_window), text_view); gtk_box_pack_start (GTK_BOX (content_area), gtk_label_new (_("Text:")), FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (content_area), scrolled_window, TRUE, TRUE, 0); scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); explanation_view = gtk_text_view_new (); gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (explanation_view), GTK_WRAP_WORD_CHAR); gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (explanation_view)), gpinstruct_lesson_test_multi_choice_question_get_explanation (question), -1); gtk_container_add (GTK_CONTAINER (scrolled_window), explanation_view); gtk_box_pack_start (GTK_BOX (content_area), gtk_label_new (_("Explanation:")), FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (content_area), scrolled_window, TRUE, TRUE, 0); if (choices_num) { answer_combobox = gtk_combo_box_new_with_model (GTK_TREE_MODEL (priv->choices_store)); GtkCellRenderer *renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (answer_combobox), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (answer_combobox), renderer, "text", TITLE_COLUMN, NULL); gtk_combo_box_set_active (GTK_COMBO_BOX (answer_combobox), gpinstruct_lesson_test_multi_choice_question_get_answer (question)); gtk_box_pack_start (GTK_BOX (content_area), gtk_label_new (_("Answer:")), FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (content_area), answer_combobox, FALSE, TRUE, 0); } gtk_widget_show_all (content_area); if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { GtkTextIter start, end; gchar *text; gtk_text_buffer_get_bounds (gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view)), &start, &end); text = gtk_text_iter_get_text (&start, &end); gpinstruct_lesson_test_multi_choice_question_set_text (question, text); g_free (text); gtk_text_buffer_get_bounds (gtk_text_view_get_buffer (GTK_TEXT_VIEW (explanation_view)), &start, &end); text = gtk_text_iter_get_text (&start, &end); gpinstruct_lesson_test_multi_choice_question_set_explanation (question, text); g_free (text); if (choices_num) gpinstruct_lesson_test_multi_choice_question_set_answer (question, gtk_combo_box_get_active (GTK_COMBO_BOX (answer_combobox))); update_questions_tree_view (GPINSTRUCT_LESSON_TEST_MULTI_CHOICE_EDITOR (user_data)); gpinstruct_editor_window_set_modified (priv->window, TRUE); gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (priv->questions_store), &iter, NULL, gtk_tree_path_get_indices (path)[0]); gtk_tree_selection_select_iter (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)), &iter); } gtk_widget_destroy (dialog); } } }
orcaData orcaGtk::ex_get_data(orcaVM* vm, int n)/*{{{*/ { if (n < 1) vm->need_param(); orcaData key = vm->get_param(0); if (type == GUI_LIST || type == GUI_TREE) { if (is<TYPE_INT>(key)) { int nth = key.Integer(); GtkTreeIter iter; gtk_tree_model_get_iter_first(store, &iter); for (int i=0; i<nth; i++) { if (!gtk_tree_model_iter_next(store, &iter)) throw orcaException(vm, "orca.index", "out of index"); } orcaList* lp = new orcaList(); int width = gtk_tree_model_get_n_columns(store); for (int i=0; i<width; i++) { GValue value = { 0, }; gtk_tree_model_get_value(store, &iter, i, &value); GType t = value.g_type; if (t == G_TYPE_STRING) { char* cp = (char*)g_value_get_string(&value); if (cp == NULL) cp = (char*)""; lp->push_back(cp); } else if (t == G_TYPE_BOOLEAN) { bool r = g_value_get_boolean(&value); lp->push_back(r); } else { lp->push_back(NIL); } g_value_unset(&value); } return lp; } string str = key.String(); if (str == "begin") { orcaGtkIter* bp = new orcaGtkIter(); bp->m_gp = this; gtk_tree_model_get_iter_first(store, &bp->m_iter); if (type == GUI_LIST) bp->m_type = GUI_LIST; else bp->m_type = GUI_TREE; return bp; } else if (type == GUI_TREE && str == "branch") { orcaTuple* path = castobj<orcaTuple>(vm->get_param(1)); if (path == NULL) { return NIL; } orcaGtkIter* bp = new orcaGtkIter(); bp->m_gp = this; bp->m_type = GUI_TREE; GtkTreeIter iter; GtkTreeIter parent; for (int i=0; i<path->size(); i++) { if (i==0) { gtk_tree_model_get_iter_first(store, &iter); for (int j=0; j<path->at(0).Integer(); j++) { if (!gtk_tree_model_iter_next(store, &iter)) throw orcaException(vm, "orca.index", "out of index"); } parent = iter; bp->m_iter = iter; continue; } if (!gtk_tree_model_iter_nth_child(store, &iter, &parent, path->at(i).Integer())) throw orcaException(vm, "orca.index", "out of index"); parent = iter; bp->m_iter = iter; } return bp; } } else if (type == GUI_ENTRY) { if (key.String() == "text") { char* p = gtk_editable_get_chars(GTK_EDITABLE(handle), 0, -1); return p; } } else if (type == GUI_TEXT) { if (key.String() == "text") { GtkTextIter start_iter, end_iter; GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(handle)); gtk_text_buffer_get_start_iter(buffer, &start_iter); gtk_text_buffer_get_end_iter(buffer, &end_iter); char* p = gtk_text_buffer_get_text(buffer, &start_iter, &end_iter, FALSE); return p; } } return NIL; }
static gboolean find_location(GtkTreeModel* model, GtkTreeIter* iter, const gchar* location, gboolean go_parent) { GtkTreeIter iter_child; GtkTreeIter iter_parent; gchar* aux_loc; gboolean valid; int len; len = strlen (location); if (len <= 0) { return FALSE; } do { gtk_tree_model_get (model, iter, MATEWEATHER_XML_COL_LOC, &aux_loc, -1); if (g_ascii_strncasecmp (aux_loc, location, len) == 0) { g_free (aux_loc); return TRUE; } if (gtk_tree_model_iter_has_child(model, iter)) { gtk_tree_model_iter_nth_child(model, &iter_child, iter, 0); if (find_location (model, &iter_child, location, FALSE)) { /* Manual copying of the iter */ iter->stamp = iter_child.stamp; iter->user_data = iter_child.user_data; iter->user_data2 = iter_child.user_data2; iter->user_data3 = iter_child.user_data3; g_free (aux_loc); return TRUE; } } g_free (aux_loc); valid = gtk_tree_model_iter_next(model, iter); } while (valid); if (go_parent) { iter_parent = *iter; while (gtk_tree_model_iter_parent (model, iter, &iter_parent)) { if (gtk_tree_model_iter_next (model, iter)) { return find_location (model, iter, location, TRUE); } iter_parent = *iter; } } return FALSE; }
/** * gtr_message_table_navigate: * @table: * @navigation: * @func: (scope call): * * Returns: (transfer none): */ GtrMsg * gtr_message_table_navigate (GtrMessageTable * table, GtrMessageTableNavigation navigation, GtrMessageTableNavigationFunc func) { GtkTreeSelection *selection; GtkTreeModel *model; GtkTreePath *path; GtkTreeIter iter; GtrMessageTablePrivate *priv; GtrMsg *msg; gboolean cont = TRUE; priv = gtr_message_table_get_instance_private (table); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)); if (!gtk_tree_selection_get_selected (selection, &model, &iter)) return NULL; switch (navigation) { case GTR_NAVIGATE_FIRST: if (!gtk_tree_model_get_iter_first (model, &iter)) return NULL; break; case GTR_NAVIGATE_LAST: { gint n_children; n_children = gtk_tree_model_iter_n_children (model, NULL); if (n_children <= 0) return NULL; if (!gtk_tree_model_iter_nth_child (model, &iter, NULL, n_children - 1)) return NULL; } break; case GTR_NAVIGATE_NEXT: if (func) { while (cont) { if (!gtk_tree_model_iter_next (model, &iter)) return NULL; gtk_tree_model_get (model, &iter, GTR_MESSAGE_TABLE_MODEL_POINTER_COLUMN, &msg, -1); if (func (msg)) cont = FALSE; } } else if (!gtk_tree_model_iter_next (model, &iter)) return NULL; break; case GTR_NAVIGATE_PREV: if (func) { while (cont) { if (!gtk_tree_model_iter_previous (model, &iter)) return NULL; gtk_tree_model_get (model, &iter, GTR_MESSAGE_TABLE_MODEL_POINTER_COLUMN, &msg, -1); if (func (msg)) cont = FALSE; } } else if (!gtk_tree_model_iter_previous (model, &iter)) return NULL; break; } gtk_tree_selection_select_iter (selection, &iter); path = gtk_tree_model_get_path (model, &iter); gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->treeview), path, NULL, TRUE, 0.5, 0.0); gtk_tree_model_get (model, &iter, GTR_MESSAGE_TABLE_MODEL_POINTER_COLUMN, &msg, -1); return msg; }
static void GTKRolloutProgress(float aarOutput[][NUM_ROLLOUT_OUTPUTS], float aarStdDev[][NUM_ROLLOUT_OUTPUTS], const rolloutcontext * prc, const cubeinfo aci[], unsigned int initial_game_count, const int iGame, const int iAlternative, const int nRank, const float rJsd, const int fStopped, const int fShowRanks, int fCubeRollout, rolloutprogress * prp) { static unsigned int n_games_todo = 0; static unsigned int n_games_done = 0; static int min_games_done = 0; char sz[32]; int i; gchar *gsz; double frac; GtkTreeIter iter; if (!prp || !prp->pwRolloutResult) return; gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(prp->pwRolloutResultList), &iter, NULL, iAlternative); gtk_list_store_set(prp->pwRolloutResultList, &iter, TRIALS_C, iGame + 1, -1); for (i = 0; i < NUM_ROLLOUT_OUTPUTS; i++) { /* result */ if (i < OUTPUT_EQUITY) strcpy(sz, OutputPercent(aarOutput[iAlternative][i])); else if (i == OUTPUT_EQUITY) strcpy(sz, OutputEquityScale(aarOutput[iAlternative][i], &aci[iAlternative], &aci[0], TRUE)); else strcpy(sz, prc->fCubeful ? OutputMWC(aarOutput[iAlternative][i], &aci[0], TRUE) : "n/a"); gtk_list_store_set(prp->pwRolloutResultList, &iter, i + 3, sz, -1); } if (prc->fCubeful) strcpy(sz, OutputMWC(aarStdDev[iAlternative][OUTPUT_CUBEFUL_EQUITY], &aci[0], FALSE)); else strcpy(sz, OutputEquityScale(aarStdDev[iAlternative][OUTPUT_EQUITY], &aci[iAlternative], &aci[0], FALSE)); gtk_list_store_set(prp->pwRolloutResultList, &iter, i + 3, sz, -1); if (fShowRanks && iGame > 1) { gtk_list_store_set(prp->pwRolloutResultList, &iter, RANK_C, nRank, -1); if (nRank != 1 || fCubeRollout) sprintf(sz, "%5.3f", rJsd); else strcpy(sz, " "); gtk_list_store_set(prp->pwRolloutResultList, &iter, i + 4, sz, -1); } /* Update progress bar with highest number trials for all the alternatives */ if (iAlternative == 0) { n_games_todo = 0; n_games_done = 0; min_games_done = prc->nTrials; } n_games_done += iGame + 1; if (!fStopped) { n_games_todo += prc->nTrials - (iGame + 1); if (iGame < min_games_done) min_games_done = iGame + 1; } if (iAlternative == (prp->n - 1)) { frac = ((float)min_games_done)/prc->nTrials; gsz = g_strdup_printf("%d/%d (%d%%)", min_games_done, prc->nTrials, (int)(100.0f * frac)); gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(prp->pwRolloutProgress), frac); gtk_progress_bar_set_text(GTK_PROGRESS_BAR(prp->pwRolloutProgress), gsz); g_free(gsz); prp->nGamesDone = min_games_done; } /* calculate estimate time left */ if ((iAlternative == (prp->n - 1)) && n_games_done > initial_game_count) { time_t t = time_left(n_games_todo, n_games_done, initial_game_count, prp->tStart); gtk_label_set_text(GTK_LABEL(prp->pwElapsed), formatDelta(time(NULL) - prp->tStart)); gtk_label_set_text(GTK_LABEL(prp->pwLeft), formatDelta(t)); } /* calculate estimated SE */ if (!iAlternative && iGame > 10) { float r; if (prc->fCubeful) { r = estimatedSE(aarStdDev[0][OUTPUT_CUBEFUL_EQUITY], iGame, prc->nTrials); gtk_label_set_text(GTK_LABEL(prp->pwSE), OutputMWC(r, &aci[0], FALSE)); } else { r = estimatedSE(aarStdDev[0][OUTPUT_EQUITY], iGame, prc->nTrials); gtk_label_set_text(GTK_LABEL(prp->pwSE), OutputEquityScale(r, &aci[0], &aci[0], FALSE)); } } return; }
static void dialog_sheet_order_update_sheet_order (SheetManager *state) { GtkTreeIter iter; Workbook *wb = wb_control_get_workbook (GNM_WBC (state->wbcg)); int i, n_sheets, n_children; GtkTreeModel *model = GTK_TREE_MODEL (state->model); GtkTreeSelection *sel = gtk_tree_view_get_selection (state->sheet_list); n_sheets = workbook_sheet_count (wb); n_children = gtk_tree_model_iter_n_children (model, NULL); if (n_sheets != n_children) { /* This signal also occurs when sheets are added or deleted. We handle this */ /* when those signals arrive. */ return; } for (i = 0; i < n_sheets; i++) { gchar *name, *new_name; gboolean is_locked; gboolean is_visible; gboolean is_rtl; GdkRGBA *back, *fore; Sheet *sheet_wb = workbook_sheet_by_index (wb, i); Sheet *sheet_model; gboolean selected; int j, row_max, col_max; for (j = i; j < n_children; j++) { if (!gtk_tree_model_iter_nth_child (model, &iter, NULL, j)) break; gtk_tree_model_get (model, &iter, SHEET_POINTER, &sheet_model, -1); if (sheet_model == sheet_wb) break; } if (j == i) continue; if (!gtk_tree_model_iter_nth_child (model, &iter, NULL, j)) break; selected = gtk_tree_selection_iter_is_selected (sel, &iter); gtk_tree_model_get (model, &iter, SHEET_LOCKED, &is_locked, SHEET_VISIBLE, &is_visible, SHEET_ROW_MAX, &row_max, SHEET_COL_MAX, &col_max, SHEET_NAME, &name, SHEET_NEW_NAME, &new_name, SHEET_POINTER, &sheet_model, BACKGROUND_COLOUR, &back, FOREGROUND_COLOUR, &fore, SHEET_DIRECTION, &is_rtl, -1); gtk_list_store_remove (state->model, &iter); g_signal_handler_block (state->model, state->model_row_insertion_listener); gtk_list_store_insert (state->model, &iter, i); g_signal_handler_unblock (state->model, state->model_row_insertion_listener); gtk_list_store_set (state->model, &iter, SHEET_LOCKED, is_locked, SHEET_LOCK_IMAGE, is_locked ? state->image_padlock : state->image_padlock_no, SHEET_VISIBLE, is_visible, SHEET_VISIBLE_IMAGE, is_visible ? state->image_visible : NULL, SHEET_ROW_MAX, row_max, SHEET_COL_MAX, col_max, SHEET_NAME, name, SHEET_NEW_NAME, new_name, SHEET_POINTER, sheet_model, BACKGROUND_COLOUR, back, FOREGROUND_COLOUR, fore, SHEET_DIRECTION, is_rtl, SHEET_DIRECTION_IMAGE, is_rtl ? state->image_rtl : state->image_ltr, -1); if (back) gdk_rgba_free (back); if (fore) gdk_rgba_free (fore); g_free (name); g_free (new_name); if (selected) gtk_tree_selection_select_iter (sel, &iter); } cb_selection_changed (NULL, state); }
static void roster_view_gtk_update_groups (RosterViewGtk *view, GtkTreeIter *heap_iter) { GtkTreeModel *model = NULL; GtkTreePath *path = NULL; GtkTreeIter iter; GSList *existing_group = NULL; int timeout = 0; gboolean go_on = FALSE; gchar *name = NULL; model = GTK_TREE_MODEL (view->priv->store); if (gtk_tree_model_iter_nth_child (model, &iter, heap_iter, 0)) { do { // If this node has children, see if it must be // folded or unfolded if (gtk_tree_model_iter_has_child (model, &iter)) { update_offline_count (view, &iter); gtk_tree_model_get (model, &iter, COLUMN_GROUP_NAME, &name, -1); if (name) { if (view->priv->folded_groups) existing_group = g_slist_find_custom (view->priv->folded_groups, name, (GCompareFunc) g_ascii_strcasecmp); path = gtk_tree_model_get_path (model, heap_iter); gtk_tree_view_expand_row (view->priv->tree_view, path, FALSE); gtk_tree_path_free (path); path = gtk_tree_model_get_path (model, &iter); if (path) { if (existing_group == NULL) { if (!gtk_tree_view_row_expanded (view->priv->tree_view, path)) { gtk_tree_view_expand_row (view->priv->tree_view, path, TRUE); } } else { if (gtk_tree_view_row_expanded (view->priv->tree_view, path)) { gtk_tree_view_collapse_row (view->priv->tree_view, path); } } gtk_tree_path_free (path); } go_on = gtk_tree_model_iter_next (model, &iter); } g_free (name); } // else remove the node (no children) else { gtk_tree_model_get (GTK_TREE_MODEL (view->priv->store), &iter, COLUMN_TIMEOUT, &timeout, -1); go_on = gtk_tree_store_remove (view->priv->store, &iter); } } while (go_on); } }
void cdda_add_to_playlist(GtkTreeIter * iter_drive, unsigned long hash) { int i = 0; GtkTreeIter iter; int target_found = 0; GtkTreeIter target_iter; playlist_t * pl = NULL; playlist_data_t * pldata = NULL; if ((pl = playlist_get_current()) == NULL) { printf("NULL\n"); return; } while (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(pl->store), &iter, NULL, i++)) { if (gtk_tree_model_iter_n_children(GTK_TREE_MODEL(pl->store), &iter) > 0) { int j = 0; int has_cdda = 0; GtkTreeIter child; while (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(pl->store), &child, &iter, j++)) { gtk_tree_model_get(GTK_TREE_MODEL(pl->store), &child, PL_COL_DATA, &pldata, -1); if (!target_found && g_str_has_prefix(pldata->file, "CDDA ")) { has_cdda = 1; } if (cdda_hash_matches(pldata->file, hash)) { return; } } if (!target_found && !has_cdda) { target_iter = iter; target_found = 1; } } else { gtk_tree_model_get(GTK_TREE_MODEL(pl->store), &iter, PL_COL_DATA, &pldata, -1); if (!target_found && !g_str_has_prefix(pldata->file, "CDDA ")) { target_iter = iter; target_found = 1; } if (cdda_hash_matches(pldata->file, hash)) { return; } } } if (target_found) { cdda_record_addlist_iter(*iter_drive, pl, &target_iter, options.playlist_is_tree); } else { cdda_record_addlist_iter(*iter_drive, pl, NULL, options.playlist_is_tree); } playlist_content_changed(pl); }
static void cb_merge_merge_clicked (G_GNUC_UNUSED GtkWidget *ignore, MergeState *state) { GtkTreeIter this_iter; gint n = 0; char *data_string = NULL, *field_string = NULL; GSList *data_list = NULL, *field_list = NULL; GnmValue *v_zone; gint field_problems = 0; gint min_length = gnm_sheet_get_max_rows (state->sheet); gint max_length = 0; v_zone = gnm_expr_entry_parse_as_value (state->zone, state->sheet); g_return_if_fail (v_zone != NULL); while (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (state->model), &this_iter, NULL, n)) { GnmValue *v_data, *v_field; gtk_tree_model_get (GTK_TREE_MODEL (state->model), &this_iter, DATA_RANGE, &data_string, FIELD_LOCATION, &field_string, -1); v_data = value_new_cellrange_str (state->sheet, data_string); v_field = value_new_cellrange_str (state->sheet, field_string); g_free (data_string); g_free (field_string); g_return_if_fail (v_data != NULL && v_field != NULL); if (!global_range_contained (state->sheet, v_field, v_zone)) field_problems++; data_list = g_slist_prepend (data_list, v_data); field_list = g_slist_prepend (field_list, v_field); n++; } if (field_problems > 0) { char *text; if (field_problems == 1) text = g_strdup (_("One field is not part of the merge zone!")); else text = g_strdup_printf (_("%i fields are not part of the merge zone!"), field_problems); go_gtk_notice_nonmodal_dialog ((GtkWindow *) state->dialog, &(state->warning_dialog), GTK_MESSAGE_ERROR, "%s", text); g_free (text); value_release (v_zone); range_list_destroy (data_list); range_list_destroy (field_list); return; } g_slist_foreach (data_list, cb_merge_find_shortest_column, &min_length); g_slist_foreach (data_list, cb_merge_find_longest_column, &max_length); if (min_length < max_length) { char *text = g_strdup_printf (_("The data columns range in length from " "%i to %i. Shall we trim the lengths to " "%i and proceed?"), min_length, max_length, min_length); if (go_gtk_query_yes_no (GTK_WINDOW (state->dialog), TRUE, "%s", text)) { g_slist_foreach (data_list, cb_merge_trim_data, &min_length); g_free (text); } else { g_free (text); value_release (v_zone); range_list_destroy (data_list); range_list_destroy (field_list); return; } } if (!cmd_merge_data (WORKBOOK_CONTROL (state->wbcg), state->sheet, v_zone, field_list, data_list)) gtk_widget_destroy (state->dialog); }
static gboolean tracker_filter_model_update (gpointer gstore) { int i, n; int all = 0; int store_pos; GtkTreeIter iter; GObject * o = G_OBJECT (gstore); GtkTreeStore * store = GTK_TREE_STORE (gstore); GtkTreeModel * model = GTK_TREE_MODEL (gstore); GPtrArray * hosts = g_ptr_array_new (); GStringChunk * strings = g_string_chunk_new (4096); GHashTable * hosts_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free); GtkTreeModel * tmodel = GTK_TREE_MODEL (g_object_get_qdata (o, TORRENT_MODEL_KEY)); const int first_tracker_pos = 2; /* offset past the "All" and the separator */ g_object_steal_qdata (o, DIRTY_KEY); /* Walk through all the torrents, tallying how many matches there are * for the various categories. Also make a sorted list of all tracker * hosts s.t. we can merge it with the existing list */ if (gtk_tree_model_iter_nth_child (tmodel, &iter, NULL, 0)) do { tr_torrent * tor; const tr_info * inf; int keyCount; char ** keys; gtk_tree_model_get (tmodel, &iter, MC_TORRENT, &tor, -1); inf = tr_torrentInfo (tor); keyCount = 0; keys = g_new (char*, inf->trackerCount); for (i=0, n=inf->trackerCount; i<n; ++i) { int k; int * count; char buf[1024]; char * key; gtr_get_host_from_url (buf, sizeof (buf), inf->trackers[i].announce); key = g_string_chunk_insert_const (strings, buf); count = g_hash_table_lookup (hosts_hash, key); if (count == NULL) { count = tr_new0 (int, 1); g_hash_table_insert (hosts_hash, key, count); g_ptr_array_add (hosts, key); } for (k=0; k<keyCount; ++k) if (!g_strcmp0 (keys[k], key)) break; if (k==keyCount) keys[keyCount++] = key; } for (i=0; i<keyCount; ++i) { int * incrementme = g_hash_table_lookup (hosts_hash, keys[i]); ++*incrementme; } g_free (keys); ++all; }
static void debug_tree_add_children (GtkTreeModel *model, DmaDebuggerQueue *debugger, GtkTreeIter* parent, guint from, const GList *children) { GList *child; GtkTreeIter iter; gboolean valid; valid = gtk_tree_model_iter_nth_child (model, &iter, parent, from); /* Add new children */ for (child = g_list_first ((GList *)children); child != NULL; child = g_list_next (child)) { IAnjutaDebuggerVariableObject *var = (IAnjutaDebuggerVariableObject *)child->data; DmaVariableData *data; if (!valid) { /* Add new tree node */ gtk_tree_store_append(GTK_TREE_STORE(model), &iter, parent); gtk_tree_store_set(GTK_TREE_STORE(model), &iter, TYPE_COLUMN, var->type == NULL ? UNKNOWN_TYPE : var->type, VALUE_COLUMN, var->value == NULL ? UNKNOWN_VALUE : var->value, VARIABLE_COLUMN, var->expression, ROOT_COLUMN, FALSE, DTREE_ENTRY_COLUMN, NULL,-1); data = NULL; } else { /* Update tree node */ if (var->type != NULL) gtk_tree_store_set(GTK_TREE_STORE(model), &iter, TYPE_COLUMN, var->type, -1); if (var->value != NULL) gtk_tree_store_set(GTK_TREE_STORE(model), &iter, VALUE_COLUMN, var->value, -1); if (var->expression != NULL) gtk_tree_store_set(GTK_TREE_STORE(model), &iter, VARIABLE_COLUMN, var->expression, -1); gtk_tree_model_get(model, &iter, DTREE_ENTRY_COLUMN, &data, -1); if (var->name == NULL) { /* Dummy node representing additional children */ if (data != NULL) { dma_variable_data_free (data); gtk_tree_store_set(GTK_TREE_STORE (model), &iter, DTREE_ENTRY_COLUMN, NULL, -1); data = NULL; } } } if ((var->name != NULL) && (data == NULL)) { /* Create new data */ data = dma_variable_data_new(var->name, TRUE); gtk_tree_store_set(GTK_TREE_STORE(model), &iter, DTREE_ENTRY_COLUMN, data, -1); } /* Clear all children if they exist */ debug_tree_remove_children (model, debugger, &iter, NULL); if ((var->children != 0) || var->has_more || (var->name == NULL)) { /* Add dummy children */ debug_tree_model_add_dummy_children (model, &iter); } valid = gtk_tree_model_iter_next (model, &iter); } /* Clear remaining old children */ if (valid) debug_tree_remove_children (model, debugger, parent, &iter); }
static void gsslrtma_populate_tree_store(GncSxSlrTreeModelAdapter *model) { GtkTreeIter sx_tree_iter; GList *sx_iter; int instances_index = -1; for (sx_iter = model->instances->sx_instance_list; sx_iter != NULL; sx_iter = sx_iter->next) { GncSxInstances *instances = (GncSxInstances*)sx_iter->data; char last_occur_date_buf[MAX_DATE_LENGTH+1]; { const GDate *last_occur = xaccSchedXactionGetLastOccurDate(instances->sx); if (last_occur == NULL || !g_date_valid(last_occur)) { g_stpcpy(last_occur_date_buf, _("Never")); } else { qof_print_gdate(last_occur_date_buf, MAX_DATE_LENGTH, last_occur); } } if (!gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(model->real), &sx_tree_iter, NULL, ++instances_index)) { gtk_tree_store_append(model->real, &sx_tree_iter, NULL); } gtk_tree_store_set(model->real, &sx_tree_iter, SLR_MODEL_COL_NAME, xaccSchedXactionGetName(instances->sx), SLR_MODEL_COL_INSTANCE_STATE, NULL, SLR_MODEL_COL_VARAIBLE_VALUE, NULL, SLR_MODEL_COL_INSTANCE_VISIBILITY, FALSE, SLR_MODEL_COL_VARIABLE_VISIBILITY, FALSE, SLR_MODEL_COL_INSTANCE_STATE_SENSITIVITY, FALSE, -1); // Insert instance information { GList *inst_iter; GtkTreeIter inst_tree_iter; char instance_date_buf[MAX_DATE_LENGTH+1]; int instance_index = -1; for (inst_iter = instances->instance_list; inst_iter != NULL; inst_iter = inst_iter->next) { GncSxInstance *inst = (GncSxInstance*)inst_iter->data; qof_print_gdate(instance_date_buf, MAX_DATE_LENGTH, &inst->date); if (!gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(model->real), &inst_tree_iter, &sx_tree_iter, ++instance_index)) { gtk_tree_store_append(model->real, &inst_tree_iter, &sx_tree_iter); } gtk_tree_store_set(model->real, &inst_tree_iter, SLR_MODEL_COL_NAME, instance_date_buf, SLR_MODEL_COL_INSTANCE_STATE, _(gnc_sx_instance_state_names[inst->state]), SLR_MODEL_COL_VARAIBLE_VALUE, NULL, SLR_MODEL_COL_INSTANCE_VISIBILITY, TRUE, SLR_MODEL_COL_VARIABLE_VISIBILITY, FALSE, SLR_MODEL_COL_INSTANCE_STATE_SENSITIVITY, inst->state != SX_INSTANCE_STATE_CREATED, -1); // Insert variable information { GList *vars = NULL, *var_iter; GtkTreeIter var_tree_iter; gint visible_variable_index = -1; vars = gnc_sx_instance_get_variables(inst); for (var_iter = vars; var_iter != NULL; var_iter = var_iter->next) { GncSxVariable *var = (GncSxVariable*)var_iter->data; GString *tmp_str; if (!var->editable) continue; if (gnc_numeric_check(var->value) == GNC_ERROR_OK) { _var_numeric_to_string(&var->value, &tmp_str); } else { tmp_str = g_string_new(_("(Need Value)")); } if (!gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(model->real), &var_tree_iter, &inst_tree_iter, ++visible_variable_index)) { gtk_tree_store_append(model->real, &var_tree_iter, &inst_tree_iter); } gtk_tree_store_set(model->real, &var_tree_iter, SLR_MODEL_COL_NAME, var->name, SLR_MODEL_COL_INSTANCE_STATE, NULL, SLR_MODEL_COL_VARAIBLE_VALUE, tmp_str->str, SLR_MODEL_COL_INSTANCE_VISIBILITY, FALSE, SLR_MODEL_COL_VARIABLE_VISIBILITY, TRUE, SLR_MODEL_COL_INSTANCE_STATE_SENSITIVITY, FALSE - 1); g_string_free(tmp_str, TRUE); } g_list_free(vars); _consume_excess_rows(model->real, visible_variable_index, &inst_tree_iter, &var_tree_iter); } } // if there are more instance iters, remove _consume_excess_rows(model->real, instance_index, &sx_tree_iter, &inst_tree_iter); } } _consume_excess_rows(model->real, instances_index, NULL, &sx_tree_iter); }
/** \brief User pressed OK. Any changes should be stored in config. * * First, all .rot files are deleted, whereafter the rotator configurations in * the rotlist are saved one by one. */ void sat_pref_rot_ok () { GDir *dir = NULL; /* directory handle */ GError *error = NULL; /* error flag and info */ gchar *buff,*dirname; const gchar *filename; GtkTreeIter iter; /* new item added to the list store */ GtkTreeModel *model; guint i,n; rotor_conf_t conf = { .name = NULL, .host = NULL, .port = 4533, .minaz = 0, .maxaz = 360, .minel = 0, .maxel = 90, .aztype = ROT_AZ_TYPE_360, }; /* delete all .rot files */ dirname = get_hwconf_dir (); dir = g_dir_open (dirname, 0, &error); if (dir) { /* read each .rot file */ while ((filename = g_dir_read_name (dir))) { if (g_str_has_suffix (filename, ".rot")) { buff = g_strconcat (dirname, G_DIR_SEPARATOR_S, filename, NULL); g_remove (buff); g_free (buff); } } } g_free (dirname); g_dir_close (dir); /* create new .rot files for the radios in the rotlist */ model = gtk_tree_view_get_model (GTK_TREE_VIEW (rotlist)); n = gtk_tree_model_iter_n_children (model, NULL); for (i = 0; i < n; i++) { /* get radio conf */ if (gtk_tree_model_iter_nth_child (model, &iter, NULL, i)) { /* store conf */ gtk_tree_model_get (model, &iter, ROT_LIST_COL_NAME, &conf.name, ROT_LIST_COL_HOST, &conf.host, ROT_LIST_COL_PORT, &conf.port, ROT_LIST_COL_MINAZ, &conf.minaz, ROT_LIST_COL_MAXAZ, &conf.maxaz, ROT_LIST_COL_MINEL, &conf.minel, ROT_LIST_COL_MAXEL, &conf.maxel, ROT_LIST_COL_AZTYPE, &conf.aztype, -1); rotor_conf_save (&conf); /* free conf buffer */ if (conf.name) g_free (conf.name); if (conf.host) g_free (conf.host); } else { sat_log_log (SAT_LOG_LEVEL_ERROR, _("%s: Failed to get ROT %s"), __func__, i); } } } /** \brief Add a new rotor configuration * \param button Pointer to the Add button. * \param data User data (null). * * This function executes the rotor configuration editor. */ static void add_cb (GtkWidget *button, gpointer data) { GtkTreeIter item; /* new item added to the list store */ GtkListStore *liststore; (void) button; /* avoid unused parameter compiler warning */ (void) data; /* avoid unused parameter compiler warning */ rotor_conf_t conf = { .name = NULL, .host = NULL, .port = 4533, .minaz = 0, .maxaz = 360, .minel = 0, .maxel = 90, .aztype = ROT_AZ_TYPE_360, }; /* run rot conf editor */ sat_pref_rot_editor_run (&conf); /* add new rot to the list */ if (conf.name != NULL) { liststore = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (rotlist))); gtk_list_store_append (liststore, &item); gtk_list_store_set (liststore, &item, ROT_LIST_COL_NAME, conf.name, ROT_LIST_COL_HOST, conf.host, ROT_LIST_COL_PORT, conf.port, ROT_LIST_COL_MINAZ, conf.minaz, ROT_LIST_COL_MAXAZ, conf.maxaz, ROT_LIST_COL_MINEL, conf.minel, ROT_LIST_COL_MAXEL, conf.maxel, ROT_LIST_COL_AZTYPE, conf.aztype, -1); g_free (conf.name); if (conf.host != NULL) g_free (conf.host); } } /** \brief Add a new rotor configuration * \param button Pointer to the Add button. * \param data User data (null). * * This function executes the rotor configuration editor. * */ static void edit_cb (GtkWidget *button, gpointer data) { GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW(rotlist)); GtkTreeModel *selmod; GtkTreeSelection *selection; GtkTreeIter iter; (void) button; /* avoid unused parameter compiler warning */ (void) data; /* avoid unused parameter compiler warning */ rotor_conf_t conf = { .name = NULL, .host = NULL, .port = 4533, .minaz = 0, .maxaz = 360, .minel = 0, .maxel = 90, .aztype = ROT_AZ_TYPE_360, }; /* If there are no entries, we have a bug since the button should have been disabled. */ if (gtk_tree_model_iter_n_children (model, NULL) < 1) { sat_log_log (SAT_LOG_LEVEL_ERROR, _("%s:%s: Edit button should have been disabled."), __FILE__, __func__); //gtk_widget_set_sensitive (button, FALSE); return; } /* get selected row FIXME: do we really need to work with two models? */ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (rotlist)); if (gtk_tree_selection_get_selected(selection, &selmod, &iter)) { gtk_tree_model_get (model, &iter, ROT_LIST_COL_NAME, &conf.name, ROT_LIST_COL_HOST, &conf.host, ROT_LIST_COL_PORT, &conf.port, ROT_LIST_COL_MINAZ, &conf.minaz, ROT_LIST_COL_MAXAZ, &conf.maxaz, ROT_LIST_COL_MINEL, &conf.minel, ROT_LIST_COL_MAXEL, &conf.maxel, ROT_LIST_COL_AZTYPE, &conf.aztype, -1); } else { GtkWidget *dialog; dialog = gtk_message_dialog_new (GTK_WINDOW (window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Select the rotator you want to edit\n"\ "and try again!")); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); return; } /* run radio configuration editor */ sat_pref_rot_editor_run (&conf); /* apply changes */ if (conf.name != NULL) { gtk_list_store_set (GTK_LIST_STORE(model), &iter, ROT_LIST_COL_NAME, conf.name, ROT_LIST_COL_HOST, conf.host, ROT_LIST_COL_PORT, conf.port, ROT_LIST_COL_MINAZ, conf.minaz, ROT_LIST_COL_MAXAZ, conf.maxaz, ROT_LIST_COL_MINEL, conf.minel, ROT_LIST_COL_MAXEL, conf.maxel, ROT_LIST_COL_AZTYPE, conf.aztype, -1); } /* clean up memory */ if (conf.name) g_free (conf.name); if (conf.host != NULL) g_free (conf.host); } /** \brief Delete selected rotator configuration * * This function is called when the user clicks the Delete button. * */ static void delete_cb (GtkWidget *button, gpointer data) { GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW(rotlist)); GtkTreeSelection *selection; GtkTreeIter iter; (void) button; /* avoid unused parameter compiler warning */ (void) data; /* avoid unused parameter compiler warning */ /* If there are no entries, we have a bug since the button should have been disabled. */ if (gtk_tree_model_iter_n_children (model, NULL) < 1) { sat_log_log (SAT_LOG_LEVEL_ERROR, _("%s:%s: Delete button should have been disabled."), __FILE__, __func__); //gtk_widget_set_sensitive (button, FALSE); return; } /* get selected row */ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (rotlist)); if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { gtk_list_store_remove (GTK_LIST_STORE(model), &iter); } else { GtkWidget *dialog; dialog = gtk_message_dialog_new (GTK_WINDOW (window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Select the rotator you want to delete\n"\ "and try again!")); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); } }
/* * this function should use a smart sorting algorithm to find * the GtkTreeIter of the bookmark *before* the place where this * bookmark should be added, but the same function can be used to * find the bookmarks we have to check to detect double bookmarks * at the same line. * * returns the bookmark closest before 'offset', or the bookmark exactly at 'offset' * * returns NULL if we have to append this as first child to the parent * */ static Tbmark *bmark_find_bookmark_before_offset(Tbfwin *bfwin, guint offset, GtkTreeIter *parent) { gint jumpsize, num_children, child; GtkTreeIter iter; num_children = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(bfwin->bookmarkstore), parent); if (num_children == 0) { return NULL; } if (num_children == 1) { gint compare; Tbmark *b; gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(bfwin->bookmarkstore), &iter, parent, 0); gtk_tree_model_get(GTK_TREE_MODEL(bfwin->bookmarkstore),&iter,PTR_COLUMN,&b, -1); bmark_update_offset_from_textmark(b); DEBUG_MSG("bmark_find_bookmark_before_offset, num_children=%d\n",num_children); compare = (offset - b->offset); if (compare <= 0) { return NULL; } else { return b; } } jumpsize = (num_children+2)/2; child = num_children + 1 - jumpsize; DEBUG_MSG("bmark_find_bookmark_before_offset, num_children=%d,jumpsize=%d,child=%d\n",num_children,jumpsize,child); while (jumpsize > 0) { gint compare; Tbmark *b; if (child > num_children) child = num_children; if (child < 1) child = 1; /* we request child-1, NOT child*/ gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(bfwin->bookmarkstore), &iter, parent, child-1); gtk_tree_model_get(GTK_TREE_MODEL(bfwin->bookmarkstore),&iter,PTR_COLUMN,&b, -1); bmark_update_offset_from_textmark(b); compare = (offset - b->offset); DEBUG_MSG("in_loop: jumpsize=%2d, child=%2d, child offset=%3d, compare=%3d\n",jumpsize,child,b->offset,compare); if (compare == 0) { return b; } else if (compare < 0) { jumpsize = (jumpsize > 3) ? (jumpsize+1)/2 : jumpsize-1; if (jumpsize <= 0) { child--; /* we request child-1, NOT child*/ if (child >= 1 && gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(bfwin->bookmarkstore), &iter, parent, child-1)) { gtk_tree_model_get(GTK_TREE_MODEL(bfwin->bookmarkstore),&iter,PTR_COLUMN,&b, -1); bmark_update_offset_from_textmark(b); DEBUG_MSG("in_loop: returning bookmark (offset %d) for previous child %d\n",b->offset, child); return b; } else{ DEBUG_MSG("in_loop: no previous child, return NULL\n"); return NULL; } } child = child - jumpsize; } else { /* compare > 0 */ jumpsize = (jumpsize > 3) ? (jumpsize+1)/2 : jumpsize-1; if (jumpsize <= 0) { DEBUG_MSG("in_loop: return bookmark (offset %d) from child %d\n",b->offset, child); return b; } child = child + jumpsize; } } DEBUG_MSG("bmark_find_bookmark_before_offset, end-of-function, return NULL\n"); return NULL; }
void uim_cand_win_horizontal_gtk_set_index(UIMCandWinHorizontalGtk *horizontal_cwin, gint index) { gint new_page, prev_index; UIMCandWinGtk *cwin; g_return_if_fail(UIM_IS_CAND_WIN_HORIZONTAL_GTK(horizontal_cwin)); cwin = UIM_CAND_WIN_GTK(horizontal_cwin); prev_index = cwin->candidate_index; if (index >= (gint) cwin->nr_candidates) cwin->candidate_index = 0; else cwin->candidate_index = index; if (cwin->candidate_index >= 0 && cwin->display_limit) new_page = cwin->candidate_index / cwin->display_limit; else new_page = cwin->page_index; if (cwin->page_index != new_page) uim_cand_win_gtk_set_page(cwin, new_page); if (cwin->candidate_index >= 0) { gint pos; struct index_button *idxbutton, *prev_selected; GtkWidget *label; if (cwin->display_limit) pos = cwin->candidate_index % cwin->display_limit; else pos = cwin->candidate_index; idxbutton = g_ptr_array_index(horizontal_cwin->buttons, pos); prev_selected = (gpointer)horizontal_cwin->selected; if (prev_selected && prev_index != cwin->candidate_index) { label = gtk_bin_get_child(GTK_BIN(prev_selected->button)); gtk_widget_queue_draw(label); } label = gtk_bin_get_child(GTK_BIN(idxbutton->button)); gtk_widget_queue_draw(label); horizontal_cwin->selected = idxbutton; /* show subwin */ if (cwin->stores->pdata[new_page]) { char *annotation = NULL; GtkTreeModel *model = GTK_TREE_MODEL(cwin->stores->pdata[new_page]); GtkTreeIter iter; gtk_tree_model_iter_nth_child(model, &iter, NULL, pos); gtk_tree_model_get(model, &iter, COLUMN_ANNOTATION, &annotation, -1); if (annotation && *annotation) { if (!cwin->sub_window.window) uim_cand_win_gtk_create_sub_window(cwin); gtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(cwin->sub_window.text_view)), annotation, -1); uim_cand_win_gtk_layout_sub_window(cwin); gtk_widget_show(cwin->sub_window.window); cwin->sub_window.active = TRUE; } else { if (cwin->sub_window.window) { gtk_widget_hide(cwin->sub_window.window); cwin->sub_window.active = FALSE; } } free(annotation); } } else { horizontal_cwin->selected = NULL; if (cwin->sub_window.window) { gtk_widget_hide(cwin->sub_window.window); cwin->sub_window.active = FALSE; } } uim_cand_win_gtk_update_label(cwin); }
int zapisz_reset_O( ROOM_INDEX_DATA *room ) { OBJ_INDEX_DATA *obj; int j, n, v; RESET_DATA *r, *temp; GtkTreeModel *model; GtkTreeIter iter, child; char buf[ MIL ], bufnum[ MIL ]; if ( ( v = SPIN_GET_VALUE( dres.spin_prz ) ) < 0 || !( obj = get_obj_index( v ) ) ) return 1; /* zmien reset O */ dres.reset->arg1 = SPIN_GET_VALUE( dres.spin_prz ); dres.reset->arg2 = SPIN_GET_VALUE( dres.spin_int ); dres.reset->arg3 = SPIN_GET_VALUE( dres.spin_pom ); /* zwolnij wszystkie komentarze i resety P podczepione do resetu O */ for ( r = dres.reset->next; r; ) if ( r->command == 'P' || r->command == '*' ) { temp = r; r = r->next; del_reset( temp ); } else break; temp = r; /* tutaj temp pamieta pierwszy reset spoza O */ r = dres.reset; model = GTK_TREE_MODEL( dres.store_inw ); /* teraz zapis przedmiotow w pojemniku jako resety P */ if ( obj->item_type == ITEM_CONTAINER ) { gtk_tree_model_iter_nth_child( model, &iter, NULL, 0 ); j = gtk_tree_model_iter_n_children( model, &iter ); for ( n = 0; n < j; n++ ) if ( gtk_tree_model_iter_nth_child( model, &child, &iter, n ) ) { OBJ_INDEX_DATA *o; gtk_tree_model_get( model, &child, KOL_WSKAZNIK, &o, -1 ); r->next = new_reset( ); r = r->next; r->command = 'P'; r->arg1 = o->vnum; } } r->next = temp; /* odzwierciedlenie powyzszych zmian na liscie resetow */ strcpy( bufnum, &dres.reset->command ); sprintf( buf, "%s -> %s", obj->short_descr, room->name ); gtk_tree_store_set( dkra.store_res, &dres.iter, KOL_VNUM, bufnum, KOL_OPIS, _( buf ), -1 ); model = GTK_TREE_MODEL( dkra.store_res ); j = gtk_tree_model_iter_n_children( model, &dres.iter ); for ( n = 0; n < j; n++ ) if ( gtk_tree_model_iter_nth_child( model, &child, &dres.iter, 0 ) ) gtk_tree_store_remove( dkra.store_res, &child ); for ( r = dres.reset->next; r && r->command == 'P'; r = r->next ) { OBJ_INDEX_DATA *o = get_obj_index( r->arg1 ); sprintf( bufnum, "%c", r->command ); strcpy( buf, o->short_descr ); gtk_tree_store_append( dkra.store_res, &iter, &dres.iter ); gtk_tree_store_set( dkra.store_res, &iter, KOL_WSKAZNIK, r, KOL_VNUM, bufnum, KOL_OPIS, _( buf ), -1 ); } return 0; }
void autocomp_run(BluefishTextView * btv, gboolean user_requested) { GtkTextIter cursorpos, iter; BluefishTextView *master = BLUEFISH_TEXT_VIEW(btv->master); gint contextnum; gunichar uc; Tfound *found=NULL; Tfoundblock *fblock = NULL; /* needed for the special case to close generix xml tags based on the top of the blockstack, or to match conditional autocompletion strings */ if (G_UNLIKELY(!master->bflang || !master->bflang->st)) return; gtk_text_buffer_get_iter_at_mark(btv->buffer, &cursorpos, gtk_text_buffer_get_insert(btv->buffer)); iter = cursorpos; gtk_text_iter_set_line_offset(&iter, 0); scan_for_autocomp_prefix(master, &iter, &cursorpos, &contextnum); DBG_AUTOCOMP("autocomp_run, got possible match start at %d in context %d, cursor is at %d\n", gtk_text_iter_get_offset(&iter), contextnum, gtk_text_iter_get_offset(&cursorpos)); /* see if character at cursor is end or symbol */ uc = gtk_text_iter_get_char(&cursorpos); if (G_UNLIKELY(uc > NUMSCANCHARS)) return; /*identstate = g_array_index(master->bflang->st->contexts, Tcontext, contextnum).identstate;*/ if (!character_is_symbol(master->bflang->st,contextnum,uc)) { /* current character is not a symbol! */ DBG_AUTOCOMP("autocomp_run, character at cursor %d '%c' is not a symbol, return\n", uc, (char) uc); acwin_cleanup(btv); return; } /* see if we have enough characters */ if (!user_requested && gtk_text_iter_get_offset(&cursorpos) - gtk_text_iter_get_offset(&iter) < main_v->props.autocomp_min_prefix_len) { DBG_AUTOCOMP("autocomp_run, prefix len %d < autocomp_min_prefix_len (%d), abort!\n" , gtk_text_iter_get_offset(&cursorpos) - gtk_text_iter_get_offset(&iter) , main_v->props.autocomp_min_prefix_len); acwin_cleanup(btv); return; } if (g_array_index(master->bflang->st->contexts, Tcontext, contextnum).has_tagclose_from_blockstack) { found = get_foundcache_at_offset(btv, gtk_text_iter_get_offset(&cursorpos), NULL); if (found) { fblock = found->numblockchange < 0 ? pop_blocks(found->numblockchange, found->fblock) : found->fblock; if (fblock && fblock->start2_o != BF_OFFSET_UNDEFINED) { DBG_AUTOCOMP("abort offering closing tag: block has an end already\n"); fblock = NULL; } /* if (g_array_index(btv->bflang->st->matches, Tpattern, fblock->patternum).tagclose_from_blockstack) { gchar *start; gtk_text_buffer_get_iter_at_mark(buffer, &it1, fblock->start1); gtk_text_buffer_get_iter_at_mark(buffer, &it2, fblock->end1); gtk_text_iter_forward_char(&it1); start = gtk_text_buffer_get_text(buffer,&it1,&it2,TRUE); g_print("close tag %s\n",start); g_free(start); }*/ } } if ((user_requested || !gtk_text_iter_equal(&iter, &cursorpos)) && (g_array_index(master->bflang->st->contexts, Tcontext, contextnum).ac != NULL || (fblock && g_array_index(master->bflang->st->matches, Tpattern, fblock->patternum).tagclose_from_blockstack) ) ) { /* we have a prefix or it is user requested, and we have a context with autocompletion or we have blockstack-tag-auto-closing */ gchar *newprefix = NULL, *prefix, *closetag = NULL; GList *items = NULL, *items2 = NULL; gboolean free_items=FALSE; /*print_ac_items(g_array_index(btv->bflang->st->contexts,Tcontext, contextnum).ac); */ prefix = gtk_text_buffer_get_text(btv->buffer, &iter, &cursorpos, TRUE); if (fblock) { GString *tmpstr; gint plen; GtkTextIter it1; gtk_text_buffer_get_iter_at_offset(btv->buffer, &it1, fblock->start1_o); tmpstr = g_string_new("</"); while(gtk_text_iter_forward_char(&it1)) { gunichar uc = gtk_text_iter_get_char(&it1); if (!g_unichar_isalnum(uc) && uc != '_') { break; } g_string_append_c(tmpstr, uc); } g_string_append_c(tmpstr, '>'); closetag = g_string_free(tmpstr, FALSE); DBG_AUTOCOMP("closetag=%s, prefix=%s\n", closetag, prefix); plen = strlen(prefix); if (plen == strlen(closetag) || strncmp(closetag, prefix, plen) != 0) { g_free(closetag); closetag = NULL; } } if (g_array_index(master->bflang->st->contexts, Tcontext, contextnum).ac) { items = g_completion_complete(g_array_index(master->bflang->st->contexts, Tcontext, contextnum).ac, prefix, &newprefix); DBG_AUTOCOMP("got %d autocompletion items for prefix %s in context %d, newprefix=%s\n", g_list_length(items), prefix, contextnum, newprefix); if (G_UNLIKELY(g_array_index(master->bflang->st->contexts, Tcontext, contextnum).autocomplete_has_conditions)) { if (found==NULL) { found = get_foundcache_at_offset(btv, gtk_text_iter_get_offset(&cursorpos), NULL); } items = process_conditional_items(btv, found, contextnum, items); free_items=TRUE; } { GCompletion *compl = identifier_ac_get_completion(master, contextnum, FALSE); DBG_IDENTIFIER("got completion %p for context %d\n", compl, contextnum); if (compl) { gchar *newprefix2 = NULL; items2 = g_completion_complete(compl, prefix, &newprefix2); DBG_IDENTIFIER("got %d identifier_items for prefix %s, newprefix=%s\n", g_list_length(items2), prefix, newprefix2); if (!newprefix) newprefix = newprefix2; else g_free(newprefix2); } } } if (closetag || items2 || (items != NULL && (items->next != NULL || strcmp(items->data, prefix) != 0))) { /* do not popup if there are 0 items, and also not if there is 1 item which equals the prefix */ GtkTreeSelection *selection; GtkTreeIter it; gboolean below; gint numitems=0; /* create the GUI */ if (!btv->autocomp) { btv->autocomp = acwin_create(btv); } else { ACWIN(btv->autocomp)->in_fill=TRUE; g_free(ACWIN(btv->autocomp)->prefix); g_free(ACWIN(btv->autocomp)->newprefix); ACWIN(btv->autocomp)->prefix = NULL; ACWIN(btv->autocomp)->newprefix = NULL; gtk_list_store_clear(ACWIN(btv->autocomp)->store); } ACWIN(btv->autocomp)->contextnum = contextnum; ACWIN(btv->autocomp)->prefix = g_strdup(prefix); if (newprefix) { ACWIN(btv->autocomp)->newprefix = g_strdup(newprefix); } acwin_calculate_window_size(ACWIN(btv->autocomp), items, items2, closetag, &numitems); below = acwin_position_at_cursor(btv); acwin_fill_tree(ACWIN(btv->autocomp), items, items2, closetag, !below, numitems); gtk_widget_show(ACWIN(btv->autocomp)->win); selection = gtk_tree_view_get_selection(ACWIN(btv->autocomp)->tree); if (below) { DBG_AUTOCOMP("autocomp_run, popup-below, get first iter for selection\n"); gtk_tree_model_get_iter_first(GTK_TREE_MODEL(ACWIN(btv->autocomp)->store), &it); } else { GtkTreePath *path; DBG_AUTOCOMP("autocomp_run, popup-above, select last iter and scroll max down\n"); gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(ACWIN(btv->autocomp)->store), &it, NULL, gtk_tree_model_iter_n_children(GTK_TREE_MODEL (ACWIN(btv->autocomp)->store), NULL) - 1); path = gtk_tree_model_get_path(GTK_TREE_MODEL(ACWIN(btv->autocomp)->store), &it); gtk_tree_view_scroll_to_cell(ACWIN(btv->autocomp)->tree, path, NULL, FALSE, 1.0, 1.0); gtk_tree_path_free(path); } /* this forces that selection changed will be called two lines below*/ gtk_tree_selection_unselect_all(selection); ACWIN(btv->autocomp)->in_fill=FALSE; DBG_AUTOCOMP("call select_iter on autocomp window\n"); gtk_tree_selection_select_iter(selection, &it); g_free(closetag); } else { acwin_cleanup(btv); } if (free_items) { g_list_free(items); } g_free(newprefix); g_free(prefix); } else { DBG_AUTOCOMP("no autocompletion data for context %d (ac=%p), or no prefix\n", contextnum, g_array_index(master->bflang->st->contexts, Tcontext, contextnum).ac); acwin_cleanup(btv); } }
int zapisz_reset_M( ROOM_INDEX_DATA *room ) { MOB_INDEX_DATA *mob; OBJ_INDEX_DATA *obj; int i, j, n, v; RESET_DATA *r, *temp; GtkTreeModel *model; GtkTreeIter iter, child; char buf[ MIL ], bufnum[ MIL ]; /* sprawdz poprawnosc danych */ if ( ( v = SPIN_GET_VALUE( dres.spin_mob ) ) < 0 || !( mob = get_mob_index( v ) ) ) return 1; for ( i = 0; i < MAX_WEAR; i++ ) { if ( ( v = SPIN_GET_VALUE( dres.spin_ekw[ i ] ) ) < 0 ) continue; if ( !( obj = get_obj_index( v ) ) ) return 2; if( dres.wear_na_item[ i ] != obj->wear_flags || ( i == WEAR_LIGHT && obj->item_type != ITEM_LIGHT ) ) /* przydalby sie dialog z komunikatem, dlaczego odmawia zapisu */ return 3; } /* zmien reset M */ dres.reset->arg1 = SPIN_GET_VALUE( dres.spin_mob ); dres.reset->arg2 = SPIN_GET_VALUE( dres.spin_int ); dres.reset->arg3 = SPIN_GET_VALUE( dres.spin_pom ); /* zwolnij wszystkie resety podczepione do resetu M */ for ( r = dres.reset->next; r; ) { if ( r->command != 'P' && r->command != 'G' && r->command != 'E' && r->command != '*' ) break; temp = r; r = r->next; del_reset( temp ); } temp = r; /* tutaj temp pamieta pierwszy reset spoza M */ r = dres.reset; model = GTK_TREE_MODEL( dres.store_inw ); /* z kazdego wybranego przedmiotu zrob reset E */ for ( i = 0; i < MAX_WEAR; i++ ) { if ( ( v = SPIN_GET_VALUE( dres.spin_ekw[ i ] ) ) == -1 ) continue; r->next = new_reset( ); r = r->next; r->command = 'E'; r->arg1 = v; r->arg3 = i; iter = dres.iter_ekw[ i ]; /* jesli przedmiot ma zawartosc, zrob z niej resety P */ if ( iter.stamp != 0 ) { j = gtk_tree_model_iter_n_children( model, &iter ); for ( n = 0; n < j; n++ ) if ( gtk_tree_model_iter_nth_child( model, &child, &iter, n ) ) { gtk_tree_model_get( model, &child, KOL_WSKAZNIK, &obj, -1 ); r->next = new_reset( ); r = r->next; r->command = 'P'; r->arg1 = obj->vnum; } } } /* teraz zapis przedmiotow "przy sobie" jako resety G */ gtk_tree_model_get_iter_first( model, &iter ); j = gtk_tree_model_iter_n_children( model, &iter ); for ( n = 0; n < j; n++ ) if ( gtk_tree_model_iter_nth_child( model, &child, &iter, n ) ) { gtk_tree_model_get( model, &child, KOL_WSKAZNIK, &obj, -1 ); r->next = new_reset( ); r = r->next; r->command = 'G'; r->arg1 = obj->vnum; /* resety G moga byc pojemnikami, wiec jeszcze raz resety P: */ { int k, l; GtkTreeIter grandchild; l = gtk_tree_model_iter_n_children( model, &child ); for ( k = 0; k < l; k++ ) if ( gtk_tree_model_iter_nth_child( model, &grandchild, &child, k ) ) { gtk_tree_model_get( model, &grandchild, KOL_WSKAZNIK, &obj, -1 ); r->next = new_reset( ); r = r->next; r->command = 'P'; r->arg1 = obj->vnum; } } } r->next = temp; /* odzwierciedlenie powyzszych zmian na liscie resetow */ strcpy( bufnum, &dres.reset->command ); sprintf( buf, "%s -> %s", mob->short_descr, room->name ); gtk_tree_store_set( dkra.store_res, &dres.iter, KOL_VNUM, bufnum, KOL_OPIS, _( buf ), -1 ); model = GTK_TREE_MODEL( dkra.store_res ); j = gtk_tree_model_iter_n_children( model, &dres.iter ); for ( n = 0; n < j; n++ ) if ( gtk_tree_model_iter_nth_child( model, &child, &dres.iter, 0 ) ) gtk_tree_store_remove( dkra.store_res, &child ); for ( r = dres.reset->next; r; r = r->next ) { switch ( r->command ) { case 'G': case 'E': gtk_tree_store_append( dkra.store_res, &iter, &dres.iter ); child = iter; break; case 'P': gtk_tree_store_append( dkra.store_res, &iter, &child ); break; case '*': continue; default: return 0; } sprintf( bufnum, "%c", r->command ); strcpy( buf, get_obj_index( r->arg1 )->short_descr ); gtk_tree_store_set( dkra.store_res, &iter, KOL_WSKAZNIK, r, KOL_VNUM, bufnum, KOL_OPIS, _( buf ), -1 ); } return 0; }
/* * Refreshes the buttons on a row (un)selection and selects the chosen sheet * for this view. */ static void cb_selection_changed (G_GNUC_UNUSED GtkTreeSelection *ignored, SheetManager *state) { GtkTreeIter iter; Sheet *sheet; gboolean has_iter; GdkRGBA *fore, *back; GtkTreeSelection *selection = gtk_tree_view_get_selection (state->sheet_list); GList *selected_rows = gtk_tree_selection_get_selected_rows (selection, NULL); gboolean multiple = gtk_tree_model_iter_n_children(GTK_TREE_MODEL (state->model), NULL) > 1; int cnt_sel = g_list_length (selected_rows); gboolean single_sel = (cnt_sel < 2); gtk_widget_set_sensitive (state->sort_asc_btn, multiple); gtk_widget_set_sensitive (state->sort_desc_btn, multiple); if (selected_rows == NULL) { gtk_widget_set_sensitive (state->up_btn, FALSE); gtk_widget_set_sensitive (state->down_btn, FALSE); gtk_widget_set_sensitive (state->delete_btn, FALSE); gtk_widget_set_sensitive (state->ccombo_back, FALSE); gtk_widget_set_sensitive (state->ccombo_fore, FALSE); gtk_widget_set_sensitive (state->add_btn, FALSE); gtk_widget_set_sensitive (state->duplicate_btn, FALSE); return; } gtk_tree_model_get_iter (GTK_TREE_MODEL (state->model), &iter, (GtkTreePath *) selected_rows->data); gtk_tree_model_get (GTK_TREE_MODEL (state->model), &iter, SHEET_POINTER, &sheet, BACKGROUND_COLOUR, &back, FOREGROUND_COLOUR, &fore, -1); if (!state->initial_colors_set) { go_combo_color_set_color_gdk (GO_COMBO_COLOR (state->ccombo_back), back); go_combo_color_set_color_gdk (GO_COMBO_COLOR (state->ccombo_fore), fore); state->initial_colors_set = TRUE; } if (back != NULL) gdk_rgba_free (back); if (fore != NULL) gdk_rgba_free (fore); gtk_widget_set_sensitive (state->ccombo_back, TRUE); gtk_widget_set_sensitive (state->ccombo_fore, TRUE); gtk_widget_set_sensitive (state->delete_btn, sheet_order_cnt_visible (state) > cnt_sel); gtk_widget_set_sensitive (state->add_btn, single_sel); gtk_widget_set_sensitive (state->duplicate_btn, single_sel); has_iter = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (state->model), &iter); g_return_if_fail (has_iter); gtk_widget_set_sensitive (state->up_btn, single_sel && !gtk_tree_selection_iter_is_selected (selection, &iter)); gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (state->model), &iter, NULL, gtk_tree_model_iter_n_children (GTK_TREE_MODEL (state->model), NULL) - 1); gtk_widget_set_sensitive (state->down_btn, single_sel && !gtk_tree_selection_iter_is_selected (selection, &iter)); if (sheet != NULL) wb_view_sheet_focus ( wb_control_view (GNM_WBC (state->wbcg)), sheet); g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_path_free); }
static void _lib_tag_gui_update (gpointer instance,gpointer self) { dt_lib_module_t *dm = (dt_lib_module_t *)self; dt_lib_keywords_t *d = (dt_lib_keywords_t*)dm->data; GtkTreeStore *store = gtk_tree_store_new(1, G_TYPE_STRING); /* initialize the tree store with known tags */ sqlite3_stmt *stmt; GtkTreeIter uncategorized, temp; memset(&uncategorized,0,sizeof(GtkTreeIter)); DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT name,icon,description FROM tags ORDER BY UPPER(name) DESC", -1, &stmt, NULL); gtk_tree_store_clear(store); while (sqlite3_step(stmt) == SQLITE_ROW) { if(strchr((const char *)sqlite3_column_text(stmt, 0),'|')==0) { /* add uncategorized root iter if not exists */ if (!uncategorized.stamp) { gtk_tree_store_insert(store, &uncategorized, NULL,0); gtk_tree_store_set(store, &uncategorized, 0, _(UNCATEGORIZED_TAG), -1); } /* adding a uncategorized tag */ gtk_tree_store_insert(store, &temp, &uncategorized,0); gtk_tree_store_set(store, &temp, 0, sqlite3_column_text(stmt, 0), -1); } else { int level = 0; char *value; GtkTreeIter current,iter; char **pch = g_strsplit((char *)sqlite3_column_text(stmt, 0),"|", -1); if (pch != NULL) { int j = 0; while (pch[j] != NULL) { gboolean found=FALSE; int children = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store),level>0?¤t:NULL); /* find child with name, if not found create and continue */ for (int k=0; k<children; k++) { if (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &iter, level>0?¤t:NULL, k)) { gtk_tree_model_get (GTK_TREE_MODEL(store), &iter, 0, &value, -1); if (strcmp(value, pch[j])==0) { current = iter; found = TRUE; break; } } } /* lets add new keyword and assign current */ if (!found) { gtk_tree_store_insert(store, &iter, level>0?¤t:NULL,0); gtk_tree_store_set(store, &iter, 0, pch[j], -1); current = iter; } level++; j++; } g_strfreev(pch); } } } gtk_tree_view_set_model(d->view, GTK_TREE_MODEL(store)); /* free store, treeview has its own storage now */ g_object_unref(store); }
static void search_tree(gpointer data) { struct search_info *info = data; GtkTreePath *path; GtkTreeViewColumn *col; GtkTreeModel *model; TraceViewStore *store; GtkTreeIter iter; GtkEntry *entry = GTK_ENTRY(info->entry); GtkComboBox *col_combo = GTK_COMBO_BOX(info->column); GtkComboBox *sel_combo = GTK_COMBO_BOX(info->selection); const gchar *title; const gchar *search_text; gint col_num; gint sel; gint search_val; gint start_row; gboolean found = FALSE; gint i = 0; col_num = gtk_combo_box_get_active(col_combo); sel = gtk_combo_box_get_active(sel_combo); if (col_num >= TRACE_VIEW_STORE_N_COLUMNS) return; search_text = gtk_entry_get_text(entry); if (!search_text || !strlen(search_text)) return; col = gtk_tree_view_get_column(info->treeview, col_num); if (!col) return; title = gtk_tree_view_column_get_title(col); if (!title) return; model = gtk_tree_view_get_model(info->treeview); if (!model) return; store = TRACE_VIEW_STORE(model); if (!trace_view_store_visible_rows(store)) return; start_row = trace_view_get_selected_row(GTK_WIDGET(info->treeview)); if (start_row < 0) start_row = 0; if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, start_row)) return; trace_set_cursor(GDK_WATCH); trace_freeze_all(); search_val = atoi(search_text); while (gtk_tree_model_iter_next(model, &iter)) { /* Needed to process the cursor change */ if (!(i++ & ((1 << 5)-1))) gtk_main_iteration_do(FALSE); found = test_row(model, &iter, sel, col_num, search_val, search_text); if (found) break; } trace_unfreeze_all(); trace_put_cursor(); if (!found) { GtkResponseType ret; gint pages = trace_view_store_get_pages(store); gint page = trace_view_store_get_page(store); if (page < pages) { ret = trace_dialog(NULL, TRACE_GUI_ASK, "Not found on this page\n" "Search next pages?"); if (ret == GTK_RESPONSE_YES) search_next_pages(info->treeview, store, sel, col_num, search_val, search_text); return; } trace_dialog(NULL, TRACE_GUI_INFO, "Not found"); return; } path = gtk_tree_model_get_path(model, &iter); select_row_from_path(info->treeview, path); gtk_tree_path_free(path); }
/*--------------------------------------------------------------------------* * PUBLIC FUNCTIONS * *--------------------------------------------------------------------------*/ void ap_gtk_add_message (APUpdateType update_type, APMessageType type, const gchar *text) { GtkTreeIter iter; struct tm *cur_time; char *time_string, *simple_text, *s; time_t *general_time; gchar *type_string; // Create the time string general_time = (time_t *) malloc (sizeof(time_t)); time (general_time); cur_time = ap_localtime (general_time); free (general_time); time_string = (char *) malloc (sizeof(char[32])); *time_string = '\0'; strftime (time_string, 31, "<b>%I:%M %p</b>", cur_time); free (cur_time); // Create the type string type_string = strdup("<b>Status</b>"); switch (type) { case AP_MESSAGE_TYPE_PROFILE: type_string = strdup (_("<b>User profile</b>")); break; case AP_MESSAGE_TYPE_AWAY: type_string = strdup (_("<b>Away message</b>")); break; case AP_MESSAGE_TYPE_AVAILABLE: type_string = strdup (_("<b>Available message</b>")); break; case AP_MESSAGE_TYPE_STATUS: type_string = strdup (_("<b>Status message</b>")); break; default: type_string = strdup (_("<b>Other</b>")); break; } // Simplify the text if (text != NULL) { simple_text = strdup (text); // Only show the first line s = (gchar *) purple_strcasestr (simple_text, "<br>"); if (s != NULL) { *s++ = '.'; *s++ = '.'; *s++ = '.'; *s = '\0'; } // Strip HTML s = simple_text; simple_text = purple_markup_strip_html (simple_text); free (s); } else { simple_text = NULL; } // Add it gtk_list_store_prepend (message_list, &iter); gtk_list_store_set (message_list, &iter, 0, time_string, 1, type_string, 2, simple_text, 3, text, -1); free (type_string); free (time_string); if (simple_text) free (simple_text); // Delete if too many if (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL(message_list), &iter, NULL, AP_GTK_MAX_MESSAGES)) { gtk_list_store_remove (message_list, &iter); } // Move the timeout bar ap_gtk_timeout_start (update_type); // Check if it needs to be visible or not if (type != AP_MESSAGE_TYPE_PROFILE && ap_is_currently_away () != ap_previously_away) { update_summary_visibility (); } }
void cheese_thumb_view_remove_item (CheeseThumbView *thumb_view, GFile *file) { CheeseThumbViewPrivate *priv = cheese_thumb_view_get_instance_private (thumb_view); gchar *filename; GtkTreeIter iter; gboolean found = FALSE; filename = g_file_get_path (file); if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->store), &iter)) { gchar *col_filename; gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter, THUMBNAIL_URL_COLUMN, &col_filename, -1); /* FIXME: col_filename is in GLib filename encoding, not ASCII. */ if (g_ascii_strcasecmp (col_filename, filename)) { while (gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->store), &iter)) { g_free (col_filename); gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter, THUMBNAIL_URL_COLUMN, &col_filename, -1); /* FIXME: col_filename is in GLib filename encoding, not ASCII. */ if (!g_ascii_strcasecmp (col_filename, filename)) { found = TRUE; break; } } } else { found = TRUE; } g_free (col_filename); g_free (filename); } else { /* A single item was in the thumbview but it's been already removed. */ g_free (filename); return; } if (!found) return; gboolean valid = gtk_list_store_remove (priv->store, &iter); if (!valid) { int len = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (priv->store), NULL); if (len <= 0) return; valid = gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (priv->store), &iter, NULL, len - 1); } GtkTreePath *tree_path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->store), &iter); gtk_icon_view_select_path (GTK_ICON_VIEW (thumb_view), tree_path); gtk_tree_path_free (tree_path); }
/* Returns 0 on success, 1 on failure */ int update_track_data_from_cdtext(cdda_drive_t * drive, GtkTreeIter * iter_drive) { CdIo_t * cdio; cdtext_t * cdtext; GtkTreeIter iter; int i; int ret = 0; cdio = cdio_open(drive->device_path, DRIVER_UNKNOWN); cdtext = cdio_get_cdtext(cdio, 0); if (cdtext == NULL) { ret = 1; } else { char tmp[MAXLEN]; tmp[0] = '\0'; if (cdtext->field[CDTEXT_PERFORMER] != NULL && *(cdtext->field[CDTEXT_PERFORMER]) != '\0') { strncat(tmp, cdtext->field[CDTEXT_PERFORMER], MAXLEN-1); strncpy(drive->disc.artist_name, cdtext->field[CDTEXT_PERFORMER], MAXLEN-1); } else { ret = 1; } strncat(tmp, ": ", MAXLEN - strlen(tmp) - 1); if (cdtext->field[CDTEXT_TITLE] != NULL && *(cdtext->field[CDTEXT_TITLE]) != '\0') { strncat(tmp, cdtext->field[CDTEXT_TITLE], MAXLEN - strlen(tmp) - 1); strncpy(drive->disc.record_name, cdtext->field[CDTEXT_TITLE], MAXLEN-1); } else { ret = 1; } if (ret == 0) { gtk_tree_store_set(music_store, iter_drive, MS_COL_NAME, tmp, -1); } } i = 0; while (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(music_store), &iter, iter_drive, i++)) { cdtext = cdio_get_cdtext(cdio, i); if (cdtext == NULL) { ret = 1; continue; } if (cdtext->field[CDTEXT_TITLE] != NULL && *(cdtext->field[CDTEXT_TITLE]) != '\0') { gtk_tree_store_set(music_store, &iter, MS_COL_NAME, cdtext->field[CDTEXT_TITLE], -1); } else { ret = 1; } } cdio_destroy(cdio); return ret; }
static gboolean gimp_container_tree_view_drop_status (GimpContainerTreeView *tree_view, GdkDragContext *context, gint x, gint y, guint time, GtkTreePath **return_path, GdkAtom *return_atom, GimpDndType *return_src_type, GimpViewable **return_src, GimpViewable **return_dest, GtkTreeViewDropPosition *return_pos) { GimpViewable *src_viewable = NULL; GimpViewable *dest_viewable = NULL; GtkTreePath *drop_path = NULL; GtkTargetList *target_list; GdkAtom target_atom; GimpDndType src_type; GtkTreeViewDropPosition drop_pos = GTK_TREE_VIEW_DROP_BEFORE; GdkDragAction drag_action = 0; if (! gimp_container_view_get_container (GIMP_CONTAINER_VIEW (tree_view)) || ! gimp_container_view_get_reorderable (GIMP_CONTAINER_VIEW (tree_view))) goto drop_impossible; target_list = gtk_drag_dest_get_target_list (GTK_WIDGET (tree_view->view)); target_atom = gtk_drag_dest_find_target (GTK_WIDGET (tree_view->view), context, target_list); if (! gtk_target_list_find (target_list, target_atom, &src_type)) goto drop_impossible; switch (src_type) { case GIMP_DND_TYPE_URI_LIST: case GIMP_DND_TYPE_TEXT_PLAIN: case GIMP_DND_TYPE_NETSCAPE_URL: case GIMP_DND_TYPE_COLOR: case GIMP_DND_TYPE_SVG: case GIMP_DND_TYPE_SVG_XML: case GIMP_DND_TYPE_COMPONENT: case GIMP_DND_TYPE_PIXBUF: break; default: { GtkWidget *src_widget = gtk_drag_get_source_widget (context); if (! src_widget) goto drop_impossible; src_viewable = gimp_dnd_get_drag_data (src_widget); if (! GIMP_IS_VIEWABLE (src_viewable)) goto drop_impossible; } break; } if (gtk_tree_view_get_path_at_pos (tree_view->view, x, y, &drop_path, NULL, NULL, NULL)) { GimpViewRenderer *renderer; GtkTreeIter iter; GdkRectangle cell_area; gtk_tree_model_get_iter (tree_view->model, &iter, drop_path); gtk_tree_model_get (tree_view->model, &iter, GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER, &renderer, -1); dest_viewable = renderer->viewable; g_object_unref (renderer); gtk_tree_view_get_cell_area (tree_view->view, drop_path, NULL, &cell_area); if (gimp_viewable_get_children (dest_viewable)) { if (gtk_tree_view_row_expanded (tree_view->view, drop_path)) { if (y >= (cell_area.y + cell_area.height / 2)) drop_pos = GTK_TREE_VIEW_DROP_INTO_OR_AFTER; else drop_pos = GTK_TREE_VIEW_DROP_BEFORE; } else { if (y >= (cell_area.y + 2 * (cell_area.height / 3))) drop_pos = GTK_TREE_VIEW_DROP_AFTER; else if (y <= (cell_area.y + cell_area.height / 3)) drop_pos = GTK_TREE_VIEW_DROP_BEFORE; else drop_pos = GTK_TREE_VIEW_DROP_INTO_OR_AFTER; } } else { if (y >= (cell_area.y + cell_area.height / 2)) drop_pos = GTK_TREE_VIEW_DROP_AFTER; else drop_pos = GTK_TREE_VIEW_DROP_BEFORE; } } else { GtkTreeIter iter; gint n_children; n_children = gtk_tree_model_iter_n_children (tree_view->model, NULL); if (n_children > 0 && gtk_tree_model_iter_nth_child (tree_view->model, &iter, NULL, n_children - 1)) { GimpViewRenderer *renderer; gtk_tree_model_get (tree_view->model, &iter, GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER, &renderer, -1); drop_path = gtk_tree_model_get_path (tree_view->model, &iter); dest_viewable = renderer->viewable; drop_pos = GTK_TREE_VIEW_DROP_AFTER; g_object_unref (renderer); } } if (dest_viewable || tree_view->priv->dnd_drop_to_empty) { if (GIMP_CONTAINER_TREE_VIEW_GET_CLASS (tree_view)->drop_possible (tree_view, src_type, src_viewable, dest_viewable, drop_path, drop_pos, &drop_pos, &drag_action)) { gdk_drag_status (context, drag_action, time); if (return_path) *return_path = drop_path; else gtk_tree_path_free (drop_path); if (return_atom) *return_atom = target_atom; if (return_src) *return_src = src_viewable; if (return_dest) *return_dest = dest_viewable; if (return_pos) *return_pos = drop_pos; return TRUE; } gtk_tree_path_free (drop_path); } drop_impossible: gdk_drag_status (context, 0, time); return FALSE; }
void write_tasks_entries (void) { gint i; xmlDocPtr doc; xmlNodePtr main_node, node, note_node; xmlAttrPtr attr; gchar temp[BUFFER_SIZE]; GtkTreeIter iter; gboolean *done; gchar *priority, *category, *summary, *desc; guint32 due_date_julian, start_date_julian; doc = xmlNewDoc((const xmlChar *) "1.0"); attr = xmlNewDocProp (doc, (const xmlChar *) "encoding", (const xmlChar *) "utf-8"); main_node = xmlNewNode(NULL, (const xmlChar *) TASKS_NAME); xmlDocSetRootElement(doc, main_node); node = xmlNewChild(main_node, NULL, (const xmlChar *) TASKS_CATEGORY_ENTRIES_NAME, (xmlChar *) NULL); i = 0; while (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(tasks_category_store), &iter, NULL, i++)) { gtk_tree_model_get(GTK_TREE_MODEL(tasks_category_store), &iter, 0, &category, -1); xmlNewChild(node, NULL, (const xmlChar *) "name", (xmlChar *) category); } node = xmlNewChild(main_node, NULL, (const xmlChar *) TASKS_ENTRIES_NAME, (xmlChar *) NULL); i = 0; while (gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(tasks_list_store), &iter, NULL, i++)) { gtk_tree_model_get(GTK_TREE_MODEL(tasks_list_store), &iter, COLUMN_DONE, &done, COLUMN_DUE_DATE_JULIAN, &due_date_julian, COLUMN_START_DATE_JULIAN, &start_date_julian, COLUMN_PRIORITY, &priority, COLUMN_CATEGORY, &category, COLUMN_SUMMARY, &summary, COLUMN_DESCRIPTION, &desc, -1); note_node = xmlNewChild(node, NULL, (const xmlChar *) "entry", (xmlChar *) NULL); sprintf(temp, "%d", (gint) done); xmlNewChild(note_node, NULL, (const xmlChar *) "status", (xmlChar *) temp); sprintf(temp, "%d", (guint32) due_date_julian); xmlNewChild(note_node, NULL, (const xmlChar *) "due_date", (xmlChar *) temp); sprintf(temp, "%d", (guint32) start_date_julian); xmlNewChild(note_node, NULL, (const xmlChar *) "start_date", (xmlChar *) temp); xmlNewChild(note_node, NULL, (const xmlChar *) "priority", (xmlChar *) priority); xmlNewChild(note_node, NULL, (const xmlChar *) "category", (xmlChar *) category); xmlNewChild(note_node, NULL, (const xmlChar *) "summary", (xmlChar *) summary); xmlNewChild(note_node, NULL, (const xmlChar *) "description", (xmlChar *) desc); } xmlSaveFormatFileEnc(prefs_get_config_filename(TASKS_ENTRIES_FILENAME), doc, "utf-8", 1); xmlFreeDoc(doc); }
void contacts_create_birthdays_window (GUI *appGUI) { GtkWidget *vbox1; GtkWidget *hseparator; GtkWidget *hbuttonbox; GtkWidget *close_button; GtkTreeViewColumn *column; GtkCellRenderer *renderer; GtkWidget *scrolledwindow; gint i, n, id, age; guint32 date; gchar *text, buffer[BUFFER_SIZE], buff[BUFFER_SIZE]; GtkTreeIter iter, n_iter; GDate *cdate_birthday, *cdate_current; guint b_day, b_month, b_year; guint c_day, c_month, c_year; gboolean flag, leap; cdate_birthday = g_date_new (); g_return_if_fail (cdate_birthday != NULL); cdate_current = g_date_new (); g_return_if_fail (cdate_current != NULL); i = n = 0; while (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (appGUI->cnt->contacts_list_store), &iter, NULL, i++)) { gtk_tree_model_get (GTK_TREE_MODEL (appGUI->cnt->contacts_list_store), &iter, COLUMN_BIRTH_DAY_DATE, &date, -1); if (date) n++; } if (n == 0) { gui_create_dialog (GTK_MESSAGE_INFO, _("No birthdays defined"), GTK_WINDOW (appGUI->main_window)); return; } appGUI->cnt->birthdays_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (appGUI->cnt->birthdays_window), _("Birthdays list")); gtk_window_set_position (GTK_WINDOW (appGUI->cnt->birthdays_window), GTK_WIN_POS_CENTER_ON_PARENT); gtk_window_set_default_size (GTK_WINDOW (appGUI->cnt->birthdays_window), config.contacts_birthdays_win_w, config.contacts_birthdays_win_h); gtk_window_set_modal (GTK_WINDOW (appGUI->cnt->birthdays_window), TRUE); g_signal_connect (G_OBJECT (appGUI->cnt->birthdays_window), "delete_event", G_CALLBACK (birthdays_window_close_cb), appGUI); gtk_window_set_transient_for (GTK_WINDOW (appGUI->cnt->birthdays_window), GTK_WINDOW (appGUI->main_window)); gtk_container_set_border_width (GTK_CONTAINER (appGUI->cnt->birthdays_window), 8); g_signal_connect (G_OBJECT (appGUI->cnt->birthdays_window), "key_press_event", G_CALLBACK (birthdays_key_press_cb), appGUI); vbox1 = gtk_vbox_new (FALSE, 0); gtk_widget_show (vbox1); gtk_container_add (GTK_CONTAINER (appGUI->cnt->birthdays_window), vbox1); scrolledwindow = gtk_scrolled_window_new (NULL, NULL); gtk_widget_show (scrolledwindow); gtk_box_pack_start (GTK_BOX (vbox1), scrolledwindow, TRUE, TRUE, 0); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_SHADOW_IN); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); appGUI->cnt->birthdays_list_store = gtk_list_store_new (BIRTHDAYS_NUM_COLUMNS, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT); appGUI->cnt->birthdays_list = gtk_tree_view_new_with_model (GTK_TREE_MODEL (appGUI->cnt->birthdays_list_store)); gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), config.contacts_rules_hint); gtk_widget_show (appGUI->cnt->birthdays_list); GTK_WIDGET_SET_FLAGS (appGUI->cnt->birthdays_list, GTK_CAN_DEFAULT); gtk_container_add (GTK_CONTAINER (scrolledwindow), appGUI->cnt->birthdays_list); appGUI->cnt->birthdays_list_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (appGUI->cnt->birthdays_list)); g_signal_connect (G_OBJECT (appGUI->cnt->birthdays_list), "button_press_event", G_CALLBACK (birthdays_list_dbclick_cb), appGUI); /* create columns */ renderer = gtk_cell_renderer_text_new (); g_object_set (G_OBJECT (renderer), "xpad", 8, NULL); column = gtk_tree_view_column_new_with_attributes (_("Name"), renderer, "text", B_COLUMN_NAME, NULL); gtk_tree_view_column_set_visible (column, TRUE); gtk_tree_view_column_set_expand (column, TRUE); gtk_tree_view_append_column (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), column); gtk_tree_view_column_set_sort_column_id (column, B_COLUMN_NAME); renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes (_("Days to birthday"), renderer, "text", B_COLUMN_DAYS_NUM, NULL); gtk_tree_view_column_set_visible (column, FALSE); gtk_tree_view_append_column (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), column); renderer = gtk_cell_renderer_text_new (); g_object_set (G_OBJECT (renderer), "xalign", 1.0, NULL); g_object_set (G_OBJECT (renderer), "xpad", 8, NULL); column = gtk_tree_view_column_new_with_attributes (_("Days to birthday"), renderer, "text", B_COLUMN_DAYS, NULL); gtk_tree_view_column_set_visible (column, TRUE); gtk_tree_view_append_column (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), column); gtk_tree_view_column_set_sort_column_id (column, B_COLUMN_DAYS_NUM); g_signal_emit_by_name (column, "clicked"); column = gtk_tree_view_column_new_with_attributes (_("Age"), renderer, "text", B_COLUMN_AGE, NULL); gtk_tree_view_column_set_visible (column, config.visible_age_column); gtk_tree_view_append_column (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), column); gtk_tree_view_column_set_sort_column_id (column, B_COLUMN_AGE); column = gtk_tree_view_column_new_with_attributes (_("Birthday date"), renderer, "text", B_COLUMN_DATE, NULL); gtk_tree_view_column_set_visible (column, config.visible_birthday_date_column); gtk_tree_view_append_column (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), column); renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes (_("Zodiac sign"), renderer, "text", B_COLUMN_ZODIAC, NULL); gtk_tree_view_column_set_visible (column, config.visible_zodiac_sign_column); gtk_tree_view_append_column (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), column); renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes ("ID", renderer, "text", B_COLUMN_ID, NULL); gtk_tree_view_column_set_visible (column, FALSE); gtk_tree_view_append_column (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), column); gtk_tree_view_set_enable_search (GTK_TREE_VIEW (appGUI->cnt->birthdays_list), FALSE); i = 0; g_date_set_julian (cdate_current, utl_get_current_julian ()); c_day = g_date_get_day (cdate_current); c_month = g_date_get_month (cdate_current); c_year = g_date_get_year (cdate_current); while (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (appGUI->cnt->contacts_list_store), &iter, NULL, i++)) { gtk_tree_model_get (GTK_TREE_MODEL (appGUI->cnt->contacts_list_store), &iter, COLUMN_BIRTH_DAY_DATE, &date, -1); if (g_date_valid_julian (date)) { /* calculate age */ g_date_set_julian (cdate_birthday, date); b_day = g_date_get_day (cdate_birthday); b_month = g_date_get_month (cdate_birthday); b_year = g_date_get_year (cdate_birthday); age = (gint) c_year - b_year; if (b_month < c_month || (b_month == c_month && b_day < c_day)) age++; if (age < 1) continue; /* name */ flag = FALSE; g_snprintf (buff, BUFFER_SIZE, "(%s)", _("None")); gtk_tree_model_get (GTK_TREE_MODEL (appGUI->cnt->contacts_list_store), &iter, COLUMN_LAST_NAME, &text, -1); if (text != NULL) { flag = TRUE; if (strcmp (text, buff) == 0) { text[0] = '\0'; flag = FALSE; } g_strlcpy (buffer, text, BUFFER_SIZE); g_free (text); } gtk_tree_model_get (GTK_TREE_MODEL (appGUI->cnt->contacts_list_store), &iter, COLUMN_FIRST_NAME, &text, -1); if (text != NULL) { if (strcmp (text, buff) == 0) { text[0] = '\0'; } if (flag == TRUE) { g_strlcat (buffer, " ", BUFFER_SIZE); g_strlcat (buffer, text, BUFFER_SIZE); } else { g_strlcpy (buffer, text, BUFFER_SIZE); } g_free (text); } gtk_tree_model_get (GTK_TREE_MODEL (appGUI->cnt->contacts_list_store), &iter, COLUMN_ID, &id, -1); gtk_list_store_append (appGUI->cnt->birthdays_list_store, &n_iter); gtk_list_store_set (appGUI->cnt->birthdays_list_store, &n_iter, B_COLUMN_ID, id, B_COLUMN_NAME, buffer, B_COLUMN_AGE, age, -1); /* calculate days to birthday */ b_year = c_year; if ((b_month < c_month) || (b_month == c_month && b_day < c_day)) b_year++; leap = FALSE; if (g_date_valid_dmy (b_day, b_month, b_year) == FALSE) { g_date_set_day (cdate_birthday, b_day - 1); leap = TRUE; } g_date_set_year (cdate_birthday, b_year); date = g_date_days_between (cdate_current, cdate_birthday); if (date == 0) { g_snprintf (buffer, BUFFER_SIZE, "%s", _("today")); } else { g_snprintf (buffer, BUFFER_SIZE, leap ? "%d + 1" : "%d", date); } g_date_strftime (buff, BUFFER_SIZE, "%A, ", cdate_birthday); g_strlcat (buff, julian_to_str (g_date_get_julian (cdate_birthday), config.date_format), BUFFER_SIZE); gtk_list_store_set (appGUI->cnt->birthdays_list_store, &n_iter, B_COLUMN_DAYS_NUM, date, B_COLUMN_DAYS, buffer, B_COLUMN_DATE, buff, B_COLUMN_ZODIAC, utl_get_zodiac_name (b_day, b_month), -1); } } g_date_free (cdate_birthday); g_date_free (cdate_current); hseparator = gtk_hseparator_new (); gtk_widget_show (hseparator); gtk_box_pack_start (GTK_BOX (vbox1), hseparator, FALSE, TRUE, 4); hbuttonbox = gtk_hbutton_box_new (); gtk_widget_show (hbuttonbox); gtk_box_pack_start (GTK_BOX (vbox1), hbuttonbox, FALSE, TRUE, 0); gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox), GTK_BUTTONBOX_END); gtk_box_set_spacing (GTK_BOX (hbuttonbox), 4); if (config.default_stock_icons) { close_button = gtk_button_new_from_stock (GTK_STOCK_CLOSE); } else { close_button = gtk_button_new_from_stock (OSMO_STOCK_BUTTON_CLOSE); } gtk_widget_show (close_button); g_signal_connect (close_button, "clicked", G_CALLBACK (button_birthdays_window_close_cb), appGUI); gtk_container_add (GTK_CONTAINER (hbuttonbox), close_button); gtk_widget_show (appGUI->cnt->birthdays_window); gtk_widget_grab_focus (close_button); }
static gboolean gtkListEditKeyPressEvent(GtkWidget* entry, GdkEventKey *evt, Ihandle *ih) { if ((evt->keyval == GDK_Up || evt->keyval == GDK_KP_Up) || (evt->keyval == GDK_Prior || evt->keyval == GDK_KP_Page_Up) || (evt->keyval == GDK_Down || evt->keyval == GDK_KP_Down) || (evt->keyval == GDK_Next || evt->keyval == GDK_KP_Page_Down)) { int pos = -1; GtkTreeIter iter; GtkTreeModel* model = NULL; GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ih->handle)); if (gtk_tree_selection_get_selected(selection, &model, &iter)) { GtkTreePath *path = gtk_tree_model_get_path(model, &iter); int* indices = gtk_tree_path_get_indices(path); pos = indices[0]; gtk_tree_path_free(path); } if (pos == -1) pos = 0; else if (evt->keyval == GDK_Up || evt->keyval == GDK_KP_Up) { pos--; if (pos < 0) pos = 0; } else if (evt->keyval == GDK_Prior || evt->keyval == GDK_KP_Page_Up) { pos -= 5; if (pos < 0) pos = 0; } else if (evt->keyval == GDK_Down || evt->keyval == GDK_KP_Down) { int count = gtk_tree_model_iter_n_children(model, NULL); pos++; if (pos > count-1) pos = count-1; } else if (evt->keyval == GDK_Next || evt->keyval == GDK_KP_Page_Down) { int count = gtk_tree_model_iter_n_children(model, NULL); pos += 5; if (pos > count-1) pos = count-1; } if (pos != -1) { GtkTreePath* path = gtk_tree_path_new_from_indices(pos, -1); g_signal_handlers_block_by_func(G_OBJECT(selection), G_CALLBACK(gtkListSelectionChanged), ih); gtk_tree_selection_select_path(selection, path); g_signal_handlers_unblock_by_func(G_OBJECT(selection), G_CALLBACK(gtkListSelectionChanged), ih); gtk_tree_path_free(path); iupAttribSetInt(ih, "_IUPLIST_OLDVALUE", pos); if (!model) model = gtkListGetModel(ih); if (gtk_tree_model_iter_nth_child(model, &iter, NULL, pos)) { gchar *text = NULL; gtk_tree_model_get(model, &iter, 0, &text, -1); if (text) gtk_entry_set_text((GtkEntry*)entry, text); } } } return iupgtkKeyPressEvent(entry, evt, ih); }
bool sc_navigate_index(girara_session_t* session, girara_argument_t* argument, girara_event_t* UNUSED(event), unsigned int UNUSED(t)) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); zathura_t* zathura = session->global.data; g_return_val_if_fail(argument != NULL, false); g_return_val_if_fail(zathura->document != NULL, false); if(zathura->ui.index == NULL) { return false; } GtkTreeView *tree_view = gtk_container_get_children(GTK_CONTAINER(zathura->ui.index))->data; GtkTreePath *path; gtk_tree_view_get_cursor(tree_view, &path, NULL); if (path == NULL) { return false; } GtkTreeModel *model = gtk_tree_view_get_model(tree_view); GtkTreeIter iter; GtkTreeIter child_iter; gboolean is_valid_path = TRUE; switch(argument->n) { case TOP: /* go to the first node */ gtk_tree_path_free(path); path = gtk_tree_path_new_first(); break; case BOTTOM: /* go to the last visiible node */ gtk_tree_path_free(path); path = gtk_tree_path_new_from_indices(gtk_tree_model_iter_n_children(model, NULL) - 1, -1); gtk_tree_model_get_iter(model, &iter, path); while (gtk_tree_model_iter_has_child(model, &iter) == TRUE && gtk_tree_view_row_expanded(tree_view, path) == TRUE) { gtk_tree_path_append_index(path, gtk_tree_model_iter_n_children(model, &iter) - 1); } break; case UP: if (gtk_tree_path_prev(path) == FALSE) { /* For some reason gtk_tree_path_up returns TRUE although we're not * moving anywhere. */ is_valid_path = gtk_tree_path_up(path) && (gtk_tree_path_get_depth(path) > 0); } else { /* row above */ while (gtk_tree_view_row_expanded(tree_view, path)) { gtk_tree_model_get_iter(model, &iter, path); /* select last child */ gtk_tree_model_iter_nth_child(model, &child_iter, &iter, gtk_tree_model_iter_n_children(model, &iter)-1); gtk_tree_path_free(path); path = gtk_tree_model_get_path(model, &child_iter); } } break; case COLLAPSE: if (gtk_tree_view_collapse_row(tree_view, path) == FALSE && gtk_tree_path_get_depth(path) > 1) { gtk_tree_path_up(path); gtk_tree_view_collapse_row(tree_view, path); } break; case DOWN: if (gtk_tree_view_row_expanded(tree_view, path) == TRUE) { gtk_tree_path_down(path); } else { do { gtk_tree_model_get_iter(model, &iter, path); if (gtk_tree_model_iter_next(model, &iter)) { gtk_tree_path_free(path); path = gtk_tree_model_get_path(model, &iter); break; } } while((is_valid_path = (gtk_tree_path_get_depth(path) > 1)) && gtk_tree_path_up(path)); } break; case EXPAND: if (gtk_tree_view_expand_row(tree_view, path, FALSE)) { gtk_tree_path_down(path); } break; case EXPAND_ALL: gtk_tree_view_expand_all(tree_view); break; case COLLAPSE_ALL: gtk_tree_view_collapse_all(tree_view); gtk_tree_path_free(path); path = gtk_tree_path_new_first(); gtk_tree_view_set_cursor(tree_view, path, NULL, FALSE); break; case TOGGLE: gtk_tree_model_get_iter(model, &iter, path); if (gtk_tree_model_iter_has_child(model, &iter) == TRUE) { if (gtk_tree_view_row_expanded(tree_view, path) == TRUE) { gtk_tree_view_collapse_row(tree_view, path); } else { gtk_tree_view_expand_row(tree_view, path, FALSE); } break; } case SELECT: cb_index_row_activated(tree_view, path, NULL, zathura); gtk_tree_path_free(path); return false; } if (is_valid_path == TRUE) { gtk_tree_view_set_cursor(tree_view, path, NULL, FALSE); } gtk_tree_path_free(path); return false; }
static void choices_tree_view_row_activated (GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer user_data) { GPInstructLessonTestMultiChoiceEditor *editor = GPINSTRUCT_LESSON_TEST_MULTI_CHOICE_EDITOR (user_data); GPInstructLessonTestMultiChoiceEditorPrivate *priv = editor->priv; GPInstructObject *object; GtkTreeIter iter; GtkWidget *scrolled_window, *text_view; if (gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->choices_store), &iter, path)) { object = questions_tree_view_get_current_data (editor); if (GPINSTRUCT_IS_LESSON_TEST_MULTI_CHOICE_QUESTION (object)) { guint choice = gtk_tree_path_get_indices (path)[0]; GPInstructLessonTestMultiChoiceQuestion *question = GPINSTRUCT_LESSON_TEST_MULTI_CHOICE_QUESTION (object); GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Choice Properties"), GTK_WINDOW (priv->window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL); GtkWidget *content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); gtk_window_set_default_size (GTK_WINDOW (dialog), 400, 300); scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); text_view = gtk_text_view_new (); gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_WORD_CHAR); gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view)), gpinstruct_lesson_test_multi_choice_question_get_choice (question, choice), -1); gtk_container_add (GTK_CONTAINER (scrolled_window), text_view); gtk_box_pack_start (GTK_BOX (content_area), gtk_label_new (_("Text:")), FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (content_area), scrolled_window, TRUE, TRUE, 0); gtk_widget_show_all (content_area); if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { GtkTextIter start, end; gtk_text_buffer_get_bounds (gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view)), &start, &end); gchar *text = gtk_text_iter_get_text (&start, &end); gpinstruct_lesson_test_multi_choice_question_set_choice (question, choice, text); g_free (text); update_choices_tree_view (GPINSTRUCT_LESSON_TEST_MULTI_CHOICE_EDITOR (user_data)); gpinstruct_editor_window_set_modified (priv->window, TRUE); gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (priv->choices_store), &iter, NULL, choice); gtk_tree_selection_select_iter (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)), &iter); } gtk_widget_destroy (dialog); } } }