1 /*
2 * KCemu -- The emulator for the KC85 homecomputer series and much more.
3 * Copyright (C) 1997-2010 Torsten Paul
4 *
5 * This program 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 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program 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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include <string>
21
22 #include "kc/system.h"
23
24 #include "kc/kc.h"
25
26 #include "ui/gtk/cmd.h"
27 #include "ui/gtk/copying.h"
28
29 using namespace std;
30
31 class CMD_copying_window_toggle : public CMD
32 {
33 private:
34 CopyingWindow *_w;
35
36 public:
CMD_copying_window_toggle(CopyingWindow * w)37 CMD_copying_window_toggle(CopyingWindow *w) : CMD("ui-copying-window-toggle")
38 {
39 _w = w;
40 register_cmd("ui-copying-window-toggle", 0);
41 register_cmd("ui-warranty-window-toggle", 1);
42 }
43
execute(CMD_Args * args,CMD_Context context)44 void execute(CMD_Args *args, CMD_Context context)
45 {
46 _w->toggle();
47 if (context == 0)
48 _w->scroll_to_copying();
49 else
50 _w->scroll_to_warranty();
51 }
52 };
53
CopyingWindow(const char * ui_xml_file)54 CopyingWindow::CopyingWindow(const char *ui_xml_file) : UI_Gtk_Window(ui_xml_file)
55 {
56 _font_desc = pango_font_description_new();
57 pango_font_description_set_family(_font_desc, "Courier");
58 pango_font_description_set_style(_font_desc, PANGO_STYLE_NORMAL);
59 pango_font_description_set_variant(_font_desc, PANGO_VARIANT_NORMAL);
60 pango_font_description_set_weight(_font_desc, PANGO_WEIGHT_NORMAL);
61 pango_font_description_set_stretch(_font_desc, PANGO_STRETCH_NORMAL);
62 pango_font_description_set_size(_font_desc, 10 * PANGO_SCALE);
63
64 _cmd = new CMD_copying_window_toggle(this);
65 }
66
~CopyingWindow(void)67 CopyingWindow::~CopyingWindow(void)
68 {
69 delete _cmd;
70 pango_font_description_free(_font_desc);
71 }
72
73 void
init(void)74 CopyingWindow::init(void)
75 {
76 /*
77 * copying window
78 */
79 _window = get_widget("copying_window");
80 gtk_signal_connect(GTK_OBJECT(_window), "delete_event",
81 GTK_SIGNAL_FUNC(cmd_exec_sft),
82 (char *)"ui-copying-window-toggle"); // FIXME:
83
84 /*
85 * scrolled window
86 */
87 _w.scrolled_window = get_widget("main_scrolledwindow");
88
89 /*
90 * label copying
91 */
92 _w.label_license = get_widget("main_label_license");
93 gtk_label_set_text(GTK_LABEL(_w.label_license), kc_get_license());
94 gtk_widget_modify_font(_w.label_license, _font_desc);
95
96 /*
97 * label warranty
98 */
99 string warranty_text = kc_get_warranty();
100 string text = warranty_text + kc_get_license_trailer();
101 _w.label_warranty = get_widget("main_label_warranty");
102 gtk_label_set_text(GTK_LABEL(_w.label_warranty), text.c_str());
103 gtk_widget_modify_font(_w.label_warranty, _font_desc);
104
105 init_dialog("ui-copying-window-toggle", NULL);
106
107 /*
108 * force allocation calculation for this window; so we get
109 * the values for the label width
110 */
111 gtk_widget_realize(_window);
112 }
113
114 void
scroll_to_copying(void)115 CopyingWindow::scroll_to_copying(void)
116 {
117 GtkAdjustment* adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(_w.scrolled_window));
118 if (adj == NULL)
119 return;
120
121 adj->value = 0.0;
122 gtk_signal_emit_by_name(GTK_OBJECT(adj), "value_changed");
123 }
124
125 void
scroll_to_warranty(void)126 CopyingWindow::scroll_to_warranty(void)
127 {
128 GtkAdjustment* adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(_w.scrolled_window));
129 if (adj == NULL)
130 return;
131
132 adj->value = _w.label_license->requisition.height;
133 gtk_signal_emit_by_name(GTK_OBJECT(adj), "value_changed");
134 }
135
136