* Added CharacterView::ScrollToCharacter(), and IsCharacterVisible().
* On text drops, the character map is now scrolling to the first character dropped. This is helpful to see the code of a character as well as the block it is contained in. * Fixed a bug in CharacterView::_FrameFor() that would not return the correct vertical position. * Made a few methods const. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38863 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
a81c488016
commit
8b7eacd6b0
@ -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.
|
* 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
|
/*static*/ void
|
||||||
CharacterView::UnicodeToUTF8(uint32 c, char* text, size_t textSize)
|
CharacterView::UnicodeToUTF8(uint32 c, char* text, size_t textSize)
|
||||||
{
|
{
|
||||||
@ -424,7 +442,7 @@ CharacterView::DoLayout()
|
|||||||
|
|
||||||
|
|
||||||
int32
|
int32
|
||||||
CharacterView::_BlockAt(BPoint point)
|
CharacterView::_BlockAt(BPoint point) const
|
||||||
{
|
{
|
||||||
// TODO: use binary search
|
// TODO: use binary search
|
||||||
for (uint32 i = 0; i < kNumUnicodeBlocks; i++) {
|
for (uint32 i = 0; i < kNumUnicodeBlocks; i++) {
|
||||||
@ -441,7 +459,8 @@ CharacterView::_BlockAt(BPoint point)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CharacterView::_GetCharacterAt(BPoint point, uint32& character, BRect* _frame)
|
CharacterView::_GetCharacterAt(BPoint point, uint32& character,
|
||||||
|
BRect* _frame) const
|
||||||
{
|
{
|
||||||
int32 i = _BlockAt(point);
|
int32 i = _BlockAt(point);
|
||||||
if (i == -1)
|
if (i == -1)
|
||||||
@ -569,7 +588,7 @@ CharacterView::_UpdateSize()
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CharacterView::_GetTopmostCharacter(uint32& character, int32& offset)
|
CharacterView::_GetTopmostCharacter(uint32& character, int32& offset) const
|
||||||
{
|
{
|
||||||
int32 top = (int32)Bounds().top;
|
int32 top = (int32)Bounds().top;
|
||||||
|
|
||||||
@ -594,7 +613,7 @@ CharacterView::_GetTopmostCharacter(uint32& character, int32& offset)
|
|||||||
|
|
||||||
|
|
||||||
BRect
|
BRect
|
||||||
CharacterView::_FrameFor(uint32 character)
|
CharacterView::_FrameFor(uint32 character) const
|
||||||
{
|
{
|
||||||
// find block containing the character
|
// find block containing the character
|
||||||
|
|
||||||
@ -609,7 +628,8 @@ CharacterView::_FrameFor(uint32 character)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32 diff = character - kUnicodeBlocks[i].start;
|
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;
|
int32 x = fGap / 2 + diff % fCharactersPerLine;
|
||||||
|
|
||||||
return BRect(x, y, x + fCharacterWidth + fGap, y + fCharacterHeight);
|
return BRect(x, y, x + fCharacterWidth + fGap, y + fCharacterHeight);
|
||||||
|
@ -31,6 +31,8 @@ public:
|
|||||||
bool IsShowingBlock(int32 blockIndex) const;
|
bool IsShowingBlock(int32 blockIndex) const;
|
||||||
|
|
||||||
void ScrollToBlock(int32 blockIndex);
|
void ScrollToBlock(int32 blockIndex);
|
||||||
|
void ScrollToCharacter(uint32 c);
|
||||||
|
bool IsCharacterVisible(uint32 c) const;
|
||||||
|
|
||||||
static void UnicodeToUTF8(uint32 c, char* text,
|
static void UnicodeToUTF8(uint32 c, char* text,
|
||||||
size_t textSize);
|
size_t textSize);
|
||||||
@ -56,14 +58,14 @@ protected:
|
|||||||
virtual void DoLayout();
|
virtual void DoLayout();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int32 _BlockAt(BPoint point);
|
int32 _BlockAt(BPoint point) const;
|
||||||
bool _GetCharacterAt(BPoint point, uint32& character,
|
bool _GetCharacterAt(BPoint point, uint32& character,
|
||||||
BRect* _frame = NULL);
|
BRect* _frame = NULL) const;
|
||||||
void _UpdateFontSize();
|
void _UpdateFontSize();
|
||||||
void _UpdateSize();
|
void _UpdateSize();
|
||||||
bool _GetTopmostCharacter(uint32& character,
|
bool _GetTopmostCharacter(uint32& character,
|
||||||
int32& offset);
|
int32& offset) const;
|
||||||
BRect _FrameFor(uint32 character);
|
BRect _FrameFor(uint32 character) const;
|
||||||
void _CopyToClipboard(const char* text);
|
void _CopyToClipboard(const char* text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -26,6 +26,7 @@
|
|||||||
#include <SplitLayoutBuilder.h>
|
#include <SplitLayoutBuilder.h>
|
||||||
#include <StringView.h>
|
#include <StringView.h>
|
||||||
#include <TextControl.h>
|
#include <TextControl.h>
|
||||||
|
#include <UnicodeChar.h>
|
||||||
|
|
||||||
#include "CharacterView.h"
|
#include "CharacterView.h"
|
||||||
#include "UnicodeBlockView.h"
|
#include "UnicodeBlockView.h"
|
||||||
@ -256,6 +257,20 @@ CharacterWindow::~CharacterWindow()
|
|||||||
void
|
void
|
||||||
CharacterWindow::MessageReceived(BMessage* message)
|
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) {
|
switch (message->what) {
|
||||||
case B_COPY:
|
case B_COPY:
|
||||||
PostMessage(message, fCharacterView);
|
PostMessage(message, fCharacterView);
|
||||||
|
@ -11,6 +11,6 @@ Application CharacterMap :
|
|||||||
UnicodeBlocks.cpp
|
UnicodeBlocks.cpp
|
||||||
UnicodeBlockView.cpp
|
UnicodeBlockView.cpp
|
||||||
|
|
||||||
: be $(TARGET_LIBSUPC++)
|
: be locale $(TARGET_LIBSUPC++)
|
||||||
: CharacterMap.rdef
|
: CharacterMap.rdef
|
||||||
;
|
;
|
||||||
|
Loading…
Reference in New Issue
Block a user