diff --git a/src/apps/charactermap/CharacterView.cpp b/src/apps/charactermap/CharacterView.cpp index a09dd33878..afa06ac0aa 100644 --- a/src/apps/charactermap/CharacterView.cpp +++ b/src/apps/charactermap/CharacterView.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2009, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Copyright 2009-2010, Axel Dörfler, axeld@pinc-software.de. * Distributed under the terms of the MIT License. */ @@ -114,6 +114,24 @@ CharacterView::ScrollToBlock(int32 blockIndex) } +void +CharacterView::ScrollToCharacter(uint32 c) +{ + if (IsCharacterVisible(c)) + return; + + BRect frame = _FrameFor(c); + BView::ScrollTo(0.0f, frame.top); +} + + +bool +CharacterView::IsCharacterVisible(uint32 c) const +{ + return Bounds().Contains(_FrameFor(c)); +} + + /*static*/ void CharacterView::UnicodeToUTF8(uint32 c, char* text, size_t textSize) { @@ -424,7 +442,7 @@ CharacterView::DoLayout() int32 -CharacterView::_BlockAt(BPoint point) +CharacterView::_BlockAt(BPoint point) const { // TODO: use binary search for (uint32 i = 0; i < kNumUnicodeBlocks; i++) { @@ -441,7 +459,8 @@ CharacterView::_BlockAt(BPoint point) bool -CharacterView::_GetCharacterAt(BPoint point, uint32& character, BRect* _frame) +CharacterView::_GetCharacterAt(BPoint point, uint32& character, + BRect* _frame) const { int32 i = _BlockAt(point); if (i == -1) @@ -569,7 +588,7 @@ CharacterView::_UpdateSize() bool -CharacterView::_GetTopmostCharacter(uint32& character, int32& offset) +CharacterView::_GetTopmostCharacter(uint32& character, int32& offset) const { int32 top = (int32)Bounds().top; @@ -594,7 +613,7 @@ CharacterView::_GetTopmostCharacter(uint32& character, int32& offset) BRect -CharacterView::_FrameFor(uint32 character) +CharacterView::_FrameFor(uint32 character) const { // find block containing the character @@ -609,7 +628,8 @@ CharacterView::_FrameFor(uint32 character) } int32 diff = character - kUnicodeBlocks[i].start; - int32 y = fTitleTops[i] + fTitleHeight + diff / fCharactersPerLine; + int32 y = fTitleTops[i] + fTitleHeight + + (diff / fCharactersPerLine) * fCharacterHeight; int32 x = fGap / 2 + diff % fCharactersPerLine; return BRect(x, y, x + fCharacterWidth + fGap, y + fCharacterHeight); diff --git a/src/apps/charactermap/CharacterView.h b/src/apps/charactermap/CharacterView.h index 41baaf1d81..8c08d50925 100644 --- a/src/apps/charactermap/CharacterView.h +++ b/src/apps/charactermap/CharacterView.h @@ -31,6 +31,8 @@ public: bool IsShowingBlock(int32 blockIndex) const; void ScrollToBlock(int32 blockIndex); + void ScrollToCharacter(uint32 c); + bool IsCharacterVisible(uint32 c) const; static void UnicodeToUTF8(uint32 c, char* text, size_t textSize); @@ -56,14 +58,14 @@ protected: virtual void DoLayout(); private: - int32 _BlockAt(BPoint point); + int32 _BlockAt(BPoint point) const; bool _GetCharacterAt(BPoint point, uint32& character, - BRect* _frame = NULL); + BRect* _frame = NULL) const; void _UpdateFontSize(); void _UpdateSize(); bool _GetTopmostCharacter(uint32& character, - int32& offset); - BRect _FrameFor(uint32 character); + int32& offset) const; + BRect _FrameFor(uint32 character) const; void _CopyToClipboard(const char* text); private: diff --git a/src/apps/charactermap/CharacterWindow.cpp b/src/apps/charactermap/CharacterWindow.cpp index b8e5e58ec8..3022407b23 100644 --- a/src/apps/charactermap/CharacterWindow.cpp +++ b/src/apps/charactermap/CharacterWindow.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2009, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2009-2010, Axel Dörfler, axeld@pinc-software.de. * Distributed under the terms of the MIT License. */ @@ -26,6 +26,7 @@ #include #include #include +#include #include "CharacterView.h" #include "UnicodeBlockView.h" @@ -256,6 +257,20 @@ CharacterWindow::~CharacterWindow() void CharacterWindow::MessageReceived(BMessage* message) { + if (message->WasDropped()) { + const char* text; + ssize_t size; + uint32 c; + if (message->FindInt32("character", (int32*)&c) == B_OK) { + fCharacterView->ScrollToCharacter(c); + return; + } else if (message->FindData("text/plain", B_MIME_TYPE, + (const void**)&text, &size) == B_OK) { + fCharacterView->ScrollToCharacter(BUnicodeChar::FromUTF8(text)); + return; + } + } + switch (message->what) { case B_COPY: PostMessage(message, fCharacterView); diff --git a/src/apps/charactermap/Jamfile b/src/apps/charactermap/Jamfile index a4879659eb..739894e86b 100644 --- a/src/apps/charactermap/Jamfile +++ b/src/apps/charactermap/Jamfile @@ -11,6 +11,6 @@ Application CharacterMap : UnicodeBlocks.cpp UnicodeBlockView.cpp - : be $(TARGET_LIBSUPC++) + : be locale $(TARGET_LIBSUPC++) : CharacterMap.rdef ;