
-- MYFIELDSUPPLIER - a class to support editable text without any
-- media associated with it.
class MYFIELDSUPPLIER is FIELDSUPPLIER;
has
initialValue;
LoadData()
external "MyFieldSupplierLoadData";
UnloadData()
do
end;
UninstallData(theContainer, theClient)
do
end;
end;
--------------------------------------
(myfield.c:)
------------
/*
File: MyField.c
supports fieldsuppliers with no media.
(derived from Texthandler.c)
*/
#include "Errors.h"
#include "Fonts.h"
#include "Memory.h"
#include "QuickDraw.h"
#include "TextEdit.h"
#include "Key.h"
typedef struct {
short font;
short size; /* points */
short face;
short kerning; /* tenth of points */
short firstSpacing; /* points */
short nextSpacing; /* points */
short leftMargin;
short topMargin;
short rightMargin;
short bottomMargin;
short alignment;
RGBColor backColor;
RGBColor foreColor;
short transparent;
} KTextStyle, *KTextStylePtr;
extern const keyID K_INITIALVALUE ; // kate
extern const keyID K_DATA;
Handle MyFieldSupplierLoadData(key* the)
{
Handle aHandle = NULL;
long aCount;
RGBColor fgcolor, bgcolor;
key* a = keyUse(1);
keyDo {
GetBackColor(&bgcolor);
GetForeColor(&fgcolor);
a[0] = keyGet(the[SELF], K_INITIALVALUE);
if (keyIsVoid(a[0])) // forgot to initialize it, try to be nice
aCount = 0;
else
aCount = strlen(keyToString(a[0])); // K_INITIALVALUE better be a STRING!
aHandle = NewHandleClear(sizeof(KTextStyle) + sizeof(long));
keyIfNULL(aHandle);
HLock(aHandle);
((KTextStylePtr)(*aHandle))->font = helvetica;
((KTextStylePtr)(*aHandle))->size = 14;
((KTextStylePtr)(*aHandle))->face = normal;
((KTextStylePtr)(*aHandle))->kerning = 0; // tenth of points
((KTextStylePtr)(*aHandle))->firstSpacing = 0; // fontAscent - points - let
fieldSupplierInstall figure it out
((KTextStylePtr)(*aHandle))->nextSpacing = 0; //line height - points - let
fieldSupplierInstall figure it out
((KTextStylePtr)(*aHandle))->leftMargin = 4; // pixels???
((KTextStylePtr)(*aHandle))->topMargin = 4;
((KTextStylePtr)(*aHandle))->rightMargin = 4;
((KTextStylePtr)(*aHandle))->bottomMargin = 4;
((KTextStylePtr)(*aHandle))->alignment = teFlushDefault;
((KTextStylePtr)(*aHandle))->backColor = bgcolor;
((KTextStylePtr)(*aHandle))->foreColor = fgcolor;
((KTextStylePtr)(*aHandle))->transparent = 1;
HUnlock(aHandle);
*((long*)(*aHandle + sizeof(KTextStyle))) = aCount;
if (aCount & 1) aCount++;
SetHandleSize(aHandle, sizeof(KTextStyle) + sizeof(long) + aCount);
keyIfError(MemError());
if (aCount) {
HLock(aHandle);
strcpy((char*)(*aHandle + sizeof(KTextStyle) + sizeof(long)),
keyToString(a[0]));
HUnlock(aHandle);
}
keyPut(the[SELF], K_DATA, keyFromHandle(aHandle));
}
keyUndo {
if (aHandle != NULL) DisposHandle(aHandle);
}
}
Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help