2020-11-17 11:16:16 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2001-2006, William Joseph.
|
|
|
|
All Rights Reserved.
|
|
|
|
|
|
|
|
This file is part of GtkRadiant.
|
|
|
|
|
|
|
|
GtkRadiant 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.
|
|
|
|
|
|
|
|
GtkRadiant 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 GtkRadiant; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "dialog.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "button.h"
|
|
|
|
#include "window.h"
|
|
|
|
|
|
|
|
ui::VBox create_dialog_vbox(int spacing, int border)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
auto vbox = ui::VBox(FALSE, spacing);
|
|
|
|
vbox.show();
|
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(vbox), border);
|
|
|
|
return vbox;
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ui::HBox create_dialog_hbox(int spacing, int border)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
auto hbox = ui::HBox(FALSE, spacing);
|
|
|
|
hbox.show();
|
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(hbox), border);
|
|
|
|
return hbox;
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ui::Frame create_dialog_frame(const char *label, ui::Shadow shadow)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
auto frame = ui::Frame(label);
|
|
|
|
frame.show();
|
|
|
|
gtk_frame_set_shadow_type(frame, (GtkShadowType) shadow);
|
|
|
|
return frame;
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ui::Table
|
|
|
|
create_dialog_table(unsigned int rows, unsigned int columns, unsigned int row_spacing, unsigned int col_spacing,
|
|
|
|
int border)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
auto table = ui::Table(rows, columns, FALSE);
|
|
|
|
table.show();
|
|
|
|
gtk_table_set_row_spacings(table, row_spacing);
|
|
|
|
gtk_table_set_col_spacings(table, col_spacing);
|
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(table), border);
|
|
|
|
return table;
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ui::Button create_dialog_button(const char *label, GCallback func, gpointer data)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
auto button = ui::Button(label);
|
|
|
|
button.dimensions(64, -1);
|
|
|
|
button.show();
|
|
|
|
button.connect("clicked", func, data);
|
|
|
|
return button;
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ui::Window
|
|
|
|
create_dialog_window(ui::Window parent, const char *title, GCallback func, gpointer data, int default_w, int default_h)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
ui::Window window = create_floating_window(title, parent);
|
|
|
|
gtk_window_set_default_size(window, default_w, default_h);
|
|
|
|
gtk_window_set_position(window, GTK_WIN_POS_CENTER_ON_PARENT);
|
|
|
|
window.connect("delete_event", func, data);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
return window;
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean modal_dialog_button_clicked(ui::Widget widget, ModalDialogButton *button)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
button->m_dialog.loop = false;
|
|
|
|
button->m_dialog.ret = button->m_value;
|
|
|
|
return TRUE;
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean modal_dialog_delete(ui::Widget widget, GdkEvent *event, ModalDialog *dialog)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
dialog->loop = 0;
|
|
|
|
dialog->ret = eIDCANCEL;
|
|
|
|
return TRUE;
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EMessageBoxReturn modal_dialog_show(ui::Window window, ModalDialog &dialog)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
gtk_grab_add(window);
|
|
|
|
window.show();
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
dialog.loop = true;
|
|
|
|
while (dialog.loop) {
|
|
|
|
gtk_main_iteration();
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
window.hide();
|
|
|
|
gtk_grab_remove(window);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
return dialog.ret;
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ui::Button create_modal_dialog_button(const char *label, ModalDialogButton &button)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
return create_dialog_button(label, G_CALLBACK(modal_dialog_button_clicked), &button);
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ui::Window
|
|
|
|
create_modal_dialog_window(ui::Window parent, const char *title, ModalDialog &dialog, int default_w, int default_h)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
return create_dialog_window(parent, title, G_CALLBACK(modal_dialog_delete), &dialog, default_w, default_h);
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ui::Window
|
|
|
|
create_fixedsize_modal_dialog_window(ui::Window parent, const char *title, ModalDialog &dialog, int width, int height)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
auto window = create_modal_dialog_window(parent, title, dialog, width, height);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
gtk_window_set_resizable(window, FALSE);
|
|
|
|
gtk_window_set_modal(window, TRUE);
|
|
|
|
gtk_window_set_position(window, GTK_WIN_POS_CENTER);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
window_remove_minmax(window);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
//window.dimensions(width, height);
|
|
|
|
//gtk_window_set_default_size(window, width, height);
|
|
|
|
//gtk_window_resize(window, width, height);
|
|
|
|
//GdkGeometry geometry = { width, height, -1, -1, width, height, -1, -1, -1, -1, GDK_GRAVITY_STATIC, };
|
|
|
|
//gtk_window_set_geometry_hints(window, window, &geometry, (GdkWindowHints)(GDK_HINT_POS|GDK_HINT_MIN_SIZE|GDK_HINT_BASE_SIZE));
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
return window;
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean dialog_button_ok(ui::Widget widget, ModalDialog *data)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
data->loop = false;
|
|
|
|
data->ret = eIDOK;
|
|
|
|
return TRUE;
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean dialog_button_cancel(ui::Widget widget, ModalDialog *data)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
data->loop = false;
|
|
|
|
data->ret = eIDCANCEL;
|
|
|
|
return TRUE;
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean dialog_button_yes(ui::Widget widget, ModalDialog *data)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
data->loop = false;
|
|
|
|
data->ret = eIDYES;
|
|
|
|
return TRUE;
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean dialog_button_no(ui::Widget widget, ModalDialog *data)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
data->loop = false;
|
|
|
|
data->ret = eIDNO;
|
|
|
|
return TRUE;
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean dialog_delete_callback(ui::Widget widget, GdkEventAny *event, ModalDialog *data)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
widget.hide();
|
|
|
|
data->loop = false;
|
|
|
|
return TRUE;
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ui::Window create_simple_modal_dialog_window(const char *title, ModalDialog &dialog, ui::Widget contents)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
ui::Window window = create_fixedsize_modal_dialog_window(ui::Window{ui::null}, title, dialog);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
auto vbox1 = create_dialog_vbox(8, 4);
|
|
|
|
window.add(vbox1);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
vbox1.add(contents);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
ui::Alignment alignment = ui::Alignment(0.5, 0.0, 0.0, 0.0);
|
|
|
|
alignment.show();
|
|
|
|
vbox1.pack_start(alignment, FALSE, FALSE, 0);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
auto button = create_dialog_button("OK", G_CALLBACK(dialog_button_ok), &dialog);
|
|
|
|
alignment.add(button);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
return window;
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RadioHBox RadioHBox_new(StringArrayRange names)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
auto hbox = ui::HBox(TRUE, 4);
|
|
|
|
hbox.show();
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
GSList *group = 0;
|
|
|
|
auto radio = ui::RadioButton(ui::null);
|
|
|
|
for (StringArrayRange::Iterator i = names.first; i != names.last; ++i) {
|
|
|
|
radio = ui::RadioButton::from(gtk_radio_button_new_with_label(group, *i));
|
|
|
|
radio.show();
|
|
|
|
hbox.pack_start(radio, FALSE, FALSE, 0);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
group = gtk_radio_button_get_group(radio);
|
|
|
|
}
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
return RadioHBox(hbox, radio);
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PathEntry PathEntry_new()
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
auto frame = ui::Frame();
|
|
|
|
frame.show();
|
|
|
|
gtk_frame_set_shadow_type(frame, GTK_SHADOW_IN);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
// path entry
|
|
|
|
auto hbox = ui::HBox(FALSE, 0);
|
|
|
|
hbox.show();
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
auto entry = ui::Entry(ui::New);
|
|
|
|
gtk_entry_set_has_frame(entry, FALSE);
|
|
|
|
entry.show();
|
|
|
|
hbox.pack_start(entry, TRUE, TRUE, 0);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
// browse button
|
|
|
|
auto button = ui::Button(ui::New);
|
|
|
|
button_set_icon(button, "ellipsis.bmp");
|
|
|
|
button.show();
|
|
|
|
hbox.pack_end(button, FALSE, FALSE, 0);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
frame.add(hbox);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
return PathEntry(frame, entry, button);
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PathEntry_setPath(PathEntry &self, const char *path)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
gtk_entry_set_text(self.m_entry, path);
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
typedef ReferenceCaller<PathEntry, void (const char *), PathEntry_setPath> PathEntrySetPathCaller;
|
2020-11-17 11:16:16 +00:00
|
|
|
|
|
|
|
void BrowsedPathEntry_clicked(ui::Widget widget, BrowsedPathEntry *self)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
self->m_browse(PathEntrySetPathCaller(self->m_entry));
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BrowsedPathEntry::BrowsedPathEntry(const BrowseCallback &browse) :
|
2021-08-04 20:23:18 +00:00
|
|
|
m_entry(PathEntry_new()),
|
|
|
|
m_browse(browse)
|
2020-11-17 11:16:16 +00:00
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
m_entry.m_button.connect("clicked", G_CALLBACK(BrowsedPathEntry_clicked), this);
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ui::Label DialogLabel_new(const char *name)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
auto label = ui::Label(name);
|
|
|
|
label.show();
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
|
|
|
|
gtk_label_set_justify(label, GTK_JUSTIFY_LEFT);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
return label;
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ui::Table DialogRow_new(const char *name, ui::Widget widget)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
auto table = ui::Table(1, 3, TRUE);
|
|
|
|
table.show();
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
gtk_table_set_col_spacings(table, 4);
|
|
|
|
gtk_table_set_row_spacings(table, 0);
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
table.attach(DialogLabel_new(name), {0, 1, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
table.attach(widget, {1, 3, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
|
2020-11-17 11:16:16 +00:00
|
|
|
|
2021-08-04 20:23:18 +00:00
|
|
|
return table;
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogVBox_packRow(ui::Box vbox, ui::Widget row)
|
|
|
|
{
|
2021-08-04 20:23:18 +00:00
|
|
|
vbox.pack_start(row, FALSE, FALSE, 0);
|
2020-11-17 11:16:16 +00:00
|
|
|
}
|