From 74bb981ed2e342cf5ea4cc50285eb960e6d68426 Mon Sep 17 00:00:00 2001 From: Luca Bacci Date: Wed, 20 Feb 2019 12:20:20 +0100 Subject: [PATCH] Use Gdk::RGBA (!25) The Gdk::RGBA data type was introduced to replace Gdk::Color in Gtkmm 3.0 [1], with Gdk::Color being deprecated in Gtkmm 3.10 [2]. With this commit we make the change to Gdk::RGBA data type which is the modern replacement to Gdk::Color. Gdk::RGBA can be used almost as a drop in replacement because it keeps most of the Gdk::Color interface. Also, this commit removes the C Gtk call introduced during the port-to-gtk3 patchset by commit: 53793527668a344fe54ceb61a1afdc39c24c5c45 repare-for-gtk3: Prepare for removal of Gtk::Widget::modify_fg() (#7) [1] Gtkmm 3.0.1 NEWS file https://gitlab.gnome.org/GNOME/gtkmm/blob/3.0.1/NEWS#L48 * RGBA replaces Color, though Color still exists because it is used by TextView. We hope to deprecated Color completely in gtkmm 3.2. [2] Gtkmm 3.10.0 NEWS file https://gitlab.gnome.org/GNOME/gtkmm/blob/3.10.0/NEWS#L127 Gdk: * Deprecate Color. Closes !25 - Modern Gtk3 - part 1 --- include/Dialog_Partition_Info.h | 6 +++++- include/DrawingAreaVisualDisk.h | 7 +++++-- include/Frame_Resizer_Base.h | 13 +++++++++---- src/Dialog_Partition_Copy.cc | 6 +++--- src/Dialog_Partition_Info.cc | 10 +++++----- src/Dialog_Partition_New.cc | 2 +- src/Dialog_Partition_Resize_Move.cc | 6 +++--- src/Dialog_Rescue_Data.cc | 3 +-- src/DrawingAreaVisualDisk.cc | 12 ++++++------ src/Frame_Resizer_Base.cc | 20 ++++++++++---------- src/Frame_Resizer_Extended.cc | 8 ++++---- 11 files changed, 52 insertions(+), 41 deletions(-) diff --git a/include/Dialog_Partition_Info.h b/include/Dialog_Partition_Info.h index 7a5851d8..7be93e2a 100644 --- a/include/Dialog_Partition_Info.h +++ b/include/Dialog_Partition_Info.h @@ -58,7 +58,11 @@ private: Glib::RefPtr pango_layout; - Gdk::Color color_partition, color_used, color_unused, color_unallocated, color_text ; + Gdk::RGBA color_partition; + Gdk::RGBA color_used; + Gdk::RGBA color_unused; + Gdk::RGBA color_unallocated; + Gdk::RGBA color_text; int used, unused, unallocated ; }; diff --git a/include/DrawingAreaVisualDisk.h b/include/DrawingAreaVisualDisk.h index 226051dd..42e9d879 100644 --- a/include/DrawingAreaVisualDisk.h +++ b/include/DrawingAreaVisualDisk.h @@ -81,7 +81,7 @@ private: int y_usage_start, usage_height ; int x_text, y_text ; - Gdk::Color color ; + Gdk::RGBA color; Glib::RefPtr pango_layout; // Pointer to real partition. (Alias to element in Win_GParted::display_partitions[] vector). @@ -115,7 +115,10 @@ private: const visual_partition * selected_vp ; int TOT_SEP, MIN_SIZE ; - Gdk::Color color_used, color_unused, color_unallocated, color_text; + Gdk::RGBA color_used; + Gdk::RGBA color_unused; + Gdk::RGBA color_unallocated; + Gdk::RGBA color_text; }; } //GParted diff --git a/include/Frame_Resizer_Base.h b/include/Frame_Resizer_Base.h index e671b566..5c53c92f 100644 --- a/include/Frame_Resizer_Base.h +++ b/include/Frame_Resizer_Base.h @@ -38,9 +38,9 @@ public: Frame_Resizer_Base() ; ~Frame_Resizer_Base() ; - void set_rgb_partition_color( const Gdk::Color & color ) ; - void override_default_rgb_unused_color( const Gdk::Color & color ) ; - + void set_rgb_partition_color(const Gdk::RGBA& color); + void override_default_rgb_unused_color(const Gdk::RGBA& color); + void set_x_min_space_before( int x_min_space_before ) ; void set_x_start( int x_start ) ; void set_x_end( int x_end ) ; @@ -78,7 +78,12 @@ protected: Gtk::DrawingArea drawingarea ; - Gdk::Color color_used, color_unused, color_arrow, color_background, color_partition, color_arrow_rectangle; + Gdk::RGBA color_used; + Gdk::RGBA color_unused; + Gdk::RGBA color_arrow; + Gdk::RGBA color_background; + Gdk::RGBA color_partition; + Gdk::RGBA color_arrow_rectangle; std::vector arrow_points; diff --git a/src/Dialog_Partition_Copy.cc b/src/Dialog_Partition_Copy.cc index 3315c4cf..b81fc03f 100644 --- a/src/Dialog_Partition_Copy.cc +++ b/src/Dialog_Partition_Copy.cc @@ -46,9 +46,9 @@ Dialog_Partition_Copy::~Dialog_Partition_Copy() void Dialog_Partition_Copy::set_data( const Partition & selected_partition, const Partition & copied_partition ) { this ->set_title( Glib::ustring::compose( _("Paste %1"), copied_partition .get_path() ) ) ; - - //set partition color - Gdk::Color partition_color( Utils::get_color( copied_partition.filesystem ) ); + + // Set partition color + Gdk::RGBA partition_color(Utils::get_color(copied_partition.filesystem)); frame_resizer_base->set_rgb_partition_color( partition_color ); //set some widely used values... diff --git a/src/Dialog_Partition_Info.cc b/src/Dialog_Partition_Info.cc index 79bf6380..80cc7255 100644 --- a/src/Dialog_Partition_Info.cc +++ b/src/Dialog_Partition_Info.cc @@ -120,14 +120,14 @@ Dialog_Partition_Info::Dialog_Partition_Info( const Partition & partition ) : pa bool Dialog_Partition_Info::drawingarea_on_draw(const Cairo::RefPtr& cr) { - Gdk::Cairo::set_source_color(cr, color_partition); + Gdk::Cairo::set_source_rgba(cr, color_partition); cr->rectangle(0, 0, 400, 60); cr->fill(); if ( partition.filesystem != FS_UNALLOCATED ) { // Used - Gdk::Cairo::set_source_color(cr, color_used); + Gdk::Cairo::set_source_rgba(cr, color_used); cr->rectangle(BORDER, BORDER, used, @@ -135,7 +135,7 @@ bool Dialog_Partition_Info::drawingarea_on_draw(const Cairo::RefPtrfill(); // Unused - Gdk::Cairo::set_source_color(cr, color_unused); + Gdk::Cairo::set_source_rgba(cr, color_unused); cr->rectangle(BORDER + used, BORDER, unused, @@ -143,7 +143,7 @@ bool Dialog_Partition_Info::drawingarea_on_draw(const Cairo::RefPtrfill(); // Unallocated - Gdk::Cairo::set_source_color(cr, color_unallocated); + Gdk::Cairo::set_source_rgba(cr, color_unallocated); cr->rectangle(BORDER + used + unused, BORDER, unallocated, @@ -152,7 +152,7 @@ bool Dialog_Partition_Info::drawingarea_on_draw(const Cairo::RefPtrmove_to(180, BORDER + 6); pango_layout->show_in_cairo_context(cr); diff --git a/src/Dialog_Partition_New.cc b/src/Dialog_Partition_New.cc index ddedb966..0bc122cd 100644 --- a/src/Dialog_Partition_New.cc +++ b/src/Dialog_Partition_New.cc @@ -373,7 +373,7 @@ void Dialog_Partition_New::combobox_changed(bool type) //set fitting resizer colors { - Gdk::Color color_temp; + Gdk::RGBA color_temp; //Background color color_temp.set((combo_type.get_active_row_number() == 2) ? "darkgrey" : "white"); frame_resizer_base->override_default_rgb_unused_color(color_temp); diff --git a/src/Dialog_Partition_Resize_Move.cc b/src/Dialog_Partition_Resize_Move.cc index 0502eab8..16e67cc7 100644 --- a/src/Dialog_Partition_Resize_Move.cc +++ b/src/Dialog_Partition_Resize_Move.cc @@ -57,9 +57,9 @@ void Dialog_Partition_Resize_Move::set_data( const Partition & selected_partitio Set_Resizer( false ) ; Resize_Move_Normal( partitions ) ; } - - //set partition color - Gdk::Color partition_color( Utils::get_color( selected_partition.filesystem ) ); + + // Set partition color + Gdk::RGBA partition_color(Utils::get_color(selected_partition.filesystem)); frame_resizer_base->set_rgb_partition_color( partition_color ); //store the original values diff --git a/src/Dialog_Rescue_Data.cc b/src/Dialog_Rescue_Data.cc index a9c40565..a9f594b9 100644 --- a/src/Dialog_Rescue_Data.cc +++ b/src/Dialog_Rescue_Data.cc @@ -69,8 +69,7 @@ void Dialog_Rescue_Data::draw_dialog() msg_label.append(_("You might encounter errors trying to view these file systems.")); Gtk::Label *inconsis_label=manage(Utils::mk_label(msg_label)); - Gdk::Color c( "red" ); - gtk_widget_modify_fg(GTK_WIDGET(inconsis_label->gobj()), GTK_STATE_NORMAL, c.gobj()); + inconsis_label->override_color(Gdk::RGBA("red"), Gtk::STATE_FLAG_NORMAL); this->get_vbox()->pack_end(*inconsis_label, Gtk::PACK_SHRINK, 5); } message->append(""); diff --git a/src/DrawingAreaVisualDisk.cc b/src/DrawingAreaVisualDisk.cc index 6589a842..af3ade32 100644 --- a/src/DrawingAreaVisualDisk.cc +++ b/src/DrawingAreaVisualDisk.cc @@ -220,7 +220,7 @@ void DrawingAreaVisualDisk::draw_partition(const Cairo::RefPtr& const visual_partition& vp) { //partition... - Gdk::Cairo::set_source_color(cr, vp.color); + Gdk::Cairo::set_source_rgba(cr, vp.color); cr->rectangle(vp.x_start, vp.y_start, vp.length, @@ -230,7 +230,7 @@ void DrawingAreaVisualDisk::draw_partition(const Cairo::RefPtr& //used.. if ( vp .used_length > 0 ) { - Gdk::Cairo::set_source_color(cr, color_used); + Gdk::Cairo::set_source_rgba(cr, color_used); cr->rectangle(vp.x_used_start, vp.y_usage_start, vp.used_length, @@ -241,7 +241,7 @@ void DrawingAreaVisualDisk::draw_partition(const Cairo::RefPtr& //unused if ( vp .unused_length > 0 ) { - Gdk::Cairo::set_source_color(cr, color_unused); + Gdk::Cairo::set_source_rgba(cr, color_unused); cr->rectangle(vp.x_unused_start, vp.y_usage_start, vp.unused_length, @@ -252,7 +252,7 @@ void DrawingAreaVisualDisk::draw_partition(const Cairo::RefPtr& //unallocated if ( vp .unallocated_length > 0 ) { - Gdk::Cairo::set_source_color(cr, color_unallocated); + Gdk::Cairo::set_source_rgba(cr, color_unallocated); cr->rectangle(vp.x_unallocated_start, vp.y_usage_start, vp.unallocated_length, @@ -263,7 +263,7 @@ void DrawingAreaVisualDisk::draw_partition(const Cairo::RefPtr& //text if ( vp .x_text > 0 ) { - Gdk::Cairo::set_source_color(cr, color_text); + Gdk::Cairo::set_source_rgba(cr, color_text); cr->move_to(vp.x_text, vp.y_text); vp.pango_layout->show_in_cairo_context(cr); } @@ -328,7 +328,7 @@ bool DrawingAreaVisualDisk::on_draw(const Cairo::RefPtr& cr) //selection if ( selected_vp ) { - Gdk::Cairo::set_source_color(cr, color_used); + Gdk::Cairo::set_source_rgba(cr, color_used); cr->rectangle(selected_vp->x_start + BORDER/2, selected_vp->y_start + BORDER/2, selected_vp->length - BORDER, diff --git a/src/Frame_Resizer_Base.cc b/src/Frame_Resizer_Base.cc index 77608a33..8a36c028 100644 --- a/src/Frame_Resizer_Base.cc +++ b/src/Frame_Resizer_Base.cc @@ -74,12 +74,12 @@ void Frame_Resizer_Base::init() this ->show_all_children(); } -void Frame_Resizer_Base::set_rgb_partition_color( const Gdk::Color & color ) +void Frame_Resizer_Base::set_rgb_partition_color(const Gdk::RGBA& color) { this ->color_partition = color ; } -void Frame_Resizer_Base::override_default_rgb_unused_color( const Gdk::Color & color ) +void Frame_Resizer_Base::override_default_rgb_unused_color(const Gdk::RGBA& color) { this ->color_unused = color ; } @@ -366,29 +366,29 @@ void Frame_Resizer_Base::draw_partition(const Cairo::RefPtr& cr) UNUSED = 0 ; // Background color - Gdk::Cairo::set_source_color(cr, color_background); + Gdk::Cairo::set_source_rgba(cr, color_background); cr->rectangle(0, 0, 536, 50); cr->fill(); // The two rectangles on each side of the partition - Gdk::Cairo::set_source_color(cr, color_arrow_rectangle); + Gdk::Cairo::set_source_rgba(cr, color_arrow_rectangle); cr->rectangle(0, 0, 10, 50); cr->fill(); cr->rectangle(526, 0, 10, 50); cr->fill(); // Partition - Gdk::Cairo::set_source_color(cr, color_partition); + Gdk::Cairo::set_source_rgba(cr, color_partition); cr->rectangle(X_START, 0, X_END - X_START, 50); cr->fill(); // Used - Gdk::Cairo::set_source_color(cr, color_used); + Gdk::Cairo::set_source_rgba(cr, color_used); cr->rectangle(X_START + BORDER, BORDER, USED, 34); cr->fill(); // Unused - Gdk::Cairo::set_source_color(cr, color_unused); + Gdk::Cairo::set_source_rgba(cr, color_unused); cr->rectangle(X_START + BORDER + USED, BORDER, UNUSED, 34); cr->fill(); @@ -414,16 +414,16 @@ void Frame_Resizer_Base::draw_resize_grip(const Cairo::RefPtr& c arrow_points[ 1 ] .set_x( X_END + GRIPPER ) ; arrow_points[ 2 ] .set_x( X_END ) ; } - + // Attach resize arrows to the partition - Gdk::Cairo::set_source_color(cr, color_arrow_rectangle); + Gdk::Cairo::set_source_rgba(cr, color_arrow_rectangle); cr->rectangle((arrow_type == ARROW_LEFT ? X_START - GRIPPER : X_END + 1) + 0.5, 5 + 0.5, 9, 40); cr->stroke(); - Gdk::Cairo::set_source_color(cr, color_arrow); + Gdk::Cairo::set_source_rgba(cr, color_arrow); cr->move_to(arrow_points[0].get_x(), arrow_points[0].get_y()); cr->line_to(arrow_points[1].get_x(), arrow_points[1].get_y()); cr->line_to(arrow_points[2].get_x(), arrow_points[2].get_y()); diff --git a/src/Frame_Resizer_Extended.cc b/src/Frame_Resizer_Extended.cc index 284c4c94..6619b360 100644 --- a/src/Frame_Resizer_Extended.cc +++ b/src/Frame_Resizer_Extended.cc @@ -162,24 +162,24 @@ bool Frame_Resizer_Extended::drawingarea_on_mouse_motion( GdkEventMotion * ev ) void Frame_Resizer_Extended::draw_partition(const Cairo::RefPtr& cr) { // Background color - Gdk::Cairo::set_source_color(cr, color_background); + Gdk::Cairo::set_source_rgba(cr, color_background); cr->rectangle(0, 0, 536, 50); cr->fill(); // The two rectangles on each side of the partition - Gdk::Cairo::set_source_color(cr, color_arrow_rectangle); + Gdk::Cairo::set_source_rgba(cr, color_arrow_rectangle); cr->rectangle(0, 0, 10, 50); cr->fill(); cr->rectangle(526, 0, 10, 50); cr->fill(); // Used - Gdk::Cairo::set_source_color(cr, color_used); + Gdk::Cairo::set_source_rgba(cr, color_used); cr->rectangle(USED_START + BORDER, BORDER, USED, 34); cr->fill(); // Partition - Gdk::Cairo::set_source_color(cr, color_partition); + Gdk::Cairo::set_source_rgba(cr, color_partition); for( short t = 0; t < 9 ; t++ ) { cr->rectangle(X_START + t + 0.5, t + 0.5, X_END - X_START - t*2, 50 - t*2);