[comp.sys.amiga.programmer] Help with WB 2.0 pulldown hack.

drtiller@uokmax.ecn.uoknor.edu (Donald Richard Tillery Jr) (06/25/91)

I need some help with a WB 2.0 pulldown I've written:


_Description_ (program source included below - THIS IS NOT A GOOD EXAMPLE OF
               PROGRAMMING, so don't use it as sample code! :-)

I use a large font for my title bars and icons, but a small one for CLI/Shells
and I wanted the same font for the pulldown menus of the WB.  I noticed LSE did
what I wanted, so I figured it was feasible, if a bit of a hack.  I wrote
AltFont.c (with help from a friend and his manuals) that contains a TextAttr
structure (RomFont) and goes through and alters the IntuiText structure of each
menu item to point to it.  This works fine.  However, it may be obvious that
upon exiting this program, the TextAttr structure goes away (well the code
below doesn't exit...but keep reading before you flame me) and thus the
references become corrupted.  Now evidently 2.0 is a virulent program and can
refresh the TextAttr structures to that of the Title bar rather than crashing
or displaying garbage pulldown menus.  I next tried allocating memory for the
TextAttr structure and leaving it allocated upon exiting.  If the machine
didn't crash (about 50% of the time), it refreshed the menus to their default
and continued.  The only functional solution was to leave the program in
memory (not big, but this is NOT what should be done...I do run this program
in my startup-sequence however) and it is stable this way.

So, my problems are these:

1-  What is the best way (using Lattice C) to create that TextAttr structure
    and leave it in memory without leaving the whole program in memory (or is
    there a way to get to the TextAttr structure of the system font which is
    in RAM somewhere and use it...it won't go away when my program exits)?

2-  Once the font has been changed, the verticle size of the menu is the
    same as it was with the larger font.  The pulldown entries are correctly
    spaced for the smaller font, however.  An "Update All" issued from the
    WorkBench menu shortens the menus to include only the number of lines
    actually occupied by the new font.  How can I issue this command from
    C (I have tried every UpdateMenu()-type function I could find and none
    of them work)?

3-  When a "Reset WB" is issued from the Tools menu, or a program that closes
    the WB re-opens it, the fonts revert to the title bar font again.  The only
    way to get back the smaller font is to re-run AltFont and now there are two
    (or more) AltFonts in memory (what a waste!).  How can I attach AltFont to
    the ResetWB command (or the OpenWorkbench() function) so that it is
    automatically re-enabled when either is issued (or make sure that the
    pulldown font is still the smaller font at the time they are issued)?


If you have any suggestions, please let me know.  The source is below (right
after my e-mail address).

Rick Tillery (drtiller@uokmax.ecn.uoknor.edu)

/* AltFont.c - to alter WB menu pulldown item font to system default */
 
#include <intuition/intuition.h>
/* #include <proto/intuition.h> */
 
#define FONT "topaz.font"
#define FONT_SIZE TOPAZ_EIGHTY
#define FONT_HEIGHT 8
#define ENTRY_HEIGHT (FONT_HEIGHT+1)
 
void noexit();
struct IntuitionBase *IntuitionBase;
char *Screen;
struct Menu *WBMenu;
struct MenuItem *MenuItem, *SubMenu;
struct IntuiText *IText;
struct TextAttr RomFont =
{
	(STRPTR)FONT, FONT_SIZE, FS_NORMAL, FPF_ROMFONT
};
 
void main(void)
{
 
	struct Screen *WBScreen;
	USHORT ItemNum = 0, SubNum = 0;
	struct Window *WBWindow;
	void *OpenLibrary();
	
	IntuitionBase = 
		(struct IntuitionBase *)OpenLibrary("intuition.library", 0);
	
	if(!(Screen = (char *)AllocMem(sizeof(struct Screen),0)))
		noexit();
 
	if(!GetScreenData((char *)&Screen,sizeof(struct Screen),WBENCHSCREEN,NULL))
		noexit();
 
	WBScreen = (struct Screen *)&Screen;
	
	WBWindow = WBScreen->FirstWindow;
		
	while (strcmp("Workbench",WBWindow->Title) 
		&& (WBWindow->NextWindow != NULL))
			WBWindow = WBWindow->NextWindow;
	
	if(strcmp("Workbench",WBWindow->Title))
		noexit();
 
	WBMenu = WBWindow->MenuStrip;
	ClearMenuStrip(WBWindow);
	while(WBMenu)
	{
		MenuItem = WBMenu->FirstItem;
		while(MenuItem)
		{
			MenuItem->TopEdge = ENTRY_HEIGHT * ItemNum++;
			MenuItem->Height = ENTRY_HEIGHT;
			IText = (struct IntuiText *)MenuItem->ItemFill;
			IText->ITextFont = &RomFont;
			
			SubMenu = MenuItem->SubItem;
			while(SubMenu)
			{
				SubMenu->TopEdge = ENTRY_HEIGHT * SubNum++;
				SubMenu->Height = ENTRY_HEIGHT;
				IText = (struct IntuiText *)SubMenu->ItemFill;
				IText->ITextFont = &RomFont;
				SubMenu = SubMenu->NextItem;
			}
			SubNum = 0;
			MenuItem = MenuItem->NextItem;
		}
        ItemNum = 0;
		WBMenu = WBMenu->NextMenu;
	}
	SetMenuStrip(WBWindow, WBWindow->MenuStrip);
	noexit();
}
 
void noexit(void)
{
	FreeMem(Screen,sizeof(struct Screen));
	if(IntuitionBase) CloseLibrary(IntuitionBase);
	Wait(0);
}
	

peter@cbmvax.commodore.com (Peter Cherna) (06/25/91)

In article <1991Jun24.213319.16123@uokmax.ecn.uoknor.edu> drtiller@uokmax.ecn.uoknor.edu (Donald Richard Tillery Jr) writes:
>
>
>I need some help with a WB 2.0 pulldown I've written:
>
>
>_Description_ (program source included below - THIS IS NOT A GOOD EXAMPLE OF
>               PROGRAMMING, so don't use it as sample code! :-)

How right you are.  I can see scant reason to want to do this.  Workbench
menus are made from the screen's font, as they should be.  That should
hardly bother you, since they're out of sight when not in use, and they're
smart enough to switch to multiple columns in order to fit, should you
choose an extremely large font.

You shouldn't be surprised to find that the menus get re-laid out every
time Workbench is reset.  A change in screen resolution or font does
require it to happen.  There is no good time to jump in and automatically
fudge with the menus either, since the reset happens asynchronously
to the OpenWorkBench() call.

I'll also warn you that not all the menu items contain IntuiTexts, and
there isn't really a guarantee they'll continue to be that way.

I suggest you leave well enough alone.  This sort of programming isn't
really a good idea.

>Rick Tillery (drtiller@uokmax.ecn.uoknor.edu)

     Peter
--
Peter Cherna, Operating Systems Development Group, Commodore-Amiga, Inc.
{uunet|rutgers}!cbmvax!peter    peter@cbmvax.commodore.com
My opinions do not necessarily represent the opinions of my employer.
"Gosh, didn't he have anything positive to say at all?"