diff --git a/src/apps/terminal/AppearPrefView.cpp b/src/apps/terminal/AppearPrefView.cpp
index 7da4e58..fc00606 100644
a
|
b
|
|
16 | 16 | #include <CheckBox.h> |
17 | 17 | #include <ColorControl.h> |
18 | 18 | #include <LayoutBuilder.h> |
| 19 | #include <List.h> |
19 | 20 | #include <Locale.h> |
20 | 21 | #include <Menu.h> |
21 | 22 | #include <MenuField.h> |
… |
… |
AppearancePrefView::_MakeFontMenu(uint32 command,
|
455 | 456 | return menu; |
456 | 457 | } |
457 | 458 | |
| 459 | static int CompareStrAsDecimalValue(const void *ptr1, const void *ptr2) |
| 460 | { |
| 461 | const char *pStr1 = *(const char **)ptr1; |
| 462 | const char *pStr2 = *(const char **)ptr2; |
| 463 | const int len1 = strlen(pStr1); |
| 464 | const int len2 = strlen(pStr2); |
| 465 | |
| 466 | if (len1 == len2) |
| 467 | return strcmp(pStr1, pStr2); |
| 468 | else if (len1 < len2) |
| 469 | return -1; |
| 470 | else |
| 471 | return 1; |
| 472 | } |
| 473 | |
| 474 | static int ListHasString(BList* pList, const char *pStr) |
| 475 | { |
| 476 | for (int32 i = 0; i < pList->CountItems(); i++) { |
| 477 | if (strcmp(static_cast<const char *>(pList->ItemAt(i)), pStr) == 0) |
| 478 | return i; |
| 479 | } |
| 480 | return -1; |
| 481 | } |
458 | 482 | |
459 | 483 | /*static*/ BMenu* |
460 | 484 | AppearancePrefView::_MakeSizeMenu(uint32 command, uint8 defaultSize) |
461 | 485 | { |
462 | | BPopUpMenu* menu = new BPopUpMenu("size"); |
463 | | int32 sizes[] = {9, 10, 11, 12, 14, 16, 18, 0}; |
464 | | |
465 | | bool found = false; |
466 | | |
467 | | for (uint32 i = 0; sizes[i]; i++) { |
468 | | BString string; |
469 | | string << sizes[i]; |
| 486 | BList* sizes = new BList(8); |
| 487 | sizes->AddItem((void *)"9"); |
| 488 | sizes->AddItem((void *)"10"); |
| 489 | sizes->AddItem((void *)"11"); |
| 490 | sizes->AddItem((void *)"12"); |
| 491 | sizes->AddItem((void *)"14"); |
| 492 | sizes->AddItem((void *)"16"); |
| 493 | sizes->AddItem((void *)"18"); |
| 494 | |
| 495 | BString defaultSizeStr; |
| 496 | defaultSizeStr << defaultSize; |
| 497 | int32 markedPos = ListHasString(sizes, defaultSizeStr.String()); |
| 498 | if (markedPos < 0) { |
| 499 | sizes->AddItem((void *)defaultSizeStr.String()); |
| 500 | sizes->SortItems(CompareStrAsDecimalValue); |
| 501 | markedPos = ListHasString(sizes, defaultSizeStr.String()); |
| 502 | } |
470 | 503 | |
471 | | BMenuItem* item = new BMenuItem(string.String(), new BMessage(command)); |
| 504 | BPopUpMenu* menu = new BPopUpMenu("size"); |
| 505 | BMenuItem* item; |
| 506 | for (int32 i = 0; i < sizes->CountItems(); i++) { |
| 507 | item = new BMenuItem(static_cast<const char *>(sizes->ItemAt(i)), |
| 508 | new BMessage(command)); |
| 509 | if (i == markedPos) item->SetMarked(true); |
472 | 510 | menu->AddItem(item); |
473 | | |
474 | | if (sizes[i] == defaultSize) { |
475 | | item->SetMarked(true); |
476 | | found = true; |
477 | | } |
478 | | } |
479 | | if (!found) { |
480 | | for (uint32 i = 0; sizes[i]; i++) { |
481 | | if (sizes[i] > defaultSize) { |
482 | | BString string; |
483 | | string << defaultSize; |
484 | | BMenuItem* item = new BMenuItem(string.String(), |
485 | | new BMessage(command)); |
486 | | item->SetMarked(true); |
487 | | menu->AddItem(item, i); |
488 | | break; |
489 | | } |
490 | | } |
491 | 511 | } |
492 | 512 | |
493 | 513 | return menu; |