2 * Copyright 2009, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
7 #include "UnicodeBlockView.h"
12 #include "UnicodeBlocks.h"
15 BlockListItem::BlockListItem(const char* label
, uint32 blockIndex
)
17 fBlockIndex(blockIndex
)
25 UnicodeBlockView::UnicodeBlockView(const char* name
)
27 fBlocks(kNumUnicodeBlocks
, true),
28 fShowPrivateBlocks(false),
29 fShowContainedBlocksOnly(false)
35 UnicodeBlockView::~UnicodeBlockView()
41 UnicodeBlockView::SetFilter(const char* filter
)
49 UnicodeBlockView::ShowPrivateBlocks(bool show
)
51 if (fShowPrivateBlocks
== show
)
54 fShowPrivateBlocks
= show
;
60 UnicodeBlockView::ShowContainedBlocksOnly(bool show
)
62 if (fShowContainedBlocksOnly
== show
)
65 fShowContainedBlocksOnly
= show
;
71 UnicodeBlockView::IsShowingBlock(int32 blockIndex
) const
73 if (blockIndex
< 0 || blockIndex
>= (int32
)kNumUnicodeBlocks
)
76 if (!fShowPrivateBlocks
&& kUnicodeBlocks
[blockIndex
].private_block
)
84 UnicodeBlockView::_UpdateBlocks()
88 for (int32 i
= 0; i
< fBlocks
.CountItems(); i
++) {
89 if (fFilter
.Length() != 0) {
90 if (strcasestr(kUnicodeBlocks
[i
].name
, fFilter
.String()) == NULL
)
94 if (!IsShowingBlock(i
))
97 AddItem(fBlocks
.ItemAt(i
));
103 UnicodeBlockView::_CreateBlocks()
106 for (uint32 i
= 0; i
< kNumUnicodeBlocks
; i
++) {
107 BlockListItem
* item
= new BlockListItem(kUnicodeBlocks
[i
].name
, i
);
108 fBlocks
.AddItem(item
);
110 float width
= StringWidth(item
->Text());
111 if (minWidth
< width
)
115 SetExplicitMinSize(BSize(minWidth
/ 2, 32));
116 SetExplicitMaxSize(BSize(minWidth
, B_SIZE_UNSET
));
123 UnicodeBlockView::SelectBlockForCharacter(uint32 character
)
125 // find block containing the character
126 int32 blockNumber
= BlockForCharacter(character
);
128 if (blockNumber
> 0) {
129 BlockListItem
* block
= fBlocks
.ItemAt(blockNumber
);
131 int32 blockIndex
= IndexOf(block
);
133 if (blockIndex
>= 0) {