/*! \brief Updates the display when drawing area is configured. * \par Function Description * This is the callback function connected to the configure event of * the GschemPageView of the main window. * * It re-pans each of its pages to keep their contents centered in the * GschemPageView. * * When the window is maximised, the zoom of every page is changed to * best fit the previously displayed area of the page in the new * area. Otherwise the current zoom level is left unchanged. * * \param [in] widget The GschemPageView which received the signal. * \param [in] event The event structure of signal configure-event. * \param [in] unused * \returns FALSE to propagate the event further. */ gboolean x_event_configure (GschemPageView *page_view, GdkEventConfigure *event, gpointer unused) { GtkAllocation current_allocation; GList *iter; PAGE *p_current = gschem_page_view_get_page (page_view); if (p_current == NULL) { /* don't want to call this if the current page isn't setup yet */ return FALSE; } g_return_val_if_fail (p_current->toplevel != NULL, FALSE); gtk_widget_get_allocation (GTK_WIDGET(page_view), ¤t_allocation); if ((current_allocation.width == page_view->previous_allocation.width) && (current_allocation.height == page_view->previous_allocation.height)) { /* the size of the drawing area has not changed -- nothing to do here */ return FALSE; } page_view->previous_allocation = current_allocation; /* re-pan each page of the TOPLEVEL */ for ( iter = geda_list_get_glist (p_current->toplevel->pages); iter != NULL; iter = g_list_next (iter) ) { gschem_page_view_set_page (page_view, (PAGE *)iter->data); if (page_view->configured) { gschem_page_view_pan_mouse (page_view, 0, 0); } else { gschem_page_view_zoom_extents (page_view, NULL); } } page_view->configured = TRUE; gschem_page_view_set_page (page_view, p_current); return FALSE; }
/*! \brief Changes the current page. * \par Function Description * This function displays the specified page <B>page</B> in the * window attached to <B>toplevel</B>. * * It changes the <B>toplevel</B>'s current page to <B>page</B>, * draws it and updates the user interface. * * <B>page</B> has to be in the list of PAGEs attached to <B>toplevel</B>. * * \param [in] w_current The toplevel environment. * \param [in] page The page to become current page. */ void x_window_set_current_page (GschemToplevel *w_current, PAGE *page) { GschemPageView *page_view = gschem_toplevel_get_current_page_view (w_current); g_return_if_fail (page != NULL); g_return_if_fail (page_view != NULL); o_redraw_cleanstates (w_current); gschem_page_view_set_page (page_view, page); i_update_menus (w_current); i_set_filename (w_current, page->page_filename); x_pagesel_update (w_current); x_multiattrib_update (w_current); gschem_page_view_update_scroll_adjustments (page_view); gschem_page_view_invalidate_all (page_view); }
/*! \brief Opens a new page from a file. * \par Function Description * This function opens the file whose name is <B>filename</B> in a * new PAGE of <B>toplevel</B>. * * If there is no page for <B>filename</B> in <B>toplevel</B>'s list * of pages, it creates a new PAGE, loads the file in it and returns * a pointer on the new page. Otherwise it returns a pointer on the * existing page. * * If the filename passed is NULL, this function creates an empty, * untitled page. The name of the untitled page is build from * configuration data ('untitled-name') and a counter for uniqueness. * * The opened page becomes the current page of <B>toplevel</B>. * * \param [in] w_current The toplevel environment. * \param [in] filename The name of the file to open or NULL for a blank page. * \returns A pointer on the new page. * * \bug This code should check to make sure any untitled filename * does not conflict with a file on disk. */ PAGE* x_window_open_page (GschemToplevel *w_current, const gchar *filename) { TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current); GschemPageView *page_view = gschem_toplevel_get_current_page_view (w_current); PAGE *page; gchar *fn; g_return_val_if_fail (toplevel != NULL, NULL); /* Generate untitled filename if none was specified */ if (filename == NULL) { gchar *cwd, *tmp, *untitled_name; EdaConfig *cfg; cwd = g_get_current_dir (); cfg = eda_config_get_context_for_path (cwd); untitled_name = eda_config_get_string (cfg, "gschem", "default-filename", NULL); tmp = g_strdup_printf ("%s_%d.sch", untitled_name, ++w_current->num_untitled); fn = g_build_filename (cwd, tmp, NULL); g_free (untitled_name); g_free(cwd); g_free(tmp); } else { fn = g_strdup (filename); } /* Return existing page if it is already loaded */ page = s_page_search (toplevel, fn); if ( page != NULL ) { g_free(fn); return page; } page = s_page_new (toplevel, fn); s_page_goto (toplevel, page); gschem_toplevel_page_changed (w_current); /* Load from file if necessary, otherwise just print a message */ if (filename != NULL) { GError *err = NULL; if (!quiet_mode) s_log_message (_("Loading schematic [%s]\n"), fn); if (!f_open (toplevel, page, (gchar *) fn, &err)) { GtkWidget *dialog; g_warning ("%s\n", err->message); dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (w_current->main_window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("<b>An error occurred while loading the requested file.</b>\n\nLoading from '%s' failed: %s. The gschem log may contain more information."), fn, err->message); gtk_window_set_title (GTK_WINDOW (dialog), _("Failed to load file")); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); g_error_free (err); } else { gtk_recent_manager_add_item (recent_manager, g_filename_to_uri(fn, NULL, NULL)); } } else { if (!quiet_mode) s_log_message (_("New file [%s]\n"), toplevel->page_current->page_filename); g_run_hook_page (w_current, "%new-page-hook", toplevel->page_current); } gschem_page_view_set_page (page_view, toplevel->page_current); o_undo_savestate (w_current, toplevel->page_current, UNDO_ALL); /* This line is generally un-needed, however if some code * wants to open a page, yet not bring it to the front, it is * needed needed to add it into the page manager. Otherwise, * it will get done in x_window_set_current_page(...) */ x_pagesel_update (w_current); /* ??? */ g_free (fn); return page; }
static void preview_init (Preview *preview) { struct event_reg_t { gchar *detailed_signal; GCallback c_handler; } drawing_area_events[] = { { "realize", G_CALLBACK (preview_callback_realize) }, { "expose_event", G_CALLBACK (x_event_expose) }, { "button_press_event", G_CALLBACK (preview_callback_button_press) }, { "configure_event", G_CALLBACK (preview_event_configure) }, { "scroll_event", G_CALLBACK (preview_event_scroll) }, { NULL, NULL } }, *tmp; GschemToplevel *preview_w_current; preview_w_current = gschem_toplevel_new (); gschem_toplevel_set_toplevel (preview_w_current, s_toplevel_new ()); preview_w_current->toplevel->load_newer_backup_func = x_fileselect_load_backup; preview_w_current->toplevel->load_newer_backup_data = preview_w_current; o_text_set_rendered_bounds_func (preview_w_current->toplevel, o_text_get_rendered_bounds, preview_w_current); i_vars_set (preview_w_current); /* be sure to turn off scrollbars */ preview_w_current->scrollbars_flag = FALSE; /* be sure to turn off the grid */ gschem_options_set_grid_mode (preview_w_current->options, GRID_MODE_NONE); /* preview_w_current windows don't have toolbars */ preview_w_current->handleboxes = FALSE; preview_w_current->toolbars = FALSE; preview_w_current->win_width = 160; preview_w_current->win_height = 120; preview_w_current->drawing_area = GTK_WIDGET (preview); preview->preview_w_current = preview_w_current; g_object_set (GTK_WIDGET (preview), "width-request", preview_w_current->win_width, "height-request", preview_w_current->win_height, NULL); preview->active = FALSE; preview->filename = NULL; preview->buffer = NULL; PAGE *preview_page = s_page_new (preview->preview_w_current->toplevel, "preview"); gschem_page_view_set_page (GSCHEM_PAGE_VIEW (preview), preview_page); gtk_widget_set_events (GTK_WIDGET (preview), GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK); for (tmp = drawing_area_events; tmp->detailed_signal != NULL; tmp++) { g_signal_connect (GTK_WIDGET (preview), tmp->detailed_signal, tmp->c_handler, preview_w_current); } }