home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ARM Club 3
/
TheARMClub_PDCD3.iso
/
programs
/
fonts
/
a_q
/
fontpool
/
!Ex-C
/
c
/
!RunImage
Wrap
Text File
|
1995-01-11
|
13KB
|
360 lines
/******************************************************************************
C-Example of FontPool v0.12
Author: Eirik Hansen
All calls available in FontPool v0.12 are demonstrated. (Though to use an
anti-aliased font on the font-menu itself, you should look at the
BASIC-Example (PROCDoIChangeMenuFont).) Helpful comments are found whenever a
FontPool related operation is performed. To facilitate locating them, these
comments are highlighted by a preceding line like '----> Comment <----'.
To prevent the function-calls from becoming a mile long, most parameters are
passed by means of a structure. This structure (FontPool_Struct) is
typedef'ed in the file 'FontPool.h'.
Note that errors are not dealt with, so if the font-menu does not show when
you click MENU it is probably because the FontManager is not present.
Alternatively you have a hilarious Font$Path.
Feel free to use this file as a framework for more serious programs. Note
that libraries such as 'win', 'event' etc. are in this example avoided since
they tend to limit flexibility, and also add severely to the filesize of the
final executable. You might find some solutions stupid, but the important
thing is to demonstrate how to interface with FontPool.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/****************** #includes.. ***********************************************/
#include "wimp.h"
#include "template.h"
#include "menu.h"
#include "os.h"
#include <stdlib.h>
#include "FontPool.h"
/****************** #defines.. ************************************************/
#ifndef FALSE
#define FALSE 0
#define TRUE 1
#endif
/****************** Global variables.. ****************************************/
BOOL Quit=FALSE;
wimp_t *TaskH;
wimp_w WorkH;
wimp_menustr *MainM;
wimp_eventstr RBlock;
char CurrentFont[48],
*FontIcon,
*ConfIcon;
/*-------------------------> The FontPool structure <-------------------------*/
FontPool_Struct FontPool;
/****************** Setting up! ***********************************************/
/*================> Yes! Setting up.. >=======================================*/
BOOL ExC_Setup(void)
{
BOOL ExC_ReadTemplates(void);
int *MItem,
Version=200;
wimp_taskinit("Ex-C", &Version, TaskH);
ExC_ReadTemplates();
MainM=menu_syshandle(menu_new("FontPool", ">Font, ~>Size, ~>Y-Size, ~>Foreground, ~>Background"));
MItem=(int *) MainM;
MItem+=7;
/*----------------------------> The next line <-------------------------------*/
/* of code ensures that a Msg_SubmenuWarning is generated when the pointer */
/* moves over the menu-item. MItem[1]=0 sets the initial item's submenu */
/* pointer. This pointer is automatically updated by the FontPool_Functions */
/* since its address is 'remembered' in FontPool.ParentItem (some 25 lines */
/* below). */
MItem[0]=wimp_MSUBLINKMSG;
MItem[1]=0;
/* The rest of the menu-items are just to illustrate a 'real' font-menu. */
MItem+=6;
MItem[0]=0; /* No flags */
MItem[1]=100; /* Ensure the item gets an arrow '=>' */
MItem+=6;
MItem[0]=0; /* No flags */
MItem[1]=100;
MItem+=6;
MItem[0]=0; /* No flags */
MItem[1]=100;
MItem+=6;
MItem[0]=wimp_MLAST; /* Last entry */
MItem[1]=100; /* dbox ptr */
MItem=(int *) MainM;
/*---------------> Setting parameters in the FontPool structure <-------------*/
FontPool.Config = 0x800C050B;
FontPool.x = 0;
FontPool.y = 0;
FontPool.RootMenu = MItem;
FontPool.FontName = CurrentFont;
FontPool.ParentItem = MItem+8;
FontPool.MenuFont = 0; /* These parameters are not used in this */
FontPool.SizeX = 0; /* C-Example. (They all have to do with */
FontPool.SizeY = 0; /* using an anti-aliased font on the */
FontPool.ItemHgt = 0; /* font-menu itself.) */
/*-------------------------> Initialising FontPool <--------------------------*/
FontPool_Hello(&FontPool);
/* Open the window... */
wimp_get_wind_state(WorkH, (wimp_wstate *) &RBlock.data.o);
wimp_open_wind(&RBlock.data.o);
return TRUE;
}
/*=================> Reading in the templates.. >=============================*/
BOOL ExC_ReadTemplates(void)
{
template *Template;
wimp_icon Icon;
template_readfile("<Ex-C$Dir>.Templates");
Template=template_find("Work");
wimp_create_wind(&Template->window, &WorkH);
wimp_get_icon_info(WorkH, 0, &Icon); /* Extract the pointer to */
FontIcon=Icon.data.indirecttext.buffer; /* the 'Current font' icon */
wimp_get_icon_info(WorkH, 8, &Icon); /* Extract the pointer to */
ConfIcon=Icon.data.indirecttext.buffer; /* the configuration number */
return TRUE;
}
/****************** Poll event handling... ************************************/
/*================> Redraw windows.. >========================================*/
/* This function is never called in this example since the wimp automatically */
/* redraws the window. */
BOOL ExC_RedrawWindow(wimp_eventdata *Data)
{
wimp_redrawstr Window;
BOOL More;
Window.w=Data->o.w;
wimp_redraw_wind(&Window, &More);
while (More)
{
wimp_get_rectangle(&Window, &More);
}
return TRUE;
}
/*================> Open windows.. >==========================================*/
BOOL ExC_OpenWindow(wimp_eventdata *Data)
{
wimp_open_wind(&Data->o);
return TRUE;
}
/*================> Closing windows... >======================================*/
/* Actually, in this case we just leave completely. */
BOOL ExC_CloseWindow(wimp_eventdata *Data)
{
Quit=TRUE;
return TRUE;
}
/*================> Button events.... >=======================================*/
BOOL ExC_ButtonEvent(wimp_eventdata *Data)
{
int x,y;
wimp_bbits ClickButton;
ClickButton=Data->but.m.bbits;
x=Data->but.m.x;
y=Data->but.m.y;
switch (ClickButton)
{
/*-----------------------> Show the font-menu directly <----------------------*/
/* FontPool.RootMenu=0 indicates to the function FontPool_MenuSelection that */
/* the font-menu was in fact the 'root-menu'. FontPool_CreateMenu displays */
/* the font-menu directly - ie. without having to go via the root-menu. */
case wimp_BMID:
FontPool.x=x-100;
FontPool.y=y+76;
FontPool.RootMenu=0;
FontPool_CreateMenu(&FontPool);
break;
/*----------------------> Show the font-menu indirectly <---------------------*/
/* It is not displayed until you move the mouse over the 'Fonts' item. The */
/* wimp then generates a Msg_SubmenuWarning and the font-menu is displayed in */
/* the function ExC_CreateASubMenu. FontPool.RootMenu=(int *) MainM (below) */
/* indicates to the function FontPool_MenuSelection that the font-menu was */
/* last displayed indirectly. */
case wimp_BRIGHT:
FontPool.RootMenu=(int *) MainM;
wimp_create_menu(MainM, x-100, y+76);
break;
/*-----------------------> Changing the configuration <-----------------------*/
/* The TRUE (below) informs FontPool to rebuild the menu immediately - ie. */
/* not waiting for the font-menu to be displayed.. (By the way, the strtoul() */
/* call below generates a compiler warning...) */
case wimp_BLEFT:
if (Data->but.m.i==7)
{
FontPool.Config=strtoul(ConfIcon, 0, 16);
FontPool_Configure(&FontPool, TRUE);
}
break;
}
return TRUE;
}
/*================> Copy the chr<32 terminated string.. >=====================*/
void ExC_CopyString(char *Get, char *Put)
{
while (*Get>31)
{
*Put++=*Get++;
}
*Put=0;
return;
}
/*================> Menu selection.... >======================================*/
BOOL ExC_DecodeMenu(wimp_eventdata *Data)
{
wimp_menustr *Menu;
wimp_mousestr *Mouse;
int *Selection;
Mouse=&Data->but.m;
Selection=(int *) Data;
Menu=MainM;
/*----------------------------------> If <------------------------------------*/
/* the menu-selection results in a font being selected, its name is in this */
/* example simply copied to the 'current font icon'. (In a serious program, */
/* this would be a neat place to do some font-operations - such as re- */
/* selecting the applications current font.) FontPool_MenuSelection returns */
/* with either NULL or a pointer to the name of the selected font. Since */
/* this pointer is in this example supplied in the call (by setting */
/* FontPool.FontName = CurrentFont) this returned pointer will always equal */
/* CurrentFont or NULL. */
if (FontPool_MenuSelection((int *) Data, &FontPool))
{
ExC_CopyString(CurrentFont, FontIcon);
}
/*---------------------------------> Else <-----------------------------------*/
/* when no font-name pointer is returned, the no-font-string (below) is */
/* copied to the same icon and the 'current font' is set to a 0-string. */
else
{
ExC_CopyString("No font selected (System font)\0", FontIcon);
CurrentFont[0]=0;
}
wimp_set_icon_state(WorkH, 0, 0, 0); /* Redraw the current font icon */
/*----------------> If ADJUST was clicked re-create the menu <----------------*/
wimp_get_point_info(Mouse);
if (Mouse->bbits==wimp_BRIGHT) FontPool_CreateMenu(&FontPool);
return TRUE;
}
/*================> A Msg_SubMenuWarning... >=================================*/
BOOL ExC_CreateASubMenu(int *Data)
{
/*-----------------> Note the '*' in the comparision below <------------------*/
if (Data[0]==*FontPool.ParentItem)
{
FontPool.x=Data[1];
FontPool.y=Data[2];
FontPool_CreateSubMenu(&FontPool);
}
return TRUE;
}
/*================> Receiving messages.... >==================================*/
BOOL ExC_Messages(wimp_eventdata *Data)
{
switch (Data->msg.hdr.action)
{
case wimp_MCLOSEDOWN:
Quit=TRUE;
break;
case wimp_MMENUWARN:
ExC_CreateASubMenu((int *) &Data->msg.data.words);
break;
}
return TRUE;
}
/****************** Polling.. *************************************************/
/*================> The main poll loop... >===================================*/
BOOL ExC_Poll(void)
{
wimp_eventstr *Result;
wimp_emask Mask;
BOOL (*FPtr)(),
(*FuncPtr[20])() = {
0, /* wimp_ENULL */
ExC_RedrawWindow, /* wimp_EREDRAW */
ExC_OpenWindow, /* wimp_EOPEN */
ExC_CloseWindow, /* wimp_ECLOSE */
0, /* wimp_EPTRLEAVE */
0, /* wimp_EPTRENTER */
ExC_ButtonEvent, /* wimp_EBUT */
0, /* wimp_EUSERDRAG */
0, /* wimp_EKEY */
ExC_DecodeMenu, /* wimp_EMENU */
0, /* wimp_ESCROLL */
0, /* wimp_ELOSECARET */
0, /* wimp_EGAINCARET */
0, /* 13 */
0, /* 14 */
0, /* 15 */
0, /* 16 */
ExC_Messages, /* wimp_ESEND */
ExC_Messages, /* wimp_ESENDWANTACK */
0 /* wimp_EACK */
};
/* Setting up poll mask */
Mask=wimp_EMNULL | wimp_EMPTRLEAVE | wimp_EMPTRENTER | wimp_EMSCROLL | wimp_EMLOSECARET | wimp_EMGAINCARET;
Result=&RBlock;
do
{
wimp_poll(Mask, Result);
FPtr=FuncPtr[Result->e];
if (FPtr) FPtr(&Result->data);
} while (!Quit);
return TRUE;
}
/****************** Main entry... *********************************************/
int main(void)
{
BOOL Return;
Return=ExC_Setup();
if (Return) Return=ExC_Poll();
/*-----------------------------> We're history <------------------------------*/
FontPool_Goodbye();
wimp_closedown();
return Return;
}