static void docked_move_resize(void) { GdkScreen *screen; int y = 0; if (!window_docked) return; screen = gtk_window_get_screen(GTK_WINDOW(window)); if (window_docked == WINDOW_DOCKED_BOTTOM) y = gdk_screen_get_height(screen) - window_frame.height; set_geometry_hints(); gtk_window_move(GTK_WINDOW(window), 0, y); cell_widget_pack(); key_widget_resize(key_widget); trace("y=%d", y); if (window_struts) gdk_window_set_type_hint(GDK_WINDOW(window->window), GDK_WINDOW_TYPE_HINT_DOCK); }
void window_set_docked(int mode) { if (mode < WINDOW_UNDOCKED) mode = WINDOW_UNDOCKED; if (mode >= WINDOW_DOCKED_BOTTOM) mode = WINDOW_DOCKED_BOTTOM; if (mode && !window_docked) window_frame_saved = window_frame; window_docked = mode; gtk_window_set_decorated(GTK_WINDOW(window), !mode); set_geometry_hints(); cell_widget_pack(); key_widget_resize(key_widget); /* Set window docking hints. FIXME This allegedly solves docking problems with some window managers but only seems to cause more problems for Compiz and Metacity. */ /* gtk_widget_hide(window); if (mode == WINDOW_UNDOCKED) gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_NORMAL); else gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DOCK); gtk_widget_show(window); */ /* Restore the old window position */ if (!mode) { update_struts(); window_frame = window_frame_saved; gtk_window_move(GTK_WINDOW(window), window_frame.x, window_frame.y); trace("moving to (%d, %d)", window_frame.x, window_frame.y); } /* Move the window into docked position */ else docked_move_resize(); }
void create_commodity_register(gchar *guid, gchar *fullname) { struct commodity_register *commodity_register = g_malloc(sizeof(struct commodity_register)); /* Record information in the descriptor */ commodity_register->guid = guid; commodity_register->fullname = fullname; COMMODITY_REGISTER_CORE.window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); COMMODITY_REGISTER_CORE.scrolled_window = gtk_scrolled_window_new (NULL,NULL); COMMODITY_REGISTER_CORE.view = GTK_TREE_VIEW(gtk_tree_view_new ()); COMMODITY_REGISTER_CORE.selection = gtk_tree_view_get_selection(COMMODITY_REGISTER_CORE.view); /* Create the model/store */ create_commodity_register_model(commodity_register); /* Column setup */ /* Timestamp */ { GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); g_signal_connect(renderer, "edited", G_CALLBACK(timestamp_edited), commodity_register); g_object_set(renderer, "editable", TRUE, NULL); /* Add timestamp column to the view */ gtk_tree_view_insert_column_with_attributes (COMMODITY_REGISTER_CORE.view, -1, "Time-stamp", renderer, "text", STORE_TIMESTAMP, NULL); commodity_register->timestamp_renderer = renderer; } /* Price */ { GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); GtkTreeViewColumn *column; g_signal_connect(renderer, "edited", G_CALLBACK(price_edited), commodity_register); g_object_set(renderer, "editable", TRUE, NULL); gtk_tree_view_insert_column_with_attributes (COMMODITY_REGISTER_CORE.view, -1, "Price", renderer, "text", STORE_PRICE, NULL); column = gtk_tree_view_get_column(COMMODITY_REGISTER_CORE.view, VIEW_PRICE); /* Right-justify the value column header */ gtk_tree_view_column_set_alignment(column, 1.0); /* Set up the data formatter */ gtk_tree_view_column_set_cell_data_func(column, renderer, price_formatter, NULL, NULL); /* Make renderer right-justify the data */ gtk_cell_renderer_set_alignment(renderer, 1.0, .5); } /* Grid lines for readability */ g_object_set (COMMODITY_REGISTER_CORE.view, "enable-grid-lines", GTK_TREE_VIEW_GRID_LINES_BOTH, NULL); /* Set geometry hints */ set_geometry_hints(GTK_WINDOW(COMMODITY_REGISTER_CORE.window), COMMODITY_WINDOW_WIDTH, COMMODITY_WINDOW_HEIGHT); gtk_container_add (GTK_CONTAINER (COMMODITY_REGISTER_CORE.scrolled_window), GTK_WIDGET(COMMODITY_REGISTER_CORE.view)); gtk_container_add (GTK_CONTAINER (COMMODITY_REGISTER_CORE.window), GTK_WIDGET(COMMODITY_REGISTER_CORE.scrolled_window)); /* Set window title to commodity name */ gtk_window_set_title(COMMODITY_REGISTER_CORE.window, commodity_register->fullname); /* Clean up memory allocations if window is destroyed */ g_signal_connect (COMMODITY_REGISTER_CORE.window, "destroy", G_CALLBACK (cleanup), commodity_register); /* Signal button press event */ g_signal_connect(COMMODITY_REGISTER_CORE.view, "button-press-event", (GCallback) mouse_button_pressed, commodity_register); /* Signal key press event */ g_signal_connect(COMMODITY_REGISTER_CORE.view, "key-press-event", (GCallback) key_pressed, commodity_register); /* Set the view's selection mode */ gtk_tree_selection_set_mode(COMMODITY_REGISTER_CORE.selection, GTK_SELECTION_BROWSE); gtk_widget_show_all (GTK_WIDGET(COMMODITY_REGISTER_CORE.window)); }
Window() : canvas(), checkbutton1("Plot 1"), checkbutton2("Plot 2"), checkbutton3("Plot 3"), label_x("X:"), label_y("Y:") { set_default_size(720, 580); Gdk::Geometry geometry; geometry.min_aspect = geometry.max_aspect = double(720)/double(580); set_geometry_hints(*this, geometry, Gdk::HINT_ASPECT); set_title("Gtkmm-PLplot test4"); canvas.set_hexpand(true); canvas.set_vexpand(true); canvas.set_background_color(Gdk::RGBA("Light Gray")); grid.set_column_homogeneous(true); checkbutton1.set_vexpand(false); checkbutton1.set_hexpand(false); checkbutton1.set_halign(Gtk::ALIGN_CENTER); checkbutton2.set_vexpand(false); checkbutton2.set_hexpand(false); checkbutton2.set_halign(Gtk::ALIGN_CENTER); checkbutton3.set_vexpand(false); checkbutton3.set_hexpand(false); checkbutton3.set_halign(Gtk::ALIGN_CENTER); std::valarray<double> x_va = Gtk::PLplot::indgen_va(1000)/50.0 - 10.0; std::valarray<double> y_va1 = sinh(x_va); std::valarray<double> y_va2 = cosh(x_va); std::valarray<double> y_va3 = tanh(x_va); //generate the data, the plot, add them to the canvas and use the return value to pass it to the checkbutton Gtk::PLplot::Plot2D *plot1 = Gtk::manage( new Gtk::PLplot::Plot2D( *Gtk::manage( new Gtk::PLplot::PlotData2D( x_va, y_va1, Gdk::RGBA("blue"), Gtk::PLplot::LineStyle::CONTINUOUS, 3.0 ) ), "X-axis", "Y-axis", "Hyperbolic sine", 0.5, 0.5, 0.0, 0.0 ) ); canvas.add_plot(*plot1); checkbutton1.connect_plot(plot1); Gtk::PLplot::Plot2D *plot2 = Gtk::manage( new Gtk::PLplot::Plot2D( *Gtk::manage( new Gtk::PLplot::PlotData2D( x_va, y_va2, Gdk::RGBA("red"), Gtk::PLplot::LineStyle::CONTINUOUS, 3.0 ) ), "X-axis", "Y-axis", "Hyperbolic cosine", 0.5, 0.5, 0.5, 0.0 ) ); canvas.add_plot(*plot2); checkbutton2.connect_plot(plot2); Gtk::PLplot::Plot2D *plot3 = Gtk::manage( new Gtk::PLplot::Plot2D( *Gtk::manage( new Gtk::PLplot::PlotData2D( x_va, y_va3, Gdk::RGBA("green"), Gtk::PLplot::LineStyle::CONTINUOUS, 3.0 ) ), "X-axis", "Y-axis", "Hyperbolic tangent", 0.4, 0.4, 0.2, 0.55 ) ); canvas.add_plot(*plot3); checkbutton3.connect_plot(plot3); checkbutton1.set_active(); checkbutton2.set_active(false); checkbutton3.set_active(); //let's make the first plot unpannable plot1->set_region_pannable(false); //let's override the background color of the second plot and hide it to make the surprise complete!! plot2->set_background_color(Gdk::RGBA("Yellow Green")); plot2->hide(); //also let's disable the region selection, for no reason whatsoever! plot2->set_region_selectable(false); //let's override the default region of this plot, this is NOT influenced by set_region_selectable()!!! plot2->set_region(-10, 10, -10, 10); //we can also change some other colors plot2->set_axes_color(Gdk::RGBA("Blue")); plot2->set_titles_color(Gdk::RGBA("Purple")); plot2->set_box_style(Gtk::PLplot::BOX_TICKS_TICK_LABELS_MAIN_AXES_MAJOR_MINOR_TICK_GRID); //lets'give the third plot a nice opaque background color plot3->set_background_color(Gdk::RGBA("White")); //but disable zooming by scrolling plot3->set_region_zoomable(false); //and give it an unusual selection box plot3->set_region_selection_color(Gdk::RGBA("Purple")); plot3->set_region_selection_width(4.0); //hook up signal_cursor_motion to the entries unsigned int plotnr = 0; while (1) { try { Gtk::PLplot::Plot2D *plot = dynamic_cast<Gtk::PLplot::Plot2D *>(canvas.get_plot(plotnr++)); plot->signal_cursor_motion().connect([this](double x, double y){ entry_x.set_text(Glib::Ascii::dtostr(x)); entry_y.set_text(Glib::Ascii::dtostr(y)); }); } catch (Gtk::PLplot::Exception &e) { break; } } grid.attach(checkbutton1, 0, 0, 1, 1); grid.attach(checkbutton2, 1, 0, 1, 1); grid.attach(checkbutton3, 2, 0, 1, 1); grid.attach(canvas, 0, 1, 3, 1); coordinates_grid.set_column_homogeneous(false); coordinates_grid.attach(label_x, 0, 0, 1, 1); coordinates_grid.attach(entry_x, 1, 0, 1, 1); coordinates_grid.attach(label_y, 2, 0, 1, 1); coordinates_grid.attach(entry_y, 3, 0, 1, 1); label_x.set_vexpand(false); label_x.set_hexpand(true); label_x.set_halign(Gtk::ALIGN_END); label_y.set_vexpand(false); label_y.set_hexpand(false); label_y.set_halign(Gtk::ALIGN_CENTER); entry_x.set_vexpand(false); entry_x.set_hexpand(false); entry_x.set_halign(Gtk::ALIGN_END); entry_y.set_vexpand(false); entry_y.set_hexpand(true); entry_y.set_halign(Gtk::ALIGN_START); coordinates_grid.set_column_spacing(5); grid.attach(coordinates_grid, 0, 2, 3, 1); grid.set_row_spacing(5); add(grid); set_border_width(10); grid.show_all(); }
Window() : show_edges_label("Show edges"), show_labels_label("Show contour labels"), edge_color_label("Contour edge color"), edge_color(Gdk::RGBA("Red")), edge_width_label("Contour edge width"), edge_width_adj(Gtk::Adjustment::create(1.0, 0.1, 10.0, 0.1, 1.0, 0.0)), edge_width_spin(edge_width_adj, 0.1, 1), nlevels_label("Number of contour edges"), nlevels_adj(Gtk::Adjustment::create(7, 3, 20, 1, 5)), nlevels_spin(nlevels_adj, 1, 0), colormap_palette_label("Colormap palette"), area_fill_pattern_label("Fill pattern"), area_lines_width_label("Fill pattern width"), area_lines_width_adj(Gtk::Adjustment::create(1.0, 0.1, 10.0, 0.1, 1.0, 0.0)), area_lines_width_spin(area_lines_width_adj, 0.1, 1), colorbar_label("Show colorbar"), paned(Gtk::ORIENTATION_VERTICAL), aspect_frame(Glib::ustring(), Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER, 1.5, false) { Glib::ustring x_title = "X-axis"; Glib::ustring y_title = "Y-axis"; Glib::ustring plot_title = "Intensity vs detector position"; // general window and canvas settings set_default_size(720, 720); Gdk::Geometry geometry; geometry.min_aspect = geometry.max_aspect = double(720)/double(720); set_geometry_hints(*this, geometry, Gdk::HINT_ASPECT); set_title("Gtkmm-PLplot test8"); canvas.set_hexpand(true); canvas.set_vexpand(true); //read in our dataset std::ifstream fs; fs.exceptions(std::ifstream::failbit | std::ifstream::badbit | std::ifstream::eofbit); // 11 x 11 dataset (I know the file layout and the data dimensions already) const int nx = 11; const int ny = 11; std::vector<double> x(nx); std::vector<double> y(ny); #ifdef GTKMM_PLPLOT_BOOST_ENABLED boost::multi_array<double, 2> z(boost::extents[nx][ny]); std::cout << "Using Boost multi_array!" << std::endl; #else double **z = Gtk::PLplot::calloc_array2d(nx, ny); #endif fs.open(TEST_CSV); std::string line; std::getline(fs, line); gchar **splitted = g_strsplit(line.c_str(), ",", 0); //first line contains the x values for (int i = 1 ; i < nx + 1 ; i++) { x[i-1] = g_ascii_strtod(splitted[i], NULL); } g_strfreev(splitted); for (int i = 0 ; i < ny ; i++) { line.clear(); std::getline(fs, line); splitted = g_strsplit(line.c_str(), ",", 0); y[i] = g_ascii_strtod(splitted[0], NULL); for (int j = 1 ; j < nx + 1 ; j++) { z[j-1][i] = g_ascii_strtod(splitted[j], NULL); } g_strfreev(splitted); } //construct the plot auto plot = Gtk::manage(new Gtk::PLplot::PlotContourShades( *Gtk::manage(new Gtk::PLplot::PlotDataSurface( x, y, z )), x_title, y_title, plot_title, 7, Gtk::PLplot::ColormapPalette::BLUE_RED, edge_color.get_rgba(), 1.0 )); canvas.add_plot(*plot); plot->set_background_color(Gdk::RGBA("Yellow Green")); //now let's set up the grid grid.set_column_homogeneous(true); grid.set_column_spacing(5); grid.set_row_homogeneous(false); grid.set_row_spacing(5); int row_counter = 0; show_edges_label.set_hexpand(true); show_edges_label.set_vexpand(false); show_edges_label.set_valign(Gtk::ALIGN_CENTER); show_edges_label.set_halign(Gtk::ALIGN_END); show_edges_switch.set_hexpand(true); show_edges_switch.set_vexpand(false); show_edges_switch.set_halign(Gtk::ALIGN_START); show_edges_switch.set_valign(Gtk::ALIGN_CENTER); show_edges_switch.set_active(plot->is_showing_edges()); show_edges_switch.property_active().signal_changed().connect([this, plot](){ if (show_edges_switch.get_active()) { edge_color.set_sensitive(); edge_width_spin.set_sensitive(); show_labels_switch.set_sensitive(); plot->show_edges(); } else { edge_color.set_sensitive(false); edge_width_spin.set_sensitive(false); show_labels_switch.set_sensitive(false); plot->hide_edges(); } }); grid.attach(show_edges_label, 0, row_counter, 1, 1); grid.attach(show_edges_switch, 1, row_counter++, 1, 1); // show contour labels show_labels_label.set_hexpand(true); show_labels_label.set_vexpand(false); show_labels_label.set_valign(Gtk::ALIGN_CENTER); show_labels_label.set_halign(Gtk::ALIGN_END); show_labels_switch.set_hexpand(true); show_labels_switch.set_vexpand(false); show_labels_switch.set_halign(Gtk::ALIGN_START); show_labels_switch.set_valign(Gtk::ALIGN_CENTER); show_labels_switch.set_active(plot->is_showing_labels()); show_labels_switch.property_active().signal_changed().connect([this, plot](){ if (show_labels_switch.get_active()) { plot->show_labels(); } else { plot->hide_labels(); } }); grid.attach(show_labels_label, 0, row_counter, 1, 1); grid.attach(show_labels_switch, 1, row_counter++, 1, 1); //color button edge_color_label.set_hexpand(true); edge_color_label.set_vexpand(false); edge_color_label.set_valign(Gtk::ALIGN_CENTER); edge_color_label.set_halign(Gtk::ALIGN_END); edge_color.set_rgba(plot->get_edge_color()); edge_color.set_use_alpha(true); edge_color.set_hexpand(true); edge_color.set_vexpand(false); edge_color.set_halign(Gtk::ALIGN_START); edge_color.set_valign(Gtk::ALIGN_CENTER); edge_color.signal_color_set().connect([this, plot](){plot->set_edge_color(edge_color.get_rgba());}); grid.attach(edge_color_label, 0, row_counter, 1, 1); grid.attach(edge_color, 1, row_counter++, 1, 1); //the edge width spinbutton edge_width_label.set_hexpand(true); edge_width_label.set_vexpand(false); edge_width_label.set_valign(Gtk::ALIGN_CENTER); edge_width_label.set_halign(Gtk::ALIGN_END); edge_width_spin.set_hexpand(true); edge_width_spin.set_vexpand(false); edge_width_spin.set_halign(Gtk::ALIGN_START); edge_width_spin.set_valign(Gtk::ALIGN_CENTER); edge_width_spin.set_wrap(true); edge_width_spin.set_snap_to_ticks(true); edge_width_spin.set_numeric(true); edge_width_spin.set_value(plot->get_edge_width()); edge_width_spin.signal_value_changed().connect([this, plot](){ plot->set_edge_width(edge_width_spin.get_value()); }); grid.attach(edge_width_label, 0, row_counter, 1, 1); grid.attach(edge_width_spin, 1, row_counter++, 1, 1); //nlevels nlevels_label.set_hexpand(true); nlevels_label.set_vexpand(false); nlevels_label.set_valign(Gtk::ALIGN_CENTER); nlevels_label.set_halign(Gtk::ALIGN_END); nlevels_spin.set_hexpand(true); nlevels_spin.set_vexpand(false); nlevels_spin.set_halign(Gtk::ALIGN_START); nlevels_spin.set_valign(Gtk::ALIGN_CENTER); nlevels_spin.set_wrap(true); nlevels_spin.set_snap_to_ticks(true); nlevels_spin.set_numeric(true); nlevels_spin.set_value(plot->get_nlevels()); nlevels_spin.signal_value_changed().connect([this, plot](){ plot->set_nlevels(nlevels_spin.get_value()); }); grid.attach(nlevels_label, 0, row_counter, 1, 1); grid.attach(nlevels_spin, 1, row_counter++, 1, 1); // colormap palette colormap_palette_label.set_hexpand(true); colormap_palette_label.set_vexpand(false); colormap_palette_label.set_valign(Gtk::ALIGN_CENTER); colormap_palette_label.set_halign(Gtk::ALIGN_END); colormap_palette_combo.set_hexpand(true); colormap_palette_combo.set_vexpand(false); colormap_palette_combo.set_halign(Gtk::ALIGN_START); colormap_palette_combo.set_valign(Gtk::ALIGN_CENTER); colormap_palette_combo.append("Default"); colormap_palette_combo.append("Blue → Red"); colormap_palette_combo.append("Blue → Yellow"); colormap_palette_combo.append("Gray"); colormap_palette_combo.append("High frequencies"); colormap_palette_combo.append("Low frequencies"); colormap_palette_combo.append("Radar"); colormap_palette_combo.set_active(plot->get_colormap_palette()); colormap_palette_combo.signal_changed().connect([this, plot](){ plot->set_colormap_palette(static_cast<Gtk::PLplot::ColormapPalette>(colormap_palette_combo.get_active_row_number())); }); grid.attach(colormap_palette_label, 0, row_counter, 1, 1); grid.attach(colormap_palette_combo, 1, row_counter++, 1, 1); //area fill pattern area_fill_pattern_label.set_hexpand(true); area_fill_pattern_label.set_vexpand(false); area_fill_pattern_label.set_valign(Gtk::ALIGN_CENTER); area_fill_pattern_label.set_halign(Gtk::ALIGN_END); area_fill_pattern_combo.set_hexpand(true); area_fill_pattern_combo.set_vexpand(false); area_fill_pattern_combo.set_halign(Gtk::ALIGN_START); area_fill_pattern_combo.set_valign(Gtk::ALIGN_CENTER); area_fill_pattern_combo.append("Solid"); area_fill_pattern_combo.append("Horizontal lines"); area_fill_pattern_combo.append("Vertical lines"); area_fill_pattern_combo.append("Upward lines at 45 degrees"); area_fill_pattern_combo.append("Downward lines at 45 degrees"); area_fill_pattern_combo.append("Upward lines at 30 degrees"); area_fill_pattern_combo.append("Downward lines at 30 degrees"); area_fill_pattern_combo.append("Horizontal and vertical lines"); area_fill_pattern_combo.append("Upward and downward lines at 45 degrees"); area_fill_pattern_combo.set_active(plot->get_area_fill_pattern()); area_fill_pattern_combo.signal_changed().connect([this, plot](){ plot->set_area_fill_pattern(static_cast<Gtk::PLplot::AreaFillPattern>(area_fill_pattern_combo.get_active_row_number())); if (area_fill_pattern_combo.get_active_row_number() == 0 /* SOLID */) { area_lines_width_spin.set_sensitive(false); } else { area_lines_width_spin.set_sensitive(); } }); grid.attach(area_fill_pattern_label, 0, row_counter, 1, 1); grid.attach(area_fill_pattern_combo, 1, row_counter++, 1, 1); //the area lines width spinbutton area_lines_width_label.set_hexpand(true); area_lines_width_label.set_vexpand(false); area_lines_width_label.set_valign(Gtk::ALIGN_CENTER); area_lines_width_label.set_halign(Gtk::ALIGN_END); area_lines_width_spin.set_hexpand(true); area_lines_width_spin.set_vexpand(false); area_lines_width_spin.set_halign(Gtk::ALIGN_START); area_lines_width_spin.set_valign(Gtk::ALIGN_CENTER); area_lines_width_spin.set_wrap(true); area_lines_width_spin.set_snap_to_ticks(true); area_lines_width_spin.set_numeric(true); area_lines_width_spin.set_value(plot->get_area_lines_width()); area_lines_width_spin.signal_value_changed().connect([this, plot](){ plot->set_area_lines_width(area_lines_width_spin.get_value()); }); area_lines_width_spin.set_sensitive(false); grid.attach(area_lines_width_label, 0, row_counter, 1, 1); grid.attach(area_lines_width_spin, 1, row_counter++, 1, 1); //colorbar colorbar_label.set_hexpand(true); colorbar_label.set_vexpand(false); colorbar_label.set_valign(Gtk::ALIGN_CENTER); colorbar_label.set_halign(Gtk::ALIGN_END); colorbar_switch.set_hexpand(true); colorbar_switch.set_vexpand(false); colorbar_switch.set_halign(Gtk::ALIGN_START); colorbar_switch.set_valign(Gtk::ALIGN_CENTER); colorbar_switch.set_active(plot->is_showing_colorbar()); colorbar_switch.property_active().signal_changed().connect([this, plot](){ if (colorbar_switch.get_active()) { plot->show_colorbar(); } else { plot->hide_colorbar(); } }); grid.attach(colorbar_label, 0, row_counter, 1, 1); grid.attach(colorbar_switch, 1, row_counter++, 1, 1); paned.add1(grid); //add canvas to grid aspect_frame.add(canvas); paned.add2(aspect_frame); //finishing up add(paned); set_border_width(10); #if GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION >= 18 paned.set_wide_handle(true); #endif paned.show_all(); }