[haiku-commits] haiku: hrev48387 - src/apps/charactermap

  • From: pulkomandy@xxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 27 Nov 2014 08:50:59 +0100 (CET)

hrev48387 adds 2 changesets to branch 'master'
old head: f891000ea0b43ca705a40b2032d1b7f3088a4548
new head: 0340e4b336ab01b78e7291c5d4ace2ba551a20f4
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=0340e4b+%5Ef891000

----------------------------------------------------------------------------

b8a8557: CharacterMap: use dynamic font menu
  
  * only update if font family update is detected.
  * character map can now detect new fonts or removed fonts without
  restarting
  
  Signed-off-by: Adrien Destugues <pulkomandy@xxxxxxxxx>
  
  Fixes #3651 part 7.

0340e4b: CharacterMap: several fixes to char. view scroll
  
  * Select items in the encoding list by block identifier rather than
  list index (there are holes in the list)
  * Scroll to the start of the list when the application starts
  * Add and use IsBlockVisible to detect when we need to make a block
  visible, avoiding unwanted scrollings in some cases with the previous
  method of testing for only one character in the block.
  
  Signed-off-by: Adrien Destugues <pulkomandy@xxxxxxxxx>
  
  Fixes some problems with previous enhancements from #3651.

                                            [ dsizzle <dcieslak@xxxxxxxxx> ]

----------------------------------------------------------------------------

5 files changed, 56 insertions(+), 8 deletions(-)
src/apps/charactermap/CharacterView.cpp    | 18 +++++++++++++--
src/apps/charactermap/CharacterView.h      |  1 +
src/apps/charactermap/CharacterWindow.cpp  | 31 +++++++++++++++++++++++---
src/apps/charactermap/CharacterWindow.h    |  4 +++-
src/apps/charactermap/UnicodeBlockView.cpp | 10 +++++++--

############################################################################

Commit:      b8a8557aa90deb8385cf3af021a2e6b4aab8d424
URL:         http://cgit.haiku-os.org/haiku/commit/?id=b8a8557
Author:      dsizzle <dcieslak@xxxxxxxxx>
Date:        Wed Nov 26 12:25:06 2014 UTC
Committer:   Adrien Destugues <pulkomandy@xxxxxxxxx>
Commit-Date: Thu Nov 27 07:31:18 2014 UTC

Ticket:      https://dev.haiku-os.org/ticket/3651

CharacterMap: use dynamic font menu

* only update if font family update is detected.
* character map can now detect new fonts or removed fonts without
restarting

Signed-off-by: Adrien Destugues <pulkomandy@xxxxxxxxx>

Fixes #3651 part 7.

----------------------------------------------------------------------------

diff --git a/src/apps/charactermap/CharacterWindow.cpp 
b/src/apps/charactermap/CharacterWindow.cpp
index 4577e2f..2fd183b 100644
--- a/src/apps/charactermap/CharacterWindow.cpp
+++ b/src/apps/charactermap/CharacterWindow.cpp
@@ -265,7 +265,8 @@ CharacterWindow::CharacterWindow()
 #endif
        menuBar->AddItem(menu);
 
-       menuBar->AddItem(_CreateFontMenu());
+       fFontMenu = _CreateFontMenu();
+       menuBar->AddItem(fFontMenu);
 
        AddCommonFilter(new EscapeMessageFilter(kMsgClearFilter));
        AddCommonFilter(new RedirectUpAndDownFilter(fUnicodeBlockView));
@@ -530,8 +531,23 @@ BMenu*
 CharacterWindow::_CreateFontMenu()
 {
        BMenu* menu = new BMenu(B_TRANSLATE("Font"));
-       BMenuItem* item;
 
+       _UpdateFontMenu(menu);
+
+       return menu;
+}
+
+
+void
+CharacterWindow::_UpdateFontMenu(BMenu* menu)
+{
+       BMenuItem* item;
+       
+       while (menu->CountItems() > 0) {
+               item = menu->RemoveItem(static_cast<long int>(0));
+               delete(item);
+       }       
+       
        font_family currentFamily;
        font_style currentStyle;
        fCharacterView->CharacterFont().GetFamilyAndStyle(&currentFamily,
@@ -568,6 +584,13 @@ CharacterWindow::_CreateFontMenu()
 
        item = menu->FindItem(currentFamily);
        item->SetMarked(true);
+}
 
-       return menu;
+
+void CharacterWindow::MenusBeginning()
+{
+       if (update_font_families(false) == true) {
+               _UpdateFontMenu(fFontMenu);
+       }       
 }
+
diff --git a/src/apps/charactermap/CharacterWindow.h 
b/src/apps/charactermap/CharacterWindow.h
index dfc65d1..33f03ab 100644
--- a/src/apps/charactermap/CharacterWindow.h
+++ b/src/apps/charactermap/CharacterWindow.h
@@ -36,7 +36,8 @@ private:
 
                        void                    _SetFont(const char* family, 
const char* style);
                        BMenu*                  _CreateFontMenu();
-
+                       void                    _UpdateFontMenu(BMenu* menu);
+                       void                    MenusBeginning();
 private:
                        BTextControl*   fFilterControl;
                        UnicodeBlockView* fUnicodeBlockView;
@@ -45,6 +46,7 @@ private:
                        BSlider*                fFontSizeSlider;
                        BStringView*    fGlyphView;
                        BStringView*    fCodeView;
+                       BMenu*                  fFontMenu;
 };
 
 #endif // CHARACTER_WINDOW_H

############################################################################

Revision:    hrev48387
Commit:      0340e4b336ab01b78e7291c5d4ace2ba551a20f4
URL:         http://cgit.haiku-os.org/haiku/commit/?id=0340e4b
Author:      dsizzle <dcieslak@xxxxxxxxx>
Date:        Wed Nov 26 17:24:39 2014 UTC
Committer:   Adrien Destugues <pulkomandy@xxxxxxxxx>
Commit-Date: Thu Nov 27 07:50:37 2014 UTC

Ticket:      https://dev.haiku-os.org/ticket/3651

CharacterMap: several fixes to char. view scroll

* Select items in the encoding list by block identifier rather than
list index (there are holes in the list)
* Scroll to the start of the list when the application starts
* Add and use IsBlockVisible to detect when we need to make a block
visible, avoiding unwanted scrollings in some cases with the previous
method of testing for only one character in the block.

Signed-off-by: Adrien Destugues <pulkomandy@xxxxxxxxx>

Fixes some problems with previous enhancements from #3651.

----------------------------------------------------------------------------

diff --git a/src/apps/charactermap/CharacterView.cpp 
b/src/apps/charactermap/CharacterView.cpp
index 529e2a9..3f311e3 100644
--- a/src/apps/charactermap/CharacterView.cpp
+++ b/src/apps/charactermap/CharacterView.cpp
@@ -38,6 +38,7 @@ CharacterView::CharacterView(const char* name)
        fCharacterFont.SetSize(fCharacterFont.Size() * 1.5f);
 
        _UpdateFontSize();
+       DoLayout();
 }
 
 
@@ -108,10 +109,10 @@ CharacterView::IsShowingBlock(int32 blockIndex) const
 void
 CharacterView::ScrollToBlock(int32 blockIndex)
 {
-       // don't scroll if the selected character is already in view.
+       // don't scroll if the selected block is already in view.
        // this prevents distracting jumps when crossing a block 
        // boundary in the character view.
-       if (IsCharacterVisible(fCurrentCharacter))
+       if (IsBlockVisible(blockIndex))   
                return;
                
        if (blockIndex < 0)
@@ -141,6 +142,19 @@ CharacterView::IsCharacterVisible(uint32 c) const
 }
 
 
+bool
+CharacterView::IsBlockVisible(int32 block) const
+{
+       int32 topBlock = _BlockAt(BPoint(Bounds().left, Bounds().top));
+       int32 bottomBlock = _BlockAt(BPoint(Bounds().right, Bounds().bottom)); 
+
+       if (block >= topBlock && block <= bottomBlock) 
+               return true;
+               
+       return false;
+}
+
+
 /*static*/ void
 CharacterView::UnicodeToUTF8(uint32 c, char* text, size_t textSize)
 {
diff --git a/src/apps/charactermap/CharacterView.h 
b/src/apps/charactermap/CharacterView.h
index 8c08d50..fc5e618 100644
--- a/src/apps/charactermap/CharacterView.h
+++ b/src/apps/charactermap/CharacterView.h
@@ -33,6 +33,7 @@ public:
                        void                    ScrollToBlock(int32 blockIndex);
                        void                    ScrollToCharacter(uint32 c);
                        bool                    IsCharacterVisible(uint32 c) 
const;
+                       bool                    IsBlockVisible(int32 block) 
const;
 
        static  void                    UnicodeToUTF8(uint32 c, char* text,
                                                                size_t 
textSize);
diff --git a/src/apps/charactermap/CharacterWindow.cpp 
b/src/apps/charactermap/CharacterWindow.cpp
index 2fd183b..77964c0 100644
--- a/src/apps/charactermap/CharacterWindow.cpp
+++ b/src/apps/charactermap/CharacterWindow.cpp
@@ -275,6 +275,8 @@ CharacterWindow::CharacterWindow()
        fUnicodeBlockView->SetTarget(this);
 
        fFilterControl->MakeFocus();
+       
+       fUnicodeBlockView->SelectBlockForCharacter(0);
 }
 
 
diff --git a/src/apps/charactermap/UnicodeBlockView.cpp 
b/src/apps/charactermap/UnicodeBlockView.cpp
index a643875..b40e40b 100644
--- a/src/apps/charactermap/UnicodeBlockView.cpp
+++ b/src/apps/charactermap/UnicodeBlockView.cpp
@@ -133,7 +133,13 @@ UnicodeBlockView::SelectBlockForCharacter(uint32 character)
                        break;
                }
 
-               Select(i);
-               ScrollToSelection();
+               BlockListItem* block = fBlocks.ItemAt(i);
+               
+               int32 blockNum = IndexOf(block);
+               
+               if (blockNum >= 0) {
+                       Select(blockNum);
+                       ScrollToSelection();
+               }
        }
 }


Other related posts:

  • » [haiku-commits] haiku: hrev48387 - src/apps/charactermap - pulkomandy