/*! \brief Closes a page. * \par Function Description * This function closes the page <B>page</B> of toplevel * <B>toplevel</B>. * * If necessary, the current page of <B>toplevel</B> is changed to * the next valid page or to a new untitled page. * * \param [in] w_current The toplevel environment. * \param [in] page The page to close. */ void x_window_close_page (GSCHEM_TOPLEVEL *w_current, PAGE *page) { TOPLEVEL *toplevel = w_current->toplevel; PAGE *new_current = NULL; GList *iter; g_return_if_fail (toplevel != NULL); g_return_if_fail (page != NULL); g_assert (page->pid != -1); /* If we're closing whilst inside a move action, re-wind the * page contents back to their state before we started */ if (w_current->inside_action && (w_current->event_state == MOVE || w_current->event_state == ENDMOVE)) { o_move_cancel (w_current); } if (page == toplevel->page_current) { /* as it will delete current page, select new current page */ /* first look up in page hierarchy */ new_current = s_page_search_by_page_id (toplevel->pages, page->up); if (new_current == NULL) { /* no up in hierarchy, choice is prev, next, new page */ iter = g_list_find( geda_list_get_glist( toplevel->pages ), page ); if ( g_list_previous( iter ) ) { new_current = (PAGE *)g_list_previous( iter )->data; } else if ( g_list_next( iter ) ) { new_current = (PAGE *)g_list_next( iter )->data; } else { /* need to add a new untitled page */ new_current = NULL; } } /* new_current will be the new current page at the end of the function */ } s_log_message (page->CHANGED ? _("Discarding page [%s]\n") : _("Closing [%s]\n"), page->page_filename); /* remove page from toplevel list of page and free */ s_page_delete (toplevel, page); /* Switch to a different page if we just removed the current */ if (toplevel->page_current == NULL) { /* Create a new page if there wasn't another to switch to */ if (new_current == NULL) { new_current = x_window_open_page (w_current, NULL); } /* change to new_current and update display */ x_window_set_current_page (w_current, new_current); } }
/*! \brief Updates the preview widget. * \par Function Description * This function update the preview: if the preview is active and a * filename has been given, it opens the file and display * it. Otherwise it display a blank page. * * \param [in] preview The preview widget. */ static void preview_update (Preview *preview) { GSCHEM_TOPLEVEL *preview_w_current = preview->preview_w_current; TOPLEVEL *preview_toplevel = preview_w_current->toplevel; int left, top, right, bottom; int width, height; if (preview_toplevel->page_current == NULL) { return; } /* delete old preview, create new page */ /* it would be better to just resets current page - Fix me */ s_page_delete (preview_toplevel, preview_toplevel->page_current); s_page_goto (preview_toplevel, s_page_new (preview_toplevel, "preview")); if (preview->active) { g_assert ((preview->filename == NULL) || (preview->buffer == NULL)); if (preview->filename != NULL) { /* open up file in current page */ f_open_flags (preview_toplevel, preview_toplevel->page_current, preview->filename, F_OPEN_RC | F_OPEN_RESTORE_CWD, NULL); /* test value returned by f_open... - Fix me */ /* we should display something if there an error occured - Fix me */ } if (preview->buffer != NULL) { /* Load the data buffer */ s_page_append_list (preview_toplevel, preview_toplevel->page_current, o_read_buffer (preview_toplevel, NULL, preview->buffer, -1, _("Preview Buffer"))); } } if (world_get_object_glist_bounds (preview_toplevel, s_page_objects (preview_toplevel->page_current), &left, &top, &right, &bottom)) { /* Clamp the canvas size to the extents of the page being previewed */ width = right - left; height = bottom - top; preview_toplevel->init_left = left - ((double)width * OVER_ZOOM_FACTOR); preview_toplevel->init_right = right + ((double)width * OVER_ZOOM_FACTOR); preview_toplevel->init_top = top - ((double)height * OVER_ZOOM_FACTOR); preview_toplevel->init_bottom = bottom + ((double)height * OVER_ZOOM_FACTOR); } /* display current page (possibly empty) */ a_zoom_extents (preview_w_current, s_page_objects (preview_toplevel->page_current), A_PAN_DONT_REDRAW); o_invalidate_all (preview_w_current); }
/*! \brief Load a subpage * * \par Function Description * Implements s_hierarchy_down_schematic(), but without changing variables * related to the UI. * * - Ensures a duplicate page is not loaded * - Does not change the current page * - Does not modify the most recent "up" page * * \param [in] page * \param [in] filename * \param [out] error * \return A pointer to the subpage or NULL if an error occured. */ PAGE* s_hierarchy_load_subpage (PAGE *page, const char *filename, GError **error) { char *string; PAGE *subpage = NULL; g_return_val_if_fail (filename != NULL, NULL); g_return_val_if_fail (page != NULL, NULL); SCM string_s = scm_call_1 (scm_c_public_ref ("geda library", "get-source-library-file"), scm_from_utf8_string (filename)); if (scm_is_false (string_s)) { g_set_error (error, EDA_ERROR, EDA_ERROR_NOLIB, _("Schematic not found in source library.")); } else { string = scm_to_utf8_string (string_s); gchar *normalized = f_normalize_filename (string, error); subpage = s_page_search (page->toplevel, normalized); if (subpage == NULL) { int success; subpage = s_page_new (page->toplevel, string); success = f_open (page->toplevel, subpage, s_page_get_filename (subpage), error); if (success) { subpage->page_control = ++page_control_counter; } else { s_page_delete (page->toplevel, subpage); subpage = NULL; } } g_free (normalized); } return subpage; }
/*! \brief Deletes the list of pages of <B>toplevel</B>. * \par Function Description * Deletes the list of pages of <B>toplevel</B>. * This function should only be called when you are finishing up. * * \param toplevel The TOPLEVEL object. */ void s_page_delete_list(TOPLEVEL *toplevel) { GList *list_copy, *iter; PAGE *page; /* s_page_delete removes items from the page list, so make a copy */ list_copy = g_list_copy (geda_list_get_glist (toplevel->pages)); for (iter = list_copy; iter != NULL; iter = g_list_next (iter)) { page = (PAGE *)iter->data; s_page_delete (toplevel, page); } g_list_free (list_copy); /* reset toplevel fields */ toplevel->page_current = NULL; }
/*! \brief Load a subpage * * \par Function Description * Implements s_hierarchy_down_schematic(), but without changing variables * related to the UI. * * - Ensures a duplicate page is not loaded * - Does not change the current page * - Does not modify the most recent "up" page * * \param [in] page * \param [in] filename * \param [out] error * \return A pointer to the subpage or NULL if an error occured. */ PAGE* s_hierarchy_load_subpage (PAGE *page, const char *filename, GError **error) { char *string; PAGE *subpage = NULL; g_return_val_if_fail (filename != NULL, NULL); g_return_val_if_fail (page != NULL, NULL); string = s_slib_search_single (filename); if (string == NULL) { g_set_error (error, EDA_ERROR, EDA_ERROR_NOLIB, _("Schematic not found in source library.")); } else { gchar *normalized = f_normalize_filename (string, error); subpage = s_page_search (page->toplevel, normalized); if (subpage == NULL) { int success; subpage = s_page_new (page->toplevel, string); success = f_open (page->toplevel, subpage, subpage->page_filename, error); if (success) { subpage->page_control = ++page_control_counter; } else { s_page_delete (page->toplevel, subpage); subpage = NULL; } } g_free (normalized); } return subpage; }
/*! \todo Finish function documentation!!! * \brief * \par Function Description * * <B>type</B> can be one of the following values: * <DL> * <DT>*</DT><DD>UNDO_ACTION * <DT>*</DT><DD>REDO_ACTION * </DL> */ void o_undo_callback(GSCHEM_TOPLEVEL *w_current, int type) { TOPLEVEL *toplevel = w_current->toplevel; UNDO *u_current; UNDO *u_next; UNDO *save_bottom; UNDO *save_tos; UNDO *save_current; int save_logging; int find_prev_data=FALSE; char *save_filename; if (w_current->undo_control == FALSE) { s_log_message(_("Undo/Redo disabled in rc file\n")); return; } if (toplevel->page_current->undo_current == NULL) { return; } if (type == UNDO_ACTION) { u_current = toplevel->page_current->undo_current->prev; } else { u_current = toplevel->page_current->undo_current->next; } u_next = toplevel->page_current->undo_current; if (u_current == NULL) { return; } if (u_next->type == UNDO_ALL && u_current->type == UNDO_VIEWPORT_ONLY) { #if DEBUG printf("Type: %d\n", u_current->type); printf("Current is an undo all, next is viewport only!\n"); #endif find_prev_data = TRUE; if (w_current->undo_type == UNDO_DISK) { u_current->filename = o_undo_find_prev_filename(u_current); } else { u_current->object_list = o_undo_find_prev_object_head (u_current); } } /* save filename */ save_filename = g_strdup (toplevel->page_current->page_filename); /* save structure so it's not nuked */ save_bottom = toplevel->page_current->undo_bottom; save_tos = toplevel->page_current->undo_tos; save_current = toplevel->page_current->undo_current; toplevel->page_current->undo_bottom = NULL; toplevel->page_current->undo_tos = NULL; toplevel->page_current->undo_current = NULL; if (w_current->undo_type == UNDO_DISK && u_current->filename) { PAGE *p_new; s_page_delete (toplevel, toplevel->page_current); p_new = s_page_new(toplevel, u_current->filename); s_page_goto (toplevel, p_new); } else if (w_current->undo_type == UNDO_MEMORY && u_current->object_list) { PAGE *p_new; s_page_delete (toplevel, toplevel->page_current); p_new = s_page_new (toplevel, save_filename); s_page_goto (toplevel, p_new); } /* temporarily disable logging */ save_logging = do_logging; do_logging = FALSE; if (w_current->undo_type == UNDO_DISK && u_current->filename) { f_open(toplevel, toplevel->page_current, u_current->filename, NULL); x_manual_resize(w_current); toplevel->page_current->page_control = u_current->page_control; toplevel->page_current->up = u_current->up; toplevel->page_current->CHANGED=1; } else if (w_current->undo_type == UNDO_MEMORY && u_current->object_list) { s_page_delete_objects (toplevel, toplevel->page_current); s_page_append_list (toplevel, toplevel->page_current, o_glist_copy_all (toplevel, u_current->object_list, NULL)); x_manual_resize(w_current); toplevel->page_current->page_control = u_current->page_control; toplevel->page_current->up = u_current->up; toplevel->page_current->CHANGED=1; } /* do misc setups */ set_window(toplevel, toplevel->page_current, u_current->left, u_current->right, u_current->top, u_current->bottom); x_hscrollbar_update(w_current); x_vscrollbar_update(w_current); /* restore logging */ do_logging = save_logging; /* set filename right */ g_free(toplevel->page_current->page_filename); toplevel->page_current->page_filename = save_filename; /* final redraw */ x_pagesel_update (w_current); x_multiattrib_update (w_current); /* Let the caller to decide if redraw or not */ o_invalidate_all (w_current); i_update_menus(w_current); /* restore saved undo structures */ toplevel->page_current->undo_bottom = save_bottom; toplevel->page_current->undo_tos = save_tos; toplevel->page_current->undo_current = save_current; if (type == UNDO_ACTION) { if (toplevel->page_current->undo_current) { toplevel->page_current->undo_current = toplevel->page_current->undo_current->prev; if (toplevel->page_current->undo_current == NULL) { toplevel->page_current->undo_current = toplevel->page_current->undo_bottom; } } } else { /* type is REDO_ACTION */ if (toplevel->page_current->undo_current) { toplevel->page_current->undo_current = toplevel->page_current->undo_current->next; if (toplevel->page_current->undo_current == NULL) { toplevel->page_current->undo_current = toplevel->page_current->undo_tos; } } } /* don't have to free data here since filename, object_list are */ /* just pointers to the real data (lower in the stack) */ if (find_prev_data) { u_current->filename = NULL; u_current->object_list = NULL; } #if DEBUG printf("\n\n---Undo----\n"); s_undo_print_all(toplevel->page_current->undo_bottom); printf("TOS: %s\n", toplevel->page_current->undo_tos->filename); printf("CURRENT: %s\n", toplevel->page_current->undo_current->filename); printf("----\n"); #endif }
/*! \brief Save schematic file and close * \par Function Description * This function will save the current schematic file before closing it. * It also deletes the page_current item in the TOPLEVEL structure. * * \param [in,out] toplevel The TOPLEVEL object containing the schematic. * \param [in] filename The file name to save the schematic to. */ void f_save_close(TOPLEVEL *toplevel, char *filename) { o_save(toplevel, filename); s_page_delete (toplevel, toplevel->page_current); }