File: GtkMessageDialog.xs

package info (click to toggle)
libgtk2-perl 2:1.2499-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,668 kB
  • ctags: 594
  • sloc: perl: 22,100; ansic: 122; makefile: 17
file content (202 lines) | stat: -rw-r--r-- 6,291 bytes parent folder | download | duplicates (3)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
 * Copyright (c) 2003-2006 by the gtk2-perl team (see the file AUTHORS)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the 
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 
 * Boston, MA  02111-1307  USA.
 *
 * $Id$
 */

#include "gtk2perl.h"

static char *
format_message (SV * format, SV ** start, int count)
{
	/* text passed to GTK+ must be UTF-8.  force it. */
	STRLEN patlen;
	gchar * pat;
	SV * message = sv_newmortal ();

	SvUTF8_on (message);
	sv_utf8_upgrade (format);
	pat = SvPV (format, patlen);
	sv_vsetpvfn (message, pat, patlen, NULL, start, count, Null(bool*));

	return SvPV_nolen (message);
}

MODULE = Gtk2::MessageDialog	PACKAGE = Gtk2::MessageDialog	PREFIX = gtk_message_dialog_

=for position SYNOPSIS

=head1 SYNOPSIS

  #
  # A modal dialog.  Note that the message is a printf-style format.
  #
  $dialog = Gtk2::MessageDialog->new ($main_application_window,
                                      'destroy-with-parent',
                                      'question', # message type
                                      'yes-no', # which set of buttons?
                                      "Pay me $%.2f?", $amount);
  $response = $dialog->run;
  if ($response eq 'yes') {
      send_bill ();
  }
  $dialog->destroy;

  #
  # A non-modal dialog.
  #
  $dialog = Gtk2::MessageDialog->new ($main_application_window,
                                      'destroy-with-parent',
                                      'question', # message type
                                      'ok-cancel', # which set of buttons?
                                      "Self-destruct now?");
  # react whenever the user responds.
  $dialog->signal_connect (response => sub {
             my ($self, $response) = @_;
             if ($response eq 'ok') {
                     do_the_thing ();
             }
             $self->destroy;
  });
  $dialog->show_all;

=cut


=for position DESCRIPTION

=head1 DESCRIPTION


Gtk2::MessageDialog is a dialog with an image representing the type of message
(Error, Question, etc.) alongside some message text.  It's simply a convenience
widget; you could construct the equivalent of Gtk2::MessageDialog from Gtk2::Dialog
without too much effort, but Gtk2::MessageDialog saves typing and helps create a
consistent look and feel for your application.

The easiest way to do a modal message dialog is to use C<< $dialog->run >>, which
automatically makes your dialog modal and waits for the user to respond to it.
You can also pass in the GTK_DIALOG_MODAL flag when creating the MessageDialog.

=cut


=for apidoc
=for args format a printf format specifier.  may be undef.
=for args ... arguments for I<$format>
Create a new Gtk2::Dialog with a simple message.  It will also include an
icon, as determined by I<$type>.  If you need buttons not available through
Gtk2::ButtonsType, use 'none' and add buttons with C<< $dialog->add_buttons >>.
=cut
GtkWidget *
gtk_message_dialog_new (class, parent, flags, type, buttons, format, ...)
	GtkWindow_ornull * parent
	GtkDialogFlags flags
	GtkMessageType type
	GtkButtonsType buttons
	SV * format
    CODE:
	if (gperl_sv_is_defined (format))
		/* the double-indirection is necessary to avoid % chars in the
		 * message string being misinterpreted. */
		RETVAL = gtk_message_dialog_new (
		           parent, flags, type, buttons,
	                   "%s",
		           format_message (format, &(ST (6)), items - 6));
	else
		RETVAL = gtk_message_dialog_new (parent, flags, type,
		                                 buttons, NULL);
		/* -Wall warns about the NULL format string here, but
		 * gtk_message_dialog_new() explicitly allows it. */
    OUTPUT:
	RETVAL

#if GTK_CHECK_VERSION(2,4,0)

=for apidoc
=for arg message a string containing Pango markup
Like C<new>, but allowing Pango markup tags in the message.  Note that this
version is not variadic.
=cut
GtkWidget *
gtk_message_dialog_new_with_markup (class, parent, flags, type, buttons, message)
	GtkWindow_ornull * parent
	GtkDialogFlags flags
	GtkMessageType type
	GtkButtonsType buttons
	gchar_ornull * message
    CODE:
	/* -Wall warns about the NULL format string here, but
	 * gtk_message_dialog_new() explicitly allows it. */
	RETVAL = gtk_message_dialog_new (parent, flags, type, buttons, NULL);
	gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (RETVAL), message);
    OUTPUT:
	RETVAL

void
gtk_message_dialog_set_markup (GtkMessageDialog *message_dialog, const gchar *str)

#endif

#if GTK_CHECK_VERSION(2,6,0)

void
gtk_message_dialog_format_secondary_text (message_dialog, message_format, ...)
	GtkMessageDialog *message_dialog
	SV * message_format
    CODE:
	if (gperl_sv_is_defined (message_format))
		gtk_message_dialog_format_secondary_text (
		  message_dialog,
		  "%s",
		  format_message (message_format, &(ST (2)), items - 2));
	else
		gtk_message_dialog_format_secondary_text (message_dialog, NULL);

void
gtk_message_dialog_format_secondary_markup (message_dialog, message_format, ...)
	GtkMessageDialog *message_dialog
	SV * message_format
    CODE:
	if (gperl_sv_is_defined (message_format))
		gtk_message_dialog_format_secondary_markup (
		  message_dialog,
		  "%s",
		  format_message (message_format, &(ST (2)), items - 2));
	else
		gtk_message_dialog_format_secondary_markup (message_dialog, NULL);

#endif

#if GTK_CHECK_VERSION(2,10,0)

void gtk_message_dialog_set_image (GtkMessageDialog *dialog, GtkWidget *image);

#endif

#if GTK_CHECK_VERSION (2, 14, 0)

GtkWidget* gtk_message_dialog_get_image (GtkMessageDialog *dialog);

#endif /* 2.14 */

#if GTK_CHECK_VERSION (2, 22, 0)

GtkWidget * gtk_message_dialog_get_message_area (GtkMessageDialog *message_dialog);

#endif /* 2.22 */