Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / tools / WiMP.c
blob0c9318cfa54f70f5f3352bcb5f32e0cb80aa4968
1 /*
2 Copyright © 1995-2009, The AROS Development Team. All rights reserved.
3 $Id$
5 WiMP -- Window manipulation program.
6 */
8 /******************************************************************************
10 NAME
12 WiMP
14 SYNOPSIS
17 LOCATION
19 Workbench:Tools
21 FUNCTION
23 Manipulates screens and windows
25 INPUTS
27 RESULT
29 NOTES
31 EXAMPLE
33 BUGS
35 SEE ALSO
37 INTERNALS
39 ******************************************************************************/
41 #define MUIMASTER_YES_INLINE_STDARG
43 #include <libraries/mui.h>
44 #include <libraries/gadtools.h>
45 #include <proto/muimaster.h>
46 #include <proto/intuition.h>
47 #include <proto/exec.h>
48 #include <proto/dos.h>
49 #include <proto/utility.h>
51 #include <stdlib.h>
52 #include <string.h>
53 #include <stdio.h>
56 static Object *app, *wnd, *list_gad;
58 static Object *close_gad, *front_gad, *back_gad, *origin_gad, *activate_gad, *zip_gad, *hide_gad, *show_gad;
59 static Object *update_gad, *rescue_gad, *showall_gad, *rethink_gad, *about_gad;
61 static Object *info_wnd, *page_gad;
63 static Object *info_scr_addr_gad, *info_scr_leftedge_gad, *info_scr_topedge_gad, *info_scr_width_gad, *info_scr_height_gad,
64 *info_scr_flags_gad, *info_scr_title_gad, *info_scr_deftitle_gad, *info_scr_firstwindow_gad;
67 static Object *info_win_addr_gad, *info_win_nextwin_gad, *info_win_leftedge_gad, *info_win_topedge_gad, *info_win_width_gad,
68 *info_win_height_gad, *info_win_minwidth_gad, *info_win_minheight_gad, *info_win_maxwidth_gad, *info_win_maxheight_gad,
69 *info_win_flags_gad, *info_win_idcmp_gad, *info_win_title_gad, *info_win_req_gad, *info_win_screen_gad,
70 *info_win_borderleft_gad, *info_win_bordertop_gad, *info_win_borderright_gad, *info_win_borderbottom_gad,
71 *info_win_parentwin_gad, *info_win_firstchild_gad, *info_win_parent_gad, *info_win_descendant_gad;
73 static ULONG lock;
76 static struct Hook close_hook, front_hook, back_hook, origin_hook, activate_hook, zip_hook, hide_hook, show_hook;
77 static struct Hook update_hook, rescue_hook, showall_hook, rethink_hook, about_hook;
78 static struct Hook display_hook, construct_hook, destruct_hook;
79 static struct Hook openinfo_hook, updateinfo_hook;
82 static const STRPTR ABOUT_TXT = "WiMP - The Window Manipulation Program\n\n"
83 "Copyright © 2000-2009 by The AROS Development Team";
84 static const STRPTR TITLE_TXT = "WiMP - The Window Manipulation Program";
85 static const STRPTR INFOTITLE_TXT = "WiMP - InfoWindow";
86 static const STRPTR CLOSESCREEN_TXT = "Do you really want to Close the selected Screen?";
87 static const STRPTR CLOSEWINDOW_TXT = "Do you really want to Close the selected Window?";
88 static const STRPTR YESNO_TXT = "Yes.|No!";
89 static const STRPTR CONTINUE_TXT = "Continue";
92 enum {
93 None_type,
94 Window_type,
95 Screen_type,
96 Max_type
100 struct ListEntry
102 LONG type;
103 APTR aptr;
104 TEXT address[20];
105 TEXT size[12];
106 TEXT pos[12];
107 TEXT status[4];
108 TEXT title[40];
111 static const char version[] = "$VER: WiMP 0.13 (06.01.2009) © AROS Dev Team";
113 /*********************************************************************************************/
115 static void Cleanup(CONST_STRPTR txt);
116 static LONG get_selected(struct Screen **scr, struct Window **win);
117 static void MakeGUI(void);
119 /*********************************************************************************************/
121 enum {
122 MN_ABOUT=1,
123 MN_QUIT,
124 MN_UPDATE,
125 MN_KILL,
126 MN_FRONT,
127 MN_BACK,
128 MN_ORIGIN,
129 MN_ACTIVATE,
130 MN_ZIP,
131 MN_HIDE,
132 MN_SHOW,
133 MN_INFO,
134 MN_RESCUE,
135 MN_SHOWALL,
136 MN_RETHINK,
139 static struct NewMenu nm[] =
141 {NM_TITLE, "Project"},
142 {NM_ITEM, "About...", NULL, 0, 0, (APTR)MN_ABOUT},
143 {NM_ITEM, NM_BARLABEL},
144 {NM_ITEM, "Quit", "Q", 0, 0, (APTR)MN_QUIT},
145 {NM_TITLE, "Window List"},
146 {NM_ITEM, "Update List", "U", 0, 0, (APTR)MN_UPDATE},
147 {NM_ITEM, NM_BARLABEL},
148 {NM_ITEM, "Kill", NULL, 0, 0, (APTR)MN_KILL},
149 {NM_ITEM, "To Front", NULL, 0, 0, (APTR)MN_FRONT},
150 {NM_ITEM, "To Back", NULL, 0, 0, (APTR)MN_BACK},
151 {NM_ITEM, "To Origin", NULL, 0, 0, (APTR)MN_ORIGIN},
152 {NM_ITEM, "Activate", NULL, 0, 0, (APTR)MN_ACTIVATE},
153 {NM_ITEM, "Zip", NULL, 0, 0, (APTR)MN_ZIP},
154 {NM_ITEM, "Hide", NULL, 0, 0, (APTR)MN_HIDE},
155 {NM_ITEM, "Show", NULL, 0, 0, (APTR)MN_SHOW},
156 {NM_ITEM, NM_BARLABEL},
157 {NM_ITEM, "Info", NULL, 0, 0, (APTR)MN_INFO},
158 {NM_TITLE, "Generic"},
159 {NM_ITEM, "Rescue All", NULL, 0, 0, (APTR)MN_RESCUE},
160 {NM_ITEM, "Show All", NULL, 0, 0, (APTR)MN_SHOWALL},
161 {NM_ITEM, "RethinkDisplay", NULL, 0, 0, (APTR)MN_RETHINK},
162 {NM_END}
165 /*********************************************************************************************/
167 static LONG get_selected(struct Screen **scr, struct Window **win)
169 *scr = NULL;
170 *win = NULL;
172 struct ListEntry *le;
173 DoMethod(list_gad, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, (IPTR)&le);
175 if (le)
177 lock = LockIBase ( 0 );
178 *scr = IntuitionBase->FirstScreen;
179 UnlockIBase ( lock );
180 /* Traverse through all Screens */
181 while ( *scr )
183 if ((le->type == Screen_type) && (le->aptr == *scr))
185 return Screen_type;
188 /* Traverse through all Windows of current Screen */
189 *win = (*scr)->FirstWindow;
190 while ( *win )
192 if ((le->type == Window_type) && (le->aptr == *win))
194 return Window_type;
197 *win = (*win)->NextWindow;
199 *scr = (*scr)->NextScreen;
202 return None_type;
205 /*********************************************************************************************/
207 AROS_UFH3(void, display_func,
208 AROS_UFHA(struct Hook * , h, A0),
209 AROS_UFHA(char ** , array, A2),
210 AROS_UFHA(struct ListEntry *, msg, A1))
212 AROS_USERFUNC_INIT;
214 if (msg)
216 if (msg->type == Window_type)
218 array[0] = " \033bWindow";
220 else
222 array[0] = "\033b\033uScreen";
224 array[1] = msg->address;
225 array[2] = msg->size;
226 array[3] = msg->pos;
227 array[4] = msg->status;
228 array[5] = msg->title;
230 else
232 array[0] = "Type";
233 array[1] = "Address";
234 array[2] = "Size";
235 array[3] = "Position";
236 array[4] = "Status";
237 array[5] = "Title";
240 AROS_USERFUNC_EXIT
243 /*********************************************************************************************/
245 AROS_UFH3(APTR, construct_func,
246 AROS_UFHA(struct Hook * , h, A0),
247 AROS_UFHA(APTR , pool, A2),
248 AROS_UFHA(struct ListEntry *, msg, A1))
250 AROS_USERFUNC_INIT
252 struct ListEntry *new = AllocPooled(pool, sizeof(*msg));
253 if (new)
254 *new = *msg;
256 return new;
258 AROS_USERFUNC_EXIT
261 /*********************************************************************************************/
263 AROS_UFH3(void, destruct_func,
264 AROS_UFHA(struct Hook * , h, A0),
265 AROS_UFHA(APTR , pool, A2),
266 AROS_UFHA(struct ListEntry *, msg, A1))
268 AROS_USERFUNC_INIT
270 FreePooled(pool, msg, sizeof(*msg));
272 AROS_USERFUNC_EXIT
275 /*********************************************************************************************/
277 AROS_UFH3(void, update_func,
278 AROS_UFHA(struct Hook *, h, A0),
279 AROS_UFHA(Object * , object, A2),
280 AROS_UFHA(APTR , msg, A1))
282 AROS_USERFUNC_INIT;
284 struct Screen *scr;
285 struct Window *win;
286 struct ListEntry entry;
288 set(list_gad, MUIA_List_Quiet, TRUE);
289 DoMethod(list_gad, MUIM_List_Clear);
291 /* Get Intuition's first Screen */
292 lock = LockIBase ( 0 );
293 scr = IntuitionBase->FirstScreen;
294 UnlockIBase ( lock );
296 /* Traverse through all Screens */
297 while ( scr )
299 entry.type = Screen_type;
300 entry.aptr = scr;
301 sprintf(entry.address, "%p", scr);
302 sprintf(entry.size, "%d x %d", scr->Width, scr->Height);
303 sprintf(entry.pos, "%d x %d", scr->LeftEdge, scr->TopEdge);
304 entry.status[0] = '\0';
305 snprintf(entry.title, sizeof(entry.title) - 1, "%s", scr->Title ? (char *)scr->Title : "");
306 DoMethod(list_gad, MUIM_List_InsertSingle, &entry, MUIV_List_Insert_Bottom);
308 /* Traverse through all Windows of current Screen */
309 win = scr->FirstWindow;
310 while ( win )
312 entry.type = Window_type;
313 entry.aptr = win;
314 sprintf(entry.address, "%p", win);
315 sprintf(entry.size, "%d x %d", win->Width, win->Height);
316 sprintf(entry.pos, "%d x %d", win->LeftEdge, win->TopEdge);
317 sprintf(entry.status, "%c%c%c",
318 (IsWindowVisible(win) ? ' ' : 'H'),
319 (IS_CHILD(win) ? 'C' : ' '),
320 (HAS_CHILDREN(win) ? 'P' : ' '));
321 snprintf(entry.title, sizeof(entry.title) - 1, "%s", win->Title ? (char *)win->Title : "");
322 DoMethod(list_gad, MUIM_List_InsertSingle, &entry, MUIV_List_Insert_Bottom);
324 win = win->NextWindow;
326 scr = scr->NextScreen;
328 set(list_gad, MUIA_List_Quiet, FALSE);
330 AROS_USERFUNC_EXIT
333 /*********************************************************************************************/
335 AROS_UFH3(void, close_func,
336 AROS_UFHA(struct Hook *, h, A0),
337 AROS_UFHA(Object * , object, A2),
338 AROS_UFHA(APTR , msg, A1))
340 AROS_USERFUNC_INIT;
342 struct Screen *scr;
343 struct Window *win;
344 switch (get_selected(&scr, &win))
346 case Screen_type :
347 if (MUI_Request(app, wnd, 0, TITLE_TXT, YESNO_TXT, CLOSESCREEN_TXT))
349 CloseScreen(scr);
351 break;
352 case Window_type :
353 if (MUI_Request(app, wnd, 0, TITLE_TXT, YESNO_TXT, CLOSEWINDOW_TXT))
355 CloseWindow(win);
357 break;
360 CallHookPkt(&update_hook, 0, 0);
362 AROS_USERFUNC_EXIT
365 /*********************************************************************************************/
367 AROS_UFH3(void, front_func,
368 AROS_UFHA(struct Hook *, h, A0),
369 AROS_UFHA(Object * , object, A2),
370 AROS_UFHA(APTR , msg, A1))
372 AROS_USERFUNC_INIT;
374 struct Screen *scr;
375 struct Window *win;
376 switch (get_selected(&scr, &win))
378 case Screen_type:
379 ScreenToFront(scr);
380 break;
381 case Window_type:
382 WindowToFront(win);
383 break;
386 CallHookPkt(&update_hook, 0, 0);
388 AROS_USERFUNC_EXIT
391 /*********************************************************************************************/
393 AROS_UFH3(void, back_func,
394 AROS_UFHA(struct Hook *, h, A0),
395 AROS_UFHA(Object * , object, A2),
396 AROS_UFHA(APTR , msg, A1))
398 AROS_USERFUNC_INIT;
400 struct Screen *scr;
401 struct Window *win;
402 switch (get_selected(&scr, &win))
404 case Screen_type:
405 ScreenToBack(scr);
406 break;
407 case Window_type:
408 WindowToBack(win);
409 break;
412 CallHookPkt(&update_hook, 0, 0);
414 AROS_USERFUNC_EXIT
417 /*********************************************************************************************/
419 AROS_UFH3(void, origin_func,
420 AROS_UFHA(struct Hook *, h, A0),
421 AROS_UFHA(Object * , object, A2),
422 AROS_UFHA(APTR , msg, A1))
424 AROS_USERFUNC_INIT;
426 struct Screen *scr;
427 struct Window *win;
428 switch (get_selected(&scr, &win))
430 case Screen_type :
431 MoveScreen ( scr, -scr->LeftEdge, -scr->TopEdge );
432 break;
433 case Window_type :
434 MoveWindow ( win, -win->RelLeftEdge, -win->RelTopEdge );
435 break;
438 Delay(5);
439 CallHookPkt(&update_hook, 0, 0);
441 AROS_USERFUNC_EXIT
444 /*********************************************************************************************/
446 AROS_UFH3(void, activate_func,
447 AROS_UFHA(struct Hook *, h, A0),
448 AROS_UFHA(Object * , object, A2),
449 AROS_UFHA(APTR , msg, A1))
451 AROS_USERFUNC_INIT;
453 struct Screen *scr;
454 struct Window *win;
455 if (get_selected(&scr, &win) == Window_type )
457 ActivateWindow ( win );
460 CallHookPkt(&update_hook, 0, 0);
462 AROS_USERFUNC_EXIT
465 /*********************************************************************************************/
467 AROS_UFH3(void, hide_func,
468 AROS_UFHA(struct Hook *, h, A0),
469 AROS_UFHA(Object * , object, A2),
470 AROS_UFHA(APTR , msg, A1))
472 AROS_USERFUNC_INIT;
474 struct Screen *scr;
475 struct Window *win;
476 if (get_selected(&scr, &win) == Window_type)
478 if ((struct Window*)XGET(wnd, MUIA_Window_Window) != win) // You can't hide WiMP
480 HideWindow ( win );
484 Delay(5);
485 CallHookPkt(&update_hook, 0, 0);
487 AROS_USERFUNC_EXIT
490 /*********************************************************************************************/
492 AROS_UFH3(void, show_func,
493 AROS_UFHA(struct Hook *, h, A0),
494 AROS_UFHA(Object * , object, A2),
495 AROS_UFHA(APTR , msg, A1))
497 AROS_USERFUNC_INIT;
499 struct Screen *scr;
500 struct Window *win;
501 if (get_selected(&scr, &win) == Window_type)
503 ShowWindow ( win );
506 Delay(5);
507 CallHookPkt(&update_hook, 0, 0);
509 AROS_USERFUNC_EXIT
512 /*********************************************************************************************/
514 AROS_UFH3(void, zip_func,
515 AROS_UFHA(struct Hook *, h, A0),
516 AROS_UFHA(Object * , object, A2),
517 AROS_UFHA(APTR , msg, A1))
519 AROS_USERFUNC_INIT;
521 struct Screen *scr;
522 struct Window *win;
523 if (get_selected(&scr, &win) == Window_type)
525 ZipWindow ( win );
528 CallHookPkt(&update_hook, 0, 0);
530 AROS_USERFUNC_EXIT
533 /*********************************************************************************************/
535 AROS_UFH3(void, showall_func,
536 AROS_UFHA(struct Hook *, h, A0),
537 AROS_UFHA(Object * , object, A2),
538 AROS_UFHA(APTR , msg, A1))
540 AROS_USERFUNC_INIT;
542 struct Screen *scr;
543 struct Window *win;
545 /* Get Intuition's first Screen */
546 lock = LockIBase ( 0 );
547 scr = IntuitionBase->FirstScreen;
548 UnlockIBase ( lock );
550 /* Traverse through all Screens */
551 while ( scr )
553 win = scr->FirstWindow;
554 /* Traverse through all Windows of current Screen */
555 while ( win )
557 /* Show Window if hidden */
558 if ( IsWindowVisible ( win ) != TRUE )
560 ShowWindow ( win );
562 win = win->NextWindow;
564 scr = scr->NextScreen;
567 Delay(5);
568 CallHookPkt(&update_hook, 0, 0);
570 AROS_USERFUNC_EXIT
573 /*********************************************************************************************/
575 AROS_UFH3(void, rescue_func,
576 AROS_UFHA(struct Hook *, h, A0),
577 AROS_UFHA(Object * , object, A2),
578 AROS_UFHA(APTR , msg, A1))
580 AROS_USERFUNC_INIT;
582 struct Screen *scr;
583 struct Window *win;
584 WORD width, height;
586 /* Get Intuition's first Screen */
587 lock = LockIBase ( 0 );
588 scr = IntuitionBase->FirstScreen;
589 UnlockIBase ( lock );
591 /* Traverse through all Screens */
592 while ( scr )
594 win = scr->FirstWindow;
595 /* Traverse through all Windows of current Screen */
596 while ( win )
598 /* Move Window onto the Screen if outside */
599 if ( win->parent == NULL )
601 WORD dx = 0, dy = 0;
602 if (win->LeftEdge < 0)
603 dx = -win->LeftEdge;
604 else if (win->LeftEdge + win->Width > win->WScreen->Width)
605 dx = win->WScreen->Width - win->Width - win->LeftEdge;
607 if (win->TopEdge + win->Height > win->WScreen->Height)
608 dy = win->WScreen->Height - win->Height - win->TopEdge;
609 else if (win->TopEdge < win->WScreen->BarHeight)
611 // try to keep the screen title bar visible
612 if (win->WScreen->BarHeight + win->Height < win->WScreen->Height)
613 dy = -win->TopEdge + win->WScreen->BarHeight;
614 else
615 dy = win->WScreen->Height - win->Height - win->TopEdge;
617 MoveWindow(win, dx, dy);
619 else
621 width = win->parent->Width;
622 height = win->parent->Height;
623 /* TODO: calculate reasonable values:
624 eg. this way only the Close Gadget my be visible :-( */
625 if ( win->RelLeftEdge < 0
626 || win->RelTopEdge <= -(win->BorderTop)
627 || win->RelLeftEdge > width
628 || win->RelTopEdge >= (height - win->BorderTop) )
630 MoveWindow ( win, - win->RelLeftEdge, - win->RelTopEdge );
633 win = win->NextWindow;
635 scr = scr->NextScreen;
638 Delay(5);
639 CallHookPkt(&update_hook, 0, 0);
641 AROS_USERFUNC_EXIT
644 /*********************************************************************************************/
646 AROS_UFH3(void, rethink_func,
647 AROS_UFHA(struct Hook *, h, A0),
648 AROS_UFHA(Object * , object, A2),
649 AROS_UFHA(APTR , msg, A1))
651 AROS_USERFUNC_INIT
653 RethinkDisplay();
654 CallHookPkt(&update_hook, 0, 0);
656 AROS_USERFUNC_EXIT
659 /*********************************************************************************************/
661 AROS_UFH3(void, about_func,
662 AROS_UFHA(struct Hook *, h, A0),
663 AROS_UFHA(Object * , object, A2),
664 AROS_UFHA(APTR , msg, A1))
666 AROS_USERFUNC_INIT
668 MUI_Request(app, wnd, 0, TITLE_TXT, CONTINUE_TXT, ABOUT_TXT);
670 AROS_USERFUNC_EXIT
673 /*********************************************************************************************/
675 AROS_UFH3(void, update_info_func,
676 AROS_UFHA(struct Hook *, h, A0),
677 AROS_UFHA(Object * , object, A2),
678 AROS_UFHA(APTR , msg, A1))
680 AROS_USERFUNC_INIT;
682 static TEXT buffer[50];
683 struct ListEntry *le;
684 struct Window *win;
685 struct Screen *scr;
687 DoMethod(list_gad, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, (IPTR)&le);
688 if (le)
690 set(close_gad, MUIA_Disabled, FALSE);
691 set(front_gad, MUIA_Disabled, FALSE);
692 set(back_gad, MUIA_Disabled, FALSE);
693 set(origin_gad, MUIA_Disabled, FALSE);
694 set(activate_gad, MUIA_Disabled, FALSE);
695 set(zip_gad, MUIA_Disabled, FALSE);
696 set(hide_gad, MUIA_Disabled, FALSE);
697 set(show_gad, MUIA_Disabled, FALSE);
699 else
701 set(close_gad, MUIA_Disabled, TRUE);
702 set(front_gad, MUIA_Disabled, TRUE);
703 set(back_gad, MUIA_Disabled, TRUE);
704 set(origin_gad, MUIA_Disabled, TRUE);
705 set(activate_gad, MUIA_Disabled, TRUE);
706 set(zip_gad, MUIA_Disabled, TRUE);
707 set(hide_gad, MUIA_Disabled, TRUE);
708 set(show_gad, MUIA_Disabled, TRUE);
711 if (XGET(info_wnd, MUIA_Window_Open))
713 if (le)
715 switch (get_selected(&scr, &win))
717 case Screen_type:
719 scr = le->aptr;
720 set(page_gad, MUIA_Group_ActivePage, 0);
722 sprintf(buffer, "%p", scr);
723 set(info_scr_addr_gad, MUIA_Text_Contents, buffer);
725 sprintf(buffer, "%d", scr->LeftEdge);
726 set(info_scr_leftedge_gad, MUIA_Text_Contents, buffer);
728 sprintf(buffer, "%d", scr->TopEdge);
729 set(info_scr_topedge_gad, MUIA_Text_Contents, buffer);
731 sprintf(buffer, "%d", scr->Width);
732 set(info_scr_width_gad, MUIA_Text_Contents, buffer);
734 sprintf(buffer, "%d", scr->Height);
735 set(info_scr_height_gad, MUIA_Text_Contents, buffer);
737 sprintf(buffer, "0x%08x", scr->Flags);
738 set(info_scr_flags_gad, MUIA_Text_Contents, buffer);
740 set(info_scr_title_gad, MUIA_Text_Contents, scr->Title);
741 set(info_scr_deftitle_gad, MUIA_Text_Contents, scr->DefaultTitle);
743 sprintf(buffer, "%p", scr->FirstWindow);
744 set(info_scr_firstwindow_gad, MUIA_Text_Contents, buffer);
746 break;
748 case Window_type:
749 win = le->aptr;
750 set(page_gad, MUIA_Group_ActivePage, 1);
752 sprintf(buffer, "%p", win);
753 set(info_win_addr_gad, MUIA_Text_Contents, buffer);
755 sprintf(buffer, "%p", win->NextWindow);
756 set(info_win_nextwin_gad, MUIA_Text_Contents, buffer);
758 sprintf(buffer, "%d", win->LeftEdge);
759 set(info_win_leftedge_gad, MUIA_Text_Contents, buffer);
761 sprintf(buffer, "%d", win->TopEdge);
762 set(info_win_topedge_gad, MUIA_Text_Contents, buffer);
764 sprintf(buffer, "%d", win->Height);
765 set(info_win_height_gad, MUIA_Text_Contents, buffer);
767 sprintf(buffer, "%d", win->Width);
768 set(info_win_width_gad, MUIA_Text_Contents, buffer);
770 sprintf(buffer, "%d", win->MinWidth);
771 set(info_win_minwidth_gad, MUIA_Text_Contents, buffer);
773 sprintf(buffer, "%d", win->MinHeight);
774 set(info_win_minheight_gad, MUIA_Text_Contents, buffer);
776 sprintf(buffer, "%d", win->MaxWidth);
777 set(info_win_maxwidth_gad, MUIA_Text_Contents, buffer);
779 sprintf(buffer, "%d", win->MaxHeight);
780 set(info_win_maxheight_gad, MUIA_Text_Contents, buffer);
782 sprintf(buffer, "0x%08x", win->Flags);
783 set(info_win_flags_gad, MUIA_Text_Contents, buffer);
785 sprintf(buffer, "0x%08x", win->IDCMPFlags);
786 set(info_win_idcmp_gad, MUIA_Text_Contents, buffer);
788 set(info_win_title_gad, MUIA_Text_Contents, win->Title);
790 sprintf(buffer, "%d", win->ReqCount);
791 set(info_win_req_gad, MUIA_Text_Contents, buffer);
793 sprintf(buffer, "%p", win->WScreen);
794 set(info_win_screen_gad, MUIA_Text_Contents, buffer);
796 sprintf(buffer, "%d", win->BorderLeft);
797 set(info_win_borderleft_gad, MUIA_Text_Contents, buffer);
799 sprintf(buffer, "%d", win->BorderTop);
800 set(info_win_bordertop_gad, MUIA_Text_Contents, buffer);
802 sprintf(buffer, "%d", win->BorderRight);
803 set(info_win_borderright_gad, MUIA_Text_Contents, buffer);
805 sprintf(buffer, "%d", win->BorderBottom);
806 set(info_win_borderbottom_gad, MUIA_Text_Contents, buffer);
808 sprintf(buffer, "%p", win->parent);
809 set(info_win_parentwin_gad, MUIA_Text_Contents, buffer);
811 sprintf(buffer, "%p", win->firstchild);
812 set(info_win_firstchild_gad, MUIA_Text_Contents, buffer);
814 sprintf(buffer, "%p", win->Parent);
815 set(info_win_parent_gad, MUIA_Text_Contents, buffer);
817 sprintf(buffer, "%p", win->Descendant);
818 set(info_win_descendant_gad, MUIA_Text_Contents, buffer);
820 break;
821 default:
822 // selected screen/window doesn't exist anymore
823 CallHookPkt(&update_hook, 0, 0);
824 break;
827 else // window is open but no entry is selected
829 set(info_scr_addr_gad, MUIA_Text_Contents, NULL);
830 set(info_scr_leftedge_gad, MUIA_Text_Contents, NULL);
831 set(info_scr_topedge_gad, MUIA_Text_Contents, NULL);
832 set(info_scr_width_gad, MUIA_Text_Contents, NULL);
833 set(info_scr_height_gad, MUIA_Text_Contents, NULL);
834 set(info_scr_flags_gad, MUIA_Text_Contents, NULL);
835 set(info_scr_title_gad, MUIA_Text_Contents, NULL);
836 set(info_scr_deftitle_gad, MUIA_Text_Contents, NULL);
837 set(info_scr_firstwindow_gad, MUIA_Text_Contents, NULL);
838 set(info_win_addr_gad, MUIA_Text_Contents, NULL);
839 set(info_win_nextwin_gad, MUIA_Text_Contents, NULL);
840 set(info_win_leftedge_gad, MUIA_Text_Contents, NULL);
841 set(info_win_topedge_gad, MUIA_Text_Contents, NULL);
842 set(info_win_height_gad, MUIA_Text_Contents, NULL);
843 set(info_win_width_gad, MUIA_Text_Contents, NULL);
844 set(info_win_minwidth_gad, MUIA_Text_Contents, NULL);
845 set(info_win_minheight_gad, MUIA_Text_Contents, NULL);
846 set(info_win_maxwidth_gad, MUIA_Text_Contents, NULL);
847 set(info_win_maxheight_gad, MUIA_Text_Contents, NULL);
848 set(info_win_flags_gad, MUIA_Text_Contents, NULL);
849 set(info_win_idcmp_gad, MUIA_Text_Contents, NULL);
850 set(info_win_title_gad, MUIA_Text_Contents, NULL);
851 set(info_win_req_gad, MUIA_Text_Contents, NULL);
852 set(info_win_screen_gad, MUIA_Text_Contents, NULL);
853 set(info_win_borderleft_gad, MUIA_Text_Contents, NULL);
854 set(info_win_bordertop_gad, MUIA_Text_Contents, NULL);
855 set(info_win_borderright_gad, MUIA_Text_Contents, NULL);
856 set(info_win_borderbottom_gad, MUIA_Text_Contents, NULL);
857 set(info_win_parentwin_gad, MUIA_Text_Contents, NULL);
858 set(info_win_firstchild_gad, MUIA_Text_Contents, NULL);
859 set(info_win_parent_gad, MUIA_Text_Contents, NULL);
860 set(info_win_descendant_gad, MUIA_Text_Contents, NULL);
864 AROS_USERFUNC_EXIT
867 /*********************************************************************************************/
869 AROS_UFH3(void, openinfo_func,
870 AROS_UFHA(struct Hook *, h, A0),
871 AROS_UFHA(Object * , object, A2),
872 AROS_UFHA(APTR , msg, A1))
874 AROS_USERFUNC_INIT
876 set(info_wnd, MUIA_Window_Open, TRUE);
877 CallHookPkt(&updateinfo_hook, 0, 0);
878 AROS_USERFUNC_EXIT
881 /*********************************************************************************************/
883 static void MakeGUI(void)
885 Object *menu = MUI_MakeObject(MUIO_MenustripNM, &nm, 0);
887 display_hook.h_Entry = (HOOKFUNC)display_func;
888 construct_hook.h_Entry = (HOOKFUNC)construct_func;
889 destruct_hook.h_Entry = (HOOKFUNC)destruct_func;
891 close_hook.h_Entry = (HOOKFUNC)close_func;
892 front_hook.h_Entry = (HOOKFUNC)front_func;
893 back_hook.h_Entry = (HOOKFUNC)back_func;
894 origin_hook.h_Entry = (HOOKFUNC)origin_func;
895 activate_hook.h_Entry = (HOOKFUNC)activate_func;
896 zip_hook.h_Entry = (HOOKFUNC)zip_func;
897 hide_hook.h_Entry = (HOOKFUNC)hide_func;
898 show_hook.h_Entry = (HOOKFUNC)show_func;
900 update_hook.h_Entry = (HOOKFUNC)update_func;
901 rescue_hook.h_Entry = (HOOKFUNC)rescue_func;
902 showall_hook.h_Entry = (HOOKFUNC)showall_func;
903 rethink_hook.h_Entry = (HOOKFUNC)rethink_func;
904 about_hook.h_Entry = (HOOKFUNC)about_func;
906 openinfo_hook.h_Entry = (HOOKFUNC)openinfo_func;
907 updateinfo_hook.h_Entry = (HOOKFUNC)update_info_func;
909 app = (Object *)ApplicationObject,
910 MUIA_Application_Title, (IPTR)"WiMP",
911 MUIA_Application_Version, (IPTR)version,
912 MUIA_Application_Copyright, (IPTR)"Copyright © 1995-2009, The AROS Development Team",
913 MUIA_Application_Author, (IPTR)"The AROS Development Team",
914 MUIA_Application_Description, (IPTR)"Window Manipulator",
915 MUIA_Application_Base, (IPTR)"WIMP",
916 MUIA_Application_SingleTask, TRUE,
917 MUIA_Application_Menustrip, (IPTR)menu,
918 SubWindow, (IPTR)(wnd = (Object *)WindowObject,
919 MUIA_Window_Title, (IPTR)TITLE_TXT,
920 MUIA_Window_ID, MAKE_ID('W', 'I', 'M', 'P'),
921 WindowContents, (IPTR)(VGroup,
922 Child, (IPTR)(VGroup,
923 GroupFrameT("Screen/Window List"),
924 Child, (IPTR)(ListviewObject,
925 MUIA_Listview_List, (IPTR)(list_gad = (Object *)ListObject,
926 InputListFrame,
927 MUIA_List_Format, (IPTR)"BAR,BAR,P=\033c BAR,P=\033c BAR,BAR,BAR",
928 MUIA_List_ConstructHook, (IPTR)&construct_hook,
929 MUIA_List_DestructHook, (IPTR)&destruct_hook,
930 MUIA_List_DisplayHook, (IPTR)&display_hook,
931 MUIA_List_Title, TRUE,
932 MUIA_CycleChain, 1,
933 End),
934 End),
935 Child, (IPTR)(HGroup,
936 Child, (IPTR)(close_gad = SimpleButton("\033iKill")),
937 Child, (IPTR)(front_gad = SimpleButton("To _Front")),
938 Child, (IPTR)(back_gad = SimpleButton("To _Back")),
939 Child, (IPTR)(origin_gad = SimpleButton("Move to _Origin")),
940 Child, (IPTR)(activate_gad = SimpleButton("_Activate")),
941 Child, (IPTR)(zip_gad = SimpleButton("_Zip")),
942 Child, (IPTR)(hide_gad = SimpleButton("_Hide")),
943 Child, (IPTR)(show_gad = SimpleButton("_Show")),
944 End),
945 Child, (IPTR)(HGroup,
946 Child, (IPTR)(update_gad = SimpleButton("_Update List")),
947 Child, (IPTR)(rescue_gad = SimpleButton("_Rescue all Windows")),
948 Child, (IPTR)(showall_gad = SimpleButton("Show all Windows")),
949 Child, (IPTR)(rethink_gad = SimpleButton("Rethink Display")),
950 Child, (IPTR)(about_gad = SimpleButton("About")),
951 End),
952 End),
953 End),
954 End), // wnd
955 SubWindow, (IPTR)(info_wnd = (Object *)WindowObject,
956 MUIA_Window_Title, (IPTR)INFOTITLE_TXT,
957 MUIA_Window_ID, MAKE_ID('W', 'I', 'N', 'F'),
958 WindowContents, (IPTR)(page_gad = (Object *)PageGroup,
959 Child, (IPTR)(HGroup,
960 Child, (IPTR)(ColGroup(2),
961 GroupFrameT("Screen"),
963 Child, (IPTR)Label("Address"),
964 Child, (IPTR)(info_scr_addr_gad = (Object *)TextObject,
965 TextFrame,
966 MUIA_Text_Contents, (IPTR)"WWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
967 MUIA_Text_SetMin, TRUE,
968 End),
969 Child, (IPTR)Label("LeftEdge"),
970 Child, (IPTR)(info_scr_leftedge_gad = (Object *)TextObject, TextFrame, End),
971 Child, (IPTR)Label("TopEdge"),
972 Child, (IPTR)(info_scr_topedge_gad = (Object *)TextObject, TextFrame, End),
973 Child, (IPTR)Label("Width"),
974 Child, (IPTR)(info_scr_width_gad = (Object *)TextObject, TextFrame, End),
975 Child, (IPTR)Label("Height"),
976 Child, (IPTR)(info_scr_height_gad = (Object *)TextObject, TextFrame, End),
977 Child, (IPTR)Label("Flags"),
978 Child, (IPTR)(info_scr_flags_gad = (Object *)TextObject, TextFrame, End),
979 Child, (IPTR)Label("Title"),
980 Child, (IPTR)(info_scr_title_gad = (Object *)TextObject, TextFrame, End),
981 Child, (IPTR)Label("DefaultTitle"),
982 Child, (IPTR)(info_scr_deftitle_gad = (Object *)TextObject, TextFrame, End),
983 Child, (IPTR)Label("FirstWindow"),
984 Child, (IPTR)(info_scr_firstwindow_gad = (Object *)TextObject, TextFrame, End),
985 End),
986 End),
987 Child, (IPTR)(HGroup,
988 Child, (IPTR)(ColGroup(2),
989 GroupFrameT("Window"),
990 Child, (IPTR)Label("Address"),
991 Child, (IPTR)(info_win_addr_gad = (Object *)TextObject,
992 TextFrame,
993 MUIA_Text_Contents, (IPTR)"WWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
994 MUIA_Text_SetMin, TRUE,
995 End),
996 Child, (IPTR)Label("NextWindow"),
997 Child, (IPTR)(info_win_nextwin_gad = (Object *)TextObject, TextFrame, End),
998 Child, (IPTR)Label("LeftEdge"),
999 Child, (IPTR)(info_win_leftedge_gad = (Object *)TextObject, TextFrame, End),
1000 Child, (IPTR)Label("TopEdge"),
1001 Child, (IPTR)(info_win_topedge_gad = (Object *)TextObject, TextFrame, End),
1002 Child, (IPTR)Label("Width"),
1003 Child, (IPTR)(info_win_width_gad = (Object *)TextObject, TextFrame, End),
1004 Child, (IPTR)Label("Height"),
1005 Child, (IPTR)(info_win_height_gad = (Object *)TextObject, TextFrame, End),
1006 Child, (IPTR)Label("MinWidth"),
1007 Child, (IPTR)(info_win_minwidth_gad = (Object *)TextObject, TextFrame, End),
1008 Child, (IPTR)Label("MinHeight"),
1009 Child, (IPTR)(info_win_minheight_gad = (Object *)TextObject, TextFrame, End),
1010 Child, (IPTR)Label("MaxWidth"),
1011 Child, (IPTR)(info_win_maxwidth_gad = (Object *)TextObject, TextFrame, End),
1012 Child, (IPTR)Label("MaxHeight"),
1013 Child, (IPTR)(info_win_maxheight_gad = (Object *)TextObject, TextFrame, End),
1014 Child, (IPTR)Label("Flags"),
1015 Child, (IPTR)(info_win_flags_gad = (Object *)TextObject, TextFrame, End),
1016 Child, (IPTR)Label("IDCMPFlags"),
1017 Child, (IPTR)(info_win_idcmp_gad = (Object *)TextObject, TextFrame, End),
1018 Child, (IPTR)Label("Title"),
1019 Child, (IPTR)(info_win_title_gad = (Object *)TextObject, TextFrame, End),
1020 Child, (IPTR)Label("ReqCount"),
1021 Child, (IPTR)(info_win_req_gad = (Object *)TextObject, TextFrame, End),
1022 Child, (IPTR)Label("WScreen"),
1023 Child, (IPTR)(info_win_screen_gad = (Object *)TextObject, TextFrame, End),
1024 Child, (IPTR)Label("BorderLeft"),
1025 Child, (IPTR)(info_win_borderleft_gad = (Object *)TextObject, TextFrame, End),
1026 Child, (IPTR)Label("BorderTop"),
1027 Child, (IPTR)(info_win_bordertop_gad = (Object *)TextObject, TextFrame, End),
1028 Child, (IPTR)Label("BorderRight"),
1029 Child, (IPTR)(info_win_borderright_gad = (Object *)TextObject, TextFrame, End),
1030 Child, (IPTR)Label("BoderBottom"),
1031 Child, (IPTR)(info_win_borderbottom_gad = (Object *)TextObject, TextFrame, End),
1032 Child, (IPTR)Label("Parent Window"),
1033 Child, (IPTR)(info_win_parentwin_gad = (Object *)TextObject, TextFrame, End),
1034 Child, (IPTR)Label("First Child"),
1035 Child, (IPTR)(info_win_firstchild_gad = (Object *)TextObject, TextFrame, End),
1036 Child, (IPTR)Label("Parent"),
1037 Child, (IPTR)(info_win_parent_gad = (Object *)TextObject, TextFrame, End),
1038 Child, (IPTR)Label("Descendant"),
1039 Child, (IPTR)(info_win_descendant_gad = (Object *)TextObject, TextFrame, End),
1040 End),
1041 End),
1042 End),
1043 End), // infownd
1044 End; // app
1046 if (! app)
1047 Cleanup(NULL); // Probably double start
1049 DoMethod(wnd, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
1050 app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
1052 DoMethod(info_wnd, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
1053 info_wnd, 3, MUIM_Set, MUIA_Window_Open, FALSE);
1055 DoMethod(list_gad, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
1056 (IPTR)app, 2, MUIM_CallHook, (IPTR)&updateinfo_hook);
1058 DoMethod(list_gad, MUIM_Notify, MUIA_Listview_DoubleClick, TRUE,
1059 (IPTR)app, 2, MUIM_CallHook, (IPTR)&openinfo_hook);
1062 // menu bar
1063 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_QUIT,
1064 (IPTR)app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
1066 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_ABOUT,
1067 (IPTR)app, 2, MUIM_CallHook, (IPTR)&about_hook);
1069 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_UPDATE,
1070 (IPTR)app, 2, MUIM_CallHook, (IPTR)&update_hook);
1072 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_KILL,
1073 (IPTR)app, 2, MUIM_CallHook, (IPTR)&close_hook);
1075 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_FRONT,
1076 (IPTR)app, 2, MUIM_CallHook, (IPTR)&front_hook);
1078 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_BACK,
1079 (IPTR)app, 2, MUIM_CallHook, (IPTR)&back_hook);
1081 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_ORIGIN,
1082 (IPTR)app, 2, MUIM_CallHook, (IPTR)&origin_hook);
1084 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_ACTIVATE,
1085 (IPTR)app, 2, MUIM_CallHook, (IPTR)&activate_hook);
1087 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_ZIP,
1088 (IPTR)app, 2, MUIM_CallHook, (IPTR)&zip_hook);
1090 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_HIDE,
1091 (IPTR)app, 2, MUIM_CallHook, (IPTR)&hide_hook);
1093 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_SHOW,
1094 (IPTR)app, 2, MUIM_CallHook, (IPTR)&show_hook);
1096 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_INFO,
1097 (IPTR)app, 2, MUIM_CallHook, (IPTR)&openinfo_hook);
1099 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_RESCUE,
1100 (IPTR)app, 2, MUIM_CallHook, (IPTR)&rescue_hook);
1102 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_SHOWALL,
1103 (IPTR)app, 2, MUIM_CallHook, (IPTR)&showall_hook);
1105 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_RETHINK,
1106 (IPTR)app, 2, MUIM_CallHook, (IPTR)&rethink_hook);
1109 // buttons first row
1110 DoMethod(close_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1111 (IPTR)app, 2, MUIM_CallHook, (IPTR)&close_hook);
1113 DoMethod(front_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1114 (IPTR)app, 2, MUIM_CallHook, (IPTR)&front_hook);
1116 DoMethod(back_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1117 (IPTR)app, 2, MUIM_CallHook, (IPTR)&back_hook);
1119 DoMethod(origin_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1120 (IPTR)app, 2, MUIM_CallHook, (IPTR)&origin_hook);
1122 DoMethod(activate_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1123 (IPTR)app, 2, MUIM_CallHook, (IPTR)&activate_hook);
1125 DoMethod(zip_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1126 (IPTR)app, 2, MUIM_CallHook, (IPTR)&zip_hook);
1128 DoMethod(hide_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1129 (IPTR)app, 2, MUIM_CallHook, (IPTR)&hide_hook);
1131 DoMethod(show_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1132 (IPTR)app, 2, MUIM_CallHook, (IPTR)&show_hook);
1135 // buttons second row
1136 DoMethod(update_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1137 (IPTR)app, 2, MUIM_CallHook, (IPTR)&update_hook);
1139 DoMethod(rescue_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1140 (IPTR)app, 2, MUIM_CallHook, (IPTR)&rescue_hook);
1142 DoMethod(showall_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1143 (IPTR)app, 2, MUIM_CallHook, (IPTR)&showall_hook);
1145 DoMethod(rethink_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1146 (IPTR)app, 2, MUIM_CallHook, (IPTR)&rethink_hook);
1148 DoMethod(about_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1149 (IPTR)app, 2, MUIM_CallHook, (IPTR)&about_hook);
1151 set(wnd, MUIA_Window_Open, TRUE);
1152 CallHookPkt(&update_hook, 0, 0);
1153 CallHookPkt(&updateinfo_hook, 0, 0);
1154 DoMethod(app, MUIM_Application_Execute);
1157 /*********************************************************************************************/
1159 static void Cleanup(CONST_STRPTR txt)
1161 MUI_DisposeObject(app);
1162 if (txt)
1164 MUI_Request(app, wnd, 0, TITLE_TXT, "OK", txt);
1165 exit(RETURN_ERROR);
1167 exit(RETURN_OK);
1170 /*********************************************************************************************/
1172 int main(int argc, char **argv)
1174 MakeGUI();
1175 Cleanup(NULL);
1176 return RETURN_OK;