File: dialogs.c

package info (click to toggle)
dia 0.97.3%2Bgit20220525-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 52,964 kB
  • sloc: ansic: 159,727; xml: 14,075; python: 6,260; cpp: 3,588; sh: 458; perl: 137; makefile: 26
file content (105 lines) | stat: -rw-r--r-- 3,731 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* Dia -- a diagram creation/manipulation program
 * Copyright (C) 1998 Alexander Larsson
 *
 * dialogs.c: helper routines for creating simple dialogs
 * Copyright (C) 2002 Lars Clausen
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include <config.h>

#include "intl.h"
#include <gtk/gtk.h>
#include "geometry.h"
#include "dialogs.h"

/* Functions to create dialog widgets.  These should, if used in other
   dialogs, go into a separate file.  They are intended for fairly small
   transient dialogs such as parameters for exports.  The functions are
   meant to be transparent in that they don't make their own structures,
   they're just collections of common actions.
*/

/**
 * dialog_make:
 * @title: dialog title
 * @okay_text: label for @okay_button
 * @cancel_text: label of @cancel_button
 * @okay_button: (out): the accept #GtkButton
 * @cancel_button: (out): the reject #GtkButton
 *
 * Creates a new dialog with a title and Ok and Cancel buttons.
 *
 * Default texts are supplied for Ok and Cancel buttons if %NULL.
 *
 * This function does not call gtk_widget_show(), do
 * gtk_widget_show_all() when all has been added.
 *
 * Returns: the created dialog and sets the two widget pointers.
 */
GtkWidget *
dialog_make (char       *title,
             char       *okay_text,
             char       *cancel_text,
             GtkWidget **okay_button,
             GtkWidget **cancel_button)
{
  GtkWidget *dialog = gtk_dialog_new ();
  GtkWidget *label = gtk_label_new (title);

  gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG(dialog))), label);

  *okay_button = gtk_button_new_with_label ((okay_text != NULL ? okay_text : _("OK")));
  *cancel_button = gtk_button_new_with_label ((cancel_text != NULL ? cancel_text : _("Cancel")));

  gtk_container_add (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dialog))),
                     *okay_button);
  gtk_container_add (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG(dialog))),
                     *cancel_button);

  return dialog;
}

/**
 * dialog_add_spinbutton:
 * @dialog: the #GtkDialog
 * @title: the spin box label
 * @min: minimum value
 * @max: the maximum value
 * @decimals: how many digits
 *
 * Adds a spinbutton with an attached label to a dialog.
 * To get an integer spinbutton, give decimals as 0.
*/
GtkSpinButton *
dialog_add_spinbutton (GtkWidget *dialog,
                       char      *title,
                       real       min,
                       real       max,
                       real       decimals) {
  GtkAdjustment *limits =
    GTK_ADJUSTMENT (gtk_adjustment_new (10.0, min, max, 1.0, 10.0, 0));
  GtkWidget *box = gtk_hbox_new (FALSE, 10);
  GtkWidget *label = gtk_label_new (title);
  GtkWidget *entry = gtk_spin_button_new (limits, 10.0, decimals);

  gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (box), entry, TRUE, TRUE, 0);
  gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), box);

  return GTK_SPIN_BUTTON (entry);
}