1 /*
2     This file is part of darktable,
3     Copyright (C) 2014-2020 darktable developers.
4 
5     darktable is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9 
10     darktable is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with darktable.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include "dtgtk/drawingarea.h"
20 
21 G_DEFINE_TYPE(GtkDarktableDrawingArea, dtgtk_drawing_area, GTK_TYPE_DRAWING_AREA);
22 
dtgtk_drawing_area_get_request_mode(GtkWidget * widget)23 static GtkSizeRequestMode dtgtk_drawing_area_get_request_mode(GtkWidget *widget)
24 {
25   return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
26 };
27 
dtgtk_drawing_area_get_preferred_height_for_width(GtkWidget * widget,gint for_width,gint * min_height,gint * nat_height)28 static void dtgtk_drawing_area_get_preferred_height_for_width(GtkWidget *widget, gint for_width,
29                                                               gint *min_height, gint *nat_height)
30 {
31   GtkDarktableDrawingArea *da = DTGTK_DRAWING_AREA(widget);
32 
33   *min_height = *nat_height = for_width * da->aspect;
34 }
35 
dtgtk_drawing_area_class_init(GtkDarktableDrawingAreaClass * class)36 static void dtgtk_drawing_area_class_init(GtkDarktableDrawingAreaClass *class)
37 {
38   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(class);
39 
40   widget_class->get_request_mode = dtgtk_drawing_area_get_request_mode;
41   widget_class->get_preferred_height_for_width = dtgtk_drawing_area_get_preferred_height_for_width;
42 }
43 
dtgtk_drawing_area_init(GtkDarktableDrawingArea * da)44 static void dtgtk_drawing_area_init(GtkDarktableDrawingArea *da)
45 {
46   gtk_widget_set_hexpand(GTK_WIDGET(da), TRUE);
47 }
48 
49 // public functions
dtgtk_drawing_area_new_with_aspect_ratio(double aspect)50 GtkWidget *dtgtk_drawing_area_new_with_aspect_ratio(double aspect)
51 {
52   GtkDarktableDrawingArea *da;
53   da = g_object_new(dtgtk_drawing_area_get_type(), NULL);
54   da->aspect = aspect;
55 
56   return (GtkWidget *)da;
57 }
58 
dtgtk_drawing_area_set_aspect_ratio(GtkWidget * widget,double aspect)59 void dtgtk_drawing_area_set_aspect_ratio(GtkWidget *widget, double aspect)
60 {
61   GtkDarktableDrawingArea *da = DTGTK_DRAWING_AREA(widget);
62   da->aspect = aspect;
63   gtk_widget_queue_resize(widget);
64 }
65 
66 // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
67 // vim: shiftwidth=2 expandtab tabstop=2 cindent
68 // kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
69