static void ListDrawDataFunc(Int16 itemNum, RectangleType *bounds, Char **itemsText) { char string[20]; StrNCopy(string, GetDisplayString(itemNum), 19); WinSetUnderlineMode(noUnderline); FntSetFont(stdFont); Int16 width = bounds->extent.x; Int16 len = StrLen(string); Boolean noFit = false; FntCharsInWidth(string, &width, &len, &noFit); WinEraseRectangle(bounds, 0); WinDrawChars(string, len, bounds->topLeft.x, bounds->topLeft.y); }
static void ListDrawDataFunc(Int16 itemNum, RectangleType *bounds, Char **itemsText) { char string[50]; if (itemNum < g_PhoneGroups.size()) { PhoneGroupPtr group = g_PhoneGroups[itemNum]; StrNCopy(string, group->GetGroupName(), 49); } else { StrCopy(string, ""); } WinSetUnderlineMode(noUnderline); FntSetFont(stdFont); Int16 width = bounds->extent.x; Int16 len = StrLen(string); Boolean noFit = false; FntCharsInWidth(string, &width, &len, &noFit); WinEraseRectangle(bounds, 0); WinDrawChars(string, len, bounds->topLeft.x, bounds->topLeft.y); }
static void BookmarksListDrawFunc(Int16 itemNum, RectangleType * bounds, char **data) { Int16 stringWidthP = 160; // max width of the string in the list selection window Int16 stringLenP; Boolean truncatedP = false; MemHandle recHandle; char * str; AppContext* appContext=GetAppContext(); Assert(itemNum >= 0); recHandle = DmQueryRecord(appContext->bookmarksDb, itemNum); Assert(recHandle); // no reason it shouldn't work if (recHandle) { str = (char*)MemHandleLock(recHandle); stringLenP = StrLen(str); FntCharsInWidth(str, &stringWidthP, &stringLenP, &truncatedP); WinDrawChars(str, stringLenP, bounds->topLeft.x, bounds->topLeft.y); MemHandleUnlock(recHandle); } }
/*********************************************************************** * * FUNCTION: DrawRecordName * * DESCRIPTION: Draws an address book record name. It is used * for the list view and note view. * * PARAMETERS: name1, name2 - first and seconds names to draw * nameExtent - the space the names must be drawn in * *x, y - where the names are drawn * * RETURNED: x is set after the last char drawn * * REVISION HISTORY: * Name Date Description * ---- ---- ----------- * roger 6/20/95 Initial Revision * frigino 970813 Rewritten. Now includes a variable ratio for * name1/name2 width allocation, a prioritization * parameter, and a word break search to allow * reclaiming of space from the low priority * name. * jmjeong 99/12/22 Abridged version. make the num of * parameters small * ***********************************************************************/ void DrawRecordName( char* name1, char* name2, UInt16 nameExtent, Int16 *x, Int16 y, Boolean center, Boolean priorityIsName1) { Int16 name1MaxWidth; Int16 name2MaxWidth; Boolean ignored; Int16 totalWidth; Char * lowPriName; Int16 highPriNameWidth; Int16 lowPriNameWidth; Int16 highPriMaxWidth; Int16 lowPriMaxWidth; Char * spaceP; UInt16 shortenedFieldWidth; UInt16 fieldSeparatorWidth; Int16 name1Length, name1Width; Int16 name2Length, name2Width; shortenedFieldWidth = FntCharsWidth(shortenedFieldString, shortenedFieldLength); fieldSeparatorWidth = FntCharsWidth(fieldSeparatorString, fieldSeparatorLength); if (*name1) { /* Only show text from the first line in the field */ name1Length = nameExtent; /* longer than possible */ name1Width = nameExtent; /* wider than possible */ FntCharsInWidth(name1, &name1Width, &name1Length, &ignored); } else { /* Set the name to the unnamed string */ name1 = UnnamedRecordStringPtr; name1Length = StrLen(UnnamedRecordStringPtr); name1Width = FntCharsWidth(UnnamedRecordStringPtr, name1Length); } if (*name2) { /* Only show text from the first line in the field */ name2Length = nameExtent; /* longer than possible */ name2Width = nameExtent; /* wider than possible */ FntCharsInWidth(name2, &name2Width, &name2Length, &ignored); } else { name2Length = 0; name2Width = 0; } /* Check if both names fit */ totalWidth = name1Width + (*name2 ? fieldSeparatorWidth : 0) + name2Width; /* * If we are supposed to center the names then move in the x position * by the amount that centers the text */ if (center && (nameExtent > totalWidth)) { *x += (nameExtent - totalWidth) / 2; } /* Special case if only name1 is given */ if (!*name2) { /* * For some reason, OS3 changed the code so that it doesn't show * ellipses if there is only name1. I liked it the old way! */ /* Does name1 fit in its maximum width? */ if (name1Width > nameExtent) { /* No. Draw it to max width minus the ellipsis */ name1Width = nameExtent-shortenedFieldWidth; FntCharsInWidth(name1, &name1Width, &name1Length, &ignored); WinDrawChars(name1, name1Length, *x, y); *x += name1Width; /* Draw ellipsis */ WinDrawChars(shortenedFieldString, shortenedFieldLength, *x, y); *x += shortenedFieldWidth; } else { /* Yes. Draw name1 within its width */ FntCharsInWidth(name1, &name1Width, &name1Length, &ignored); WinDrawChars(name1, name1Length, *x, y); *x += name1Width; } return; } /* Remove name separator width */ nameExtent -= fieldSeparatorWidth; /* Test if both names fit */ if ((name1Width + name2Width) <= nameExtent) { name1MaxWidth = name1Width; name2MaxWidth = name2Width; } else { /* * They dont fit. One or both needs truncation * Establish name priorities and their allowed widths * Change this to alter the ratio of the low and high * priority name spaces */ highPriMaxWidth = (nameExtent << 1)/3; /* 1/3 to low and 2/3 to high */ lowPriMaxWidth = nameExtent-highPriMaxWidth; /* Save working copies of names and widths based on priority */ if (priorityIsName1) { /* Priority is name1 */ highPriNameWidth = name1Width; lowPriName = name2; lowPriNameWidth = name2Width; } else { /* Priority is name2 */ highPriNameWidth = name2Width; lowPriName = name1; lowPriNameWidth = name1Width; } /* Does high priority name fit in high priority max width? */ if (highPriNameWidth > highPriMaxWidth) { /* No. Look for word break in low priority name */ spaceP = StrChr(lowPriName, spaceChr); if (spaceP != NULL) { /* Found break. Set low priority name width to break width */ lowPriNameWidth = FntCharsWidth(lowPriName, spaceP-lowPriName); /* * Reclaim width from low pri name width to low pri max width, * if smaller. */ if (lowPriNameWidth < lowPriMaxWidth) { lowPriMaxWidth = lowPriNameWidth; /* Set new high pri max width */ highPriMaxWidth = nameExtent-lowPriMaxWidth; } } } else { /* Yes. Adjust maximum widths */ highPriMaxWidth = highPriNameWidth; lowPriMaxWidth = nameExtent-highPriMaxWidth; } /* Convert priority widths back to name widths */ if (priorityIsName1) { /* Priority is name1 */ name1Width = highPriNameWidth; name2Width = lowPriNameWidth; name1MaxWidth = highPriMaxWidth; name2MaxWidth = lowPriMaxWidth; } else { /* Priority is name2 */ name1Width = lowPriNameWidth; name2Width = highPriNameWidth; name1MaxWidth = lowPriMaxWidth; name2MaxWidth = highPriMaxWidth; } } /* Does name1 fit in its maximum width? */ if (name1Width > name1MaxWidth) { /* No. Draw it to max width minus the ellipsis */ name1Width = name1MaxWidth-shortenedFieldWidth; FntCharsInWidth(name1, &name1Width, &name1Length, &ignored); WinDrawChars(name1, name1Length, *x, y); *x += name1Width; /* Draw ellipsis */ WinDrawChars(shortenedFieldString, shortenedFieldLength, *x, y); *x += shortenedFieldWidth; } else { /* Yes. Draw name1 within its width */ FntCharsInWidth(name1, &name1Width, &name1Length, &ignored); WinDrawChars(name1, name1Length, *x, y); *x += name1Width; } if (*name1 && *name2) { /* Draw name separator */ WinDrawChars(fieldSeparatorString, fieldSeparatorLength, *x, y); *x += fieldSeparatorWidth; } /* Draw name2 within its maximum width */ FntCharsInWidth(name2, &name2MaxWidth, &name2Length, &ignored); WinDrawChars(name2, name2Length, *x, y); *x += name2MaxWidth; }
void PrivDrawCell(void* table, Int16 row, Int16 column, RectanglePtr bounds) { char string[50]; FontID font = stdFont; if (g_CurrentRow != row) { if (g_CurrentMemHandle) { MemHandleUnlock(g_CurrentMemHandle); g_CurrentMemHandle = NULL; } } if (g_CurrentMemHandle == NULL) { Err err = GetSMSRecord(g_SmsDb, g_SelectedCategory, row + g_CurrentPage * TABLE_PAGE_SIZE, g_CurrentRecord, g_CurrentMemHandle, true); if (err) return; g_CurrentRow = row; } switch(column) { case 0: StrCopy(string, ""); if (g_SelectedCategory == CAT_INBOX) { if (IsRecordRead(&g_CurrentRecord)) { StrCopy(string, ""); } else { font = symbolFont; StrCopy(string, "\020"); } } else if (g_SelectedCategory == CAT_SENT) { if (IsRecordRequestReport(&g_CurrentRecord)) { font = symbolFont; if (IsRecordDelivered(&g_CurrentRecord)) { StrCopy(string, "\026"); } else { StrCopy(string, "\024"); } } } break; case 1: StrNCopy(string, g_CurrentRecord.personName, 48); if (StrLen(string) == 0) { StrNCopy(string, g_CurrentRecord.phoneNumber, 48); } break; case 2: StrNCopy(string, g_CurrentRecord.content, 48); break; case 3: { DateTimeType smsDatetime; TimSecondsToDateTime(g_CurrentRecord.time, &smsDatetime); UInt32 nowSeconds = TimGetSeconds(); DateTimeType nowDatetime; TimSecondsToDateTime(nowSeconds, &nowDatetime); if ((nowDatetime.year == smsDatetime.year) && (nowDatetime.month == smsDatetime.month) && (nowDatetime.day == smsDatetime.day)) { TimeToAscii(smsDatetime.hour, smsDatetime.minute, tfColon24h, string); } else { StrCopy(string, DayOfWeekInChinese[DayOfWeek(smsDatetime.month, smsDatetime.day, smsDatetime.year)]); DateTemplateToAscii(" ^3z-^0z", smsDatetime.month, smsDatetime.day, smsDatetime.year, string + 2, 47); } MemHandleUnlock(g_CurrentMemHandle); g_CurrentMemHandle = NULL; } break; default: StrCopy(string, ""); } WinPushDrawState(); RGBColorType foreColor, backColor; foreColor.index = 0; backColor.index = 0; if ((row == g_CurrentSelection) && (column != 0)) { foreColor.r = 255; foreColor.g = 255; foreColor.b = 255; backColor.r = 10; backColor.g = 36; backColor.b = 106; } else if (row % 2 == 0) { backColor.r = 255; backColor.g = 255; backColor.b = 255; foreColor.r = 0; foreColor.g = 0; foreColor.b = 0; } else { backColor.r = 220; backColor.g = 220; backColor.b = 220; foreColor.r = 0; foreColor.g = 0; foreColor.b = 0; } WinSetForeColorRGB(&foreColor, NULL); WinSetTextColorRGB(&foreColor, NULL); WinSetBackColorRGB(&backColor, NULL); WinSetUnderlineMode(noUnderline); FntSetFont(font); Int16 width = bounds->extent.x - 2; Int16 len = StrLen(string); Boolean noFit = false; FntCharsInWidth(string, &width, &len, &noFit); UInt16 x = bounds->topLeft.x; UInt16 y = bounds->topLeft.y; bounds->topLeft.x += - 1; bounds->topLeft.y += 0; bounds->extent.x += 2; bounds->extent.y += 0; WinEraseRectangle(bounds, 0); WinDrawGrayLine( bounds->topLeft.x + bounds->extent.x - 2, bounds->topLeft.y, bounds->topLeft.x + bounds->extent.x - 2, bounds->topLeft.y + bounds->extent.y);// - 2); WinDrawChars(string, len, x, y); WinPopDrawState(); }