Ticket #3651: 3651-Enh7.patch

File 3651-Enh7.patch, 2.4 KB (added by dsizzle, 5 years ago)

lazily-build font menu patch, now with check for updated font families

  • src/apps/charactermap/CharacterWindow.cpp

    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()  
    265265#endif
    266266    menuBar->AddItem(menu);
    267267
    268     menuBar->AddItem(_CreateFontMenu());
     268    fFontMenu = _CreateFontMenu();
     269    menuBar->AddItem(fFontMenu);
    269270
    270271    AddCommonFilter(new EscapeMessageFilter(kMsgClearFilter));
    271272    AddCommonFilter(new RedirectUpAndDownFilter(fUnicodeBlockView));
    BMenu*  
    530531CharacterWindow::_CreateFontMenu()
    531532{
    532533    BMenu* menu = new BMenu(B_TRANSLATE("Font"));
    533     BMenuItem* item;
    534534
     535    _UpdateFontMenu(menu);
     536
     537    return menu;
     538}
     539
     540
     541void
     542CharacterWindow::_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   
    535551    font_family currentFamily;
    536552    font_style currentStyle;
    537553    fCharacterView->CharacterFont().GetFamilyAndStyle(&currentFamily,
    CharacterWindow::_CreateFontMenu()  
    568584
    569585    item = menu->FindItem(currentFamily);
    570586    item->SetMarked(true);
     587}
    571588
    572     return menu;
     589
     590void CharacterWindow::MenusBeginning()
     591{
     592    if (update_font_families(false) == true) {
     593        _UpdateFontMenu(fFontMenu);
     594    }   
    573595}
     596
  • src/apps/charactermap/CharacterWindow.h

    diff --git a/src/apps/charactermap/CharacterWindow.h b/src/apps/charactermap/CharacterWindow.h
    index dfc65d1..33f03ab 100644
    a b private:  
    3636
    3737            void            _SetFont(const char* family, const char* style);
    3838            BMenu*          _CreateFontMenu();
    39 
     39            void            _UpdateFontMenu(BMenu* menu);
     40            void            MenusBeginning();
    4041private:
    4142            BTextControl*   fFilterControl;
    4243            UnicodeBlockView* fUnicodeBlockView;
    private:  
    4546            BSlider*        fFontSizeSlider;
    4647            BStringView*    fGlyphView;
    4748            BStringView*    fCodeView;
     49            BMenu*          fFontMenu;
    4850};
    4951
    5052#endif  // CHARACTER_WINDOW_H