Some more autodoc fixes.
[AROS.git] / workbench / tools / WiMP.c
blob99ed05a26de60844c8137f6daa8b3c53e46a922a
1 /*
2 Copyright © 1995-2011, 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 SYS: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>
46 #include <proto/alib.h>
47 #include <proto/muimaster.h>
48 #include <proto/intuition.h>
49 #include <proto/exec.h>
50 #include <proto/dos.h>
51 #include <proto/utility.h>
53 #include <stdlib.h>
54 #include <string.h>
55 #include <stdio.h>
58 static Object *app, *wnd, *list_gad;
60 static Object *close_gad, *front_gad, *back_gad, *origin_gad, *activate_gad, *zip_gad, *hide_gad, *show_gad;
61 static Object *update_gad, *rescue_gad, *showall_gad, *rethink_gad, *about_gad;
63 static Object *info_wnd, *page_gad;
65 static Object *info_scr_addr_gad, *info_scr_leftedge_gad, *info_scr_topedge_gad, *info_scr_width_gad, *info_scr_height_gad,
66 *info_scr_flags_gad, *info_scr_title_gad, *info_scr_deftitle_gad, *info_scr_firstwindow_gad;
69 static Object *info_win_addr_gad, *info_win_nextwin_gad, *info_win_leftedge_gad, *info_win_topedge_gad, *info_win_width_gad,
70 *info_win_height_gad, *info_win_minwidth_gad, *info_win_minheight_gad, *info_win_maxwidth_gad, *info_win_maxheight_gad,
71 *info_win_flags_gad, *info_win_idcmp_gad, *info_win_title_gad, *info_win_req_gad, *info_win_screen_gad,
72 *info_win_borderleft_gad, *info_win_bordertop_gad, *info_win_borderright_gad, *info_win_borderbottom_gad,
73 *info_win_parentwin_gad, *info_win_firstchild_gad, *info_win_parent_gad, *info_win_descendant_gad;
75 static ULONG lock;
78 static struct Hook close_hook, front_hook, back_hook, origin_hook, activate_hook, zip_hook, hide_hook, show_hook;
79 static struct Hook update_hook, rescue_hook, showall_hook, rethink_hook, about_hook;
80 static struct Hook display_hook, construct_hook, destruct_hook;
81 static struct Hook openinfo_hook, updateinfo_hook;
84 static const STRPTR ABOUT_TXT = "WiMP - The Window Manipulation Program\n\n"
85 "Copyright © 2000-2009 by The AROS Development Team";
86 static const STRPTR TITLE_TXT = "WiMP - The Window Manipulation Program";
87 static const STRPTR INFOTITLE_TXT = "WiMP - InfoWindow";
88 static const STRPTR CLOSESCREEN_TXT = "Do you really want to Close the selected Screen?";
89 static const STRPTR CLOSEWINDOW_TXT = "Do you really want to Close the selected Window?";
90 static const STRPTR YESNO_TXT = "Yes.|No!";
91 static const STRPTR CONTINUE_TXT = "Continue";
94 enum {
95 None_type,
96 Window_type,
97 Screen_type,
98 Max_type
102 struct ListEntry
104 LONG type;
105 APTR aptr;
106 TEXT address[20];
107 TEXT size[12];
108 TEXT pos[12];
109 TEXT status[4];
110 TEXT title[40];
113 static const char version[] = "$VER: WiMP 0.13 (06.01.2009) © AROS Dev Team";
115 /*********************************************************************************************/
117 static void Cleanup(CONST_STRPTR txt);
118 static LONG get_selected(struct Screen **scr, struct Window **win);
119 static void MakeGUI(void);
121 /*********************************************************************************************/
123 enum {
124 MN_ABOUT=1,
125 MN_QUIT,
126 MN_UPDATE,
127 MN_KILL,
128 MN_FRONT,
129 MN_BACK,
130 MN_ORIGIN,
131 MN_ACTIVATE,
132 MN_ZIP,
133 MN_HIDE,
134 MN_SHOW,
135 MN_INFO,
136 MN_RESCUE,
137 MN_SHOWALL,
138 MN_RETHINK,
141 static struct NewMenu nm[] =
143 {NM_TITLE, "Project"},
144 {NM_ITEM, "About...", NULL, 0, 0, (APTR)MN_ABOUT},
145 {NM_ITEM, NM_BARLABEL},
146 {NM_ITEM, "Quit", "Q", 0, 0, (APTR)MN_QUIT},
147 {NM_TITLE, "Window List"},
148 {NM_ITEM, "Update List", "U", 0, 0, (APTR)MN_UPDATE},
149 {NM_ITEM, NM_BARLABEL},
150 {NM_ITEM, "Kill", NULL, 0, 0, (APTR)MN_KILL},
151 {NM_ITEM, "To Front", NULL, 0, 0, (APTR)MN_FRONT},
152 {NM_ITEM, "To Back", NULL, 0, 0, (APTR)MN_BACK},
153 {NM_ITEM, "To Origin", NULL, 0, 0, (APTR)MN_ORIGIN},
154 {NM_ITEM, "Activate", NULL, 0, 0, (APTR)MN_ACTIVATE},
155 {NM_ITEM, "Zip", NULL, 0, 0, (APTR)MN_ZIP},
156 {NM_ITEM, "Hide", NULL, 0, 0, (APTR)MN_HIDE},
157 {NM_ITEM, "Show", NULL, 0, 0, (APTR)MN_SHOW},
158 {NM_ITEM, NM_BARLABEL},
159 {NM_ITEM, "Info", NULL, 0, 0, (APTR)MN_INFO},
160 {NM_TITLE, "Generic"},
161 {NM_ITEM, "Rescue All", NULL, 0, 0, (APTR)MN_RESCUE},
162 {NM_ITEM, "Show All", NULL, 0, 0, (APTR)MN_SHOWALL},
163 {NM_ITEM, "RethinkDisplay", NULL, 0, 0, (APTR)MN_RETHINK},
164 {NM_END}
167 /*********************************************************************************************/
169 static LONG get_selected(struct Screen **scr, struct Window **win)
171 *scr = NULL;
172 *win = NULL;
174 struct ListEntry *le;
175 DoMethod(list_gad, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, (IPTR)&le);
177 if (le)
179 lock = LockIBase ( 0 );
180 *scr = IntuitionBase->FirstScreen;
181 UnlockIBase ( lock );
182 /* Traverse through all Screens */
183 while ( *scr )
185 if ((le->type == Screen_type) && (le->aptr == *scr))
187 return Screen_type;
190 /* Traverse through all Windows of current Screen */
191 *win = (*scr)->FirstWindow;
192 while ( *win )
194 if ((le->type == Window_type) && (le->aptr == *win))
196 return Window_type;
199 *win = (*win)->NextWindow;
201 *scr = (*scr)->NextScreen;
204 return None_type;
207 /*********************************************************************************************/
209 AROS_UFH3(void, display_func,
210 AROS_UFHA(struct Hook * , h, A0),
211 AROS_UFHA(char ** , array, A2),
212 AROS_UFHA(struct ListEntry *, msg, A1))
214 AROS_USERFUNC_INIT;
216 if (msg)
218 if (msg->type == Window_type)
220 array[0] = " \033bWindow";
222 else
224 array[0] = "\033b\033uScreen";
226 array[1] = msg->address;
227 array[2] = msg->size;
228 array[3] = msg->pos;
229 array[4] = msg->status;
230 array[5] = msg->title;
232 else
234 array[0] = "Type";
235 array[1] = "Address";
236 array[2] = "Size";
237 array[3] = "Position";
238 array[4] = "Status";
239 array[5] = "Title";
242 AROS_USERFUNC_EXIT
245 /*********************************************************************************************/
247 AROS_UFH3(APTR, construct_func,
248 AROS_UFHA(struct Hook * , h, A0),
249 AROS_UFHA(APTR , pool, A2),
250 AROS_UFHA(struct ListEntry *, msg, A1))
252 AROS_USERFUNC_INIT
254 struct ListEntry *new = AllocPooled(pool, sizeof(*msg));
255 if (new)
256 *new = *msg;
258 return new;
260 AROS_USERFUNC_EXIT
263 /*********************************************************************************************/
265 AROS_UFH3(void, destruct_func,
266 AROS_UFHA(struct Hook * , h, A0),
267 AROS_UFHA(APTR , pool, A2),
268 AROS_UFHA(struct ListEntry *, msg, A1))
270 AROS_USERFUNC_INIT
272 FreePooled(pool, msg, sizeof(*msg));
274 AROS_USERFUNC_EXIT
277 /*********************************************************************************************/
279 AROS_UFH3(void, update_func,
280 AROS_UFHA(struct Hook *, h, A0),
281 AROS_UFHA(Object * , object, A2),
282 AROS_UFHA(APTR , msg, A1))
284 AROS_USERFUNC_INIT;
286 struct Screen *scr;
287 struct Window *win;
288 struct ListEntry entry;
290 set(list_gad, MUIA_List_Quiet, TRUE);
291 DoMethod(list_gad, MUIM_List_Clear);
293 /* Get Intuition's first Screen */
294 lock = LockIBase ( 0 );
295 scr = IntuitionBase->FirstScreen;
296 UnlockIBase ( lock );
298 /* Traverse through all Screens */
299 while ( scr )
301 entry.type = Screen_type;
302 entry.aptr = scr;
303 sprintf(entry.address, "%p", scr);
304 sprintf(entry.size, "%d x %d", scr->Width, scr->Height);
305 sprintf(entry.pos, "%d x %d", scr->LeftEdge, scr->TopEdge);
306 entry.status[0] = '\0';
307 snprintf(entry.title, sizeof(entry.title) - 1, "%s", scr->Title ? (char *)scr->Title : "");
308 DoMethod(list_gad, MUIM_List_InsertSingle, &entry, MUIV_List_Insert_Bottom);
310 /* Traverse through all Windows of current Screen */
311 win = scr->FirstWindow;
312 while ( win )
314 entry.type = Window_type;
315 entry.aptr = win;
316 sprintf(entry.address, "%p", win);
317 sprintf(entry.size, "%d x %d", win->Width, win->Height);
318 sprintf(entry.pos, "%d x %d", win->LeftEdge, win->TopEdge);
319 sprintf(entry.status, "%c%c%c",
320 (IsWindowVisible(win) ? ' ' : 'H'),
321 (IS_CHILD(win) ? 'C' : ' '),
322 (HAS_CHILDREN(win) ? 'P' : ' '));
323 snprintf(entry.title, sizeof(entry.title) - 1, "%s", win->Title ? (char *)win->Title : "");
324 DoMethod(list_gad, MUIM_List_InsertSingle, &entry, MUIV_List_Insert_Bottom);
326 win = win->NextWindow;
328 scr = scr->NextScreen;
330 set(list_gad, MUIA_List_Quiet, FALSE);
332 AROS_USERFUNC_EXIT
335 /*********************************************************************************************/
337 AROS_UFH3(void, close_func,
338 AROS_UFHA(struct Hook *, h, A0),
339 AROS_UFHA(Object * , object, A2),
340 AROS_UFHA(APTR , msg, A1))
342 AROS_USERFUNC_INIT;
344 struct Screen *scr;
345 struct Window *win;
346 switch (get_selected(&scr, &win))
348 case Screen_type :
349 if (MUI_Request(app, wnd, 0, TITLE_TXT, YESNO_TXT, CLOSESCREEN_TXT))
351 CloseScreen(scr);
353 break;
354 case Window_type :
355 if (MUI_Request(app, wnd, 0, TITLE_TXT, YESNO_TXT, CLOSEWINDOW_TXT))
357 CloseWindow(win);
359 break;
362 CallHookPkt(&update_hook, 0, 0);
364 AROS_USERFUNC_EXIT
367 /*********************************************************************************************/
369 AROS_UFH3(void, front_func,
370 AROS_UFHA(struct Hook *, h, A0),
371 AROS_UFHA(Object * , object, A2),
372 AROS_UFHA(APTR , msg, A1))
374 AROS_USERFUNC_INIT;
376 struct Screen *scr;
377 struct Window *win;
378 switch (get_selected(&scr, &win))
380 case Screen_type:
381 ScreenToFront(scr);
382 break;
383 case Window_type:
384 WindowToFront(win);
385 break;
388 CallHookPkt(&update_hook, 0, 0);
390 AROS_USERFUNC_EXIT
393 /*********************************************************************************************/
395 AROS_UFH3(void, back_func,
396 AROS_UFHA(struct Hook *, h, A0),
397 AROS_UFHA(Object * , object, A2),
398 AROS_UFHA(APTR , msg, A1))
400 AROS_USERFUNC_INIT;
402 struct Screen *scr;
403 struct Window *win;
404 switch (get_selected(&scr, &win))
406 case Screen_type:
407 ScreenToBack(scr);
408 break;
409 case Window_type:
410 WindowToBack(win);
411 break;
414 CallHookPkt(&update_hook, 0, 0);
416 AROS_USERFUNC_EXIT
419 /*********************************************************************************************/
421 AROS_UFH3(void, origin_func,
422 AROS_UFHA(struct Hook *, h, A0),
423 AROS_UFHA(Object * , object, A2),
424 AROS_UFHA(APTR , msg, A1))
426 AROS_USERFUNC_INIT;
428 struct Screen *scr;
429 struct Window *win;
430 switch (get_selected(&scr, &win))
432 case Screen_type :
433 MoveScreen ( scr, -scr->LeftEdge, -scr->TopEdge );
434 break;
435 case Window_type :
436 MoveWindow ( win, -win->RelLeftEdge, -win->RelTopEdge );
437 break;
440 Delay(5);
441 CallHookPkt(&update_hook, 0, 0);
443 AROS_USERFUNC_EXIT
446 /*********************************************************************************************/
448 AROS_UFH3(void, activate_func,
449 AROS_UFHA(struct Hook *, h, A0),
450 AROS_UFHA(Object * , object, A2),
451 AROS_UFHA(APTR , msg, A1))
453 AROS_USERFUNC_INIT;
455 struct Screen *scr;
456 struct Window *win;
457 if (get_selected(&scr, &win) == Window_type )
459 ActivateWindow ( win );
462 CallHookPkt(&update_hook, 0, 0);
464 AROS_USERFUNC_EXIT
467 /*********************************************************************************************/
469 AROS_UFH3(void, hide_func,
470 AROS_UFHA(struct Hook *, h, A0),
471 AROS_UFHA(Object * , object, A2),
472 AROS_UFHA(APTR , msg, A1))
474 AROS_USERFUNC_INIT;
476 struct Screen *scr;
477 struct Window *win;
478 if (get_selected(&scr, &win) == Window_type)
480 if ((struct Window*)XGET(wnd, MUIA_Window_Window) != win) // You can't hide WiMP
482 HideWindow ( win );
486 Delay(5);
487 CallHookPkt(&update_hook, 0, 0);
489 AROS_USERFUNC_EXIT
492 /*********************************************************************************************/
494 AROS_UFH3(void, show_func,
495 AROS_UFHA(struct Hook *, h, A0),
496 AROS_UFHA(Object * , object, A2),
497 AROS_UFHA(APTR , msg, A1))
499 AROS_USERFUNC_INIT;
501 struct Screen *scr;
502 struct Window *win;
503 if (get_selected(&scr, &win) == Window_type)
505 ShowWindow (win, WINDOW_FRONTMOST);
508 Delay(5);
509 CallHookPkt(&update_hook, 0, 0);
511 AROS_USERFUNC_EXIT
514 /*********************************************************************************************/
516 AROS_UFH3(void, zip_func,
517 AROS_UFHA(struct Hook *, h, A0),
518 AROS_UFHA(Object * , object, A2),
519 AROS_UFHA(APTR , msg, A1))
521 AROS_USERFUNC_INIT;
523 struct Screen *scr;
524 struct Window *win;
525 if (get_selected(&scr, &win) == Window_type)
527 ZipWindow ( win );
530 CallHookPkt(&update_hook, 0, 0);
532 AROS_USERFUNC_EXIT
535 /*********************************************************************************************/
537 AROS_UFH3(void, showall_func,
538 AROS_UFHA(struct Hook *, h, A0),
539 AROS_UFHA(Object * , object, A2),
540 AROS_UFHA(APTR , msg, A1))
542 AROS_USERFUNC_INIT;
544 struct Screen *scr;
545 struct Window *win;
547 /* Get Intuition's first Screen */
548 lock = LockIBase ( 0 );
549 scr = IntuitionBase->FirstScreen;
550 UnlockIBase ( lock );
552 /* Traverse through all Screens */
553 while ( scr )
555 win = scr->FirstWindow;
556 /* Traverse through all Windows of current Screen */
557 while ( win )
559 /* Show Window if hidden */
560 if ( IsWindowVisible ( win ) != TRUE )
562 ShowWindow (win, WINDOW_FRONTMOST);
564 win = win->NextWindow;
566 scr = scr->NextScreen;
569 Delay(5);
570 CallHookPkt(&update_hook, 0, 0);
572 AROS_USERFUNC_EXIT
575 /*********************************************************************************************/
577 AROS_UFH3(void, rescue_func,
578 AROS_UFHA(struct Hook *, h, A0),
579 AROS_UFHA(Object * , object, A2),
580 AROS_UFHA(APTR , msg, A1))
582 AROS_USERFUNC_INIT;
584 struct Screen *scr;
585 struct Window *win;
586 WORD width, height;
588 /* Get Intuition's first Screen */
589 lock = LockIBase ( 0 );
590 scr = IntuitionBase->FirstScreen;
591 UnlockIBase ( lock );
593 /* Traverse through all Screens */
594 while ( scr )
596 win = scr->FirstWindow;
597 /* Traverse through all Windows of current Screen */
598 while ( win )
600 /* Move Window onto the Screen if outside */
601 if ( win->parent == NULL )
603 WORD dx = 0, dy = 0;
604 if (win->LeftEdge < 0)
605 dx = -win->LeftEdge;
606 else if (win->LeftEdge + win->Width > win->WScreen->Width)
607 dx = win->WScreen->Width - win->Width - win->LeftEdge;
609 if (win->TopEdge + win->Height > win->WScreen->Height)
610 dy = win->WScreen->Height - win->Height - win->TopEdge;
611 else if (win->TopEdge < win->WScreen->BarHeight)
613 // try to keep the screen title bar visible
614 if (win->WScreen->BarHeight + win->Height < win->WScreen->Height)
615 dy = -win->TopEdge + win->WScreen->BarHeight;
616 else
617 dy = win->WScreen->Height - win->Height - win->TopEdge;
619 MoveWindow(win, dx, dy);
621 else
623 width = win->parent->Width;
624 height = win->parent->Height;
625 /* TODO: calculate reasonable values:
626 eg. this way only the Close Gadget my be visible :-( */
627 if ( win->RelLeftEdge < 0
628 || win->RelTopEdge <= -(win->BorderTop)
629 || win->RelLeftEdge > width
630 || win->RelTopEdge >= (height - win->BorderTop) )
632 MoveWindow ( win, - win->RelLeftEdge, - win->RelTopEdge );
635 win = win->NextWindow;
637 scr = scr->NextScreen;
640 Delay(5);
641 CallHookPkt(&update_hook, 0, 0);
643 AROS_USERFUNC_EXIT
646 /*********************************************************************************************/
648 AROS_UFH3(void, rethink_func,
649 AROS_UFHA(struct Hook *, h, A0),
650 AROS_UFHA(Object * , object, A2),
651 AROS_UFHA(APTR , msg, A1))
653 AROS_USERFUNC_INIT
655 RethinkDisplay();
656 CallHookPkt(&update_hook, 0, 0);
658 AROS_USERFUNC_EXIT
661 /*********************************************************************************************/
663 AROS_UFH3(void, about_func,
664 AROS_UFHA(struct Hook *, h, A0),
665 AROS_UFHA(Object * , object, A2),
666 AROS_UFHA(APTR , msg, A1))
668 AROS_USERFUNC_INIT
670 MUI_Request(app, wnd, 0, TITLE_TXT, CONTINUE_TXT, ABOUT_TXT);
672 AROS_USERFUNC_EXIT
675 /*********************************************************************************************/
677 AROS_UFH3(void, update_info_func,
678 AROS_UFHA(struct Hook *, h, A0),
679 AROS_UFHA(Object * , object, A2),
680 AROS_UFHA(APTR , msg, A1))
682 AROS_USERFUNC_INIT;
684 static TEXT buffer[50];
685 struct ListEntry *le;
686 struct Window *win;
687 struct Screen *scr;
689 DoMethod(list_gad, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, (IPTR)&le);
690 if (le)
692 set(close_gad, MUIA_Disabled, FALSE);
693 set(front_gad, MUIA_Disabled, FALSE);
694 set(back_gad, MUIA_Disabled, FALSE);
695 set(origin_gad, MUIA_Disabled, FALSE);
696 set(activate_gad, MUIA_Disabled, FALSE);
697 set(zip_gad, MUIA_Disabled, FALSE);
698 set(hide_gad, MUIA_Disabled, FALSE);
699 set(show_gad, MUIA_Disabled, FALSE);
701 else
703 set(close_gad, MUIA_Disabled, TRUE);
704 set(front_gad, MUIA_Disabled, TRUE);
705 set(back_gad, MUIA_Disabled, TRUE);
706 set(origin_gad, MUIA_Disabled, TRUE);
707 set(activate_gad, MUIA_Disabled, TRUE);
708 set(zip_gad, MUIA_Disabled, TRUE);
709 set(hide_gad, MUIA_Disabled, TRUE);
710 set(show_gad, MUIA_Disabled, TRUE);
713 if (XGET(info_wnd, MUIA_Window_Open))
715 if (le)
717 switch (get_selected(&scr, &win))
719 case Screen_type:
721 scr = le->aptr;
722 set(page_gad, MUIA_Group_ActivePage, 0);
724 sprintf(buffer, "%p", scr);
725 set(info_scr_addr_gad, MUIA_Text_Contents, buffer);
727 sprintf(buffer, "%d", scr->LeftEdge);
728 set(info_scr_leftedge_gad, MUIA_Text_Contents, buffer);
730 sprintf(buffer, "%d", scr->TopEdge);
731 set(info_scr_topedge_gad, MUIA_Text_Contents, buffer);
733 sprintf(buffer, "%d", scr->Width);
734 set(info_scr_width_gad, MUIA_Text_Contents, buffer);
736 sprintf(buffer, "%d", scr->Height);
737 set(info_scr_height_gad, MUIA_Text_Contents, buffer);
739 sprintf(buffer, "0x%08x", scr->Flags);
740 set(info_scr_flags_gad, MUIA_Text_Contents, buffer);
742 set(info_scr_title_gad, MUIA_Text_Contents, scr->Title);
743 set(info_scr_deftitle_gad, MUIA_Text_Contents, scr->DefaultTitle);
745 sprintf(buffer, "%p", scr->FirstWindow);
746 set(info_scr_firstwindow_gad, MUIA_Text_Contents, buffer);
748 break;
750 case Window_type:
751 win = le->aptr;
752 set(page_gad, MUIA_Group_ActivePage, 1);
754 sprintf(buffer, "%p", win);
755 set(info_win_addr_gad, MUIA_Text_Contents, buffer);
757 sprintf(buffer, "%p", win->NextWindow);
758 set(info_win_nextwin_gad, MUIA_Text_Contents, buffer);
760 sprintf(buffer, "%d", win->LeftEdge);
761 set(info_win_leftedge_gad, MUIA_Text_Contents, buffer);
763 sprintf(buffer, "%d", win->TopEdge);
764 set(info_win_topedge_gad, MUIA_Text_Contents, buffer);
766 sprintf(buffer, "%d", win->Height);
767 set(info_win_height_gad, MUIA_Text_Contents, buffer);
769 sprintf(buffer, "%d", win->Width);
770 set(info_win_width_gad, MUIA_Text_Contents, buffer);
772 sprintf(buffer, "%d", win->MinWidth);
773 set(info_win_minwidth_gad, MUIA_Text_Contents, buffer);
775 sprintf(buffer, "%d", win->MinHeight);
776 set(info_win_minheight_gad, MUIA_Text_Contents, buffer);
778 sprintf(buffer, "%d", win->MaxWidth);
779 set(info_win_maxwidth_gad, MUIA_Text_Contents, buffer);
781 sprintf(buffer, "%d", win->MaxHeight);
782 set(info_win_maxheight_gad, MUIA_Text_Contents, buffer);
784 sprintf(buffer, "0x%08x", (unsigned int)win->Flags);
785 set(info_win_flags_gad, MUIA_Text_Contents, buffer);
787 sprintf(buffer, "0x%08x", (unsigned int)win->IDCMPFlags);
788 set(info_win_idcmp_gad, MUIA_Text_Contents, buffer);
790 set(info_win_title_gad, MUIA_Text_Contents, win->Title);
792 sprintf(buffer, "%d", win->ReqCount);
793 set(info_win_req_gad, MUIA_Text_Contents, buffer);
795 sprintf(buffer, "%p", win->WScreen);
796 set(info_win_screen_gad, MUIA_Text_Contents, buffer);
798 sprintf(buffer, "%d", win->BorderLeft);
799 set(info_win_borderleft_gad, MUIA_Text_Contents, buffer);
801 sprintf(buffer, "%d", win->BorderTop);
802 set(info_win_bordertop_gad, MUIA_Text_Contents, buffer);
804 sprintf(buffer, "%d", win->BorderRight);
805 set(info_win_borderright_gad, MUIA_Text_Contents, buffer);
807 sprintf(buffer, "%d", win->BorderBottom);
808 set(info_win_borderbottom_gad, MUIA_Text_Contents, buffer);
810 sprintf(buffer, "%p", win->parent);
811 set(info_win_parentwin_gad, MUIA_Text_Contents, buffer);
813 sprintf(buffer, "%p", win->firstchild);
814 set(info_win_firstchild_gad, MUIA_Text_Contents, buffer);
816 sprintf(buffer, "%p", win->Parent);
817 set(info_win_parent_gad, MUIA_Text_Contents, buffer);
819 sprintf(buffer, "%p", win->Descendant);
820 set(info_win_descendant_gad, MUIA_Text_Contents, buffer);
822 break;
823 default:
824 // selected screen/window doesn't exist anymore
825 CallHookPkt(&update_hook, 0, 0);
826 break;
829 else // window is open but no entry is selected
831 set(info_scr_addr_gad, MUIA_Text_Contents, NULL);
832 set(info_scr_leftedge_gad, MUIA_Text_Contents, NULL);
833 set(info_scr_topedge_gad, MUIA_Text_Contents, NULL);
834 set(info_scr_width_gad, MUIA_Text_Contents, NULL);
835 set(info_scr_height_gad, MUIA_Text_Contents, NULL);
836 set(info_scr_flags_gad, MUIA_Text_Contents, NULL);
837 set(info_scr_title_gad, MUIA_Text_Contents, NULL);
838 set(info_scr_deftitle_gad, MUIA_Text_Contents, NULL);
839 set(info_scr_firstwindow_gad, MUIA_Text_Contents, NULL);
840 set(info_win_addr_gad, MUIA_Text_Contents, NULL);
841 set(info_win_nextwin_gad, MUIA_Text_Contents, NULL);
842 set(info_win_leftedge_gad, MUIA_Text_Contents, NULL);
843 set(info_win_topedge_gad, MUIA_Text_Contents, NULL);
844 set(info_win_height_gad, MUIA_Text_Contents, NULL);
845 set(info_win_width_gad, MUIA_Text_Contents, NULL);
846 set(info_win_minwidth_gad, MUIA_Text_Contents, NULL);
847 set(info_win_minheight_gad, MUIA_Text_Contents, NULL);
848 set(info_win_maxwidth_gad, MUIA_Text_Contents, NULL);
849 set(info_win_maxheight_gad, MUIA_Text_Contents, NULL);
850 set(info_win_flags_gad, MUIA_Text_Contents, NULL);
851 set(info_win_idcmp_gad, MUIA_Text_Contents, NULL);
852 set(info_win_title_gad, MUIA_Text_Contents, NULL);
853 set(info_win_req_gad, MUIA_Text_Contents, NULL);
854 set(info_win_screen_gad, MUIA_Text_Contents, NULL);
855 set(info_win_borderleft_gad, MUIA_Text_Contents, NULL);
856 set(info_win_bordertop_gad, MUIA_Text_Contents, NULL);
857 set(info_win_borderright_gad, MUIA_Text_Contents, NULL);
858 set(info_win_borderbottom_gad, MUIA_Text_Contents, NULL);
859 set(info_win_parentwin_gad, MUIA_Text_Contents, NULL);
860 set(info_win_firstchild_gad, MUIA_Text_Contents, NULL);
861 set(info_win_parent_gad, MUIA_Text_Contents, NULL);
862 set(info_win_descendant_gad, MUIA_Text_Contents, NULL);
866 AROS_USERFUNC_EXIT
869 /*********************************************************************************************/
871 AROS_UFH3(void, openinfo_func,
872 AROS_UFHA(struct Hook *, h, A0),
873 AROS_UFHA(Object * , object, A2),
874 AROS_UFHA(APTR , msg, A1))
876 AROS_USERFUNC_INIT
878 set(info_wnd, MUIA_Window_Open, TRUE);
879 CallHookPkt(&updateinfo_hook, 0, 0);
880 AROS_USERFUNC_EXIT
883 /*********************************************************************************************/
885 static void MakeGUI(void)
887 Object *menu = MUI_MakeObject(MUIO_MenustripNM, &nm, 0);
889 display_hook.h_Entry = (HOOKFUNC)display_func;
890 construct_hook.h_Entry = (HOOKFUNC)construct_func;
891 destruct_hook.h_Entry = (HOOKFUNC)destruct_func;
893 close_hook.h_Entry = (HOOKFUNC)close_func;
894 front_hook.h_Entry = (HOOKFUNC)front_func;
895 back_hook.h_Entry = (HOOKFUNC)back_func;
896 origin_hook.h_Entry = (HOOKFUNC)origin_func;
897 activate_hook.h_Entry = (HOOKFUNC)activate_func;
898 zip_hook.h_Entry = (HOOKFUNC)zip_func;
899 hide_hook.h_Entry = (HOOKFUNC)hide_func;
900 show_hook.h_Entry = (HOOKFUNC)show_func;
902 update_hook.h_Entry = (HOOKFUNC)update_func;
903 rescue_hook.h_Entry = (HOOKFUNC)rescue_func;
904 showall_hook.h_Entry = (HOOKFUNC)showall_func;
905 rethink_hook.h_Entry = (HOOKFUNC)rethink_func;
906 about_hook.h_Entry = (HOOKFUNC)about_func;
908 openinfo_hook.h_Entry = (HOOKFUNC)openinfo_func;
909 updateinfo_hook.h_Entry = (HOOKFUNC)update_info_func;
911 app = (Object *)ApplicationObject,
912 MUIA_Application_Title, (IPTR)"WiMP",
913 MUIA_Application_Version, (IPTR)version,
914 MUIA_Application_Copyright, (IPTR)"Copyright © 1995-2009, The AROS Development Team",
915 MUIA_Application_Author, (IPTR)"The AROS Development Team",
916 MUIA_Application_Description, (IPTR)"Window Manipulator",
917 MUIA_Application_Base, (IPTR)"WIMP",
918 MUIA_Application_SingleTask, TRUE,
919 MUIA_Application_Menustrip, (IPTR)menu,
920 SubWindow, (IPTR)(wnd = (Object *)WindowObject,
921 MUIA_Window_Title, (IPTR)TITLE_TXT,
922 MUIA_Window_ID, MAKE_ID('W', 'I', 'M', 'P'),
923 WindowContents, (IPTR)(VGroup,
924 Child, (IPTR)(VGroup,
925 GroupFrameT("Screen/Window List"),
926 Child, (IPTR)(ListviewObject,
927 MUIA_Listview_List, (IPTR)(list_gad = (Object *)ListObject,
928 InputListFrame,
929 MUIA_List_Format, (IPTR)"BAR,BAR,P=\033c BAR,P=\033c BAR,BAR,BAR",
930 MUIA_List_ConstructHook, (IPTR)&construct_hook,
931 MUIA_List_DestructHook, (IPTR)&destruct_hook,
932 MUIA_List_DisplayHook, (IPTR)&display_hook,
933 MUIA_List_Title, TRUE,
934 MUIA_CycleChain, 1,
935 End),
936 End),
937 Child, (IPTR)(HGroup,
938 Child, (IPTR)(close_gad = SimpleButton("\033iKill")),
939 Child, (IPTR)(front_gad = SimpleButton("To _Front")),
940 Child, (IPTR)(back_gad = SimpleButton("To _Back")),
941 Child, (IPTR)(origin_gad = SimpleButton("Move to _Origin")),
942 Child, (IPTR)(activate_gad = SimpleButton("_Activate")),
943 Child, (IPTR)(zip_gad = SimpleButton("_Zip")),
944 Child, (IPTR)(hide_gad = SimpleButton("_Hide")),
945 Child, (IPTR)(show_gad = SimpleButton("_Show")),
946 End),
947 Child, (IPTR)(HGroup,
948 Child, (IPTR)(update_gad = SimpleButton("_Update List")),
949 Child, (IPTR)(rescue_gad = SimpleButton("_Rescue all Windows")),
950 Child, (IPTR)(showall_gad = SimpleButton("Show all Windows")),
951 Child, (IPTR)(rethink_gad = SimpleButton("Rethink Display")),
952 Child, (IPTR)(about_gad = SimpleButton("About")),
953 End),
954 End),
955 End),
956 End), // wnd
957 SubWindow, (IPTR)(info_wnd = (Object *)WindowObject,
958 MUIA_Window_Title, (IPTR)INFOTITLE_TXT,
959 MUIA_Window_ID, MAKE_ID('W', 'I', 'N', 'F'),
960 WindowContents, (IPTR)(page_gad = (Object *)PageGroup,
961 Child, (IPTR)(HGroup,
962 Child, (IPTR)(ColGroup(2),
963 GroupFrameT("Screen"),
965 Child, (IPTR)Label("Address"),
966 Child, (IPTR)(info_scr_addr_gad = (Object *)TextObject,
967 TextFrame,
968 MUIA_Text_Contents, (IPTR)"WWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
969 MUIA_Text_SetMin, TRUE,
970 End),
971 Child, (IPTR)Label("LeftEdge"),
972 Child, (IPTR)(info_scr_leftedge_gad = (Object *)TextObject, TextFrame, End),
973 Child, (IPTR)Label("TopEdge"),
974 Child, (IPTR)(info_scr_topedge_gad = (Object *)TextObject, TextFrame, End),
975 Child, (IPTR)Label("Width"),
976 Child, (IPTR)(info_scr_width_gad = (Object *)TextObject, TextFrame, End),
977 Child, (IPTR)Label("Height"),
978 Child, (IPTR)(info_scr_height_gad = (Object *)TextObject, TextFrame, End),
979 Child, (IPTR)Label("Flags"),
980 Child, (IPTR)(info_scr_flags_gad = (Object *)TextObject, TextFrame, End),
981 Child, (IPTR)Label("Title"),
982 Child, (IPTR)(info_scr_title_gad = (Object *)TextObject, TextFrame, End),
983 Child, (IPTR)Label("DefaultTitle"),
984 Child, (IPTR)(info_scr_deftitle_gad = (Object *)TextObject, TextFrame, End),
985 Child, (IPTR)Label("FirstWindow"),
986 Child, (IPTR)(info_scr_firstwindow_gad = (Object *)TextObject, TextFrame, End),
987 End),
988 End),
989 Child, (IPTR)(HGroup,
990 Child, (IPTR)(ColGroup(2),
991 GroupFrameT("Window"),
992 Child, (IPTR)Label("Address"),
993 Child, (IPTR)(info_win_addr_gad = (Object *)TextObject,
994 TextFrame,
995 MUIA_Text_Contents, (IPTR)"WWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
996 MUIA_Text_SetMin, TRUE,
997 End),
998 Child, (IPTR)Label("NextWindow"),
999 Child, (IPTR)(info_win_nextwin_gad = (Object *)TextObject, TextFrame, End),
1000 Child, (IPTR)Label("LeftEdge"),
1001 Child, (IPTR)(info_win_leftedge_gad = (Object *)TextObject, TextFrame, End),
1002 Child, (IPTR)Label("TopEdge"),
1003 Child, (IPTR)(info_win_topedge_gad = (Object *)TextObject, TextFrame, End),
1004 Child, (IPTR)Label("Width"),
1005 Child, (IPTR)(info_win_width_gad = (Object *)TextObject, TextFrame, End),
1006 Child, (IPTR)Label("Height"),
1007 Child, (IPTR)(info_win_height_gad = (Object *)TextObject, TextFrame, End),
1008 Child, (IPTR)Label("MinWidth"),
1009 Child, (IPTR)(info_win_minwidth_gad = (Object *)TextObject, TextFrame, End),
1010 Child, (IPTR)Label("MinHeight"),
1011 Child, (IPTR)(info_win_minheight_gad = (Object *)TextObject, TextFrame, End),
1012 Child, (IPTR)Label("MaxWidth"),
1013 Child, (IPTR)(info_win_maxwidth_gad = (Object *)TextObject, TextFrame, End),
1014 Child, (IPTR)Label("MaxHeight"),
1015 Child, (IPTR)(info_win_maxheight_gad = (Object *)TextObject, TextFrame, End),
1016 Child, (IPTR)Label("Flags"),
1017 Child, (IPTR)(info_win_flags_gad = (Object *)TextObject, TextFrame, End),
1018 Child, (IPTR)Label("IDCMPFlags"),
1019 Child, (IPTR)(info_win_idcmp_gad = (Object *)TextObject, TextFrame, End),
1020 Child, (IPTR)Label("Title"),
1021 Child, (IPTR)(info_win_title_gad = (Object *)TextObject, TextFrame, End),
1022 Child, (IPTR)Label("ReqCount"),
1023 Child, (IPTR)(info_win_req_gad = (Object *)TextObject, TextFrame, End),
1024 Child, (IPTR)Label("WScreen"),
1025 Child, (IPTR)(info_win_screen_gad = (Object *)TextObject, TextFrame, End),
1026 Child, (IPTR)Label("BorderLeft"),
1027 Child, (IPTR)(info_win_borderleft_gad = (Object *)TextObject, TextFrame, End),
1028 Child, (IPTR)Label("BorderTop"),
1029 Child, (IPTR)(info_win_bordertop_gad = (Object *)TextObject, TextFrame, End),
1030 Child, (IPTR)Label("BorderRight"),
1031 Child, (IPTR)(info_win_borderright_gad = (Object *)TextObject, TextFrame, End),
1032 Child, (IPTR)Label("BoderBottom"),
1033 Child, (IPTR)(info_win_borderbottom_gad = (Object *)TextObject, TextFrame, End),
1034 Child, (IPTR)Label("Parent Window"),
1035 Child, (IPTR)(info_win_parentwin_gad = (Object *)TextObject, TextFrame, End),
1036 Child, (IPTR)Label("First Child"),
1037 Child, (IPTR)(info_win_firstchild_gad = (Object *)TextObject, TextFrame, End),
1038 Child, (IPTR)Label("Parent"),
1039 Child, (IPTR)(info_win_parent_gad = (Object *)TextObject, TextFrame, End),
1040 Child, (IPTR)Label("Descendant"),
1041 Child, (IPTR)(info_win_descendant_gad = (Object *)TextObject, TextFrame, End),
1042 End),
1043 End),
1044 End),
1045 End), // infownd
1046 End; // app
1048 if (! app)
1049 Cleanup(NULL); // Probably double start
1051 DoMethod(wnd, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
1052 app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
1054 DoMethod(info_wnd, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
1055 info_wnd, 3, MUIM_Set, MUIA_Window_Open, FALSE);
1057 DoMethod(list_gad, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
1058 (IPTR)app, 2, MUIM_CallHook, (IPTR)&updateinfo_hook);
1060 DoMethod(list_gad, MUIM_Notify, MUIA_Listview_DoubleClick, TRUE,
1061 (IPTR)app, 2, MUIM_CallHook, (IPTR)&openinfo_hook);
1064 // menu bar
1065 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_QUIT,
1066 (IPTR)app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
1068 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_ABOUT,
1069 (IPTR)app, 2, MUIM_CallHook, (IPTR)&about_hook);
1071 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_UPDATE,
1072 (IPTR)app, 2, MUIM_CallHook, (IPTR)&update_hook);
1074 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_KILL,
1075 (IPTR)app, 2, MUIM_CallHook, (IPTR)&close_hook);
1077 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_FRONT,
1078 (IPTR)app, 2, MUIM_CallHook, (IPTR)&front_hook);
1080 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_BACK,
1081 (IPTR)app, 2, MUIM_CallHook, (IPTR)&back_hook);
1083 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_ORIGIN,
1084 (IPTR)app, 2, MUIM_CallHook, (IPTR)&origin_hook);
1086 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_ACTIVATE,
1087 (IPTR)app, 2, MUIM_CallHook, (IPTR)&activate_hook);
1089 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_ZIP,
1090 (IPTR)app, 2, MUIM_CallHook, (IPTR)&zip_hook);
1092 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_HIDE,
1093 (IPTR)app, 2, MUIM_CallHook, (IPTR)&hide_hook);
1095 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_SHOW,
1096 (IPTR)app, 2, MUIM_CallHook, (IPTR)&show_hook);
1098 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_INFO,
1099 (IPTR)app, 2, MUIM_CallHook, (IPTR)&openinfo_hook);
1101 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_RESCUE,
1102 (IPTR)app, 2, MUIM_CallHook, (IPTR)&rescue_hook);
1104 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_SHOWALL,
1105 (IPTR)app, 2, MUIM_CallHook, (IPTR)&showall_hook);
1107 DoMethod(app, MUIM_Notify, MUIA_Application_MenuAction, MN_RETHINK,
1108 (IPTR)app, 2, MUIM_CallHook, (IPTR)&rethink_hook);
1111 // buttons first row
1112 DoMethod(close_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1113 (IPTR)app, 2, MUIM_CallHook, (IPTR)&close_hook);
1115 DoMethod(front_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1116 (IPTR)app, 2, MUIM_CallHook, (IPTR)&front_hook);
1118 DoMethod(back_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1119 (IPTR)app, 2, MUIM_CallHook, (IPTR)&back_hook);
1121 DoMethod(origin_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1122 (IPTR)app, 2, MUIM_CallHook, (IPTR)&origin_hook);
1124 DoMethod(activate_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1125 (IPTR)app, 2, MUIM_CallHook, (IPTR)&activate_hook);
1127 DoMethod(zip_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1128 (IPTR)app, 2, MUIM_CallHook, (IPTR)&zip_hook);
1130 DoMethod(hide_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1131 (IPTR)app, 2, MUIM_CallHook, (IPTR)&hide_hook);
1133 DoMethod(show_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1134 (IPTR)app, 2, MUIM_CallHook, (IPTR)&show_hook);
1137 // buttons second row
1138 DoMethod(update_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1139 (IPTR)app, 2, MUIM_CallHook, (IPTR)&update_hook);
1141 DoMethod(rescue_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1142 (IPTR)app, 2, MUIM_CallHook, (IPTR)&rescue_hook);
1144 DoMethod(showall_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1145 (IPTR)app, 2, MUIM_CallHook, (IPTR)&showall_hook);
1147 DoMethod(rethink_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1148 (IPTR)app, 2, MUIM_CallHook, (IPTR)&rethink_hook);
1150 DoMethod(about_gad, MUIM_Notify, MUIA_Pressed, FALSE,
1151 (IPTR)app, 2, MUIM_CallHook, (IPTR)&about_hook);
1153 set(wnd, MUIA_Window_Open, TRUE);
1154 CallHookPkt(&update_hook, 0, 0);
1155 CallHookPkt(&updateinfo_hook, 0, 0);
1156 DoMethod(app, MUIM_Application_Execute);
1159 /*********************************************************************************************/
1161 static void Cleanup(CONST_STRPTR txt)
1163 MUI_DisposeObject(app);
1164 if (txt)
1166 MUI_Request(app, wnd, 0, TITLE_TXT, "OK", txt);
1167 exit(RETURN_ERROR);
1169 exit(RETURN_OK);
1172 /*********************************************************************************************/
1174 int main(int argc, char **argv)
1176 MakeGUI();
1177 Cleanup(NULL);
1178 return RETURN_OK;