BPortLink now has a FlushWithReply() method itself.
BPortLink::AttachString() now accepts a length argument, and will no longer send a terminating null byte; LinkMsgReader::ReadString(), however, will make sure the string read is null terminated. Changed client communication code to use FlushWithReply() instead of Flush() and GetNextReply() - there were many bugs and shortcomings in the code, I hope I've fixed them all. Converted ClientFontList.cpp to our coding style (but not completely, the class members are missing). Some more cleanup - I hope Adi will adopt our coding style one day! git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12998 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, OpenBeOS
|
||||
// Copyright (c) 2001-2005, Haiku
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
@@ -44,312 +44,274 @@
|
||||
# define STRACE(x) ;
|
||||
#endif
|
||||
|
||||
class FontListFamily
|
||||
{
|
||||
public:
|
||||
FontListFamily(void);
|
||||
~FontListFamily(void);
|
||||
BString name;
|
||||
BList *styles;
|
||||
int32 flags;
|
||||
|
||||
class FontListFamily {
|
||||
public:
|
||||
FontListFamily(void);
|
||||
~FontListFamily(void);
|
||||
|
||||
BString name;
|
||||
BList *styles;
|
||||
int32 flags;
|
||||
};
|
||||
|
||||
|
||||
FontListFamily::FontListFamily(void)
|
||||
{
|
||||
styles=new BList(0);
|
||||
flags=0;
|
||||
styles = new BList(0);
|
||||
flags = 0;
|
||||
}
|
||||
|
||||
|
||||
FontListFamily::~FontListFamily(void)
|
||||
{
|
||||
BString *s;
|
||||
s=(BString*)styles->RemoveItem(0L);
|
||||
while(s)
|
||||
{
|
||||
delete s;
|
||||
s=(BString*)styles->RemoveItem(0L);
|
||||
for (int32 i = styles->CountItems(); i-- > 0; ) {
|
||||
delete (BString *)styles->ItemAt(i);
|
||||
}
|
||||
|
||||
delete styles;
|
||||
}
|
||||
|
||||
|
||||
ClientFontList::ClientFontList(void)
|
||||
{
|
||||
STRACE(("ClientFontList()\n"));
|
||||
familylist=new BList(0);
|
||||
fontlock=create_sem(1,"fontlist_sem");
|
||||
familylist = new BList(0);
|
||||
fontlock = create_sem(1,"fontlist_sem");
|
||||
}
|
||||
|
||||
|
||||
ClientFontList::~ClientFontList(void)
|
||||
{
|
||||
STRACE(("~ClientFontList()\n"));
|
||||
|
||||
acquire_sem(fontlock);
|
||||
|
||||
font_family *fam;
|
||||
while(familylist->ItemAt(0L)!=NULL)
|
||||
{
|
||||
fam=(font_family *)familylist->RemoveItem(0L);
|
||||
delete fam;
|
||||
for (int32 i = familylist->CountItems(); i-- > 0; ) {
|
||||
delete (font_family *)familylist->ItemAt(i);
|
||||
}
|
||||
familylist->MakeEmpty();
|
||||
|
||||
delete familylist;
|
||||
delete_sem(fontlock);
|
||||
}
|
||||
|
||||
bool ClientFontList::Update(bool check_only)
|
||||
|
||||
bool
|
||||
ClientFontList::Update(bool checkOnly)
|
||||
{
|
||||
STRACE(("ClientFontList::Update(%s) - %s\n", (check_only)?"true":"false",SERVER_FONT_LIST));
|
||||
|
||||
STRACE(("ClientFontList::Update(%s) - %s\n", checkOnly ? "true" : "false",
|
||||
SERVER_FONT_LIST));
|
||||
|
||||
// Open the font list kept in font list
|
||||
acquire_sem(fontlock);
|
||||
|
||||
// We're going to ask the server whether the list has changed
|
||||
port_id serverport;
|
||||
serverport=find_port(SERVER_PORT_NAME);
|
||||
|
||||
bool needs_update=true;
|
||||
BPortLink serverlink(serverport);
|
||||
port_id port = find_port(SERVER_PORT_NAME);
|
||||
|
||||
if(serverport!=B_NAME_NOT_FOUND)
|
||||
{
|
||||
int32 code=SERVER_FALSE;
|
||||
serverlink.StartMessage(AS_QUERY_FONTS_CHANGED);
|
||||
serverlink.Flush();
|
||||
serverlink.GetNextReply(&code);
|
||||
|
||||
// Attached Data: none
|
||||
// Reply: SERVER_TRUE if fonts have changed, SERVER_FALSE if not
|
||||
|
||||
needs_update=(code==SERVER_TRUE)?true:false;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool needsUpdate = true;
|
||||
BPortLink link(port);
|
||||
|
||||
if (port >= B_OK) {
|
||||
link.StartMessage(AS_QUERY_FONTS_CHANGED);
|
||||
|
||||
int32 code;
|
||||
if (link.FlushWithReply(code) == B_OK)
|
||||
needsUpdate = code == SERVER_TRUE;
|
||||
} else {
|
||||
STRACE(("ClientFontList::Update(): Couldn't find app_server port\n"));
|
||||
}
|
||||
|
||||
if(check_only)
|
||||
{
|
||||
if (checkOnly || !needsUpdate) {
|
||||
release_sem(fontlock);
|
||||
return needs_update;
|
||||
return needsUpdate;
|
||||
}
|
||||
|
||||
// Don't update the list if nothing has changed
|
||||
if(needs_update)
|
||||
{
|
||||
BFile file(SERVER_FONT_LIST,B_READ_ONLY);
|
||||
BMessage fontmsg, familymsg;
|
||||
|
||||
if(file.InitCheck()==B_OK)
|
||||
{
|
||||
if(fontmsg.Unflatten(&file)==B_OK)
|
||||
{
|
||||
#ifdef DEBUG_CLIENT_FONT_LIST
|
||||
printf("Font message contents:\n");
|
||||
fontmsg.PrintToStream();
|
||||
#endif
|
||||
BFile file(SERVER_FONT_LIST,B_READ_ONLY);
|
||||
BMessage fontMessage;
|
||||
|
||||
// Empty the font list
|
||||
FontListFamily *flf=(FontListFamily*)familylist->RemoveItem(0L);
|
||||
BString sty, extra;
|
||||
int32 famindex, styindex;
|
||||
bool tempbool;
|
||||
|
||||
while(flf)
|
||||
{
|
||||
STRACE(("Removing %s from list\n",flf->name.String()));
|
||||
delete flf;
|
||||
flf=(FontListFamily*)familylist->RemoveItem(0L);
|
||||
}
|
||||
STRACE(("\n"));
|
||||
|
||||
famindex=0;
|
||||
|
||||
// Repopulate with new listings
|
||||
while(fontmsg.FindMessage("family",famindex,&familymsg)==B_OK)
|
||||
{
|
||||
famindex++;
|
||||
|
||||
flf=new FontListFamily();
|
||||
familylist->AddItem(flf);
|
||||
familymsg.FindString("name",&(flf->name));
|
||||
if (file.InitCheck() == B_OK
|
||||
&& fontMessage.Unflatten(&file) == B_OK) {
|
||||
#ifdef DEBUG_CLIENT_FONT_LIST
|
||||
printf("Font message contents:\n");
|
||||
fontmsg.PrintToStream();
|
||||
#endif
|
||||
|
||||
STRACE(("Adding %s to list\n",flf->name.String()));
|
||||
styindex=0;
|
||||
// Empty the font list
|
||||
FontListFamily *family;
|
||||
while ((family = (FontListFamily *)familylist->RemoveItem(0L)) != NULL) {
|
||||
STRACE(("Removing %s from list\n", family->name.String()));
|
||||
delete family;
|
||||
|
||||
}
|
||||
STRACE(("\n"));
|
||||
|
||||
// populate family with styles
|
||||
while(familymsg.FindString("styles",styindex,&sty)==B_OK)
|
||||
{
|
||||
STRACE(("\tAdding %s\n",sty.String()));
|
||||
styindex++;
|
||||
flf->styles->AddItem(new BString(sty));
|
||||
}
|
||||
|
||||
if(familymsg.FindBool("tuned",&tempbool)==B_OK)
|
||||
{
|
||||
STRACE(("Family %s has tuned fonts\n", flf->name.String()));
|
||||
flf->flags|=B_HAS_TUNED_FONT;
|
||||
}
|
||||
|
||||
if(familymsg.FindBool("fixed",&tempbool)==B_OK)
|
||||
{
|
||||
STRACE(("Family %s is fixed-width\n", flf->name.String()));
|
||||
flf->flags|=B_IS_FIXED;
|
||||
}
|
||||
familymsg.MakeEmpty();
|
||||
|
||||
}
|
||||
// Repopulate with new listings
|
||||
int32 familyIndex = 0;
|
||||
BMessage familyMessage;
|
||||
while (fontMessage.FindMessage("family", familyIndex++, &familyMessage) == B_OK) {
|
||||
family = new FontListFamily();
|
||||
familylist->AddItem(family);
|
||||
familyMessage.FindString("name", &family->name);
|
||||
|
||||
serverlink.StartMessage(AS_UPDATED_CLIENT_FONTLIST);
|
||||
serverlink.Flush();
|
||||
|
||||
release_sem(fontlock);
|
||||
return false;
|
||||
STRACE(("Adding %s to list\n", family->name.String()));
|
||||
|
||||
int32 styleIndex = 0;
|
||||
|
||||
// populate family with styles
|
||||
BString string;
|
||||
while (familyMessage.FindString("styles", styleIndex++, &string) == B_OK) {
|
||||
STRACE(("\tAdding %s\n", string.String()));
|
||||
family->styles->AddItem(new BString(string));
|
||||
}
|
||||
|
||||
if (familyMessage.FindBool("tuned")) {
|
||||
STRACE(("Family %s has tuned fonts\n", family->name.String()));
|
||||
family->flags |= B_HAS_TUNED_FONT;
|
||||
}
|
||||
|
||||
if (familyMessage.FindBool("fixed")) {
|
||||
STRACE(("Family %s is fixed-width\n", family->name.String()));
|
||||
family->flags |= B_IS_FIXED;
|
||||
}
|
||||
familyMessage.MakeEmpty();
|
||||
}
|
||||
|
||||
link.StartMessage(AS_UPDATED_CLIENT_FONTLIST);
|
||||
link.Flush();
|
||||
}
|
||||
|
||||
} // end if Unflatten==B_OK
|
||||
} // end if InitCheck==B_OK
|
||||
} // end if needs_update
|
||||
|
||||
release_sem(fontlock);
|
||||
return false;
|
||||
}
|
||||
|
||||
int32 ClientFontList::CountFamilies(void)
|
||||
|
||||
int32
|
||||
ClientFontList::CountFamilies(void)
|
||||
{
|
||||
STRACE(("ClientFontList::CountFamilies\n"));
|
||||
STRACE(("ClientFontList::CountFamilies\n"));
|
||||
acquire_sem(fontlock);
|
||||
int32 count=familylist->CountItems();
|
||||
int32 count = familylist->CountItems();
|
||||
release_sem(fontlock);
|
||||
return count;
|
||||
}
|
||||
|
||||
status_t ClientFontList::GetFamily(int32 index, font_family *name, uint32 *flags)
|
||||
|
||||
status_t
|
||||
ClientFontList::GetFamily(int32 index, font_family *name, uint32 *flags)
|
||||
{
|
||||
STRACE(("ClientFontList::GetFamily(%ld)\n",index));
|
||||
if(!name)
|
||||
{
|
||||
if (!name) {
|
||||
STRACE(("ClientFontList::GetFamily: NULL font_family parameter\n"));
|
||||
return B_ERROR;
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
|
||||
|
||||
acquire_sem(fontlock);
|
||||
FontListFamily *flf=(FontListFamily*)familylist->ItemAt(index);
|
||||
if(!flf)
|
||||
{
|
||||
|
||||
FontListFamily *family = (FontListFamily *)familylist->ItemAt(index);
|
||||
if (family == NULL) {
|
||||
STRACE(("ClientFontList::GetFamily: index not found\n"));
|
||||
return B_ERROR;
|
||||
}
|
||||
strcpy(*name,flf->name.String());
|
||||
|
||||
|
||||
release_sem(fontlock);
|
||||
|
||||
// ToDo: respect size of "name"
|
||||
strcpy(*name, family->name.String());
|
||||
|
||||
release_sem(fontlock);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
int32 ClientFontList::CountStyles(font_family f)
|
||||
|
||||
int32
|
||||
ClientFontList::CountStyles(font_family f)
|
||||
{
|
||||
acquire_sem(fontlock);
|
||||
|
||||
FontListFamily *flf=NULL;
|
||||
int32 i, count=familylist->CountItems();
|
||||
bool found=false;
|
||||
|
||||
for(i=0; i<count;i++)
|
||||
{
|
||||
flf=(FontListFamily *)familylist->ItemAt(i);
|
||||
if(!flf)
|
||||
FontListFamily *family = NULL;
|
||||
int32 i, count = familylist->CountItems();
|
||||
bool found = false;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
family = (FontListFamily *)familylist->ItemAt(i);
|
||||
if (!family)
|
||||
continue;
|
||||
if(flf->name.ICompare(f)==0)
|
||||
{
|
||||
found=true;
|
||||
|
||||
if (family->name.ICompare(f) == 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
count=(found)?flf->styles->CountItems():0;
|
||||
|
||||
|
||||
count = found ? family->styles->CountItems() : 0;
|
||||
|
||||
release_sem(fontlock);
|
||||
return count;
|
||||
}
|
||||
|
||||
status_t ClientFontList::GetStyle(font_family family, int32 index, font_style *name,uint32 *flags, uint16 *face)
|
||||
{
|
||||
if(!name || !(*name) || !family)
|
||||
return B_ERROR;
|
||||
|
||||
acquire_sem(fontlock);
|
||||
|
||||
FontListFamily *flf=NULL;
|
||||
BString *style;
|
||||
int32 i, count=familylist->CountItems();
|
||||
bool found=false;
|
||||
|
||||
for(i=0; i<count;i++)
|
||||
{
|
||||
flf=(FontListFamily *)familylist->ItemAt(i);
|
||||
if(!flf)
|
||||
status_t
|
||||
ClientFontList::GetStyle(font_family fontFamily, int32 index, font_style *name,
|
||||
uint32 *flags, uint16 *face)
|
||||
{
|
||||
if (!name || !*name || !fontFamily)
|
||||
return B_ERROR;
|
||||
|
||||
acquire_sem(fontlock);
|
||||
|
||||
FontListFamily *family = NULL;
|
||||
BString *style;
|
||||
int32 i, count = familylist->CountItems();
|
||||
bool found = false;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
family = (FontListFamily *)familylist->ItemAt(i);
|
||||
if (!family)
|
||||
continue;
|
||||
if(flf->name.ICompare(family)==0)
|
||||
{
|
||||
found=true;
|
||||
|
||||
if (family->name.ICompare(fontFamily) == 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!found)
|
||||
{
|
||||
release_sem(fontlock);
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
style=(BString*)flf->styles->ItemAt(index);
|
||||
if(!style)
|
||||
{
|
||||
|
||||
if (!found) {
|
||||
release_sem(fontlock);
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
strcpy(*name,style->String());
|
||||
style = (BString *)family->styles->ItemAt(index);
|
||||
if (!style) {
|
||||
release_sem(fontlock);
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
if(flags)
|
||||
*flags=flf->flags;
|
||||
strcpy(*name, style->String());
|
||||
|
||||
if(face)
|
||||
{
|
||||
if(style->ICompare("Roman")==0 ||
|
||||
style->ICompare("Regular")==0 ||
|
||||
style->ICompare("Normal")==0 ||
|
||||
style->ICompare("Light")==0 ||
|
||||
style->ICompare("Medium")==0 ||
|
||||
style->ICompare("Plain")==0)
|
||||
{
|
||||
*face|=B_REGULAR_FACE;
|
||||
if (flags)
|
||||
*flags = family->flags;
|
||||
|
||||
if (face) {
|
||||
if (!style->ICompare("Roman")
|
||||
|| !style->ICompare("Regular")
|
||||
|| !style->ICompare("Normal")
|
||||
|| !style->ICompare("Light")
|
||||
|| !style->ICompare("Medium")
|
||||
|| !style->ICompare("Plain")) {
|
||||
*face |= B_REGULAR_FACE;
|
||||
STRACE(("GetStyle: %s Roman face\n", style->String()));
|
||||
}
|
||||
else
|
||||
if(style->ICompare("Bold")==0)
|
||||
{
|
||||
*face|=B_BOLD_FACE;
|
||||
} else if (!style->ICompare("Bold")) {
|
||||
*face |= B_BOLD_FACE;
|
||||
STRACE(("GetStyle: %s Bold face\n"));
|
||||
}
|
||||
else
|
||||
if(style->ICompare("Italic")==0)
|
||||
{
|
||||
*face|=B_ITALIC_FACE;
|
||||
STRACE(("GetStyle: %s Italic face\n"));
|
||||
}
|
||||
else
|
||||
if(style->ICompare("Bold Italic")==0)
|
||||
{
|
||||
*face|=B_ITALIC_FACE | B_BOLD_FACE;
|
||||
STRACE(("GetStyle: %s Bold Italic face\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
STRACE(("GetStyle: %s Unknown face %s\n", style->String()));
|
||||
}
|
||||
}
|
||||
|
||||
} else if (!style->ICompare("Italic")) {
|
||||
*face|=B_ITALIC_FACE;
|
||||
STRACE(("GetStyle: %s Italic face\n"));
|
||||
} else if (!style->ICompare("Bold Italic")) {
|
||||
*face|=B_ITALIC_FACE | B_BOLD_FACE;
|
||||
STRACE(("GetStyle: %s Bold Italic face\n"));
|
||||
} else {
|
||||
STRACE(("GetStyle: %s Unknown face %s\n", style->String()));
|
||||
}
|
||||
}
|
||||
|
||||
release_sem(fontlock);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user