2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
6 /*********************************************************************************************/
9 #include "registertab.h"
11 #if USE_SHARED_COOLIMAGES
12 #include <libraries/coolimages.h>
13 #include <proto/coolimages.h>
15 #include <linklibs/coolimages.h>
18 #include <stdlib.h> /* for exit() */
22 /*********************************************************************************************/
24 #define ARG_TEMPLATE "FROM,EDIT/S,USE/S,SAVE/S,MAP/K,PUBSCREEN/K"
31 #define ARG_PUBSCREEN 5
35 /*********************************************************************************************/
46 {&IntuitionBase
, "intuition.library" , 39, TRUE
},
47 {&GfxBase
, "graphics.library" , 40, TRUE
}, /* 40, because of WriteChunkyPixels */
48 {&GadToolsBase
, "gadtools.library" , 39, TRUE
},
49 {&UtilityBase
, "utility.library" , 39, TRUE
},
50 {&IFFParseBase
, "iffparse.library" , 39, TRUE
},
51 {&CyberGfxBase
, "cybergraphics.library", 39, FALSE
},
52 {&DataTypesBase
, "datatypes.library" , 39, FALSE
},
53 #if USE_SHARED_COOLIMAGES
54 {&CoolImagesBase
, "coolimages.library" , 1, TRUE
},
59 /*********************************************************************************************/
66 LONG (*handler
)(LONG
, IPTR
);
70 pagetable
[NUM_PAGES
] =
72 {MSG_GAD_TAB_LANGUAGE
, page_language_handler
},
73 {MSG_GAD_TAB_COUNTRY
, page_country_handler
},
74 {MSG_GAD_TAB_TIMEZONE
, page_timezone_handler
}
77 /*********************************************************************************************/
84 const struct CoolImage
*image
;
87 buttontable
[NUM_BUTTONS
] =
89 #if USE_SHARED_COOLIMAGES
90 {MSG_GAD_SAVE
, (const struct CoolImage
*)COOL_SAVEIMAGE_ID
},
91 {MSG_GAD_USE
, (const struct CoolImage
*)COOL_DOTIMAGE_ID
},
92 {MSG_GAD_CANCEL
, (const struct CoolImage
*)COOL_CANCELIMAGE_ID
}
94 {MSG_GAD_SAVE
, &cool_saveimage
},
95 {MSG_GAD_USE
, &cool_dotimage
},
96 {MSG_GAD_CANCEL
, &cool_cancelimage
}
100 /*********************************************************************************************/
102 static struct RegisterTabItem regitems
[NUM_PAGES
+ 1];
103 static struct RegisterTab reg
;
104 static struct RDArgs
*myargs
;
105 static WORD activetab
;
106 static IPTR args
[NUM_ARGS
];
108 /*********************************************************************************************/
110 static void CloseLibs(void);
111 static void FreeArguments(void);
112 static void FreeVisual(void);
113 static void KillPages(void);
114 static void KillWin(void);
115 static void KillGadgets(void);
117 /*********************************************************************************************/
119 WORD
ShowMessage(CONST_STRPTR title
, CONST_STRPTR text
, CONST_STRPTR gadtext
)
121 struct EasyStruct es
;
123 es
.es_StructSize
= sizeof(es
);
126 es
.es_TextFormat
= text
;
127 es
.es_GadgetFormat
= gadtext
;
129 return EasyRequestArgs(win
, &es
, NULL
, NULL
);
132 /*********************************************************************************************/
134 void Cleanup(CONST_STRPTR msg
)
138 if (IntuitionBase
&& !((struct Process
*)FindTask(NULL
))->pr_CLI
)
140 ShowMessage("Locale", msg
, MSG(MSG_OK
));
142 printf("Locale: %s\n", msg
);
160 /*********************************************************************************************/
162 static void OpenLibs(void)
166 for(li
= libtable
; li
->var
; li
++)
168 if (!((*(struct Library
**)li
->var
) = OpenLibrary(li
->name
, li
->version
)))
172 sprintf(s
, MSG(MSG_CANT_OPEN_LIB
), li
->name
, li
->version
);
180 /*********************************************************************************************/
182 static void CloseLibs(void)
186 for(li
= libtable
; li
->var
; li
++)
188 if (*(struct Library
**)li
->var
) CloseLibrary((*(struct Library
**)li
->var
));
192 /*********************************************************************************************/
194 static void GetArguments(void)
196 if (!(myargs
= ReadArgs(ARG_TEMPLATE
, args
, NULL
)))
198 Fault(IoErr(), 0, s
, 256);
202 if (!args
[ARG_FROM
]) args
[ARG_FROM
] = (IPTR
)CONFIGNAME_ENV
;
205 /*********************************************************************************************/
207 static void FreeArguments(void)
209 if (myargs
) FreeArgs(myargs
);
212 /*********************************************************************************************/
214 static void GetVisual(void)
216 scr
= LockPubScreen((CONST_STRPTR
)args
[ARG_PUBSCREEN
]);
217 if (!scr
) Cleanup(MSG(MSG_CANT_LOCK_SCR
));
219 dri
= GetScreenDrawInfo(scr
);
220 if (!dri
) Cleanup(MSG(MSG_CANT_GET_DRI
));
222 vi
= GetVisualInfoA(scr
, NULL
);
223 if (!vi
) Cleanup(MSG(MSG_CANT_GET_VI
));
227 truecolor
= GetBitMapAttr(scr
->RastPort
.BitMap
, BMA_DEPTH
) >= 15;
231 /*********************************************************************************************/
233 static void FreeVisual(void)
235 if (vi
) FreeVisualInfo(vi
);
236 if (dri
) FreeScreenDrawInfo(scr
, dri
);
237 if (scr
) UnlockPubScreen(NULL
, scr
);
240 /*********************************************************************************************/
242 static void MakePages(void)
244 static const struct CoolImage
*tabimages
[] =
246 #if USE_SHARED_COOLIMAGES
247 (const struct CoolImage
*)COOL_HEADIMAGE_ID
,
248 (const struct CoolImage
*)COOL_FLAGIMAGE_ID
,
249 (const struct CoolImage
*)COOL_CLOCKIMAGE_ID
258 BOOL cool_imageclass_ok
= FALSE
;
262 #if USE_SHARED_COOLIMAGES
263 cool_imageclass_ok
= (CoolImagesBase
!= NULL
);
265 cool_imageclass_ok
= InitCoolImageClass(CyberGfxBase
);
267 if (cool_imageclass_ok
)
271 GetRGB32(scr
->ViewPort
.ColorMap
,
272 dri
->dri_Pens
[BACKGROUNDPEN
],
276 bgcol
= ((col
[0] & 0xFF000000) >> 8) +
277 ((col
[1] & 0xFF000000) >> 16) +
278 ((col
[2] & 0xFF000000) >> 24);
283 for(i
= 0; i
< NUM_PAGES
; i
++)
285 regitems
[i
].text
= MSG(pagetable
[i
].nameid
);
286 if (cool_imageclass_ok
)
288 #if USE_SHARED_COOLIMAGES
289 tabimages
[i
] = (const struct CoolImage
*)COOL_ObtainImageA((ULONG
)tabimages
[i
], NULL
);
291 regitems
[i
].image
= NewObject(NULL
, COOLIMAGECLASS
, IA_Width
, tabimages
[i
]->width
,
292 IA_Height
, tabimages
[i
]->height
,
293 COOLIM_CoolImage
, (IPTR
)tabimages
[i
] ,
294 COOLIM_BgColor
, bgcol
,
297 regitems
[i
].image
= NewObject(cool_imageclass
, NULL
, IA_Width
, tabimages
[i
]->width
,
298 IA_Height
, tabimages
[i
]->height
,
299 COOLIM_CoolImage
, (IPTR
)tabimages
[i
] ,
300 COOLIM_BgColor
, bgcol
,
304 if (!(pagetable
[i
].handler(PAGECMD_INIT
, 0)))
306 Cleanup(MSG(MSG_CANT_CREATE_GADGET
));
310 InitRegisterTab(®
, regitems
);
314 /*********************************************************************************************/
316 static void KillPages(void)
320 for(i
= 0; i
< NUM_PAGES
; i
++)
322 pagetable
[i
].handler(PAGECMD_CLEANUP
, 0);
323 if (regitems
[i
].image
) DisposeObject(regitems
[i
].image
);
326 #if !USE_SHARED_COOLIMAGES
327 CleanupCoolImageClass();
331 /*********************************************************************************************/
333 static void LayoutButtons(void)
335 struct RastPort temprp
;
336 WORD i
, w
, maxtextlen
= 0, maximheight
= 0;
338 InitRastPort(&temprp
);
339 SetFont(&temprp
, dri
->dri_Font
);
341 for(i
= 0; i
< 3; i
++)
343 #if USE_SHARED_COOLIMAGES
344 buttontable
[i
].image
= (const struct CoolImage
*)COOL_ObtainImageA((ULONG
)buttontable
[i
].image
, NULL
);
348 w
= TextLength(&temprp
, MSG(buttontable
[i
].nameid
), strlen(MSG(buttontable
[i
].nameid
)));
351 if (buttontable
[i
].image
->height
> maximheight
)
352 maximheight
= buttontable
[i
].image
->height
;
354 w
+= IMBUTTON_EXTRAWIDTH
+ buttontable
[i
].image
->width
;
358 buttontable
[i
].image
= NULL
;
360 if (w
> maxtextlen
) maxtextlen
= w
;
364 buttonwidth
= w
+ BUTTON_EXTRAWIDTH
;
365 buttonheight
= dri
->dri_Font
->tf_YSize
+ BUTTON_EXTRAHEIGHT
;
369 maximheight
+= IMBUTTON_EXTRAHEIGHT
;
370 if (maximheight
> buttonheight
) buttonheight
= maximheight
;
373 DeinitRastPort(&temprp
);
376 /*********************************************************************************************/
378 static void LayoutGUI(void)
380 WORD w
, max_pagewidth
= 0;
381 WORD h
, max_pageheight
= 0;
386 for(i
= 0; i
< NUM_PAGES
; i
++)
388 if (!(pagetable
[i
].handler(PAGECMD_LAYOUT
, 0)))
389 Cleanup(MSG(MSG_CANT_CREATE_GADGET
));
391 w
= pagetable
[i
].handler(PAGECMD_GETMINWIDTH
, 0);
392 h
= pagetable
[i
].handler(PAGECMD_GETMINHEIGHT
, 0);
394 if (w
> max_pagewidth
) max_pagewidth
= w
;
395 if (h
> max_pageheight
) max_pageheight
= h
;
398 LayoutRegisterTab(®
, scr
, dri
, TRUE
);
399 if (reg
.width
> max_pagewidth
) max_pagewidth
= reg
.width
;
401 i
= buttonwidth
* NUM_BUTTONS
+ SPACE_X
* (NUM_BUTTONS
- 1) - TABBORDER_X
* 2;
402 if (i
> max_pagewidth
) max_pagewidth
= i
;
404 SetRegisterTabPos(®
, scr
->WBorLeft
+ BORDER_X
, scr
->WBorTop
+ scr
->Font
->ta_YSize
+ 1 + BORDER_Y
);
406 pages_left
= scr
->WBorLeft
+ BORDER_X
+ TABBORDER_X
;
407 pages_top
= scr
->WBorTop
+ scr
->Font
->ta_YSize
+ 1 + BORDER_Y
+ reg
.height
+ TABBORDER_Y
;
408 pages_width
= max_pagewidth
;
409 pages_height
= max_pageheight
;
411 SetRegisterTabFrameSize(®
, pages_width
+ TABBORDER_X
* 2,
412 pages_height
+ TABBORDER_Y
* 2);
414 for(i
= 0; i
< NUM_PAGES
; i
++)
416 pagetable
[i
].handler(PAGECMD_SETDOMLEFT
, pages_left
);
417 pagetable
[i
].handler(PAGECMD_SETDOMTOP
, pages_top
);
418 pagetable
[i
].handler(PAGECMD_SETDOMWIDTH
, max_pagewidth
);
419 pagetable
[i
].handler(PAGECMD_SETDOMHEIGHT
, max_pageheight
);
422 winwidth
= pages_width
+ TABBORDER_X
* 2 + BORDER_X
* 2;
423 winheight
= pages_height
+ buttonheight
+ SPACE_Y
+ reg
.height
+ TABBORDER_Y
* 2 + BORDER_Y
* 2;
426 /*********************************************************************************************/
428 static void MakeGadgets(void)
430 WORD x
= scr
->WBorLeft
+ BORDER_X
;
431 WORD y
= scr
->WBorTop
+ scr
->Font
->ta_YSize
+ 1 + winheight
- BORDER_Y
- buttonheight
;
434 struct TagItem tags
[] =
438 {GA_Width
, buttonwidth
},
439 {GA_Height
, buttonheight
},
443 {COOLBT_CoolImage
, 0 },
444 {GA_RelVerify
, TRUE
},
448 #if USE_SHARED_COOLIMAGES
450 Cleanup(MSG(MSG_CANT_CREATE_GADGET
));
452 if (!InitCoolButtonClass(CyberGfxBase
))
453 Cleanup(MSG(MSG_CANT_CREATE_GADGET
));
456 spacex
= (pages_width
+ TABBORDER_X
* 2 - buttonwidth
* NUM_BUTTONS
) * 16 / (NUM_BUTTONS
- 1);
458 for(i
= 0; i
< NUM_BUTTONS
; i
++)
460 if (i
== NUM_BUTTONS
- 1)
462 tags
[0].ti_Data
= x
+ pages_width
+ TABBORDER_X
* 2 - buttonwidth
;
466 tags
[0].ti_Data
= x
+ (buttonwidth
* 16 + spacex
) * i
/ 16;
469 tags
[4].ti_Data
= (IPTR
)MSG(buttontable
[i
].nameid
);
470 tags
[5].ti_Data
= buttontable
[i
].nameid
;
471 tags
[7].ti_Data
= (IPTR
)buttontable
[i
].image
;
473 if (i
> 0) tags
[6].ti_Data
= (IPTR
)buttontable
[i
- 1].gad
;
475 #if USE_SHARED_COOLIMAGES
476 buttontable
[i
].gad
= NewObjectA(NULL
, COOLBUTTONGCLASS
, tags
);
478 buttontable
[i
].gad
= NewObjectA(cool_buttonclass
, NULL
, tags
);
481 if (!buttontable
[i
].gad
) Cleanup(MSG(MSG_CANT_CREATE_GADGET
));
485 for(i
= 0; i
< NUM_PAGES
; i
++)
487 if (!(pagetable
[i
].handler(PAGECMD_MAKEGADGETS
, 0)))
488 Cleanup(MSG(MSG_CANT_CREATE_GADGET
));
492 /*********************************************************************************************/
494 static void KillGadgets(void)
498 for(i
= 0; i
< 3; i
++)
500 if (buttontable
[i
].gad
) DisposeObject((Object
*)buttontable
[i
].gad
);
503 #if !USE_SHARED_COOLIMAGES
504 CleanupCoolButtonClass();
508 /*********************************************************************************************/
510 static void ActivatePage(WORD which
)
512 if (which
== activetab
) return;
516 pagetable
[activetab
].handler(PAGECMD_REMGADGETS
, 0);
519 SetDrMd(win
->RPort
, JAM1
),
520 SetAPen(win
->RPort
, dri
->dri_Pens
[BACKGROUNDPEN
]);
521 RectFill(win
->RPort
, pages_left
, pages_top
, pages_left
+ pages_width
- 1, pages_top
+ pages_height
- 1);
525 pagetable
[activetab
].handler(PAGECMD_ADDGADGETS
, 0);
530 /*********************************************************************************************/
532 static void MakeWin(void)
534 static struct IBox zoom
;
535 WORD w
, t
, h
, wx
, wy
;
537 w
= winwidth
+ scr
->WBorLeft
+ scr
->WBorRight
;
538 t
= scr
->WBorTop
+ scr
->Font
->ta_YSize
+ 1;
539 h
= winheight
+ t
+ scr
->WBorBottom
;
541 wx
= (scr
->Width
- w
) / 2;
542 wy
= (scr
->Height
- h
) / 2;
549 win
= OpenWindowTags(0, WA_PubScreen
, (IPTR
)scr
,
552 WA_InnerWidth
, winwidth
,
553 WA_InnerHeight
, winheight
,
554 WA_Title
, (IPTR
)MSG(MSG_WINTITLE
) ,
555 WA_CloseGadget
, TRUE
,
557 WA_DepthGadget
, TRUE
,
559 WA_Gadgets
, (IPTR
)buttontable
[0].gad
,
560 WA_NewLookMenus
, TRUE
,
561 WA_Zoom
, (IPTR
)&zoom
,
562 WA_IDCMP
, REGISTERTAB_IDCMP
|
569 IDCMP_REFRESHWINDOW
,
572 SetMenuStrip(win
, menus
);
574 RenderRegisterTab(win
->RPort
, ®
, TRUE
);
580 /*********************************************************************************************/
582 static void KillWin(void)
584 pagetable
[reg
.active
].handler(PAGECMD_REMGADGETS
, 0);
588 RemoveGList(win
, buttontable
[0].gad
, NUM_BUTTONS
);
595 /*********************************************************************************************/
597 void TellGUI(LONG cmd
)
601 for(i
= 0; i
< NUM_PAGES
; i
++)
603 pagetable
[i
].handler(cmd
, 0);
607 /*********************************************************************************************/
609 static void HandleAll(void)
611 struct IntuiMessage
*msg
;
612 struct MenuItem
*item
;
619 WaitPort(win
->UserPort
);
621 while((msg
= GT_GetIMsg(win
->UserPort
)))
623 if (HandleRegisterTabInput(®
, msg
))
625 ActivatePage(reg
.active
);
627 else if (pagetable
[activetab
].handler(PAGECMD_HANDLEINPUT
, (IPTR
)msg
))
630 else switch (msg
->Class
)
632 case IDCMP_CLOSEWINDOW
:
636 case IDCMP_REFRESHWINDOW
:
637 GT_BeginRefresh(win
);
639 GT_RefreshWindow(win
, NULL
);
640 RenderRegisterTab(win
->RPort
, ®
, TRUE
);
641 pagetable
[activetab
].handler(PAGECMD_REFRESH
, 0);
643 GT_EndRefresh(win
, TRUE
);
646 case IDCMP_VANILLAKEY
:
653 } /* switch(msg->Code) */
657 gad
= (struct Gadget
*)msg
->IAddress
;
658 switch(gad
->GadgetID
)
661 if (!SavePrefs(CONFIGNAME_ENVARC
)) break;
665 if (!SavePrefs(CONFIGNAME_ENV
)) break;
677 while(men
!= MENUNULL
)
679 if ((item
= ItemAddress(menus
, men
)))
683 switch((ULONG
)GTMENUITEM_USERDATA(item
))
685 case MSG_MEN_PROJECT_OPEN
:
686 if ((filename
= GetFile(MSG(MSG_ASL_OPEN_TITLE
), "SYS:Prefs/Presets", FALSE
)))
692 case MSG_MEN_PROJECT_SAVEAS
:
693 if ((filename
= GetFile(MSG(MSG_ASL_SAVE_TITLE
), "SYS:Prefs/Presets", TRUE
)))
699 case MSG_MEN_PROJECT_QUIT
:
703 case MSG_MEN_EDIT_DEFAULT
:
707 case MSG_MEN_EDIT_LASTSAVED
:
708 LoadPrefs(CONFIGNAME_ENVARC
);
711 case MSG_MEN_EDIT_RESTORE
:
715 case MSG_MEN_SETTINGS_CREATEICONS
:
718 } /* switch(GTMENUITEM_USERDATA(item)) */
720 men
= item
->NextSelect
;
725 } /* while(men != MENUNULL) */
728 } /* else switch (msg->Class) */
732 } /* while((msg = GT_GetIMsg(win->UserPort))) */
734 } /* while (!quitme) */
737 /*********************************************************************************************/
741 InitLocale("System/Prefs/Locale.catalog", 1);
745 InitPrefs((STRPTR
)args
[ARG_FROM
], (args
[ARG_USE
] ? TRUE
: FALSE
), (args
[ARG_SAVE
] ? TRUE
: FALSE
));
758 /*********************************************************************************************/