1 //////////////////////////////////////////////////////////////
3 // AROS PORT by LuKeJerry (at) gmail.com //
4 // Based on the program version with standard window //
7 // -- last update: 26-04-2012 //
8 // - Fixed the notification //
9 // - Use D(bug()) macros //
10 // -------------------------------------------------------- //
12 // -- translated to ENG from 26-09-2011 //
13 // -- converted TABs to 4-Spaces //
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( //
25 // - Even in static mode, put BiB window //
26 // active when mouse cursor goes to very //
27 // bottom of screen //
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 //
34 //////////////////////////////////////////////////////////////
37 #include <aros/debug.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>
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"
68 #define ARG_AUTOREMAP 2
69 #define ARG_BACKGROUND 3
71 #define BIB_PREFS "ENV:Iconbar.prefs"
73 /*****************************************************************************/
75 BOOL BiB_Exit
= FALSE
,
77 Bar_Background
= FALSE
,
78 PositionMenuOK
= FALSE
,
79 Image
= FALSE
, // <--- FIXME: "Image" seems not used at all
80 Window_Active
= FALSE
,
82 MenuWindow_Open
= FALSE
,
97 ImageHeight
, // <--- FIXME: ...also: ImageWidth, ImageHeight not used at all
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,
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
;
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
];
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
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
161 struct BitMap
*bm
[3];
163 struct Struct_BackgroundData
166 int Height
; // height
170 /*****************************************************************************/
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
[])
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
;
204 int result
= RETURN_OK
;
209 // Started from Shell
210 if (!(rda
= ReadArgs(TEMPLATE
, args
, NULL
)))
212 PrintFault(IoErr(), argv
[0]);
216 if (args
[ARG_AUTOREMAP
]) Icon_Remap
= TRUE
;
218 if (args
[ARG_BACKGROUND
]) Bar_Background
= TRUE
;
222 // Started from WB: Read ToolTypes
223 struct WBStartup
*wbs
=(struct WBStartup
*)argv
;
224 struct WBArg
*wba
=&wbs
->sm_ArgList
[wbs
->sm_NumArgs
-1];
227 if (!(*wba
->wa_Name
))
232 oldcd
=CurrentDir(wba
->wa_Lock
);
233 if ((dob
=GetDiskObjectNew(wba
->wa_Name
)))
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")))
245 if ((str
=FindToolType(dob
->do_ToolTypes
, "BACKGROUND")))
246 Bar_Background
= TRUE
;
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
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
)
281 D(bug("[IconBar] Notification started\n"));
292 FirstOpening
= FALSE
;
297 while (BiB_Exit
==FALSE
)
301 if (GetMsg(BIBport
) != NULL
)
303 D(bug("[IconBar] Prefs modified!\n"));
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();
337 CheckMousePosition();
339 } // ---- end of main loop
344 for(x
=0; x
<SUM_ICON
; x
++)
348 FreeDiskObject(Icon
[x
]);
352 if(BMP_Buffer
) FreeBitMap(BMP_Buffer
);
353 if(BMP_DoubleBuffer
) FreeBitMap(BMP_DoubleBuffer
);
357 if(picture
[x
]) DisposeDTObject(picture
[x
]);
360 // Close notification of prefs change
364 FreeMem(nr
, sizeof(struct NotifyRequest
));
366 DeleteMsgPort(BIBport
);
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
);
379 /*****************************************************************************/
384 int x
, TextLenght
, NumChars
;
386 Icons_Struct
[0].Icon_OK
= FALSE
;
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)
398 //FIXME: A better error handling might be added
399 D(bug("[IconBar] Prefs error\n"));
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
;
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
,
447 IconControl(Icon
[IconCounter
],
448 ICONCTRLA_GetWidth
, &Icons_Struct
[IconCounter
].Icon_Width
,
449 ICONCTRLA_GetHeight
, &Icons_Struct
[IconCounter
].Icon_Height
,
450 ICONCTRLA_SetNewIconsSupport
, TRUE
,
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
;
473 if (IconCounter
== SUM_ICON
) break;
475 //FIXME: A better error handling might be added
476 D(bug("[IconBar] Not found icon %s.\n", Icons_Struct
[IconCounter
].Icon_Path
));
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);
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
;
511 Lenght
= Lenght
+ 10;
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)
529 "SYS:System/Images/bibgfx/left" ,
530 "SYS:System/Images/bibgfx/middle",
531 "SYS:System/Images/bibgfx/right"
536 picture
[x
] = NewDTObject (name
[x
],
537 DTA_GroupID
, GID_PICTURE
,
539 PDTA_DestMode
, PMODE_V43
,
540 OBP_Precision
, PRECISION_IMAGE
,
541 PDTA_Screen
, (ULONG
)Screen_struct
,
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
);
552 PDTA_DestBitMap
, (LONG
)&bm
[x
],
553 DTA_NominalHoriz
, (LONG
)&BackgroundData
[x
].Width
,
554 DTA_NominalVert
, (LONG
)&BackgroundData
[x
].Height
,
561 /*****************************************************************************/
563 void SetWindowParameters(void)
571 Icons_Struct
[0].Icon_PositionX
= 0;
573 for (y
=0; y
<(LevelCounter
); y
++)
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"));
599 Levels_Struct
[y
+1].Beginning
= x
;
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
;
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
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
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
)
680 // LJ: Temporary disabled mouse cases in function Decode_IDCMP
682 switch (KomIDCMP
->Class
)
684 case IDCMP_CLOSEWINDOW
:
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
));
718 Icons_Struct
[MouseIcon
].Icon_Status
= Icons_Struct
[MouseIcon
].Icon_Status
& 0x07;
723 case IDCMP_MOUSEBUTTONS
:
724 switch (KomIDCMP
->Code
)
727 Icons_Struct
[MouseIcon
].Icon_Status
= Icons_Struct
[MouseIcon
].Icon_Status
| SELECTED_ICON
;
730 D(bug("[IconBar] Icon #%d\n", MouseIcon
));
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
758 switch(KomIDCMP
->Code
)
761 if((KomIDCMP
->Qualifier
) & IEQUALIFIER_LSHIFT
)
768 for(x
=0; x
<SUM_ICON
; x
++)
778 for(x
=Levels_Struct
[CurrentLevel
].Beginning
; x
<IconCounter
; x
++)
782 DrawIconState(Window_struct
->RPort
,
785 Icons_Struct
[x
].Icon_PositionX
,
786 Icons_Struct
[x
].Icon_PositionY
,
788 ICONDRAWA_Frameless
, TRUE
,
789 ICONDRAWA_EraseBackground
, FALSE
,
796 case RAWKEY_NM_WHEEL_DOWN
:
798 if(CurrentLevel
== (LevelCounter
-1 )) CurrentLevel
= 0;
799 Show_Selected_Level();
803 case RAWKEY_NM_WHEEL_UP
:
805 if(CurrentLevel
< 0) CurrentLevel
= LevelCounter
- 2;
806 Show_Selected_Level();
815 case IDCMP_INACTIVEWINDOW
:
816 if(rbm
== 0) Window_Active
= FALSE
;
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
);
833 case IDCMP_INTUITICKS
:
840 void Change_State(int Reset
)
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)
852 if((Icons_Struct
[x
].Icon_Status
& ICON_ACTIVE
) == 0 && Icons_Struct
[x
].Icon_Status
< 4)
855 Icons_Struct
[x
].Icon_Status
= (Icons_Struct
[x
].Icon_Status
- 1) & 0xC7;
859 Icons_Struct
[x
].Icon_Status
= (Icons_Struct
[x
].Icon_Status
+ 1) & 0xC7;
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,
885 DrawIconState(&RP_DoubleBuffer
, //Window_struct->RPort,
888 0, //Icons_Struct[IconNumber].Icon_PositionX,
889 Icons_Struct
[IconNumber
].Icon_PositionY
- MovingTable
[(Icons_Struct
[IconNumber
].Icon_Status
& 0x07)],
891 ICONDRAWA_Frameless
, TRUE
,
892 ICONDRAWA_EraseBackground
, FALSE
,
895 BltBitMapRastPort(BMP_DoubleBuffer
,
898 Window_struct
->RPort
,
899 Icons_Struct
[IconNumber
].Icon_PositionX
,
901 Icons_Struct
[IconNumber
].Icon_Width
+ 1,
906 void Blink_Icon(int IconNumber
)
908 int x
, Tryb
=IDS_SELECTED
;
912 Insert_Icon(Tryb
, IconNumber
);
915 if(Tryb
== IDS_NORMAL
) Tryb
= IDS_SELECTED
;
916 else Tryb
= IDS_NORMAL
;
920 BOOL
OpenMainWindow(void)
924 if((Screen_struct
=LockPubScreen(NULL
)) != NULL
)
926 BltBitMapRastPort(Screen_struct
->RastPort
.BitMap
,
927 (ScreenWidth
>>1) - (WindowWidth
>>1),
928 ScreenHeight
- WindowHeight
,
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],
948 WindowHeight
- BackgroundData
[0].Height
,
949 BackgroundData
[0].Width
,
950 BackgroundData
[0].Height
,
955 BltBitMapRastPort(bm
[1],
959 BackgroundData
[0].Width
+ x
* BackgroundData
[1].Width
,
960 WindowHeight
- BackgroundData
[1].Height
,
961 BackgroundData
[1].Width
,
962 BackgroundData
[1].Height
,
966 BltBitMapRastPort(bm
[1],
970 BackgroundData
[0].Width
+ x
* BackgroundData
[1].Width
,
971 WindowHeight
- BackgroundData
[1].Height
,
972 y
- BackgroundData
[1].Width
* a
,
973 BackgroundData
[1].Height
,
976 BltBitMapRastPort(bm
[2],
980 WindowWidth
- BackgroundData
[2].Width
,
981 WindowHeight
- BackgroundData
[2].Height
,
982 BackgroundData
[2].Width
,
983 BackgroundData
[2].Height
,
985 } else if(picture
[1]) {
986 for(x
=0; x
<WindowWidth
; x
=x
+BackgroundData
[1].Width
)
988 BltBitMapRastPort(bm
[1],
993 WindowHeight
- BackgroundData
[1].Height
,
994 BackgroundData
[1].Width
,
995 BackgroundData
[1].Height
,
1000 if(Icon_Remap
== TRUE
)
1002 D(bug("[IconBar] Iconremap is true!\n"));
1004 for(x
=Levels_Struct
[CurrentLevel
].Beginning
; x
<IconCounter
; x
++)
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
,
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
|
1031 WA_IDCMP
, IDCMP_NEWSIZE
|
1033 IDCMP_INACTIVEWINDOW
|
1039 D(bug("[IconBar] Window opened\n"));
1041 WindowMask
= 1 << Window_struct
->UserPort
->mp_SigBit
;
1043 BltBitMapRastPort(BMP_Buffer
,
1045 Window_struct
->RPort
,
1051 for(x
=Levels_Struct
[CurrentLevel
].Beginning
; x
<IconCounter
; x
++)
1055 DrawIconState(Window_struct
->RPort
,
1058 Icons_Struct
[x
].Icon_PositionX
,
1059 Icons_Struct
[x
].Icon_PositionY
,
1061 ICONDRAWA_Frameless
, TRUE
,
1062 ICONDRAWA_EraseBackground
, FALSE
,
1067 D(bug("[IconBar] Can't open main toolbar window\n"));
1072 Window_Active
= TRUE
;
1077 void CloseMainWindow(void)
1079 D(bug("[IconBar] ClosingMainWindow...\n"));
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
;
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
)
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)
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
)
1143 void OpenMenuWindow(void)
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
|
1157 IDCMP_INACTIVEWINDOW
,
1158 WA_Flags
,WFLG_ACTIVATE
|
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
);
1202 if(PositionMenuOK
== TRUE
)
1204 if(Position
== (LevelCounter
- 1))
1208 CurrentLevel
= Position
;
1209 Show_Selected_Level();
1214 void Decode_IDCMP2(struct IntuiMessage
*KomIDCMP
)
1216 int x
, kolA
, kolB
, dluG
, x4
;
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;
1234 if(Position
!= OldPosition
)
1236 for(x
=0; x
<LevelCounter
; x
++)
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
));
1270 case IDCMP_MOUSEBUTTONS
: //LJ: Adding IDCMP_ seems to do the trick...
1271 switch (KomIDCMP
->Code
)
1274 MenuWindow_Open
= FALSE
;
1280 case IDCMP_INACTIVEWINDOW
:
1281 MenuWindow_Open
= FALSE
;
1286 void Launch_Program(char *Program
)
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
);
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"));
1312 if (Window_Open
== TRUE
)
1314 D(bug("[IconBar] The Main window is open.. so let's close it...\n"));
1318 for(x
=0; x
<SUM_ICON
; x
++)
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"));
1344 FirstOpening
= FALSE
;