Problem:
My app can open multiple databases, so I've decided to display
database name in app title. There is a category trigger on the same line.
Now imagine a database name being rather long, and a user selecting a
new category, which is also long. When displayed, this category name
is drawn over the title, cutting off it's right part. Then they selet a next
category which is shorter. The title line contains garbage.

To avoid this, I decided to truncate title with ellipses each time
a new category is selected.

Initially, I wrote it as

static void fixTitle( void )
{
   RectangleType r;
   FrmGetObjectBounds( frmP, FrmGetObjectIndex( frmP,
     ListCategoryPopTrigger ), &r );
   RctSetRectangle( &r, 0, 0, r.topLeft.x, 13 );
   FntSetFont( boldFont );
   if( FrmVisible(frmP) ) FrmEraseForm( frmP );
   FrmDrawForm( frmP );
   WinEraseRectangle( &r, 3 );
   WinGlueDrawTruncChars(gPref.dbName, StrLen(gPref.dbName), 2, 0,
     r.extent.x-2);
   WinInvertRectangle( &r, 3 );
}

It works fine on black&white models, but under OS3.5  it looks
ugly because of WinInvertRectangle...

So my final solution was

static char strTitle[dmDBNameLength];
...
   RectangleType r; Int16 w,len;
   FrmGetObjectBounds( frmP, FrmGetObjectIndex( frmP,
     ListCategoryPopTrigger ), &r );
   FntSetFont( boldFont );
   w=r.topLeft.x-4;
   StrCopy( strTitle, gPref.dbName );
   if( FntCharsWidth(gPref.dbName,(len=StrLen(gPref.dbName))) > w )
   {
     Boolean trunc; Char chel; ChrHorizEllipsis(&chel);
     w -= FntCharWidth(chel);
     FntCharsInWidth( gPref.dbName, &w, &len, &trunc );
     strTitle[len]=chel; strTitle[len+1]=0;
   }
   if( FrmVisible(frmP) ) FrmEraseForm( frmP );
   FrmSetTitle( frmP, strTitle );
   FrmDrawForm( frmP );

This works fine under OS3.5, but is very slow...

Ivan

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to