1 | #include <stdio.h> |
---|
2 | |
---|
3 | //--------------------------------------------------------------------- |
---|
4 | #include <windows.h> // required for all Windows applications |
---|
5 | #include "resource.h" |
---|
6 | #include <stdio.h> |
---|
7 | #include <stdlib.h> |
---|
8 | #include <stdarg.h> |
---|
9 | #include <io.h> |
---|
10 | #include <sys/types.h> |
---|
11 | #include <sys/stat.h> |
---|
12 | |
---|
13 | #include "cmtw_utils.h" |
---|
14 | |
---|
15 | #include "cmt.h" |
---|
16 | #include "cmt_use.h" |
---|
17 | #include "cmt_constituent.h" |
---|
18 | #include "cmt_generator.h" |
---|
19 | #include "cmt_system.h" |
---|
20 | #include "cmt_symbol.h" |
---|
21 | #include "cmt_tag.h" |
---|
22 | #include "cmt_error.h" |
---|
23 | //--------------------------------------------------------------------- |
---|
24 | |
---|
25 | //--------------------------------------------------------------------- |
---|
26 | #define USE_THREADS 1 |
---|
27 | //--------------------------------------------------------------------- |
---|
28 | |
---|
29 | //--------------------------------------------------------------------- |
---|
30 | // |
---|
31 | // Class definitions |
---|
32 | // |
---|
33 | //--------------------------------------------------------------------- |
---|
34 | |
---|
35 | //--------------------------------------------------------------------- |
---|
36 | class Cmtw; |
---|
37 | //--------------------------------------------------------------------- |
---|
38 | |
---|
39 | //--------------------------------------------------------------------- |
---|
40 | class PackageCreator : public WDialog |
---|
41 | { |
---|
42 | public: |
---|
43 | PackageCreator (Cmtw& cmtw); |
---|
44 | |
---|
45 | int run (HINSTANCE instance, HWND father); |
---|
46 | virtual void action (UINT message_type, |
---|
47 | WPARAM parameter1, |
---|
48 | LPARAM parameter2); |
---|
49 | void init_action (); |
---|
50 | void menu_action (int menu_item, WPARAM parameter1, LPARAM parameter2); |
---|
51 | |
---|
52 | private: |
---|
53 | Cmtw& _cmtw; |
---|
54 | }; |
---|
55 | //--------------------------------------------------------------------- |
---|
56 | |
---|
57 | //--------------------------------------------------------------------- |
---|
58 | class CMT_Run : public WDialog |
---|
59 | { |
---|
60 | public: |
---|
61 | CMT_Run (Cmtw& cmtw); |
---|
62 | |
---|
63 | int run (HINSTANCE instance, HWND father); |
---|
64 | void action (UINT message_type, |
---|
65 | WPARAM parameter1, |
---|
66 | LPARAM parameter2); |
---|
67 | |
---|
68 | void init_action (); |
---|
69 | |
---|
70 | void menu_action (int menu_item, WPARAM parameter1, LPARAM parameter2); |
---|
71 | |
---|
72 | private: |
---|
73 | Cmtw& _cmtw; |
---|
74 | }; |
---|
75 | //--------------------------------------------------------------------- |
---|
76 | |
---|
77 | //--------------------------------------------------------------------- |
---|
78 | class ConstituentEditor : public WDialog |
---|
79 | { |
---|
80 | public: |
---|
81 | ConstituentEditor (cmt_string& line, Cmtw& cmtw); |
---|
82 | |
---|
83 | int run (HINSTANCE instance, HWND father); |
---|
84 | virtual void action (UINT message_type, |
---|
85 | WPARAM parameter1, |
---|
86 | LPARAM parameter2); |
---|
87 | void init_action (); |
---|
88 | void menu_action (int menu_item, WPARAM parameter1, LPARAM parameter2); |
---|
89 | |
---|
90 | private: |
---|
91 | cmt_string& _line; |
---|
92 | Cmtw& _cmtw; |
---|
93 | WEdit _type; |
---|
94 | WEdit _name; |
---|
95 | WList _modules; |
---|
96 | }; |
---|
97 | //--------------------------------------------------------------------- |
---|
98 | |
---|
99 | //--------------------------------------------------------------------- |
---|
100 | class path_selector : public CmtThread |
---|
101 | { |
---|
102 | public: |
---|
103 | static path_selector& instance (); |
---|
104 | |
---|
105 | void start (const cmt_string& path); |
---|
106 | void run (); |
---|
107 | |
---|
108 | private: |
---|
109 | path_selector (); |
---|
110 | |
---|
111 | cmt_string _path; |
---|
112 | }; |
---|
113 | //--------------------------------------------------------------------- |
---|
114 | |
---|
115 | //--------------------------------------------------------------------- |
---|
116 | class Cmtw |
---|
117 | { |
---|
118 | public: |
---|
119 | static Cmtw& instance (); |
---|
120 | BOOL initialize (HINSTANCE instance, HINSTANCE previous_instance, |
---|
121 | int show_mode); |
---|
122 | BOOL run (); |
---|
123 | void disable_package_menu_items (); |
---|
124 | void enable_package_menu_items (); |
---|
125 | void do_show_uses (); |
---|
126 | void do_select_path (); |
---|
127 | void do_select_package (const cmt_string& name = ""); |
---|
128 | void do_select_version (); |
---|
129 | void do_select_tag (const cmt_string& name); |
---|
130 | void do_config (); |
---|
131 | void do_save_requirements (); |
---|
132 | void do_genmake (); |
---|
133 | void do_genmsdev (); |
---|
134 | void do_build_make_setup (); |
---|
135 | void do_build_constituents_makefile (); |
---|
136 | void do_build_constituent_makefiles (); |
---|
137 | bool is_version (const cmt_string& name); |
---|
138 | void select_package (const cmt_string& path, |
---|
139 | const cmt_string& package); |
---|
140 | void select_path (const cmt_string& path, |
---|
141 | const cmt_string& prefix = "", |
---|
142 | int level = 0); |
---|
143 | int show_tags (HWND window, int x, int y, cmt_string& selected_name); |
---|
144 | |
---|
145 | const char* _application_name; |
---|
146 | const char* _title; |
---|
147 | |
---|
148 | HINSTANCE _instance; |
---|
149 | HWND _window; |
---|
150 | |
---|
151 | HWND _the_dialog; |
---|
152 | |
---|
153 | WList _path_list; |
---|
154 | WList _package_list; |
---|
155 | WEdit _package; |
---|
156 | WList _version_list; |
---|
157 | |
---|
158 | WList _requirements; |
---|
159 | |
---|
160 | WList _show_uses; |
---|
161 | WList _show_constituents; |
---|
162 | WList _show_macros; |
---|
163 | WList _show_sets; |
---|
164 | WList _output; |
---|
165 | |
---|
166 | WRadio _set_uses; |
---|
167 | WRadio _set_constituents; |
---|
168 | WRadio _set_macros; |
---|
169 | WRadio _set_sets; |
---|
170 | WRadio _set_output; |
---|
171 | |
---|
172 | WTab _tab; |
---|
173 | WEdit _tag; |
---|
174 | CmtMutex dir_mutex; |
---|
175 | |
---|
176 | private: |
---|
177 | |
---|
178 | Cmtw (); |
---|
179 | |
---|
180 | static LRESULT CALLBACK process_messages (HWND window, |
---|
181 | UINT message_type, |
---|
182 | WPARAM parameter1, |
---|
183 | LPARAM parameter2); |
---|
184 | static LRESULT CALLBACK handle_dialog (HWND dialog, |
---|
185 | UINT message_type, |
---|
186 | WPARAM parameter1, |
---|
187 | LPARAM parameter2); |
---|
188 | |
---|
189 | HANDLE* _objects; |
---|
190 | int _object_count; |
---|
191 | }; |
---|
192 | //--------------------------------------------------------------------- |
---|
193 | |
---|
194 | |
---|
195 | |
---|
196 | //--------------------------------------------------------------------- |
---|
197 | int APIENTRY WinMain (HINSTANCE instance, |
---|
198 | HINSTANCE previous_instance, |
---|
199 | LPSTR command_line, |
---|
200 | int show_mode) |
---|
201 | //--------------------------------------------------------------------- |
---|
202 | { |
---|
203 | Cmtw& cmtw = Cmtw::instance (); |
---|
204 | |
---|
205 | cmtw.initialize (instance, previous_instance, show_mode); |
---|
206 | |
---|
207 | return cmtw.run (); |
---|
208 | |
---|
209 | UNREFERENCED_PARAMETER (command_line); |
---|
210 | |
---|
211 | return (0); |
---|
212 | } |
---|
213 | |
---|
214 | |
---|
215 | |
---|
216 | //--------------------------------------------------------------------- |
---|
217 | // |
---|
218 | // Class implementations |
---|
219 | // |
---|
220 | //--------------------------------------------------------------------- |
---|
221 | |
---|
222 | //--------------------------------------------------------------------- |
---|
223 | PackageCreator::PackageCreator (Cmtw& cmtw) : _cmtw (cmtw) |
---|
224 | { |
---|
225 | } |
---|
226 | |
---|
227 | int PackageCreator::run (HINSTANCE instance, HWND father) |
---|
228 | { |
---|
229 | return (WDialog::run (instance, father, IDD_NEWPACKAGE)); |
---|
230 | } |
---|
231 | |
---|
232 | void PackageCreator::action (UINT message_type, |
---|
233 | WPARAM parameter1, |
---|
234 | LPARAM parameter2) |
---|
235 | { |
---|
236 | } |
---|
237 | |
---|
238 | void PackageCreator::init_action () |
---|
239 | { |
---|
240 | WList list (_dialog, IDNP_PATHLIST); |
---|
241 | |
---|
242 | list.copy (_cmtw._path_list); |
---|
243 | } |
---|
244 | |
---|
245 | void PackageCreator::menu_action (int menu_item, |
---|
246 | WPARAM parameter1, |
---|
247 | LPARAM parameter2) |
---|
248 | { |
---|
249 | switch (menu_item) |
---|
250 | { |
---|
251 | case IDOK: |
---|
252 | { |
---|
253 | WList list (_dialog, IDNP_PATHLIST); |
---|
254 | WEdit p (_dialog, IDNP_PACKAGE); |
---|
255 | WEdit v (_dialog, IDNP_VERSION); |
---|
256 | WEdit pr (_dialog, IDNP_PREFIX); |
---|
257 | |
---|
258 | cmt_string path = list.get_selected (); |
---|
259 | cmt_string package = p.get (); |
---|
260 | cmt_string version = v.get (); |
---|
261 | cmt_string prefix = pr.get (); |
---|
262 | |
---|
263 | mysb s (_cmtw._output); |
---|
264 | cout << "cmt config " << package << " " << |
---|
265 | version << " " << |
---|
266 | path << " " << |
---|
267 | prefix << endl; |
---|
268 | |
---|
269 | if ((package != "") && |
---|
270 | (version != "")) |
---|
271 | { |
---|
272 | if (prefix != "") |
---|
273 | { |
---|
274 | if (path != "") |
---|
275 | { |
---|
276 | path += CmtSystem::file_separator (); |
---|
277 | } |
---|
278 | path += prefix; |
---|
279 | } |
---|
280 | Cmt::configure (); |
---|
281 | Cmt::do_create (package, version, path); |
---|
282 | } |
---|
283 | } |
---|
284 | break; |
---|
285 | case IDCANCEL: |
---|
286 | break; |
---|
287 | default: |
---|
288 | break; |
---|
289 | } |
---|
290 | } |
---|
291 | //--------------------------------------------------------------------- |
---|
292 | |
---|
293 | //--------------------------------------------------------------------- |
---|
294 | CMT_Run::CMT_Run (Cmtw& cmtw) : _cmtw (cmtw) |
---|
295 | { |
---|
296 | } |
---|
297 | |
---|
298 | int CMT_Run::run (HINSTANCE instance, HWND father) |
---|
299 | { |
---|
300 | return (WDialog::run (instance, father, IDD_CMT)); |
---|
301 | } |
---|
302 | |
---|
303 | void CMT_Run::action (UINT message_type, |
---|
304 | WPARAM parameter1, |
---|
305 | LPARAM parameter2) |
---|
306 | { |
---|
307 | } |
---|
308 | |
---|
309 | void CMT_Run::init_action () |
---|
310 | { |
---|
311 | } |
---|
312 | |
---|
313 | void CMT_Run::menu_action (int menu_item, |
---|
314 | WPARAM parameter1, |
---|
315 | LPARAM parameter2) |
---|
316 | { |
---|
317 | switch (menu_item) |
---|
318 | { |
---|
319 | case IDCMT_EXECUTE: |
---|
320 | { |
---|
321 | WEdit command (_dialog, IDCMT_COMMAND); |
---|
322 | WList output (_dialog, IDCMT_OUTPUT); |
---|
323 | |
---|
324 | cmt_string c = "cmt "; |
---|
325 | c += command.get (); |
---|
326 | |
---|
327 | output.clear (); |
---|
328 | { |
---|
329 | mysb s (output); |
---|
330 | cout << c << endl; |
---|
331 | Cmt::parser (c); |
---|
332 | } |
---|
333 | } |
---|
334 | break; |
---|
335 | case IDCANCEL: |
---|
336 | break; |
---|
337 | default: |
---|
338 | break; |
---|
339 | } |
---|
340 | } |
---|
341 | //--------------------------------------------------------------------- |
---|
342 | |
---|
343 | //--------------------------------------------------------------------- |
---|
344 | path_selector& path_selector::instance () |
---|
345 | { |
---|
346 | static path_selector the_instance; |
---|
347 | |
---|
348 | return (the_instance); |
---|
349 | } |
---|
350 | |
---|
351 | path_selector::path_selector () |
---|
352 | { |
---|
353 | } |
---|
354 | |
---|
355 | void path_selector::start (const cmt_string& path) |
---|
356 | { |
---|
357 | Cmtw& cmtw = Cmtw::instance (); |
---|
358 | |
---|
359 | if (is_running ()) |
---|
360 | { |
---|
361 | { |
---|
362 | mysb s (cmtw._output); |
---|
363 | cout << "Path selector already running. Please retry later..." << endl; |
---|
364 | } |
---|
365 | return; |
---|
366 | } |
---|
367 | |
---|
368 | _path = path; |
---|
369 | CmtThread::start (); |
---|
370 | } |
---|
371 | |
---|
372 | void path_selector::run () |
---|
373 | { |
---|
374 | Cmtw& cmtw = Cmtw::instance (); |
---|
375 | |
---|
376 | cmtw._package_list.clear (); |
---|
377 | cmtw._version_list.clear (); |
---|
378 | cmtw._requirements.clear (); |
---|
379 | cmtw._show_uses.clear (); |
---|
380 | cmtw._show_constituents.clear (); |
---|
381 | cmtw._tag.clear (); |
---|
382 | cmtw._show_macros.clear (); |
---|
383 | cmtw._show_sets.clear (); |
---|
384 | cmtw._output.clear (); |
---|
385 | |
---|
386 | { |
---|
387 | mysb s (cmtw._output); |
---|
388 | cout << "Path selector started." << endl; |
---|
389 | } |
---|
390 | |
---|
391 | cmtw.disable_package_menu_items (); |
---|
392 | |
---|
393 | cmtw.select_path (_path); |
---|
394 | |
---|
395 | { |
---|
396 | mysb s (cmtw._output); |
---|
397 | cout << "Path selector terminated." << endl; |
---|
398 | } |
---|
399 | |
---|
400 | } |
---|
401 | //--------------------------------------------------------------------- |
---|
402 | |
---|
403 | //--------------------------------------------------------------------- |
---|
404 | ConstituentEditor::ConstituentEditor (cmt_string& line, Cmtw& cmtw) : |
---|
405 | _line (line), _cmtw (cmtw) |
---|
406 | { |
---|
407 | } |
---|
408 | |
---|
409 | int ConstituentEditor::run (HINSTANCE instance, HWND father) |
---|
410 | { |
---|
411 | return (WDialog::run (instance, father, IDD_CONSTITUENT)); |
---|
412 | } |
---|
413 | |
---|
414 | void ConstituentEditor::action (UINT message_type, |
---|
415 | WPARAM parameter1, |
---|
416 | LPARAM parameter2) |
---|
417 | { |
---|
418 | } |
---|
419 | |
---|
420 | void ConstituentEditor::init_action () |
---|
421 | { |
---|
422 | _type.init (_dialog, IDCE_TYPE); |
---|
423 | _name.init (_dialog, IDCE_NAME); |
---|
424 | _modules.init (_dialog, IDCE_MODULES); |
---|
425 | |
---|
426 | CmtSystem::cmt_string_vector words; |
---|
427 | |
---|
428 | CmtSystem::split (_line, " ", words); |
---|
429 | |
---|
430 | if (words.size () >= 2) |
---|
431 | { |
---|
432 | const cmt_string& t = words[0]; |
---|
433 | if ((t == "library") || |
---|
434 | (t == "application")) |
---|
435 | { |
---|
436 | const cmt_string& name = words[1]; |
---|
437 | |
---|
438 | Constituent* constituent = Constituent::find (name); |
---|
439 | if (constituent != 0) |
---|
440 | { |
---|
441 | _type.set (t); |
---|
442 | _name.set (name); |
---|
443 | _modules.set (constituent->modules); |
---|
444 | } |
---|
445 | } |
---|
446 | } |
---|
447 | } |
---|
448 | |
---|
449 | void ConstituentEditor::menu_action (int menu_item, |
---|
450 | WPARAM parameter1, |
---|
451 | LPARAM parameter2) |
---|
452 | { |
---|
453 | switch (menu_item) |
---|
454 | { |
---|
455 | case IDOK: |
---|
456 | break; |
---|
457 | case IDCANCEL: |
---|
458 | break; |
---|
459 | case IDCE_MODULES: |
---|
460 | if (HIWORD (parameter1) == LBN_DBLCLK) |
---|
461 | { |
---|
462 | cmt_string file_name = _modules.get_selected (); |
---|
463 | cmt_string line = Generator::build_dependencies (file_name); |
---|
464 | |
---|
465 | mysb sb (_cmtw._output); |
---|
466 | cout << line << endl; |
---|
467 | } |
---|
468 | break; |
---|
469 | case IDCE_EDITMODULES: |
---|
470 | { |
---|
471 | ListEditor editor (_modules); |
---|
472 | editor.run (_cmtw._instance, _dialog); |
---|
473 | } |
---|
474 | break; |
---|
475 | default: |
---|
476 | break; |
---|
477 | } |
---|
478 | } |
---|
479 | //--------------------------------------------------------------------- |
---|
480 | |
---|
481 | //--------------------------------------------------------------------- |
---|
482 | Cmtw& Cmtw::instance () |
---|
483 | { |
---|
484 | static Cmtw the_instance; |
---|
485 | |
---|
486 | return (the_instance); |
---|
487 | } |
---|
488 | |
---|
489 | BOOL Cmtw::initialize (HINSTANCE instance, HINSTANCE previous_instance, |
---|
490 | int show_mode) |
---|
491 | { |
---|
492 | WNDCLASS window_class; |
---|
493 | |
---|
494 | // Fill in window class structure with parameters that describe the |
---|
495 | // main window. |
---|
496 | |
---|
497 | if (!previous_instance) |
---|
498 | { |
---|
499 | window_class.style = CS_OWNDC; |
---|
500 | window_class.lpfnWndProc = (WNDPROC) process_messages; |
---|
501 | window_class.cbClsExtra = 0; |
---|
502 | window_class.cbWndExtra = 0; |
---|
503 | window_class.hInstance = instance; |
---|
504 | window_class.hIcon = LoadIcon (instance, _application_name); |
---|
505 | window_class.hCursor = LoadCursor (NULL, IDC_ARROW); |
---|
506 | window_class.hbrBackground = (HBRUSH) (COLOR_MENU+1); |
---|
507 | window_class.lpszMenuName = "TEXTFXMENU"; |
---|
508 | window_class.lpszClassName = _application_name; |
---|
509 | |
---|
510 | if (!RegisterClass (&window_class)) return (FALSE); |
---|
511 | } |
---|
512 | |
---|
513 | _instance = instance; |
---|
514 | |
---|
515 | _window = CreateWindow (_application_name, |
---|
516 | _title, |
---|
517 | WS_OVERLAPPEDWINDOW, |
---|
518 | CW_USEDEFAULT, 0, 440, 590, |
---|
519 | NULL, |
---|
520 | NULL, |
---|
521 | _instance, |
---|
522 | NULL); |
---|
523 | |
---|
524 | // If window could not be created, return "failure" |
---|
525 | |
---|
526 | if (!_window) |
---|
527 | { |
---|
528 | return (FALSE); |
---|
529 | } |
---|
530 | |
---|
531 | ShowWindow (_window, show_mode); |
---|
532 | UpdateWindow (_window); |
---|
533 | |
---|
534 | return (TRUE); |
---|
535 | } |
---|
536 | |
---|
537 | BOOL Cmtw::run () |
---|
538 | { |
---|
539 | MSG message; |
---|
540 | DWORD result; |
---|
541 | HANDLE objects[1]; |
---|
542 | int count = 0; |
---|
543 | |
---|
544 | while (TRUE) |
---|
545 | { |
---|
546 | result = MsgWaitForMultipleObjects (count, objects, FALSE, |
---|
547 | INFINITE, QS_ALLINPUT); |
---|
548 | if (result == (WAIT_OBJECT_0 + count)) |
---|
549 | { |
---|
550 | while (PeekMessage (&message, NULL, 0, 0, PM_REMOVE)) |
---|
551 | { |
---|
552 | if ((_the_dialog == NULL) || |
---|
553 | !IsDialogMessage (_the_dialog, &message)) |
---|
554 | { |
---|
555 | if (!TranslateAccelerator (message.hwnd, NULL, &message)) |
---|
556 | { |
---|
557 | if (message.message == WM_QUIT) return (0); |
---|
558 | |
---|
559 | TranslateMessage (&message); |
---|
560 | DispatchMessage (&message); |
---|
561 | } |
---|
562 | } |
---|
563 | } |
---|
564 | } |
---|
565 | else |
---|
566 | { |
---|
567 | // For future async objects |
---|
568 | } |
---|
569 | } |
---|
570 | |
---|
571 | return (message.wParam); |
---|
572 | } |
---|
573 | |
---|
574 | void Cmtw::disable_package_menu_items () |
---|
575 | { |
---|
576 | HMENU menu = GetMenu (_window); |
---|
577 | EnableMenuItem (menu, IDM_CONFIG, MFS_GRAYED | MF_BYCOMMAND); |
---|
578 | EnableMenuItem (menu, IDM_GENMAKE, MFS_GRAYED | MF_BYCOMMAND); |
---|
579 | EnableMenuItem (menu, IDM_GENMSDEV, MFS_GRAYED | MF_BYCOMMAND); |
---|
580 | EnableMenuItem (menu, IDM_BUILDSETUP, MFS_GRAYED | MF_BYCOMMAND); |
---|
581 | EnableMenuItem (menu, IDM_BUILDCONSTITUENTSMAKEFILE, |
---|
582 | MFS_GRAYED | MF_BYCOMMAND); |
---|
583 | EnableMenuItem (menu, IDM_BUILDCONSTITUENTMAKEFILE, |
---|
584 | MFS_GRAYED | MF_BYCOMMAND); |
---|
585 | |
---|
586 | _show_uses.disable (); |
---|
587 | _show_constituents.disable (); |
---|
588 | _show_macros.disable (); |
---|
589 | _show_sets.disable (); |
---|
590 | _requirements.disable (); |
---|
591 | } |
---|
592 | |
---|
593 | void Cmtw::enable_package_menu_items () |
---|
594 | { |
---|
595 | HMENU menu = GetMenu (_window); |
---|
596 | EnableMenuItem (menu, IDM_CONFIG, MFS_ENABLED | MF_BYCOMMAND); |
---|
597 | EnableMenuItem (menu, IDM_GENMAKE, MFS_ENABLED | MF_BYCOMMAND); |
---|
598 | EnableMenuItem (menu, IDM_GENMSDEV, MFS_ENABLED | MF_BYCOMMAND); |
---|
599 | EnableMenuItem (menu, IDM_BUILDSETUP, MFS_ENABLED | MF_BYCOMMAND); |
---|
600 | EnableMenuItem (menu, IDM_BUILDCONSTITUENTSMAKEFILE, |
---|
601 | MFS_ENABLED | MF_BYCOMMAND); |
---|
602 | EnableMenuItem (menu, IDM_BUILDCONSTITUENTMAKEFILE, |
---|
603 | MFS_GRAYED | MF_BYCOMMAND); |
---|
604 | |
---|
605 | _show_uses.enable (); |
---|
606 | _show_constituents.enable (); |
---|
607 | _show_macros.enable (); |
---|
608 | _show_sets.enable (); |
---|
609 | _requirements.enable (); |
---|
610 | } |
---|
611 | |
---|
612 | void Cmtw::do_show_uses () |
---|
613 | { |
---|
614 | mysb s (_show_uses); |
---|
615 | Use::show_all (); |
---|
616 | } |
---|
617 | |
---|
618 | void Cmtw::do_select_path () |
---|
619 | { |
---|
620 | cmt_string path = _path_list.get_selected (); |
---|
621 | |
---|
622 | path_selector& selector = path_selector::instance (); |
---|
623 | |
---|
624 | #ifdef USE_THREADS |
---|
625 | selector.start (path); |
---|
626 | #else |
---|
627 | { |
---|
628 | mysb s (_output); |
---|
629 | cout << "running thread "<< endl; |
---|
630 | } |
---|
631 | |
---|
632 | _package_list.clear (); |
---|
633 | _version_list.clear (); |
---|
634 | _requirements.clear (); |
---|
635 | _show_uses.clear (); |
---|
636 | _show_constituents.clear (); |
---|
637 | _tag.clear (); |
---|
638 | _show_macros.clear (); |
---|
639 | _show_sets.clear (); |
---|
640 | _output.clear (); |
---|
641 | |
---|
642 | disable_package_menu_items (); |
---|
643 | |
---|
644 | select_path (path); |
---|
645 | #endif |
---|
646 | } |
---|
647 | |
---|
648 | void Cmtw::do_select_package (const cmt_string& name) |
---|
649 | { |
---|
650 | _requirements.clear (); |
---|
651 | _show_uses.clear (); |
---|
652 | _show_constituents.clear (); |
---|
653 | _tag.clear (); |
---|
654 | _show_macros.clear (); |
---|
655 | _show_sets.clear (); |
---|
656 | _output.clear (); |
---|
657 | |
---|
658 | disable_package_menu_items (); |
---|
659 | |
---|
660 | cmt_string path; |
---|
661 | cmt_string package; |
---|
662 | |
---|
663 | path = _path_list.get_selected (); |
---|
664 | |
---|
665 | if (name == "") package = _package_list.get_selected (); |
---|
666 | else package = name; |
---|
667 | |
---|
668 | select_package (path, package); |
---|
669 | } |
---|
670 | |
---|
671 | void Cmtw::do_select_version () |
---|
672 | { |
---|
673 | cmt_string path; |
---|
674 | cmt_string package; |
---|
675 | cmt_string version; |
---|
676 | bool ok; |
---|
677 | |
---|
678 | path = _path_list.get_selected (); |
---|
679 | |
---|
680 | package = _package.get (); |
---|
681 | if (package == "") package = _package_list.get_selected (); |
---|
682 | |
---|
683 | version = _version_list.get_selected (); |
---|
684 | |
---|
685 | _requirements.clear (); |
---|
686 | _tag.clear (); |
---|
687 | _show_uses.clear (); |
---|
688 | _show_constituents.clear (); |
---|
689 | _show_macros.clear (); |
---|
690 | _show_sets.clear (); |
---|
691 | _output.clear (); |
---|
692 | |
---|
693 | if (version == "") |
---|
694 | { |
---|
695 | mysb s (_output); |
---|
696 | cout << "Please select a version first" << endl; |
---|
697 | return; |
---|
698 | } |
---|
699 | |
---|
700 | { |
---|
701 | mysb s (_output); |
---|
702 | ok = Cmt::load (path, package, version); |
---|
703 | _requirements.set ("requirements"); |
---|
704 | } |
---|
705 | |
---|
706 | if (!ok) |
---|
707 | { |
---|
708 | mysb s (_output); |
---|
709 | CmtError::print (); |
---|
710 | } |
---|
711 | else |
---|
712 | { |
---|
713 | { |
---|
714 | mysb s (_output); |
---|
715 | Cmt::set_standard_macros (); |
---|
716 | } |
---|
717 | |
---|
718 | { |
---|
719 | mysb s (_show_uses); |
---|
720 | Cmt::action = action_show_uses; |
---|
721 | Cmt::quiet = false; |
---|
722 | Use::show_all (); |
---|
723 | } |
---|
724 | { |
---|
725 | mysb s (_show_constituents); |
---|
726 | Cmt::action = action_show_constituents; |
---|
727 | Cmt::quiet = true; |
---|
728 | Constituent::show_all (); |
---|
729 | } |
---|
730 | { |
---|
731 | mysb s (_show_macros); |
---|
732 | Cmt::action = action_show_macros; |
---|
733 | Cmt::print_macros (Csh); |
---|
734 | } |
---|
735 | { |
---|
736 | mysb s (_show_sets); |
---|
737 | Cmt::action = action_show_sets; |
---|
738 | Cmt::print_macros (Csh); |
---|
739 | } |
---|
740 | { |
---|
741 | Symbol* symbol = Symbol::find ("tag"); |
---|
742 | if (symbol != 0) |
---|
743 | { |
---|
744 | const cmt_string tag = symbol->build_macro_value (); |
---|
745 | _tag.set (tag); |
---|
746 | } |
---|
747 | } |
---|
748 | } |
---|
749 | enable_package_menu_items (); |
---|
750 | } |
---|
751 | |
---|
752 | void Cmtw::do_select_tag (const cmt_string& name) |
---|
753 | { |
---|
754 | cmt_string path; |
---|
755 | cmt_string package; |
---|
756 | cmt_string version; |
---|
757 | bool ok; |
---|
758 | |
---|
759 | path = _path_list.get_selected (); |
---|
760 | |
---|
761 | package = _package.get (); |
---|
762 | if (package == "") package = _package_list.get_selected (); |
---|
763 | |
---|
764 | version = _version_list.get_selected (); |
---|
765 | |
---|
766 | _show_macros.clear (); |
---|
767 | { |
---|
768 | mysb s (_output); |
---|
769 | ok = Cmt::load (path, package, version, name); |
---|
770 | } |
---|
771 | if (!ok) return; |
---|
772 | |
---|
773 | Cmt::quiet = true; |
---|
774 | Cmt::set_standard_macros (); |
---|
775 | |
---|
776 | { |
---|
777 | mysb s (_show_macros); |
---|
778 | Cmt::print_macros (Csh); |
---|
779 | } |
---|
780 | } |
---|
781 | |
---|
782 | void Cmtw::do_config () |
---|
783 | { |
---|
784 | mysb s (_output); |
---|
785 | Cmt::do_config (); |
---|
786 | } |
---|
787 | |
---|
788 | void Cmtw::do_save_requirements () |
---|
789 | { |
---|
790 | cmt_string text; |
---|
791 | |
---|
792 | _requirements.get (text); |
---|
793 | |
---|
794 | FILE* f = fopen ("requirements", "wb"); |
---|
795 | if (f != NULL) |
---|
796 | { |
---|
797 | text.write (f); |
---|
798 | fclose (f); |
---|
799 | } |
---|
800 | } |
---|
801 | |
---|
802 | void Cmtw::do_genmake () |
---|
803 | { |
---|
804 | cmt_string line = _show_constituents.get_selected (); |
---|
805 | CmtSystem::cmt_string_vector words; |
---|
806 | |
---|
807 | CmtSystem::split (line, " ", words); |
---|
808 | |
---|
809 | if (words.size () >= 2) |
---|
810 | { |
---|
811 | const cmt_string& t = words[0]; |
---|
812 | if ((t == "library") || |
---|
813 | (t == "application")) |
---|
814 | { |
---|
815 | const cmt_string& name = words[1]; |
---|
816 | |
---|
817 | mysb s (_output); |
---|
818 | Cmt::build_makefile (name); |
---|
819 | } |
---|
820 | } |
---|
821 | else |
---|
822 | { |
---|
823 | mysb s (_output); |
---|
824 | Cmt::build_makefile (""); |
---|
825 | } |
---|
826 | } |
---|
827 | |
---|
828 | void Cmtw::do_genmsdev () |
---|
829 | { |
---|
830 | cmt_string line = _show_constituents.get_selected (); |
---|
831 | CmtSystem::cmt_string_vector words; |
---|
832 | |
---|
833 | CmtSystem::split (line, " ", words); |
---|
834 | |
---|
835 | if (words.size () >= 2) |
---|
836 | { |
---|
837 | const cmt_string& t = words[0]; |
---|
838 | if ((t == "library") || |
---|
839 | (t == "application")) |
---|
840 | { |
---|
841 | const cmt_string& name = words[1]; |
---|
842 | |
---|
843 | mysb s (_output); |
---|
844 | Cmt::build_msdev_file (name); |
---|
845 | } |
---|
846 | } |
---|
847 | else |
---|
848 | { |
---|
849 | mysb s (_output); |
---|
850 | Cmt::build_msdev_file (""); |
---|
851 | } |
---|
852 | } |
---|
853 | |
---|
854 | void Cmtw::do_build_make_setup () |
---|
855 | { |
---|
856 | cmt_string package = _package_list.get_selected (); |
---|
857 | cmt_string version = _version_list.get_selected (); |
---|
858 | |
---|
859 | if ((package != "") && (version != "")) |
---|
860 | { |
---|
861 | mysb s (_output); |
---|
862 | Generator::build_make_setup (package); |
---|
863 | } |
---|
864 | } |
---|
865 | |
---|
866 | void Cmtw::do_build_constituents_makefile () |
---|
867 | { |
---|
868 | cmt_string package = _package_list.get_selected (); |
---|
869 | cmt_string version = _version_list.get_selected (); |
---|
870 | |
---|
871 | if ((package != "") && (version != "")) |
---|
872 | { |
---|
873 | mysb s (_output); |
---|
874 | Generator::build_constituents_makefile (package); |
---|
875 | } |
---|
876 | } |
---|
877 | |
---|
878 | void Cmtw::do_build_constituent_makefiles () |
---|
879 | { |
---|
880 | cmt_string package; |
---|
881 | cmt_string version; |
---|
882 | |
---|
883 | package = _package_list.get_selected (); |
---|
884 | if (package == "") package = _package.get (); |
---|
885 | |
---|
886 | version = _version_list.get_selected (); |
---|
887 | |
---|
888 | if ((package != "") && (version != "")) |
---|
889 | { |
---|
890 | cmt_string line = _show_constituents.get_selected (); |
---|
891 | CmtSystem::cmt_string_vector words; |
---|
892 | |
---|
893 | CmtSystem::split (line, " ", words); |
---|
894 | |
---|
895 | if (words.size () >= 2) |
---|
896 | { |
---|
897 | const cmt_string& t = words[0]; |
---|
898 | if ((t == "library") || |
---|
899 | (t == "application")) |
---|
900 | { |
---|
901 | int i; |
---|
902 | |
---|
903 | const cmt_string& name = words[1]; |
---|
904 | mysb s (_output); |
---|
905 | Generator::build_constituent_makefile (name); |
---|
906 | |
---|
907 | for (i = 2; i < words.size (); i++) |
---|
908 | { |
---|
909 | const cmt_string& module = words[i]; |
---|
910 | Generator::build_dependencies (module); |
---|
911 | } |
---|
912 | } |
---|
913 | } |
---|
914 | } |
---|
915 | } |
---|
916 | |
---|
917 | bool Cmtw::is_version (const cmt_string& name) |
---|
918 | { |
---|
919 | const cmt_string numbers = "0123456789"; |
---|
920 | const int starting = 0; |
---|
921 | const int at_key = 1; |
---|
922 | const int at_number = 2; |
---|
923 | |
---|
924 | int state = starting; |
---|
925 | int pos; |
---|
926 | |
---|
927 | for (pos = 0; pos < name.size (); pos++) |
---|
928 | { |
---|
929 | char c = name[pos]; |
---|
930 | |
---|
931 | if (numbers.find (c) == cmt_string::npos) |
---|
932 | { |
---|
933 | switch (state) |
---|
934 | { |
---|
935 | case starting: |
---|
936 | state = at_key; |
---|
937 | break; |
---|
938 | case at_key: |
---|
939 | return (false); |
---|
940 | case at_number: |
---|
941 | state = at_key; |
---|
942 | break; |
---|
943 | } |
---|
944 | } |
---|
945 | else |
---|
946 | { |
---|
947 | switch (state) |
---|
948 | { |
---|
949 | case starting: |
---|
950 | return (false); |
---|
951 | case at_key: |
---|
952 | state = at_number; |
---|
953 | break; |
---|
954 | case at_number: |
---|
955 | break; |
---|
956 | } |
---|
957 | } |
---|
958 | } |
---|
959 | |
---|
960 | return ((state == at_number)); |
---|
961 | } |
---|
962 | |
---|
963 | void Cmtw::select_package (const cmt_string& path, |
---|
964 | const cmt_string& package) |
---|
965 | { |
---|
966 | // |
---|
967 | // Only do something if it is a directory. |
---|
968 | // |
---|
969 | |
---|
970 | _version_list.clear (); |
---|
971 | |
---|
972 | bool test; |
---|
973 | |
---|
974 | cmt_string pattern = path; |
---|
975 | pattern += CmtSystem::file_separator (); |
---|
976 | pattern += package; |
---|
977 | |
---|
978 | /* |
---|
979 | { |
---|
980 | mysb sb (_output); |
---|
981 | cout << "scan> testing directory pattern=" << pattern << endl; |
---|
982 | } |
---|
983 | */ |
---|
984 | |
---|
985 | dir_mutex.lock (); |
---|
986 | test = CmtSystem::test_directory (pattern); |
---|
987 | dir_mutex.unlock (); |
---|
988 | if (!test) return; |
---|
989 | |
---|
990 | // |
---|
991 | // The scan_dir requests a pattern <dir>/<name> to scan <dir> |
---|
992 | // |
---|
993 | |
---|
994 | pattern += CmtSystem::file_separator (); |
---|
995 | pattern += "*"; |
---|
996 | |
---|
997 | CmtSystem::cmt_string_vector list; |
---|
998 | |
---|
999 | dir_mutex.lock (); |
---|
1000 | CmtSystem::scan_dir (pattern, list); |
---|
1001 | dir_mutex.unlock (); |
---|
1002 | |
---|
1003 | if (list.size () == 0) return; |
---|
1004 | |
---|
1005 | int i; |
---|
1006 | for (i = 0; i < list.size (); i++) |
---|
1007 | { |
---|
1008 | const cmt_string& name = list[i]; |
---|
1009 | |
---|
1010 | /* |
---|
1011 | { |
---|
1012 | mysb sb (_output); |
---|
1013 | cout << "scan10> name=" << name; |
---|
1014 | } |
---|
1015 | */ |
---|
1016 | |
---|
1017 | cmt_string version; |
---|
1018 | CmtSystem::basename (name, version); |
---|
1019 | |
---|
1020 | if (is_version (version)) |
---|
1021 | { |
---|
1022 | cmt_string req; |
---|
1023 | |
---|
1024 | req = name; |
---|
1025 | req += CmtSystem::file_separator (); |
---|
1026 | req += "cmt"; |
---|
1027 | req += CmtSystem::file_separator (); |
---|
1028 | req += "requirements"; |
---|
1029 | |
---|
1030 | dir_mutex.lock (); |
---|
1031 | test = CmtSystem::test_file (req); |
---|
1032 | dir_mutex.unlock (); |
---|
1033 | if (test) |
---|
1034 | { |
---|
1035 | _version_list.append (version); |
---|
1036 | } |
---|
1037 | else |
---|
1038 | { |
---|
1039 | req = name; |
---|
1040 | req += CmtSystem::file_separator (); |
---|
1041 | req += "mgr"; |
---|
1042 | req += CmtSystem::file_separator (); |
---|
1043 | req += "requirements"; |
---|
1044 | |
---|
1045 | dir_mutex.lock (); |
---|
1046 | test = CmtSystem::test_file (req); |
---|
1047 | dir_mutex.unlock (); |
---|
1048 | if (test) |
---|
1049 | { |
---|
1050 | _version_list.append (version); |
---|
1051 | } |
---|
1052 | } |
---|
1053 | } |
---|
1054 | else |
---|
1055 | { |
---|
1056 | /* |
---|
1057 | { |
---|
1058 | mysb sb (_output); |
---|
1059 | cout << " -> stop" << endl; |
---|
1060 | } |
---|
1061 | */ |
---|
1062 | } |
---|
1063 | } |
---|
1064 | } |
---|
1065 | |
---|
1066 | void Cmtw::select_path (const cmt_string& path, |
---|
1067 | const cmt_string& prefix, |
---|
1068 | int level) |
---|
1069 | { |
---|
1070 | long handle = 0; |
---|
1071 | // |
---|
1072 | // Only do something if it is a directory. |
---|
1073 | // |
---|
1074 | |
---|
1075 | cmt_string full_path = path; |
---|
1076 | if (prefix != "") |
---|
1077 | { |
---|
1078 | full_path += CmtSystem::file_separator (); |
---|
1079 | full_path += prefix; |
---|
1080 | } |
---|
1081 | |
---|
1082 | if (full_path[full_path.size () -1] == ':') |
---|
1083 | { |
---|
1084 | full_path += CmtSystem::file_separator (); |
---|
1085 | } |
---|
1086 | |
---|
1087 | /* |
---|
1088 | { |
---|
1089 | mysb sb (_output); |
---|
1090 | cout << "scan> testing directory " << full_path << endl; |
---|
1091 | } |
---|
1092 | */ |
---|
1093 | |
---|
1094 | bool test; |
---|
1095 | |
---|
1096 | dir_mutex.lock (); |
---|
1097 | test = CmtSystem::test_directory (full_path); |
---|
1098 | dir_mutex.unlock (); |
---|
1099 | if (!test) return; |
---|
1100 | |
---|
1101 | // |
---|
1102 | // The scan_dir requests a pattern <dir>/<name> to scan <dir> |
---|
1103 | // |
---|
1104 | cmt_string pattern = full_path; |
---|
1105 | pattern += CmtSystem::file_separator (); |
---|
1106 | pattern += "*"; |
---|
1107 | |
---|
1108 | CmtSystem::cmt_string_vector list; |
---|
1109 | |
---|
1110 | dir_mutex.lock (); |
---|
1111 | CmtSystem::scan_dir (pattern, list); |
---|
1112 | dir_mutex.unlock (); |
---|
1113 | |
---|
1114 | if (list.size () == 0) return; |
---|
1115 | |
---|
1116 | // Will be set if at least one directory is a version directory |
---|
1117 | bool has_package = false; |
---|
1118 | |
---|
1119 | cmt_string pack; |
---|
1120 | CmtSystem::basename (full_path, pack); |
---|
1121 | |
---|
1122 | int i; |
---|
1123 | for (i = 0; i < list.size (); i++) |
---|
1124 | { |
---|
1125 | const cmt_string& name = list[i]; |
---|
1126 | |
---|
1127 | /* |
---|
1128 | { |
---|
1129 | mysb sb (_output); |
---|
1130 | cout << "scan8> level=" << level << " name=" << name; |
---|
1131 | } |
---|
1132 | */ |
---|
1133 | |
---|
1134 | cmt_string version; |
---|
1135 | CmtSystem::basename (name, version); |
---|
1136 | |
---|
1137 | // |
---|
1138 | // All entries at this level may be "legal" version directories. |
---|
1139 | // |
---|
1140 | // So we go down but no more then one level deep. |
---|
1141 | // The next level we request that the entry is a version |
---|
1142 | // and that there is a mgr/requirements file below. |
---|
1143 | // |
---|
1144 | |
---|
1145 | if (level == 0) |
---|
1146 | { |
---|
1147 | /* |
---|
1148 | { |
---|
1149 | mysb sb (_output); |
---|
1150 | cout << " -> down" << endl; |
---|
1151 | } |
---|
1152 | */ |
---|
1153 | |
---|
1154 | cmt_string p = ""; |
---|
1155 | |
---|
1156 | if (prefix != "") |
---|
1157 | { |
---|
1158 | p += prefix; |
---|
1159 | p += CmtSystem::file_separator (); |
---|
1160 | } |
---|
1161 | |
---|
1162 | p += version; |
---|
1163 | |
---|
1164 | select_path (path, p, level + 1); |
---|
1165 | } |
---|
1166 | else if (is_version (version)) |
---|
1167 | { |
---|
1168 | cmt_string req; |
---|
1169 | |
---|
1170 | req = name; |
---|
1171 | req += CmtSystem::file_separator (); |
---|
1172 | req += "cmt"; |
---|
1173 | req += CmtSystem::file_separator (); |
---|
1174 | req += "requirements"; |
---|
1175 | |
---|
1176 | dir_mutex.lock (); |
---|
1177 | test = CmtSystem::test_file (req); |
---|
1178 | dir_mutex.unlock (); |
---|
1179 | if (test) |
---|
1180 | { |
---|
1181 | /* |
---|
1182 | { |
---|
1183 | mysb sb (_output); |
---|
1184 | cout << " -> mgr" << endl; |
---|
1185 | cout << pack << " " << version << " " << full_path << endl; |
---|
1186 | } |
---|
1187 | */ |
---|
1188 | |
---|
1189 | has_package = true; |
---|
1190 | |
---|
1191 | break; |
---|
1192 | } |
---|
1193 | else |
---|
1194 | { |
---|
1195 | req = name; |
---|
1196 | req += CmtSystem::file_separator (); |
---|
1197 | req += "mgr"; |
---|
1198 | req += CmtSystem::file_separator (); |
---|
1199 | req += "requirements"; |
---|
1200 | |
---|
1201 | dir_mutex.lock (); |
---|
1202 | test = CmtSystem::test_file (req); |
---|
1203 | dir_mutex.unlock (); |
---|
1204 | if (test) |
---|
1205 | { |
---|
1206 | has_package = true; |
---|
1207 | |
---|
1208 | break; |
---|
1209 | } |
---|
1210 | } |
---|
1211 | } |
---|
1212 | else |
---|
1213 | { |
---|
1214 | /* |
---|
1215 | { |
---|
1216 | mysb sb (_output); |
---|
1217 | cout << " -> stop" << endl; |
---|
1218 | } |
---|
1219 | */ |
---|
1220 | } |
---|
1221 | } |
---|
1222 | |
---|
1223 | if (has_package) |
---|
1224 | { |
---|
1225 | // |
---|
1226 | // At least one version was found here. |
---|
1227 | // |
---|
1228 | |
---|
1229 | _package_list.append (prefix); |
---|
1230 | |
---|
1231 | select_path (path, prefix, 0); |
---|
1232 | } |
---|
1233 | } |
---|
1234 | |
---|
1235 | int Cmtw::show_tags (HWND window, int x, int y, cmt_string& selected_name) |
---|
1236 | { |
---|
1237 | const Tag::TagPtrVector& tags = Tag::tags (); |
---|
1238 | |
---|
1239 | int selected; |
---|
1240 | |
---|
1241 | HMENU menu = CreatePopupMenu (); |
---|
1242 | |
---|
1243 | for (int i = 0; i < tags.size (); i++) |
---|
1244 | { |
---|
1245 | Tag* tag = tags[i]; |
---|
1246 | |
---|
1247 | if (tag != 0) |
---|
1248 | { |
---|
1249 | AppendMenu (menu, MFT_STRING, IDM_FIRSTTAG + i, |
---|
1250 | tag->name.c_str ()); |
---|
1251 | } |
---|
1252 | } |
---|
1253 | |
---|
1254 | selected = (int) TrackPopupMenu (menu, TPM_TOPALIGN | |
---|
1255 | TPM_LEFTALIGN | |
---|
1256 | TPM_RETURNCMD, |
---|
1257 | x, y, 0, window, NULL); |
---|
1258 | |
---|
1259 | if (selected >= IDM_FIRSTTAG) |
---|
1260 | { |
---|
1261 | char name[80]; |
---|
1262 | |
---|
1263 | GetMenuString (menu, selected - IDM_FIRSTTAG, name, sizeof (name), |
---|
1264 | MF_BYPOSITION); |
---|
1265 | |
---|
1266 | selected_name = name; |
---|
1267 | |
---|
1268 | _tag.set (selected_name); |
---|
1269 | |
---|
1270 | do_select_tag (selected_name); |
---|
1271 | } |
---|
1272 | |
---|
1273 | return (selected); |
---|
1274 | } |
---|
1275 | |
---|
1276 | Cmtw::Cmtw () : _application_name ("CMTW"), _title ("CMTW Test Application") |
---|
1277 | { |
---|
1278 | _the_dialog = 0; |
---|
1279 | _objects = 0; |
---|
1280 | _object_count = 0; |
---|
1281 | } |
---|
1282 | |
---|
1283 | LRESULT CALLBACK Cmtw::process_messages (HWND window, |
---|
1284 | UINT message_type, |
---|
1285 | WPARAM parameter1, |
---|
1286 | LPARAM parameter2) |
---|
1287 | { |
---|
1288 | Cmtw& cmtw = Cmtw::instance (); |
---|
1289 | |
---|
1290 | int menu_item; |
---|
1291 | static HPEN blue_pen; |
---|
1292 | static HPEN red_pen; |
---|
1293 | |
---|
1294 | SetLastError (0); |
---|
1295 | |
---|
1296 | switch (message_type) |
---|
1297 | { |
---|
1298 | case WM_CREATE: |
---|
1299 | { |
---|
1300 | HDC context; |
---|
1301 | LOGFONT log_font; |
---|
1302 | HFONT font; |
---|
1303 | |
---|
1304 | context = GetDC (window); |
---|
1305 | |
---|
1306 | memset (&log_font, 0, sizeof(LOGFONT)); |
---|
1307 | log_font.lfHeight = -72; |
---|
1308 | strcpy ((LPSTR) &(log_font.lfFaceName), "arial"); |
---|
1309 | |
---|
1310 | font = CreateFontIndirect (&log_font); |
---|
1311 | SelectObject (context, font); |
---|
1312 | |
---|
1313 | blue_pen = CreatePen (PS_SOLID, 1, RGB(0,0,255)); |
---|
1314 | red_pen = CreatePen (PS_SOLID, 1, RGB(255,0,0)); |
---|
1315 | } |
---|
1316 | |
---|
1317 | cmtw._window = window; |
---|
1318 | |
---|
1319 | cmtw._the_dialog = CreateDialog (cmtw._instance, |
---|
1320 | MAKEINTRESOURCE(IDD_DIALOGBAR), |
---|
1321 | window, |
---|
1322 | (DLGPROC) handle_dialog); |
---|
1323 | |
---|
1324 | cmtw.disable_package_menu_items (); |
---|
1325 | |
---|
1326 | break; |
---|
1327 | |
---|
1328 | case WM_COMMAND: |
---|
1329 | menu_item = LOWORD (parameter1); |
---|
1330 | |
---|
1331 | switch (menu_item) |
---|
1332 | { |
---|
1333 | case IDM_EXIT: |
---|
1334 | DestroyWindow (window); |
---|
1335 | break; |
---|
1336 | case IDM_CONFIG: |
---|
1337 | cmtw.do_config (); |
---|
1338 | break; |
---|
1339 | case IDM_GENMAKE: |
---|
1340 | cmtw.do_genmake (); |
---|
1341 | break; |
---|
1342 | case IDM_GENMSDEV: |
---|
1343 | cmtw.do_genmsdev (); |
---|
1344 | break; |
---|
1345 | case IDM_BUILDSETUP: |
---|
1346 | cmtw.do_build_make_setup (); |
---|
1347 | break; |
---|
1348 | case IDM_BUILDCONSTITUENTSMAKEFILE: |
---|
1349 | cmtw.do_build_constituents_makefile (); |
---|
1350 | break; |
---|
1351 | case IDM_BUILDCONSTITUENTMAKEFILE: |
---|
1352 | cmtw.do_build_constituent_makefiles (); |
---|
1353 | break; |
---|
1354 | case IDM_NEWPACKAGE: |
---|
1355 | { |
---|
1356 | PackageCreator creator (cmtw); |
---|
1357 | |
---|
1358 | creator.run (cmtw._instance, window); |
---|
1359 | } |
---|
1360 | break; |
---|
1361 | case IDM_CMT: |
---|
1362 | { |
---|
1363 | CMT_Run cmt (cmtw); |
---|
1364 | |
---|
1365 | cmt.run (cmtw._instance, window); |
---|
1366 | } |
---|
1367 | break; |
---|
1368 | default: |
---|
1369 | return (DefWindowProc (window, message_type, |
---|
1370 | parameter1, parameter2)); |
---|
1371 | } |
---|
1372 | break; |
---|
1373 | case WM_DESTROY: |
---|
1374 | PostQuitMessage (0); |
---|
1375 | break; |
---|
1376 | default: |
---|
1377 | return (DefWindowProc (window, message_type, parameter1, parameter2)); |
---|
1378 | } |
---|
1379 | return (0); |
---|
1380 | } |
---|
1381 | |
---|
1382 | LRESULT CALLBACK Cmtw::handle_dialog (HWND dialog, |
---|
1383 | UINT message_type, |
---|
1384 | WPARAM parameter1, |
---|
1385 | LPARAM parameter2) |
---|
1386 | { |
---|
1387 | Cmtw& cmtw = Cmtw::instance (); |
---|
1388 | |
---|
1389 | int menu_item; |
---|
1390 | |
---|
1391 | switch (message_type) |
---|
1392 | { |
---|
1393 | case WM_CREATE: |
---|
1394 | break; |
---|
1395 | case WM_SETFONT: |
---|
1396 | break; |
---|
1397 | case WM_INITDIALOG: |
---|
1398 | { |
---|
1399 | int x = 0; |
---|
1400 | int y = 0; |
---|
1401 | int width; |
---|
1402 | int height; |
---|
1403 | RECT rectangle; |
---|
1404 | |
---|
1405 | GetWindowRect (dialog, &rectangle); |
---|
1406 | |
---|
1407 | width = rectangle.right - rectangle.left; |
---|
1408 | height = rectangle.bottom - rectangle.top; |
---|
1409 | |
---|
1410 | MoveWindow (cmtw._window, x, y, width, height, TRUE); |
---|
1411 | } |
---|
1412 | |
---|
1413 | cmtw._path_list.init (dialog, IDM_PATHLIST); |
---|
1414 | cmtw._package_list.init (dialog, IDM_PACKAGELIST); |
---|
1415 | cmtw._package.init (dialog, IDM_PACKAGE); |
---|
1416 | cmtw._version_list.init (dialog, IDM_VERSIONLIST); |
---|
1417 | |
---|
1418 | cmtw._requirements.init (dialog, IDM_REQUIREMENTS); |
---|
1419 | |
---|
1420 | cmtw._show_uses.init (dialog, IDM_USES); |
---|
1421 | cmtw._show_constituents.init (dialog, IDM_CONSTITUENTS); |
---|
1422 | cmtw._show_macros.init (dialog, IDM_MACROS); |
---|
1423 | cmtw._show_sets.init (dialog, IDM_SETS); |
---|
1424 | cmtw._output.init (dialog, IDM_OUTPUT); |
---|
1425 | |
---|
1426 | cmtw._set_uses.init (dialog, IDM_SETUSES); |
---|
1427 | cmtw._set_constituents.init (dialog, IDM_SETCONSTITUENTS); |
---|
1428 | cmtw._set_macros.init (dialog, IDM_SETMACROS); |
---|
1429 | cmtw._set_sets.init (dialog, IDM_SETSETS); |
---|
1430 | cmtw._set_output.init (dialog, IDM_SETOUTPUT); |
---|
1431 | |
---|
1432 | cmtw._tag.init (dialog, IDM_TAG); |
---|
1433 | |
---|
1434 | cmtw._tab.add ("uses", |
---|
1435 | cmtw._show_uses, |
---|
1436 | cmtw._set_uses); |
---|
1437 | cmtw._tab.add ("constituents", |
---|
1438 | cmtw._show_constituents, |
---|
1439 | cmtw._set_constituents); |
---|
1440 | cmtw._tab.add ("macros", |
---|
1441 | cmtw._show_macros, |
---|
1442 | cmtw._set_macros); |
---|
1443 | cmtw._tab.add ("sets", |
---|
1444 | cmtw._show_sets, |
---|
1445 | cmtw._set_sets); |
---|
1446 | cmtw._tab.add ("output", |
---|
1447 | cmtw._output, |
---|
1448 | cmtw._set_output); |
---|
1449 | |
---|
1450 | cmtw._tab.select ("uses"); |
---|
1451 | |
---|
1452 | { |
---|
1453 | CmtSystem::cmt_string_vector paths; |
---|
1454 | CmtSystem::cmt_string_vector path_sources; |
---|
1455 | |
---|
1456 | CmtSystem::get_cmt_paths (paths, path_sources); |
---|
1457 | |
---|
1458 | cmtw._path_list.set (paths); |
---|
1459 | } |
---|
1460 | |
---|
1461 | break; |
---|
1462 | case WM_COMMAND: |
---|
1463 | menu_item = LOWORD (parameter1); |
---|
1464 | |
---|
1465 | switch (menu_item) |
---|
1466 | { |
---|
1467 | case IDM_PATHLIST: |
---|
1468 | if (HIWORD (parameter1) == LBN_DBLCLK) |
---|
1469 | { |
---|
1470 | cmtw.do_select_path (); |
---|
1471 | } |
---|
1472 | break; |
---|
1473 | case IDM_PACKAGELIST: |
---|
1474 | if (HIWORD (parameter1) == LBN_DBLCLK) |
---|
1475 | { |
---|
1476 | cmtw.do_select_package (); |
---|
1477 | } |
---|
1478 | break; |
---|
1479 | case IDM_PACKAGE: |
---|
1480 | { |
---|
1481 | cmt_string name = cmtw._package.get (); |
---|
1482 | cmtw.do_select_package (name); |
---|
1483 | } |
---|
1484 | break; |
---|
1485 | case IDM_VERSIONLIST: |
---|
1486 | if (HIWORD (parameter1) == LBN_DBLCLK) |
---|
1487 | { |
---|
1488 | cmtw.do_select_version (); |
---|
1489 | } |
---|
1490 | break; |
---|
1491 | case IDM_USES: |
---|
1492 | break; |
---|
1493 | case IDM_CONSTITUENTS: |
---|
1494 | if (HIWORD (parameter1) == LBN_DBLCLK) |
---|
1495 | { |
---|
1496 | cmt_string line = cmtw._show_constituents.get_selected (); |
---|
1497 | ConstituentEditor editor (line, cmtw); |
---|
1498 | |
---|
1499 | editor.run (cmtw._instance, dialog); |
---|
1500 | } |
---|
1501 | else |
---|
1502 | { |
---|
1503 | cmt_string line = cmtw._show_constituents.get_selected (); |
---|
1504 | |
---|
1505 | HMENU menu = GetMenu (cmtw._window); |
---|
1506 | |
---|
1507 | if (line == "") |
---|
1508 | { |
---|
1509 | EnableMenuItem (menu, IDM_BUILDCONSTITUENTMAKEFILE, |
---|
1510 | MFS_GRAYED | MF_BYCOMMAND); |
---|
1511 | } |
---|
1512 | else |
---|
1513 | { |
---|
1514 | EnableMenuItem (menu, IDM_BUILDCONSTITUENTMAKEFILE, |
---|
1515 | MFS_ENABLED | MF_BYCOMMAND); |
---|
1516 | } |
---|
1517 | } |
---|
1518 | break; |
---|
1519 | case IDM_TAG: |
---|
1520 | { |
---|
1521 | int x = 0; |
---|
1522 | int y = 0; |
---|
1523 | RECT rectangle; |
---|
1524 | |
---|
1525 | GetWindowRect (GetDlgItem (dialog, IDM_TAG), &rectangle); |
---|
1526 | x = rectangle.left; |
---|
1527 | y = rectangle.top; |
---|
1528 | |
---|
1529 | cmt_string name (80); |
---|
1530 | int selected = cmtw.show_tags (dialog, x, y, name); |
---|
1531 | } |
---|
1532 | break; |
---|
1533 | case IDM_SETUSES: |
---|
1534 | cmtw._tab.select ("uses"); |
---|
1535 | break; |
---|
1536 | case IDM_SETMACROS: |
---|
1537 | cmtw._tab.select ("macros"); |
---|
1538 | break; |
---|
1539 | case IDM_SETSETS: |
---|
1540 | cmtw._tab.select ("sets"); |
---|
1541 | break; |
---|
1542 | case IDM_SETCONSTITUENTS: |
---|
1543 | cmtw._tab.select ("constituents"); |
---|
1544 | break; |
---|
1545 | case IDM_SETOUTPUT: |
---|
1546 | cmtw._tab.select ("output"); |
---|
1547 | break; |
---|
1548 | case IDM_MACROS: |
---|
1549 | if (HIWORD (parameter1) == LBN_DBLCLK) |
---|
1550 | { |
---|
1551 | cmt_string line = cmtw._show_macros.get_selected (); |
---|
1552 | mysb s (cmtw._output); |
---|
1553 | cout << line << endl; |
---|
1554 | } |
---|
1555 | break; |
---|
1556 | case IDM_REQUIREMENTS: |
---|
1557 | if (HIWORD (parameter1) == LBN_DBLCLK) |
---|
1558 | { |
---|
1559 | ListEditor editor (cmtw._requirements); |
---|
1560 | |
---|
1561 | editor.run (cmtw._instance, dialog); |
---|
1562 | } |
---|
1563 | break; |
---|
1564 | case IDM_EDITREQUIREMENTS: |
---|
1565 | { |
---|
1566 | ListEditor editor (cmtw._requirements); |
---|
1567 | |
---|
1568 | editor.run (cmtw._instance, dialog); |
---|
1569 | } |
---|
1570 | break; |
---|
1571 | case IDM_SAVEREQUIREMENTS: |
---|
1572 | { |
---|
1573 | cmtw.do_save_requirements (); |
---|
1574 | } |
---|
1575 | break; |
---|
1576 | case IDM_EDITPATHS: |
---|
1577 | { |
---|
1578 | ListEditor editor (cmtw._path_list); |
---|
1579 | |
---|
1580 | editor.run (cmtw._instance, dialog); |
---|
1581 | } |
---|
1582 | break; |
---|
1583 | case IDM_OUTPUT: |
---|
1584 | break; |
---|
1585 | } |
---|
1586 | break; |
---|
1587 | case WM_ACTIVATE: |
---|
1588 | menu_item = LOWORD (parameter1); |
---|
1589 | |
---|
1590 | break; |
---|
1591 | default: |
---|
1592 | return (FALSE); |
---|
1593 | } |
---|
1594 | return (TRUE); |
---|
1595 | } |
---|
1596 | //--------------------------------------------------------------------- |
---|
1597 | |
---|