Build fix for x86_64.
[AROS.git] / workbench / tools / BoingIconBar / iconbar.c
blob9ada93894761ce71c38663d8bba5a09be7e92839
1 //////////////////////////////////////////////////////////////
2 // //
3 // AROS PORT by LuKeJerry (at) gmail.com //
4 // Based on the program version with standard window //
5 // + BackFill //
6 // //
7 // -- last update: 26-04-2012 //
8 // - Fixed the notification //
9 // - Use D(bug()) macros //
10 // -------------------------------------------------------- //
11 // //
12 // -- translated to ENG from 26-09-2011 //
13 // -- converted TABs to 4-Spaces //
14 // //
15 // - FIXME: //
16 // //
17 // . When there are more icons than the screen width //
18 // can handle, exceeding icons should appear in the //
19 // next submenu. Seems that icon space is allocated, //
20 // but icon is not appearing //
21 // Look in: Read_Prefs( and SetWindowParameters( //
22 // //
23 // TO DO: //
24 // //
25 // - Even in static mode, put BiB window //
26 // active when mouse cursor goes to very //
27 // bottom of screen //
28 // //
29 // - Add possibility to show icon labels //
30 // - Add support for screennotify //
31 // - Add support for d&d to add an icon to a dock //
32 // - Add commodities CX support //
33 // //
34 //////////////////////////////////////////////////////////////
36 #define DEBUG 0
37 #include <aros/debug.h>
39 #include <stdio.h>
40 #include <string.h>
41 #include <stdlib.h>
42 #include <proto/workbench.h>
43 #include <proto/icon.h>
44 #include <proto/exec.h>
45 #include <proto/intuition.h>
46 #include <proto/graphics.h>
47 #include <proto/gadtools.h>
48 #include <proto/dos.h>
49 #include <proto/datatypes.h>
50 #include <exec/types.h>
51 #include <exec/libraries.h>
52 #include <workbench/icon.h>
53 #include <workbench/startup.h>
54 #include <intuition/intuition.h>
55 #include <intuition/imageclass.h>
56 #include <datatypes/datatypes.h>
57 #include <datatypes/pictureclass.h>
58 #include <devices/rawkeycodes.h>
59 #include <dos/dos.h>
61 #define SUM_ICON 200
62 #define ICON_ACTIVE (1<<7)
63 #define SELECTED_ICON (1<<6)
65 #define TEMPLATE "SPACE/N/K,STATIC/N/K,AUTOREMAP/S,BACKGROUND/S"
66 #define ARG_SPACE 0
67 #define ARG_STATIC 1
68 #define ARG_AUTOREMAP 2
69 #define ARG_BACKGROUND 3
71 #define BIB_PREFS "ENV:Iconbar.prefs"
73 /*****************************************************************************/
75 BOOL BiB_Exit = FALSE,
76 Icon_Remap = FALSE,
77 Bar_Background = FALSE,
78 PositionMenuOK = FALSE,
79 Image = FALSE, // <--- FIXME: "Image" seems not used at all
80 Window_Active = FALSE,
81 Window_Open = FALSE,
82 MenuWindow_Open = FALSE,
83 FirstOpening = TRUE;
85 int Static = 0,
86 Spacing = 5,
87 CurrentLevel = 0,
88 lbm = 0,
89 rbm = 0;
91 int WindowHeight,
92 WindowWidth,
93 ScreenHeight,
94 ScreenWidth,
95 IconWidth,
96 ImageWidth,
97 ImageHeight, // <--- FIXME: ...also: ImageWidth, ImageHeight not used at all
98 Position,
99 OldPosition,
100 IconCounter,
101 LevelCounter,
102 MouseIcon,
103 Lenght,
104 BeginningWindow,
105 EndingWindow,
106 Window_Max_X,
107 Window_Max_Y;
109 char version[] = "$VER: BoingIconBar 1.02 (26.04.2012) ©2012 Robert 'Phibrizzo' Krajcarz";
111 char Background_name[256], // <-- FIXME: Background_name not used at all,
112 BufferList[20], // but might be interesting to implement
113 MovingTable[8] = {0, 4, 7, 9, 10, 9, 7, 4};
115 ULONG WindowMask = 0,
116 MenuMask = 0,
117 WindowSignal;
119 IPTR args[] = {(IPTR)&Spacing, (IPTR)&Static, 0, 0};
121 /*****************************************************************************/
123 struct DiskObject *Icon[SUM_ICON];
125 struct Window *Window_struct, *MenuWindow_struct; // FIXME: really ugly _struct names...
126 struct Screen *Screen_struct;
128 struct BitMap *BMP_Buffer, *BMP_DoubleBuffer;
129 struct RastPort RP_Buffer, RP_DoubleBuffer;
131 // struct of icons
133 struct Icon_Struct
135 int Icon_Height; // icon height
136 int Icon_Width; // icon width
137 int Icon_PositionX; // X position on main window
138 int Icon_PositionY; // Y position on main window
139 int Icon_Status; // status of icon: normal or selected
140 BOOL Icon_OK; // everything OK with icon
141 char Icon_Path[255]; // name to path of icon
142 } Icons_Struct[SUM_ICON];
144 // struct of submenu
146 struct Level_Struct
148 char Level_Name[20]; // name submenu - level name
149 int Beginning; // first icon on menu
150 int WindowPos_X; // X position main window
151 int WindowPos_Y; // Y position main window
152 } Levels_Struct[11];
154 struct TextAttr Topaz8 = {"topaz.font",8,0,FPF_ROMFONT};
156 struct IntuiText Names = {1,0,JAM1,0,0,&Topaz8,BufferList,NULL};
158 // background pictures
160 Object *picture[3];
161 struct BitMap *bm[3];
163 struct Struct_BackgroundData
165 int Width; // width
166 int Height; // height
167 } BackgroundData[3];
170 /*****************************************************************************/
171 // functions
172 int ReadPrefs(void); // load prefs
173 void LoadBackground(void); //load background pictures
174 void SetWindowParameters(void); // check window sizes
175 void Decode_IDCMP(struct IntuiMessage *KomIDCMP); // decode IDCMP main signals
176 void Change_State(int Reset); // change icon state
177 void Insert_Icon(int Tryb, int IconNumber); // draw icon
178 void Blink_Icon(int IconNumber); // blink the icon
179 BOOL OpenMainWindow(void); // open main window
180 void CloseMainWindow(void); // close main window
181 void CheckMousePosition(void); // check mouse position
182 void Show_Selected_Level(void); // change the submenu
183 void OpenMenuWindow(void); // open menu window
184 void CloseMenuWindow(void); // close menu window
185 void Decode_IDCMP2(struct IntuiMessage *KomIDCMP); // decode IDCMP menu signals
186 void Launch_Program(char *Program); // start the chosed program
187 void Settings(void); // open the prefs program
188 void Reload_BiB(void); // reload the BiB
191 /*****************************************************************************/
193 int main(int argc, char *argv[])
195 int x, outt = FALSE;
197 struct IntuiMessage *KomIDCMP, KopiaIDCMP;
198 struct RDArgs *rda = NULL;
199 struct DiskObject *dob = NULL;
200 struct NotifyRequest *nr;
201 struct MsgPort *BIBport;
202 BOOL notification = FALSE;
203 BPTR out = BNULL;
204 int result = RETURN_OK;
206 // Read arguments
207 if (argc)
209 // Started from Shell
210 if (!(rda = ReadArgs(TEMPLATE, args, NULL)))
212 PrintFault(IoErr(), argv[0]);
213 return RETURN_FAIL;
216 if (args[ARG_AUTOREMAP]) Icon_Remap = TRUE;
218 if (args[ARG_BACKGROUND]) Bar_Background = TRUE;
220 out = Output();
221 } else {
222 // Started from WB: Read ToolTypes
223 struct WBStartup *wbs=(struct WBStartup*)argv;
224 struct WBArg *wba=&wbs->sm_ArgList[wbs->sm_NumArgs-1];
225 BPTR oldcd;
227 if (!(*wba->wa_Name))
229 return RETURN_FAIL;
232 oldcd=CurrentDir(wba->wa_Lock);
233 if ((dob=GetDiskObjectNew(wba->wa_Name)))
235 char *str;
237 if ((str=FindToolType(dob->do_ToolTypes, "SPACE")))
238 *(ULONG*)args[ARG_SPACE]=(ULONG)atoi(str);
240 if ((str=FindToolType(dob->do_ToolTypes, "STATIC")))
241 *(ULONG*)args[ARG_STATIC]=(ULONG)atoi(str);
243 if ((str=FindToolType(dob->do_ToolTypes, "AUTOREMAP")))
244 Icon_Remap = TRUE;
245 if ((str=FindToolType(dob->do_ToolTypes, "BACKGROUND")))
246 Bar_Background = TRUE;
249 CurrentDir(oldcd);
250 outt = TRUE;
253 if (out || outt)
255 Spacing = *(LONG*)args[ARG_SPACE];
256 Static = *(LONG*)args[ARG_STATIC];
260 D(bug("[IconBar] Specified options: SPACE=%d, STATIC=%d, AUTOREMAP=%d\n", Spacing, Static, Icon_Remap));
262 // Read the prefs file, fail if it doesn't exist
263 if(ReadPrefs())
265 // Set notification of prefs change
266 if ((BIBport = CreateMsgPort()))
268 if ((nr = AllocMem(sizeof(struct NotifyRequest), MEMF_CLEAR)))
270 nr->nr_Name = BIB_PREFS;
272 D(bug("[IconBar] prefs filename: %s\n",nr->nr_Name));
274 nr->nr_Flags = NRF_SEND_MESSAGE;
275 nr->nr_stuff.nr_Signal.nr_Task = FindTask(NULL);
276 nr->nr_stuff.nr_Msg.nr_Port = BIBport;
278 if (StartNotify(nr) != DOSFALSE)
280 notification = TRUE;
281 D(bug("[IconBar] Notification started\n"));
285 if (Bar_Background)
286 LoadBackground();
288 if(Static)
290 Delay(Static * 50);
291 OpenMainWindow();
292 FirstOpening = FALSE;
295 // ---- main loop
297 while (BiB_Exit==FALSE)
299 if(notification)
301 if (GetMsg(BIBport) != NULL)
303 D(bug("[IconBar] Prefs modified!\n"));
304 Reload_BiB();
308 if(Window_Open || MenuWindow_Open)
310 WindowSignal = Wait(WindowMask | MenuMask);
312 if(WindowSignal & WindowMask)
314 while((KomIDCMP = GT_GetIMsg(Window_struct->UserPort)))
316 CopyMem(KomIDCMP, &KopiaIDCMP, sizeof(struct IntuiMessage));
317 GT_ReplyIMsg(KomIDCMP);
318 Decode_IDCMP(&KopiaIDCMP);
321 if(!(Static) && Window_Active == FALSE) CloseMainWindow();
324 if(WindowSignal & MenuMask)
326 while((KomIDCMP = GT_GetIMsg(MenuWindow_struct->UserPort)))
328 CopyMem(KomIDCMP, &KopiaIDCMP, sizeof(struct IntuiMessage));
329 GT_ReplyIMsg(KomIDCMP);
330 Decode_IDCMP2(&KopiaIDCMP);
333 if(MenuWindow_Open == FALSE) CloseMenuWindow();
335 } else {
336 Delay(50);
337 CheckMousePosition();
339 } // ---- end of main loop
341 // ---- close all
342 CloseMainWindow();
344 for(x=0; x<SUM_ICON; x++)
346 if(Icon[x] != NULL)
348 FreeDiskObject(Icon[x]);
352 if(BMP_Buffer) FreeBitMap(BMP_Buffer);
353 if(BMP_DoubleBuffer) FreeBitMap(BMP_DoubleBuffer);
355 for(x=0; x<3; x++)
357 if(picture[x]) DisposeDTObject(picture[x]);
360 // Close notification of prefs change
361 if(notification)
362 EndNotify(nr);
363 if(nr)
364 FreeMem(nr, sizeof(struct NotifyRequest));
365 if(BIBport)
366 DeleteMsgPort(BIBport);
368 } else {
369 D(bug("[IconBar] No prefs found!\n"));
370 result = RETURN_FAIL;
372 D(bug("[IconBar] Quitting...\n"));
374 if (rda) FreeArgs(rda);
375 if (dob) FreeDiskObject(dob);
376 return(result);
379 /*****************************************************************************/
381 int ReadPrefs(void)
383 BPTR Prefs;
384 int x, TextLenght, NumChars;
386 Icons_Struct[0].Icon_OK = FALSE;
387 IconCounter = 0;
388 LevelCounter = 0;
389 Lenght = 0;
391 if((Prefs = Open(BIB_PREFS, MODE_OLDFILE)))
393 FGets(Prefs, Icons_Struct[0].Icon_Path, 255);
395 if(strncmp(Icons_Struct[0].Icon_Path, "BOING_PREFS", 11) != 0)
397 Close(Prefs);
398 //FIXME: A better error handling might be added
399 D(bug("[IconBar] Prefs error\n"));
400 return(0);
403 if((Screen_struct = LockPubScreen(NULL)) != NULL)
405 while (FGets(Prefs, Icons_Struct[IconCounter].Icon_Path, 255))
407 NumChars = strlen(Icons_Struct[IconCounter].Icon_Path);
408 Icons_Struct[IconCounter].Icon_Path[NumChars-1] = '\0';
410 if (Icons_Struct[IconCounter].Icon_Path[0] == ';')
412 D(bug("[IconBar] Found a submenu! Name lenght = %d, last char = %d\n",
413 NumChars, Icons_Struct[IconCounter].Icon_Path[NumChars-1]));
415 if (NumChars > 20) NumChars = 20;
416 Icons_Struct[IconCounter].Icon_Path[19] = '\0';
418 for (x=1; x<NumChars; x++)
420 Levels_Struct[LevelCounter].Level_Name[x-1] = Icons_Struct[IconCounter].Icon_Path[x];
423 D(bug("[IconBar] x after \'for\' = %d\n", x));
425 strcpy(BufferList, Levels_Struct[LevelCounter].Level_Name);
427 D(bug("[IconBar] Level name: %s\n", Levels_Struct[LevelCounter].Level_Name));
429 TextLenght = IntuiTextLength(&Names);
431 if (TextLenght > Lenght) Lenght = TextLenght;
433 D(bug("[IconBar] IntuiTextLenght = %d\n", TextLenght));
435 D(bug("[IconBar] Submenu %d - %s, beginning %d\n",
436 LevelCounter, Levels_Struct[LevelCounter].Level_Name, Levels_Struct[LevelCounter].Beginning));
438 Levels_Struct[LevelCounter].Beginning = IconCounter;
439 LevelCounter++;
440 } else {
441 D(bug("[IconBar] Loading icon #%d - name: %s\n", IconCounter, Icons_Struct[IconCounter].Icon_Path));
443 if ((Icon[IconCounter] = GetIconTags(Icons_Struct[IconCounter].Icon_Path,
444 ICONGETA_RemapIcon, FALSE,
445 TAG_DONE)))
447 IconControl(Icon[IconCounter],
448 ICONCTRLA_GetWidth, &Icons_Struct[IconCounter].Icon_Width,
449 ICONCTRLA_GetHeight, &Icons_Struct[IconCounter].Icon_Height,
450 ICONCTRLA_SetNewIconsSupport, TRUE,
451 TAG_END);
453 if (Icons_Struct[IconCounter].Icon_Width == 0)
455 Icons_Struct[IconCounter].Icon_Width = Icon[IconCounter]->do_Gadget.Width;
458 if (Icons_Struct[IconCounter].Icon_Height == 0)
460 Icons_Struct[IconCounter].Icon_Height = Icon[IconCounter]->do_Gadget.Height;
463 LayoutIcon(Icon[IconCounter], Screen_struct, NULL);
465 D(bug("[IconBar] Dimension icon #%d: Widht=%d Height=%d\n",
466 IconCounter, Icons_Struct[IconCounter].Icon_Width, Icons_Struct[IconCounter].Icon_Height));
468 D(bug("[IconBar] Icon %d loaded\n", IconCounter));
470 Icons_Struct[IconCounter].Icon_OK = TRUE;
471 IconCounter++;
473 if (IconCounter == SUM_ICON) break;
474 } else {
475 //FIXME: A better error handling might be added
476 D(bug("[IconBar] Not found icon %s.\n", Icons_Struct[IconCounter].Icon_Path));
480 Close(Prefs);
482 ScreenWidth = Screen_struct->Width;
483 ScreenHeight = Screen_struct->Height;
485 UnlockPubScreen(NULL, Screen_struct);
487 Levels_Struct[LevelCounter].Beginning = IconCounter;
489 D(bug("[IconBar] Screen size: Width=%d, Height=%d\n", ScreenWidth, ScreenHeight));
491 SetWindowParameters();
493 IconCounter = Levels_Struct[1].Beginning;
494 WindowWidth = Levels_Struct[0].WindowPos_X;
495 WindowHeight = Levels_Struct[0].WindowPos_Y;
497 BeginningWindow = (ScreenWidth>>1) - (WindowWidth>>1);
498 EndingWindow = (ScreenWidth>>1) + (WindowWidth>>1);
500 CurrentLevel = 0;
502 sprintf(Levels_Struct[LevelCounter].Level_Name, "Settings");
503 sprintf(Names.IText, "%s", Levels_Struct[LevelCounter].Level_Name);
505 TextLenght = IntuiTextLength(&Names);
507 if (TextLenght > Lenght) Lenght = TextLenght;
509 LevelCounter++;
511 Lenght = Lenght + 10;
512 } else {
513 //FIXME: A better error handling might be added
514 D(bug("[IconBar] Error reading screen parameters\n"));
518 return Icons_Struct[0].Icon_OK;
521 /*****************************************************************************/
523 void LoadBackground(void)
525 int x;
527 STRPTR name[3] =
529 "SYS:System/Images/bibgfx/left" ,
530 "SYS:System/Images/bibgfx/middle",
531 "SYS:System/Images/bibgfx/right"
534 for (x=0; x<3; x++)
536 picture[x] = NewDTObject (name[x],
537 DTA_GroupID, GID_PICTURE,
538 PDTA_Remap, TRUE,
539 PDTA_DestMode, PMODE_V43,
540 OBP_Precision, PRECISION_IMAGE,
541 PDTA_Screen, (ULONG)Screen_struct,
542 TAG_END);
544 if (picture[x])
546 D(bug("[IconBar] Loading image n. %d - name: %s\n",x,name[x]));
548 DoDTMethod(picture[x], NULL, NULL, DTM_PROCLAYOUT, NULL, DTSIF_NEWSIZE);
550 GetDTAttrs
551 ( picture[x],
552 PDTA_DestBitMap, (LONG)&bm[x],
553 DTA_NominalHoriz, (LONG)&BackgroundData[x].Width,
554 DTA_NominalVert, (LONG)&BackgroundData[x].Height,
555 TAG_END
561 /*****************************************************************************/
563 void SetWindowParameters(void)
566 int x, y;
568 Window_Max_X = 0;
569 Window_Max_Y = 0;
571 Icons_Struct[0].Icon_PositionX = 0;
573 for (y=0; y<(LevelCounter); y++)
575 WindowHeight = 0;
576 WindowWidth = 0;
578 IconCounter = Levels_Struct[y+1].Beginning;
580 for (x=Levels_Struct[y].Beginning; x<IconCounter; x++)
582 if (Icons_Struct[x].Icon_OK)
584 if (Icons_Struct[x].Icon_Height > WindowHeight)
586 WindowHeight = Icons_Struct[x].Icon_Height;
589 if (Icons_Struct[x].Icon_Width > IconWidth)
591 IconWidth = Icons_Struct[x].Icon_Width;
594 if ((WindowWidth + Icons_Struct[x].Icon_Width + 35) > ScreenWidth)
596 D(bug("[IconBar] Exceeding the size of the screen, can't display all icons!\n"));
598 IconCounter = x;
599 Levels_Struct[y+1].Beginning = x;
600 break;
603 WindowWidth = WindowWidth + Icons_Struct[x].Icon_Width + Spacing;
605 Icons_Struct[x].Icon_PositionY = 10;
607 if ((x+1) != IconCounter)
609 Icons_Struct[x+1].Icon_PositionX = WindowWidth;
612 else break;
615 for (x=Levels_Struct[y].Beginning; x<IconCounter; x++)
617 if (Icons_Struct[x].Icon_OK)
619 Icons_Struct[x].Icon_PositionX = Icons_Struct[x].Icon_PositionX + 15;
620 Icons_Struct[x].Icon_PositionY = (WindowHeight>>1) - (Icons_Struct[x].Icon_Height>>1) + 15;
624 Levels_Struct[y].WindowPos_X = WindowWidth + 30;
625 Levels_Struct[y].WindowPos_Y = WindowHeight + 20;
627 if (Levels_Struct[y].WindowPos_X > ScreenWidth)
628 Levels_Struct[y].WindowPos_X = WindowWidth;
630 if (Window_Max_X < Levels_Struct[y].WindowPos_X)
631 Window_Max_X = Levels_Struct[y].WindowPos_X;
633 if (Window_Max_Y < Levels_Struct[y].WindowPos_Y)
634 Window_Max_Y = Levels_Struct[y].WindowPos_Y;
636 D(bug("[IconBar] Window size %d: S=%d, W=%d\n", y, Levels_Struct[y].WindowPos_X, Levels_Struct[y].WindowPos_Y));
639 D(bug("[IconBar] Maximum window size: S=%d, W=%d\n", Window_Max_X, Window_Max_Y));
640 D(bug("[IconBar] Icon width: %d\n", IconWidth));
642 if((Screen_struct=LockPubScreen(NULL)) != NULL)
644 BMP_Buffer = AllocBitMap
646 Window_Max_X,
647 Window_Max_Y,
648 GetBitMapAttr(Screen_struct->RastPort.BitMap, BMA_DEPTH),
649 BMF_MINPLANES | BMF_CLEAR,
650 Screen_struct->RastPort.BitMap
653 InitRastPort(&RP_Buffer);
654 RP_Buffer.BitMap = BMP_Buffer;
655 RP_Buffer.Layer = NULL;
657 BMP_DoubleBuffer = AllocBitMap
659 IconWidth + 8,
660 Window_Max_Y,
661 GetBitMapAttr(Screen_struct->RastPort.BitMap, BMA_DEPTH),
662 BMF_MINPLANES | BMF_CLEAR,
663 Screen_struct->RastPort.BitMap
666 InitRastPort(&RP_DoubleBuffer);
667 RP_DoubleBuffer.BitMap = BMP_DoubleBuffer;
668 RP_DoubleBuffer.Layer = NULL;
670 UnlockPubScreen(NULL,Screen_struct);
674 /*****************************************************************************/
676 void Decode_IDCMP(struct IntuiMessage *KomIDCMP)
678 int x;
680 // LJ: Temporary disabled mouse cases in function Decode_IDCMP
682 switch (KomIDCMP->Class)
684 case IDCMP_CLOSEWINDOW:
685 BiB_Exit = TRUE;
686 break;
688 case IDCMP_MOUSEMOVE:
689 for(MouseIcon=Levels_Struct[CurrentLevel].Beginning; MouseIcon<IconCounter; MouseIcon++)
691 if(Icons_Struct[MouseIcon].Icon_OK)
693 // too noisy: D(bug("[IconBar] Mouse position in the window X=%d, Y=%d\n",
694 // KomIDCMP->MouseX, KomIDCMP->MouseY));
696 if((ScreenHeight - Screen_struct->MouseY) > WindowHeight)
698 Window_Active = FALSE;
701 if(KomIDCMP->MouseX > Icons_Struct[MouseIcon].Icon_PositionX &&
702 KomIDCMP->MouseX < Icons_Struct[MouseIcon].Icon_PositionX + Icons_Struct[MouseIcon].Icon_Width &&
703 KomIDCMP->MouseY > 0 &&
704 KomIDCMP->MouseY < WindowHeight - 5)
706 if((Icons_Struct[MouseIcon].Icon_Status & ICON_ACTIVE) != ICON_ACTIVE)
708 for(x=Levels_Struct[CurrentLevel].Beginning; x<IconCounter; x++)
710 Icons_Struct[x].Icon_Status = Icons_Struct[x].Icon_Status & 0x07;
713 Icons_Struct[MouseIcon].Icon_Status = ICON_ACTIVE | (SELECTED_ICON * lbm);
714 D(bug("[IconBar] Pointer on icon #%d\n", MouseIcon));
716 break;
718 Icons_Struct[MouseIcon].Icon_Status = Icons_Struct[MouseIcon].Icon_Status & 0x07;
721 break;
723 case IDCMP_MOUSEBUTTONS:
724 switch (KomIDCMP->Code)
726 case SELECTDOWN:
727 Icons_Struct[MouseIcon].Icon_Status = Icons_Struct[MouseIcon].Icon_Status | SELECTED_ICON;
728 lbm = 1;
730 D(bug("[IconBar] Icon #%d\n", MouseIcon));
731 break;
733 case SELECTUP:
734 lbm = 0;
736 if((Icons_Struct[MouseIcon].Icon_Status & (SELECTED_ICON | ICON_ACTIVE)) == (SELECTED_ICON | ICON_ACTIVE))
738 Blink_Icon(MouseIcon);
740 D(bug("[IconBar] Launching program function with param: %s\n",
741 Icons_Struct[MouseIcon].Icon_Path));
742 Launch_Program(Icons_Struct[MouseIcon].Icon_Path);
744 D(bug("[IconBar] Icon #%d confirmed\n", MouseIcon));
747 Icons_Struct[MouseIcon].Icon_Status = Icons_Struct[MouseIcon].Icon_Status & 0xBF; //10001111b
749 break;
751 case MENUDOWN:
752 rbm = 1;
753 OpenMenuWindow();
754 break;
757 case IDCMP_RAWKEY:
758 switch(KomIDCMP->Code)
760 case RAWKEY_ESCAPE:
761 if((KomIDCMP->Qualifier) & IEQUALIFIER_LSHIFT)
763 BiB_Exit = TRUE;
765 break;
767 case RAWKEY_F1:
768 for(x=0; x<SUM_ICON; x++)
770 if(Icon[x] != NULL)
772 LayoutIcon(Icon[x],
773 Screen_struct,
774 NULL);
778 for(x=Levels_Struct[CurrentLevel].Beginning; x<IconCounter; x++)
780 if(Icon[x] != NULL)
782 DrawIconState(Window_struct->RPort,
783 Icon[x],
784 NULL,
785 Icons_Struct[x].Icon_PositionX,
786 Icons_Struct[x].Icon_PositionY,
787 IDS_NORMAL,
788 ICONDRAWA_Frameless, TRUE,
789 ICONDRAWA_EraseBackground, FALSE,
790 TAG_DONE);
793 break;
795 case RAWKEY_F2:
796 case RAWKEY_NM_WHEEL_DOWN:
797 CurrentLevel++;
798 if(CurrentLevel == (LevelCounter -1 )) CurrentLevel = 0;
799 Show_Selected_Level();
800 break;
802 case RAWKEY_F3:
803 case RAWKEY_NM_WHEEL_UP:
804 CurrentLevel--;
805 if(CurrentLevel < 0) CurrentLevel = LevelCounter - 2;
806 Show_Selected_Level();
807 break;
809 case RAWKEY_F4:
810 Settings();
811 break;
813 break;
815 case IDCMP_INACTIVEWINDOW:
816 if(rbm == 0) Window_Active = FALSE;
817 lbm = 0;
819 if(Static)
821 for(x=Levels_Struct[CurrentLevel].Beginning; x<IconCounter; x++)
823 if(Icons_Struct[x].Icon_Status != 0)
825 Icons_Struct[x].Icon_Status = 0;
826 Insert_Icon(IDS_NORMAL, x);
831 break;
833 case IDCMP_INTUITICKS:
834 Change_State(0);
835 break;
840 void Change_State(int Reset)
842 int x;
844 for(x=Levels_Struct[CurrentLevel].Beginning; x<IconCounter; x++)
846 if(Icons_Struct[x].Icon_OK)
848 if(Icons_Struct[x].Icon_Status != 0)
850 if(Reset == 0)
852 if((Icons_Struct[x].Icon_Status & ICON_ACTIVE) == 0 && Icons_Struct[x].Icon_Status < 4)
854 // 11000111b
855 Icons_Struct[x].Icon_Status = (Icons_Struct[x].Icon_Status - 1) & 0xC7;
857 else
859 Icons_Struct[x].Icon_Status = (Icons_Struct[x].Icon_Status + 1) & 0xC7;
862 else
864 Icons_Struct[x].Icon_Status = 0;
867 Insert_Icon((Icons_Struct[x].Icon_Status & SELECTED_ICON) ? IDS_SELECTED : IDS_NORMAL, x);
873 void Insert_Icon(int Tryb, int IconNumber)
875 BltBitMapRastPort(BMP_Buffer,
876 Icons_Struct[IconNumber].Icon_PositionX,
878 &RP_DoubleBuffer, //Window_struct->RPort,
879 0, //Icons_Struct[IconNumber].Icon_PositionX,
881 Icons_Struct[IconNumber].Icon_Width + 1,
882 WindowHeight,
883 0xC0);
885 DrawIconState(&RP_DoubleBuffer, //Window_struct->RPort,
886 Icon[IconNumber],
887 NULL,
888 0, //Icons_Struct[IconNumber].Icon_PositionX,
889 Icons_Struct[IconNumber].Icon_PositionY - MovingTable[(Icons_Struct[IconNumber].Icon_Status & 0x07)],
890 Tryb,
891 ICONDRAWA_Frameless, TRUE,
892 ICONDRAWA_EraseBackground, FALSE,
893 TAG_DONE);
895 BltBitMapRastPort(BMP_DoubleBuffer,
898 Window_struct->RPort,
899 Icons_Struct[IconNumber].Icon_PositionX,
901 Icons_Struct[IconNumber].Icon_Width + 1,
902 WindowHeight,
903 0xC0);
906 void Blink_Icon(int IconNumber)
908 int x, Tryb=IDS_SELECTED;
910 for(x=0; x<8; x++)
912 Insert_Icon(Tryb, IconNumber);
913 Delay(3);
915 if(Tryb == IDS_NORMAL) Tryb = IDS_SELECTED;
916 else Tryb = IDS_NORMAL;
920 BOOL OpenMainWindow(void)
922 int x, y, a;
924 if((Screen_struct=LockPubScreen(NULL)) != NULL)
926 BltBitMapRastPort(Screen_struct->RastPort.BitMap,
927 (ScreenWidth>>1) - (WindowWidth>>1),
928 ScreenHeight - WindowHeight,
929 &RP_Buffer,
930 0, 0,
931 Window_Max_X,
932 Window_Max_Y,
933 0xC0);
935 UnlockPubScreen(NULL,Screen_struct);
938 if(picture[0] && picture[1] && picture[2])
940 y = WindowWidth - BackgroundData[0].Width - BackgroundData[2].Width;
941 a = y / BackgroundData[1].Width;
943 BltBitMapRastPort(bm[0],
946 &RP_Buffer,
948 WindowHeight - BackgroundData[0].Height,
949 BackgroundData[0].Width,
950 BackgroundData[0].Height,
951 0xC0);
953 for(x=0; x<a; x++)
955 BltBitMapRastPort(bm[1],
958 &RP_Buffer,
959 BackgroundData[0].Width + x * BackgroundData[1].Width,
960 WindowHeight - BackgroundData[1].Height,
961 BackgroundData[1].Width,
962 BackgroundData[1].Height,
963 0xC0);
966 BltBitMapRastPort(bm[1],
969 &RP_Buffer,
970 BackgroundData[0].Width + x * BackgroundData[1].Width,
971 WindowHeight - BackgroundData[1].Height,
972 y - BackgroundData[1].Width * a,
973 BackgroundData[1].Height,
974 0xC0);
976 BltBitMapRastPort(bm[2],
979 &RP_Buffer,
980 WindowWidth - BackgroundData[2].Width,
981 WindowHeight - BackgroundData[2].Height,
982 BackgroundData[2].Width,
983 BackgroundData[2].Height,
984 0xC0);
985 } else if(picture[1]) {
986 for(x=0; x<WindowWidth; x=x+BackgroundData[1].Width)
988 BltBitMapRastPort(bm[1],
991 &RP_Buffer,
993 WindowHeight - BackgroundData[1].Height,
994 BackgroundData[1].Width,
995 BackgroundData[1].Height,
996 0xC0);
1000 if(Icon_Remap == TRUE)
1002 D(bug("[IconBar] Iconremap is true!\n"));
1004 for(x=Levels_Struct[CurrentLevel].Beginning; x<IconCounter; x++)
1006 if(Icon[x]!=NULL)
1008 // D(bug("[Iconbar] Icon#%d-%s was not NULL, so LayoutIcon Adapt a palette-mapped icon to display\n", x, Icons_Struct[x].Icon_Path);
1009 LayoutIcon(Icon[x], Screen_struct, NULL);
1014 D(bug("[IconBar] Opening window: S=%d, W=%d\n", WindowWidth, WindowHeight));
1016 if((Window_struct = OpenWindowTags(NULL,
1017 WA_Left, BeginningWindow,
1018 WA_Top, ScreenHeight - WindowHeight,
1019 WA_InnerWidth, WindowWidth,
1020 WA_InnerHeight, WindowHeight,
1021 WA_ReportMouse, TRUE,
1022 WA_MouseQueue, 3,
1023 WA_Borderless, TRUE,
1024 WA_SizeGadget, FALSE,
1025 WA_Activate, ((FirstOpening && Static) ? FALSE : TRUE),
1026 WA_PubScreenName, NULL,
1027 WA_BackFill, LAYERS_NOBACKFILL,
1028 WA_Flags, WFLG_NOCAREREFRESH|
1029 WFLG_SMART_REFRESH|
1030 WFLG_RMBTRAP,
1031 WA_IDCMP, IDCMP_NEWSIZE|
1032 IDCMP_RAWKEY|
1033 IDCMP_INACTIVEWINDOW|
1034 IDCMP_MOUSEMOVE|
1035 IDCMP_INTUITICKS|
1036 IDCMP_MOUSEBUTTONS,
1037 TAG_END)))
1039 D(bug("[IconBar] Window opened\n"));
1041 WindowMask = 1 << Window_struct->UserPort->mp_SigBit;
1043 BltBitMapRastPort(BMP_Buffer,
1044 0, 0,
1045 Window_struct->RPort,
1046 0, 0,
1047 WindowWidth,
1048 WindowHeight,
1049 0xC0);
1051 for(x=Levels_Struct[CurrentLevel].Beginning; x<IconCounter; x++)
1053 if(Icon[x] != NULL)
1055 DrawIconState(Window_struct->RPort,
1056 Icon[x],
1057 NULL,
1058 Icons_Struct[x].Icon_PositionX,
1059 Icons_Struct[x].Icon_PositionY,
1060 IDS_NORMAL,
1061 ICONDRAWA_Frameless, TRUE,
1062 ICONDRAWA_EraseBackground, FALSE,
1063 TAG_DONE);
1066 } else {
1067 D(bug("[IconBar] Can't open main toolbar window\n"));
1068 return FALSE;
1071 Window_Open = TRUE;
1072 Window_Active = TRUE;
1074 return TRUE;
1077 void CloseMainWindow(void)
1079 D(bug("[IconBar] ClosingMainWindow...\n"));
1081 int x;
1083 if(Window_struct) CloseWindow(Window_struct);
1085 for(x=Levels_Struct[CurrentLevel].Beginning; x<IconCounter; x++)
1087 Icons_Struct[x].Icon_Status = 0;
1090 Window_Open = FALSE;
1091 WindowMask = 0;
1094 void CheckMousePosition(void)
1096 // noisy: D(bug("[IconBar] Mouse current position: Y=%d\n", Screen_struct->MouseY));
1098 if((Screen_struct->MouseY == ScreenHeight - 1) &&
1099 Window_Open == FALSE &&
1100 Screen_struct->MouseX > BeginningWindow &&
1101 Screen_struct->MouseX < EndingWindow)
1103 D(bug("[IconBar] Opening the window\n"));
1104 if(OpenMainWindow() == FALSE)
1106 BiB_Exit = TRUE;
1110 // LJ: trying to make window active when going to very bottom of the screen
1111 // even in static mode - but it doesn't work because this code is checked
1112 // only in static=0 mode
1114 else if ((Screen_struct->MouseY == ScreenHeight - 1) &&
1115 Window_Open == TRUE &&
1116 Screen_struct->MouseX > BeginningWindow &&
1117 Screen_struct->MouseX < EndingWindow)
1119 D(bug("[IconBar] You're at the very bottom! I should make this window active!\n"));
1120 Window_Active = TRUE;
1124 void Show_Selected_Level(void)
1126 CloseMainWindow();
1128 IconCounter = Levels_Struct[CurrentLevel+1].Beginning;
1129 WindowWidth = Levels_Struct[CurrentLevel].WindowPos_X;
1130 WindowHeight = Levels_Struct[CurrentLevel].WindowPos_Y;
1131 BeginningWindow = (ScreenWidth>>1) - (WindowWidth>>1);
1132 EndingWindow = (ScreenWidth>>1) + (WindowWidth>>1);
1134 //LJ: delay needed for AROS, otherwise garbage from old icons remains
1135 Delay(10); //10 ms seems to be enough
1137 if(OpenMainWindow() == FALSE)
1139 BiB_Exit = TRUE;
1143 void OpenMenuWindow(void)
1145 int x;
1147 if((MenuWindow_struct = OpenWindowTags(NULL,
1148 WA_Left, Screen_struct->MouseX,
1149 WA_Top, Screen_struct->MouseY,
1150 WA_InnerWidth, Lenght + 1,
1151 WA_InnerHeight, LevelCounter << 4,
1152 WA_AutoAdjust, TRUE,
1153 WA_ReportMouse, TRUE,
1154 WA_Borderless, TRUE,
1155 WA_IDCMP,IDCMP_MOUSEBUTTONS|
1156 IDCMP_MOUSEMOVE|
1157 IDCMP_INACTIVEWINDOW,
1158 WA_Flags,WFLG_ACTIVATE|
1159 WFLG_RMBTRAP|
1160 WFLG_SMART_REFRESH,
1161 TAG_END)))
1163 MenuMask = 1 << MenuWindow_struct->UserPort->mp_SigBit;
1165 SetAPen(MenuWindow_struct->RPort, 1);
1166 Move(MenuWindow_struct->RPort, Lenght, 0);
1167 Draw(MenuWindow_struct->RPort, Lenght, LevelCounter << 4);
1168 Draw(MenuWindow_struct->RPort, 0, LevelCounter << 4);
1169 SetAPen(MenuWindow_struct->RPort, 2);
1170 Draw(MenuWindow_struct->RPort, 0, 0);
1171 Draw(MenuWindow_struct->RPort, Lenght, 0);
1173 SetAPen(MenuWindow_struct->RPort, 1);
1174 Move(MenuWindow_struct->RPort, 0, (LevelCounter - 1) << 4);
1175 Draw(MenuWindow_struct->RPort, Lenght - 1, (LevelCounter - 1) << 4);
1177 SetAPen(MenuWindow_struct->RPort, 2);
1178 Move(MenuWindow_struct->RPort, 0, ((LevelCounter - 1) << 4) + 1);
1179 Draw(MenuWindow_struct->RPort, Lenght - 1, ((LevelCounter - 1) << 4) + 1);
1181 for(x=0; x<LevelCounter; x++)
1183 if(x == CurrentLevel) Names.FrontPen = 2;
1184 else Names.FrontPen = 1;
1186 strcpy(BufferList, Levels_Struct[x].Level_Name);
1188 PrintIText(MenuWindow_struct->RPort, &Names, 5, (x << 4) + 5);
1190 D(bug("[IconBar] Level %d: %s\n", x, Levels_Struct[x].Level_Name));
1192 MenuWindow_Open = TRUE;
1194 else D(bug("[IconBar] Can't open menu\n"));
1197 void CloseMenuWindow(void)
1199 CloseWindow(MenuWindow_struct);
1200 MenuMask = 0;
1202 if(PositionMenuOK == TRUE)
1204 if(Position == (LevelCounter - 1))
1206 Settings();
1207 } else {
1208 CurrentLevel = Position;
1209 Show_Selected_Level();
1214 void Decode_IDCMP2(struct IntuiMessage *KomIDCMP)
1216 int x, kolA, kolB, dluG, x4;
1218 dluG = Lenght - 2;
1220 switch(KomIDCMP->Class)
1222 case IDCMP_MOUSEMOVE:
1223 if(MenuWindow_struct->MouseX > 0 &&
1224 MenuWindow_struct->MouseX < Lenght &&
1225 MenuWindow_struct->MouseY >0)
1227 Position = MenuWindow_struct->MouseY >> 4;
1229 else
1231 Position = 100;
1234 if(Position != OldPosition)
1236 for(x=0; x<LevelCounter; x++)
1238 x4 = (x << 4) + 2;
1240 if(x == Position)
1242 kolA = 2;
1243 kolB = 1;
1245 else
1247 kolA = 0;
1248 kolB = 0;
1251 SetAPen(MenuWindow_struct->RPort, kolA);
1252 Move(MenuWindow_struct->RPort, dluG, x4);
1253 Draw(MenuWindow_struct->RPort, dluG, x4 + 13);
1254 Draw(MenuWindow_struct->RPort, 2, x4 + 13);
1255 SetAPen(MenuWindow_struct->RPort, kolB);
1256 Draw(MenuWindow_struct->RPort, 2, x4);
1257 Draw(MenuWindow_struct->RPort, dluG, x4);
1260 if(Position != CurrentLevel && Position != 100)
1261 PositionMenuOK = TRUE;
1262 else PositionMenuOK = FALSE;
1264 OldPosition = Position;
1266 D(bug("[IconBar] Menu %d, level %d\n", Position, CurrentLevel));
1268 break;
1270 case IDCMP_MOUSEBUTTONS: //LJ: Adding IDCMP_ seems to do the trick...
1271 switch (KomIDCMP->Code)
1273 case MENUUP:
1274 MenuWindow_Open = FALSE;
1275 rbm = 0;
1276 break;
1278 break;
1280 case IDCMP_INACTIVEWINDOW:
1281 MenuWindow_Open = FALSE;
1282 break;
1286 void Launch_Program(char *Program)
1288 BPTR oldlock;
1290 // Get current directory lock
1291 oldlock = CurrentDir(NULL);
1293 D(bug("[IconBar] Launch_Program %s\n", Program));
1294 OpenWorkbenchObject(Program, TAG_DONE);
1296 // Go back to old directory
1297 CurrentDir(oldlock);
1300 void Settings(void)
1302 if (!OpenWorkbenchObject("PROGDIR:BIBPrefs", TAG_DONE))
1303 OpenWorkbenchObject("SYS:Prefs/BIBPrefs", TAG_DONE);
1306 void Reload_BiB(void)
1308 D(bug("[IconBar] Reloading BiB...\n"));
1310 int x;
1312 if (Window_Open == TRUE)
1314 D(bug("[IconBar] The Main window is open.. so let's close it...\n"));
1315 CloseMainWindow();
1318 for(x=0; x<SUM_ICON; x++)
1320 if(Icon[x] != NULL)
1322 FreeDiskObject(Icon[x]);
1324 Icons_Struct[x].Icon_Height = 0;
1325 Icons_Struct[x].Icon_Width = 0;
1326 Icons_Struct[x].Icon_PositionX = 0;
1327 Icons_Struct[x].Icon_PositionY = 0;
1330 if(BMP_Buffer) FreeBitMap(BMP_Buffer);
1332 if(BMP_DoubleBuffer) FreeBitMap(BMP_DoubleBuffer);
1334 if(ReadPrefs() == FALSE)
1336 D(bug("[IconBar] Prefs error\n"));
1337 return;
1340 if(Static)
1342 Delay(Static * 50);
1343 OpenMainWindow();
1344 FirstOpening = FALSE;