Commit | Line | Data |
---|---|---|
69695f33 MW |
1 | /* Copyright (c) 2006 by Arkkra Enterprises */ |
2 | /* All rights reserved */ | |
3 | ||
4 | // Code for Help menu item from main toolbar | |
5 | ||
6 | #include "globals.H" | |
7 | #include "Preferences.H" | |
8 | #include "Config.H" | |
9 | #include "Help.H" | |
10 | #include <FL/fl_ask.H> | |
11 | #include <string.h> | |
12 | #include <stdlib.h> | |
13 | ||
14 | ||
15 | // Window for browsing Mup User's Guide | |
16 | ||
17 | Uguide_browser::Uguide_browser(void) | |
18 | : Fl_Double_Window(0, 0, Default_width, Default_height, "Mup User's Guide") | |
19 | { | |
20 | browser_p = new Fl_Help_View(x(), y(), w(), h(), ""); | |
21 | // Set font/size and arrange to get notified of changes in them | |
22 | font_change_reg_p = new Font_change_registration(font_change_cb, (void *) this); | |
23 | ||
24 | // Haven't loaded the User's Guide yet | |
25 | loaded = false; | |
26 | ||
27 | // Allow browser window to be made as big as the user wants | |
28 | size_range(Min_width, Min_height, 0, 0); | |
29 | resizable((Fl_Widget *)browser_p); | |
30 | ||
31 | // Fix problem with following relative links properly. | |
32 | browser_p->link(resolve_link); | |
33 | ||
34 | // Arrange for destructor to clean up new-ed widgets | |
35 | end(); | |
36 | } | |
37 | ||
38 | ||
39 | Uguide_browser::~Uguide_browser(void) | |
40 | { | |
41 | delete font_change_reg_p; | |
42 | font_change_reg_p = 0; | |
43 | } | |
44 | ||
45 | ||
46 | // Load Mup User's Guide into browser, if haven't already done so. | |
47 | ||
48 | void | |
49 | Uguide_browser::load_uguide(void) | |
50 | { | |
51 | if (!loaded) { | |
52 | // Entry under File Locations tells the base directory | |
53 | // for Mup documentation. We concatenate the uguide/index.file | |
54 | // to that directory to get top level file for User's Guide. | |
55 | char * base_url; | |
56 | (void) Preferences_p->get(Mup_documentation_location, base_url, | |
57 | Default_Mup_documentation_location); | |
58 | const char * url = users_guide_index_file(base_url); | |
59 | ||
60 | // Fltk has a bug (at least in some versions): | |
61 | // the documentation claims load() | |
62 | // returns -1 on failure, but in fact it always returns 0. | |
63 | // So the strncmp attempts to deduce if it failed. | |
64 | if (browser_p->load(url) != 0 || | |
65 | strstr(browser_p->value(), "Mup User's Guide") | |
66 | == 0) { | |
67 | fl_alert("Unable to load User's Guide.\n %s\n" | |
68 | "Check settings in Config > File Locations", url); | |
69 | } | |
70 | else { | |
71 | loaded = true; | |
72 | } | |
73 | } | |
74 | } | |
75 | ||
76 | ||
77 | // Callback for when user changes font/size | |
78 | ||
79 | void | |
80 | Uguide_browser::font_change_cb(void * data, Fl_Font font, unsigned char size) | |
81 | { | |
82 | ((Uguide_browser *)data)->font_change(font, size); | |
83 | } | |
84 | ||
85 | void | |
86 | Uguide_browser::font_change(Fl_Font font, unsigned char size) | |
87 | { | |
88 | browser_p->textfont(font); | |
89 | browser_p->textsize(size); | |
90 | } | |
91 | ||
92 | // On Windows, Fl_Help_View doesn't seem to properly follow relative | |
93 | // URLs (it goes relative to current working directory rather than | |
94 | // relative to the file containing the link), | |
95 | // so we use the link() callback to prepend the proper directory. | |
96 | // On Linux, things work fine without this kludge, but things also | |
97 | // work with it, so to keep code common, we do it always. | |
98 | ||
99 | const char * | |
100 | Uguide_browser::resolve_link(Fl_Widget * help_browser_p, const char * uri) | |
101 | { | |
102 | static char link_path[FL_PATH_MAX]; | |
103 | ||
104 | if (strncmp(uri, "http:", 5) == 0) { | |
105 | // Uguide has a few links to arkkra.com. | |
106 | // They won't actually work, because we don't handle | |
107 | // http, but it's better to let them through than to | |
108 | // change the path and really confuse the user. | |
109 | return(uri); | |
110 | } | |
111 | ||
112 | char * base_url; | |
113 | (void) Preferences_p->get(Mup_documentation_location, base_url, | |
114 | Default_Mup_documentation_location); | |
115 | (void) sprintf(link_path, "%s%c%s%c%s", base_url, dir_separator(), | |
116 | uguide_directory, dir_separator(), | |
117 | fl_filename_name(uri)); | |
118 | return((const char *) link_path); | |
119 | } | |
120 | ||
121 | //---- Hints for user when they use Mupmate for the first time | |
122 | // (or they can ask to see it later too) | |
123 | ||
124 | const char * Welcome_message = | |
125 | "Welcome to Mupmate. Mupmate provides an interface to the\n" | |
126 | "Mup music publication program from Arkkra Enterprises,\n" | |
127 | "making it easy to edit, display, and print musical scores.\n" | |
128 | "\n" | |
129 | "If you have not used Mup before, you should begin by selecting\n" | |
130 | " Help > Mup User's Guide\n" | |
131 | "for information on how to use Mup.\n" | |
132 | "\n" | |
133 | "You may also want to verify that the settings under\n" | |
134 | " Config > File Locations and Config > Preferences\n" | |
135 | "are what you want, and adjust them if you wish.\n" | |
136 | "\n" | |
137 | "You are welcome to try out Mup for free to decide whether\n" | |
138 | "it meets your needs. If you decide to keep it, select\n" | |
139 | " Config > Registration Form\n"; | |
140 | ||
141 | StartupHints::StartupHints(void) | |
142 | : Fl_Double_Window(Default_width - 100, Default_height - 100, | |
143 | "Mup Startup Hints") | |
144 | { | |
145 | text_p = new Fl_Text_Display(20, 20, w() - 40, h() - 90); | |
146 | resizable((Fl_Widget *) text_p); | |
147 | text_p->buffer( new Fl_Text_Buffer () ); | |
148 | font_change_reg_p = new Font_change_registration(font_change_cb, (void *) this); | |
149 | text_p->buffer()->text(Welcome_message); | |
150 | char * doc_dir; | |
151 | (void) Preferences_p->get(Mup_documentation_location, doc_dir, | |
152 | Default_Mup_documentation_location); | |
153 | text_p->buffer()->append("\nAdditional documentation is available in the folder:\n "); | |
154 | text_p->buffer()->append(doc_dir); | |
155 | ||
156 | OK_p = new Fl_Return_Button(w() / 2 - 50, h() - 50, 100, 30, | |
157 | "OK"); | |
158 | OK_p->callback(OK_cb, this); | |
159 | show(); | |
160 | end(); | |
161 | ||
162 | Preferences_p->set(Showed_startup_hints, 1); | |
163 | Preferences_p->flush(); | |
164 | } | |
165 | ||
166 | StartupHints::~StartupHints() | |
167 | { | |
168 | delete font_change_reg_p; | |
169 | font_change_reg_p = 0; | |
170 | } | |
171 | ||
172 | // Callback for user clicking OK when done reading startup hints | |
173 | ||
174 | CALL_BACK(StartupHints, OK) | |
175 | { | |
176 | hide(); | |
177 | } | |
178 | ||
179 | ||
180 | // Callback for when user changes font/size | |
181 | ||
182 | void | |
183 | StartupHints::font_change_cb(void * data, Fl_Font font, unsigned char size) | |
184 | { | |
185 | ((StartupHints *)data)->font_change(font, size); | |
186 | } | |
187 | ||
188 | void | |
189 | StartupHints::font_change(Fl_Font font, unsigned char size) | |
190 | { | |
191 | text_p->textfont(font); | |
192 | text_p->textsize(size); | |
193 | text_p->redisplay_range(0, text_p->buffer()->length()); | |
194 | } | |
195 | ||
196 | //-----the "About" window----------------------------------------------- | |
197 | ||
198 | About_dialog::About_dialog(void) | |
199 | : Fl_Double_Window(270, 200, "About Mupmate") | |
200 | { | |
201 | message_p = new Fl_Multiline_Output(20, 20, w() - 40, 120, ""); | |
202 | message_p->value("\n Mupmate is a user interface\n" | |
203 | " for the Mup music publisher\n" | |
204 | " program from www.arkkra.com\n" | |
205 | "\n" | |
206 | " This is Version 5.3"); | |
207 | // Hide the cursor by making same color as background | |
208 | message_p->cursor_color(message_p->color()); | |
209 | ||
210 | ok_p = new Fl_Return_Button((w() - 100) / 2, 155, 100, 30, "OK"); | |
211 | ok_p->callback(OK_cb, this); | |
212 | ||
213 | // Arrange for destructor to clean up new-ed widgets | |
214 | end(); | |
215 | } | |
216 | ||
217 | About_dialog::~About_dialog(void) | |
218 | { | |
219 | } | |
220 | ||
221 | ||
222 | CALL_BACK(About_dialog, OK) | |
223 | { | |
224 | hide(); | |
225 | } | |
226 | ||
227 | //------the Help menu item from main toolbar----------------------------- | |
228 | ||
229 | Help::Help(void) | |
230 | { | |
231 | uguide_p = 0; | |
232 | startup_hints_p = 0; | |
233 | about_p = 0; | |
234 | } | |
235 | ||
236 | Help::~Help(void) | |
237 | { | |
238 | if (about_p != 0) { | |
239 | delete about_p; | |
240 | about_p = 0; | |
241 | } | |
242 | if (startup_hints_p != 0) { | |
243 | delete startup_hints_p; | |
244 | startup_hints_p = 0; | |
245 | } | |
246 | if (uguide_p != 0) { | |
247 | delete uguide_p; | |
248 | uguide_p = 0; | |
249 | } | |
250 | } | |
251 | ||
252 | ||
253 | // Callback for when user requests viewing the Mup User's Guide | |
254 | ||
255 | CALL_BACK(Help, Uguide) | |
256 | { | |
257 | if (uguide_p == 0) { | |
258 | // first time, create widget | |
259 | uguide_p = new Uguide_browser(); | |
260 | } | |
261 | // Always attempt to load in case URL was bad last time but okay now. | |
262 | // If already loaded, this will be a no-op. | |
263 | uguide_p->load_uguide(); | |
264 | uguide_p->show(); | |
265 | } | |
266 | ||
267 | ||
268 | // Callback for when user clicks "Startup Hints" button | |
269 | ||
270 | CALL_BACK(Help, Startup_Hints) | |
271 | { | |
272 | // We delete any existing instance and start over, | |
273 | // just in case the path to the documentation has changed. | |
274 | if (startup_hints_p != 0) { | |
275 | delete startup_hints_p; | |
276 | } | |
277 | startup_hints_p = new StartupHints(); | |
278 | startup_hints_p->show(); | |
279 | } | |
280 | ||
281 | ||
282 | // Callback for when user clicks "About" button | |
283 | ||
284 | CALL_BACK(Help, About) | |
285 | { | |
286 | if (about_p == 0) { | |
287 | // first time, create widget | |
288 | about_p = new About_dialog(); | |
289 | } | |
290 | about_p->show(); | |
291 | } |