From f9791574d3d5262b4d4402b493a2783e331e1390 Mon Sep 17 00:00:00 2001
From: dsizzle <dcieslak@yahoo.com>
Date: Wed, 26 Nov 2014 12:25:06 +0000
Subject: [PATCH] 3651: Enhancement 7 - implemented lazily-built font menu,
only update if font family update is detected.
---
src/apps/charactermap/CharacterWindow.cpp | 29 ++++++++++++++++++++++++++---
src/apps/charactermap/CharacterWindow.h | 4 +++-
2 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/src/apps/charactermap/CharacterWindow.cpp b/src/apps/charactermap/CharacterWindow.cpp
index 4577e2f..2fd183b 100644
a
|
b
|
CharacterWindow::CharacterWindow()
|
265 | 265 | #endif |
266 | 266 | menuBar->AddItem(menu); |
267 | 267 | |
268 | | menuBar->AddItem(_CreateFontMenu()); |
| 268 | fFontMenu = _CreateFontMenu(); |
| 269 | menuBar->AddItem(fFontMenu); |
269 | 270 | |
270 | 271 | AddCommonFilter(new EscapeMessageFilter(kMsgClearFilter)); |
271 | 272 | AddCommonFilter(new RedirectUpAndDownFilter(fUnicodeBlockView)); |
… |
… |
BMenu*
|
530 | 531 | CharacterWindow::_CreateFontMenu() |
531 | 532 | { |
532 | 533 | BMenu* menu = new BMenu(B_TRANSLATE("Font")); |
533 | | BMenuItem* item; |
534 | 534 | |
| 535 | _UpdateFontMenu(menu); |
| 536 | |
| 537 | return menu; |
| 538 | } |
| 539 | |
| 540 | |
| 541 | void |
| 542 | CharacterWindow::_UpdateFontMenu(BMenu* menu) |
| 543 | { |
| 544 | BMenuItem* item; |
| 545 | |
| 546 | while (menu->CountItems() > 0) { |
| 547 | item = menu->RemoveItem(static_cast<long int>(0)); |
| 548 | delete(item); |
| 549 | } |
| 550 | |
535 | 551 | font_family currentFamily; |
536 | 552 | font_style currentStyle; |
537 | 553 | fCharacterView->CharacterFont().GetFamilyAndStyle(¤tFamily, |
… |
… |
CharacterWindow::_CreateFontMenu()
|
568 | 584 | |
569 | 585 | item = menu->FindItem(currentFamily); |
570 | 586 | item->SetMarked(true); |
| 587 | } |
571 | 588 | |
572 | | return menu; |
| 589 | |
| 590 | void CharacterWindow::MenusBeginning() |
| 591 | { |
| 592 | if (update_font_families(false) == true) { |
| 593 | _UpdateFontMenu(fFontMenu); |
| 594 | } |
573 | 595 | } |
| 596 | |
diff --git a/src/apps/charactermap/CharacterWindow.h b/src/apps/charactermap/CharacterWindow.h
index dfc65d1..33f03ab 100644
a
|
b
|
private:
|
36 | 36 | |
37 | 37 | void _SetFont(const char* family, const char* style); |
38 | 38 | BMenu* _CreateFontMenu(); |
39 | | |
| 39 | void _UpdateFontMenu(BMenu* menu); |
| 40 | void MenusBeginning(); |
40 | 41 | private: |
41 | 42 | BTextControl* fFilterControl; |
42 | 43 | UnicodeBlockView* fUnicodeBlockView; |
… |
… |
private:
|
45 | 46 | BSlider* fFontSizeSlider; |
46 | 47 | BStringView* fGlyphView; |
47 | 48 | BStringView* fCodeView; |
| 49 | BMenu* fFontMenu; |
48 | 50 | }; |
49 | 51 | |
50 | 52 | #endif // CHARACTER_WINDOW_H |