CharacterMap: improved initial window size, and position.
* By making it scale with the font size, and by using BWindow::CenterOnScreen(). * Minor cleanup.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2009-2010, Axel Dörfler, [email protected].
|
* Copyright 2009-2015, Axel Dörfler, [email protected].
|
||||||
* Copyright 2011, Philippe Saint-Pierre, [email protected].
|
* Copyright 2011, Philippe Saint-Pierre, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
@@ -33,9 +33,11 @@
|
|||||||
#include "CharacterView.h"
|
#include "CharacterView.h"
|
||||||
#include "UnicodeBlockView.h"
|
#include "UnicodeBlockView.h"
|
||||||
|
|
||||||
|
|
||||||
#undef B_TRANSLATION_CONTEXT
|
#undef B_TRANSLATION_CONTEXT
|
||||||
#define B_TRANSLATION_CONTEXT "CharacterWindow"
|
#define B_TRANSLATION_CONTEXT "CharacterWindow"
|
||||||
|
|
||||||
|
|
||||||
static const uint32 kMsgUnicodeBlockSelected = 'unbs';
|
static const uint32 kMsgUnicodeBlockSelected = 'unbs';
|
||||||
static const uint32 kMsgCharacterChanged = 'chch';
|
static const uint32 kMsgCharacterChanged = 'chch';
|
||||||
static const uint32 kMsgFontSelected = 'fnts';
|
static const uint32 kMsgFontSelected = 'fnts';
|
||||||
@@ -123,9 +125,9 @@ private:
|
|||||||
|
|
||||||
CharacterWindow::CharacterWindow()
|
CharacterWindow::CharacterWindow()
|
||||||
:
|
:
|
||||||
BWindow(BRect(100, 100, 700, 550), B_TRANSLATE_SYSTEM_NAME("CharacterMap"),
|
BWindow(BRect(100, 100, 700, 550), B_TRANSLATE_SYSTEM_NAME("CharacterMap"),
|
||||||
B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE
|
B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE
|
||||||
| B_AUTO_UPDATE_SIZE_LIMITS)
|
| B_AUTO_UPDATE_SIZE_LIMITS)
|
||||||
{
|
{
|
||||||
BMessage settings;
|
BMessage settings;
|
||||||
_LoadSettings(settings);
|
_LoadSettings(settings);
|
||||||
@@ -134,6 +136,10 @@ CharacterWindow::CharacterWindow()
|
|||||||
if (settings.FindRect("window frame", &frame) == B_OK) {
|
if (settings.FindRect("window frame", &frame) == B_OK) {
|
||||||
MoveTo(frame.LeftTop());
|
MoveTo(frame.LeftTop());
|
||||||
ResizeTo(frame.Width(), frame.Height());
|
ResizeTo(frame.Width(), frame.Height());
|
||||||
|
} else {
|
||||||
|
float scaling = be_plain_font->Size() / 12.0f;
|
||||||
|
ResizeTo(Frame().Width() * scaling, Frame().Height() * scaling);
|
||||||
|
CenterOnScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
// create GUI
|
// create GUI
|
||||||
@@ -173,11 +179,11 @@ CharacterWindow::CharacterWindow()
|
|||||||
const char* family;
|
const char* family;
|
||||||
const char* style;
|
const char* style;
|
||||||
BString displayName;
|
BString displayName;
|
||||||
|
|
||||||
if (settings.FindString("font family", &family) == B_OK
|
if (settings.FindString("font family", &family) == B_OK
|
||||||
&& settings.FindString("font style", &style) == B_OK) {
|
&& settings.FindString("font style", &style) == B_OK) {
|
||||||
_SetFont(family, style);
|
_SetFont(family, style);
|
||||||
displayName << family << " " << style;
|
displayName << family << " " << style;
|
||||||
} else {
|
} else {
|
||||||
font_family currentFontFamily;
|
font_family currentFontFamily;
|
||||||
font_style currentFontStyle;
|
font_style currentFontStyle;
|
||||||
@@ -211,18 +217,17 @@ CharacterWindow::CharacterWindow()
|
|||||||
fCodeView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED,
|
fCodeView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED,
|
||||||
fCodeView->PreferredSize().Height()));
|
fCodeView->PreferredSize().Height()));
|
||||||
|
|
||||||
// set minimum width for character pane to prevent UI
|
// Set minimum width for character pane to prevent UI
|
||||||
// from jumping when longer code strings are displayed.
|
// from jumping when longer code strings are displayed.
|
||||||
// use 'w' character for sizing as it's likely the widest
|
// use 'w' character for sizing as it's likely the widest
|
||||||
// character for a Latin font. 40 characters is a little
|
// character for a Latin font. 40 characters is a little
|
||||||
// wider than needed so hopefully this covers other
|
// wider than needed so hopefully this covers other
|
||||||
// non-Latin fonts that may be wider.
|
// non-Latin fonts that may be wider.
|
||||||
BFont viewFont;
|
BFont viewFont;
|
||||||
fCodeView->GetFont(&viewFont);
|
fCodeView->GetFont(&viewFont);
|
||||||
fCharacterView->SetExplicitMinSize(BSize(viewFont.StringWidth(
|
fCharacterView->SetExplicitMinSize(BSize(viewFont.StringWidth("w") * 40,
|
||||||
"w") * 40,
|
|
||||||
B_SIZE_UNSET));
|
B_SIZE_UNSET));
|
||||||
|
|
||||||
BLayoutBuilder::Group<>(this, B_VERTICAL)
|
BLayoutBuilder::Group<>(this, B_VERTICAL)
|
||||||
.Add(menuBar)
|
.Add(menuBar)
|
||||||
.AddGroup(B_HORIZONTAL)
|
.AddGroup(B_HORIZONTAL)
|
||||||
@@ -275,7 +280,7 @@ CharacterWindow::CharacterWindow()
|
|||||||
fUnicodeBlockView->SetTarget(this);
|
fUnicodeBlockView->SetTarget(this);
|
||||||
|
|
||||||
fFilterControl->MakeFocus();
|
fFilterControl->MakeFocus();
|
||||||
|
|
||||||
fUnicodeBlockView->SelectBlockForCharacter(0);
|
fUnicodeBlockView->SelectBlockForCharacter(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,7 +349,7 @@ CharacterWindow::MessageReceived(BMessage* message)
|
|||||||
|
|
||||||
fGlyphView->SetText(glyph);
|
fGlyphView->SetText(glyph);
|
||||||
fCodeView->SetText(text);
|
fCodeView->SetText(text);
|
||||||
|
|
||||||
fUnicodeBlockView->SelectBlockForCharacter(character);
|
fUnicodeBlockView->SelectBlockForCharacter(character);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -369,12 +374,12 @@ CharacterWindow::MessageReceived(BMessage* message)
|
|||||||
fSelectedFontItem = item;
|
fSelectedFontItem = item;
|
||||||
|
|
||||||
_SetFont(item->Menu()->Name(), item->Label());
|
_SetFont(item->Menu()->Name(), item->Label());
|
||||||
|
|
||||||
BString displayName;
|
BString displayName;
|
||||||
displayName << item->Menu()->Name() << " " << item->Label();
|
displayName << item->Menu()->Name() << " " << item->Label();
|
||||||
|
|
||||||
fFontSizeSlider->SetLabel(displayName);
|
fFontSizeSlider->SetLabel(displayName);
|
||||||
|
|
||||||
item = item->Menu()->Superitem();
|
item = item->Menu()->Superitem();
|
||||||
item->SetMarked(true);
|
item->SetMarked(true);
|
||||||
}
|
}
|
||||||
@@ -467,7 +472,7 @@ CharacterWindow::_LoadSettings(BMessage& settings)
|
|||||||
{
|
{
|
||||||
BFile file;
|
BFile file;
|
||||||
status_t status = _OpenSettings(file, B_READ_ONLY);
|
status_t status = _OpenSettings(file, B_READ_ONLY);
|
||||||
if (status < B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
return settings.Unflatten(&file);
|
return settings.Unflatten(&file);
|
||||||
@@ -533,7 +538,6 @@ BMenu*
|
|||||||
CharacterWindow::_CreateFontMenu()
|
CharacterWindow::_CreateFontMenu()
|
||||||
{
|
{
|
||||||
BMenu* menu = new BMenu(B_TRANSLATE("Font"));
|
BMenu* menu = new BMenu(B_TRANSLATE("Font"));
|
||||||
|
|
||||||
_UpdateFontMenu(menu);
|
_UpdateFontMenu(menu);
|
||||||
|
|
||||||
return menu;
|
return menu;
|
||||||
@@ -589,10 +593,9 @@ CharacterWindow::_UpdateFontMenu(BMenu* menu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CharacterWindow::MenusBeginning()
|
void
|
||||||
|
CharacterWindow::MenusBeginning()
|
||||||
{
|
{
|
||||||
if (update_font_families(false) == true) {
|
if (update_font_families(false) == true)
|
||||||
_UpdateFontMenu(fFontMenu);
|
_UpdateFontMenu(fFontMenu);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user