* The text control is now back - instead of overwriting BTextView::KeyDown(),
we now use a plain BTextControl, and a custom message filter. For some reason, BHandler::AddFilter() does not work, though, this needs some investigation. * Enabled the font menu again, the font in the text control is changed as well. * Made the default window size a bit smaller on large screens. * Scrolling to the selection does not seem to work before Show() - looks like a bug in the layout implementation. * Moved some methods around to match their declaration order. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29698 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -7,11 +7,12 @@ UsePrivateHeaders interface ;
|
||||
Preference Keymap :
|
||||
KeyboardLayout.cpp
|
||||
KeyboardLayoutView.cpp
|
||||
KeymapApplication.cpp
|
||||
KeymapWindow.cpp
|
||||
KeymapListItem.cpp
|
||||
Keymap.cpp
|
||||
KeymapTextView.cpp
|
||||
KeymapApplication.cpp
|
||||
KeymapListItem.cpp
|
||||
KeymapMessageFilter.cpp
|
||||
KeymapWindow.cpp
|
||||
|
||||
: be tracker
|
||||
: Keymap.rdef
|
||||
;
|
||||
;
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2009, Axel Dörfler, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include "KeymapMessageFilter.h"
|
||||
|
||||
#include <AppDefs.h>
|
||||
#include <Message.h>
|
||||
|
||||
#include "Keymap.h"
|
||||
|
||||
|
||||
KeymapMessageFilter::KeymapMessageFilter(message_delivery delivery,
|
||||
message_source source, Keymap* keymap)
|
||||
: BMessageFilter(delivery, source),
|
||||
fKeymap(keymap)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
KeymapMessageFilter::~KeymapMessageFilter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
KeymapMessageFilter::SetKeymap(Keymap* keymap)
|
||||
{
|
||||
fKeymap = keymap;
|
||||
}
|
||||
|
||||
|
||||
filter_result
|
||||
KeymapMessageFilter::Filter(BMessage* message, BHandler** /*_target*/)
|
||||
{
|
||||
if (fKeymap == NULL || message->what != B_KEY_DOWN)
|
||||
return B_DISPATCH_MESSAGE;
|
||||
|
||||
// TODO: add dead key handling!
|
||||
|
||||
int32 modifiers;
|
||||
int32 key;
|
||||
if (message->FindInt32("modifiers", &modifiers) == B_OK
|
||||
&& message->FindInt32("key", &key) == B_OK) {
|
||||
// replace "bytes", and "raw_char"/"byte"
|
||||
char* string;
|
||||
int32 numBytes;
|
||||
fKeymap->GetChars(key, modifiers, 0, &string, &numBytes);
|
||||
if (string != NULL) {
|
||||
message->ReplaceString("bytes", string);
|
||||
delete[] string;
|
||||
}
|
||||
|
||||
fKeymap->GetChars(key, 0, 0, &string, &numBytes);
|
||||
if (string != NULL) {
|
||||
message->ReplaceInt32("raw_char", string[0]);
|
||||
message->ReplaceInt8("byte", string[0]);
|
||||
delete[] string;
|
||||
}
|
||||
}
|
||||
|
||||
return B_DISPATCH_MESSAGE;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2009, Axel Dörfler, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef KEYMAP_MESSAGE_FILTER_H
|
||||
#define KEYMAP_MESSAGE_FILTER_H
|
||||
|
||||
|
||||
#include <MessageFilter.h>
|
||||
|
||||
class Keymap;
|
||||
|
||||
|
||||
class KeymapMessageFilter : public BMessageFilter {
|
||||
public:
|
||||
KeymapMessageFilter(
|
||||
message_delivery delivery = B_ANY_DELIVERY,
|
||||
message_source source = B_ANY_SOURCE,
|
||||
Keymap* keymap = NULL);
|
||||
virtual ~KeymapMessageFilter();
|
||||
|
||||
void SetKeymap(Keymap* keymap);
|
||||
|
||||
virtual filter_result Filter(BMessage* message, BHandler** _target);
|
||||
|
||||
private:
|
||||
Keymap* fKeymap;
|
||||
};
|
||||
|
||||
#endif // KEYMAP_MESSAGE_FILTER_H
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004-2006 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Jérôme Duval
|
||||
*/
|
||||
|
||||
#include "KeymapTextView.h"
|
||||
|
||||
|
||||
KeymapTextView::KeymapTextView(BRect frame,
|
||||
const char *name,
|
||||
BRect textRect,
|
||||
uint32 resizeMask,
|
||||
uint32 flags) :
|
||||
BTextView(frame, name, textRect, resizeMask, flags)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
KeymapTextView::KeyDown(const char *bytes, int32 numBytes)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
KeymapTextView::FakeKeyDown(const char *bytes, int32 numBytes)
|
||||
{
|
||||
BTextView::KeyDown(bytes, numBytes);
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright 2004-2006 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Jérôme Duval
|
||||
*/
|
||||
|
||||
#ifndef KEYMAPTEXTVIEW_H
|
||||
#define KEYMAPTEXTVIEW_H
|
||||
|
||||
#include <TextView.h>
|
||||
|
||||
class KeymapTextView : public BTextView
|
||||
{
|
||||
public:
|
||||
KeymapTextView(BRect frame,
|
||||
const char *name,
|
||||
BRect textRect,
|
||||
uint32 resizeMask,
|
||||
uint32 flags = B_WILL_DRAW | B_PULSE_NEEDED);
|
||||
virtual void KeyDown(const char *bytes, int32 numBytes);
|
||||
virtual void FakeKeyDown(const char *bytes, int32 numBytes);
|
||||
};
|
||||
|
||||
|
||||
#endif //KEYMAPTEXTVIEW_H
|
||||
@@ -25,10 +25,12 @@
|
||||
#include <Screen.h>
|
||||
#include <ScrollView.h>
|
||||
#include <StringView.h>
|
||||
#include <TextControl.h>
|
||||
|
||||
#include "KeyboardLayoutView.h"
|
||||
#include "KeymapListItem.h"
|
||||
#include "KeymapApplication.h"
|
||||
#include "KeymapListItem.h"
|
||||
#include "KeymapMessageFilter.h"
|
||||
|
||||
|
||||
static const uint32 kMsgMenuFileOpen = 'mMFO';
|
||||
@@ -57,6 +59,8 @@ KeymapWindow::KeymapWindow()
|
||||
fKeyboardLayoutView = new KeyboardLayoutView("layout");
|
||||
fKeyboardLayoutView->SetKeymap(&fCurrentMap);
|
||||
|
||||
fTextControl = new BTextControl("Sample and Clipboard:", "", NULL);
|
||||
|
||||
fUseButton = new BButton("useButton", "Use", new BMessage(kMsgUseKeymap));
|
||||
fRevertButton = new BButton("revertButton", "Revert",
|
||||
new BMessage(kMsgRevertKeymap));
|
||||
@@ -68,6 +72,8 @@ KeymapWindow::KeymapWindow()
|
||||
.Add(_CreateMapLists(), 0.25)
|
||||
.Add(BGroupLayoutBuilder(B_VERTICAL, 10)
|
||||
.Add(fKeyboardLayoutView)
|
||||
//.Add(new BStringView("text label", "Sample and Clipboard:"))
|
||||
.Add(fTextControl)
|
||||
.AddGlue(0.0)
|
||||
.Add(BGroupLayoutBuilder(B_HORIZONTAL, 10)
|
||||
.AddGlue(0.0)
|
||||
@@ -75,21 +81,15 @@ KeymapWindow::KeymapWindow()
|
||||
.Add(fRevertButton)))
|
||||
.SetInsets(10, 10, 10, 10)));
|
||||
|
||||
#if 0
|
||||
BMenuItem *item = fFontMenu->FindMarked();
|
||||
if (item) {
|
||||
fMapView->SetFontFamily(item->Label());
|
||||
}
|
||||
#endif
|
||||
|
||||
// Try and find the current map name in the two list views (if the name
|
||||
// was read at all) - this will also load the fCurrentMap
|
||||
if (!_SelectCurrentMap(fSystemListView)
|
||||
&& !_SelectCurrentMap(fUserListView))
|
||||
fUserListView->Select(0L);
|
||||
fKeyboardLayoutView->SetTarget(fTextControl->TextView());
|
||||
AddCommonFilter(new KeymapMessageFilter(B_PROGRAMMED_DELIVERY, B_ANY_SOURCE,
|
||||
&fCurrentMap));
|
||||
// TODO: this does not work for some reason, investigate!
|
||||
// fTextControl->AddFilter(fTextFilter);
|
||||
|
||||
_UpdateButtons();
|
||||
|
||||
// Make sure the user keymap directory exists
|
||||
BPath path;
|
||||
find_directory(B_USER_SETTINGS_DIRECTORY, &path);
|
||||
path.Append("Keymap");
|
||||
@@ -121,13 +121,26 @@ KeymapWindow::KeymapWindow()
|
||||
|
||||
// See if we can use a larger default size
|
||||
if (screen.Frame().Width() > 1200) {
|
||||
width = 1000;
|
||||
width = 900;
|
||||
height = 400;
|
||||
}
|
||||
|
||||
// TODO: store and restore position and size!
|
||||
ResizeTo(width, height);
|
||||
MoveTo(BAlert::AlertPosition(width, height));
|
||||
|
||||
// TODO: this might be a bug in the interface kit, but scrolling to
|
||||
// selection does not correctly work unless the window is shown.
|
||||
Show();
|
||||
Lock();
|
||||
|
||||
// Try and find the current map name in the two list views (if the name
|
||||
// was read at all) - this will also load the fCurrentMap
|
||||
if (!_SelectCurrentMap(fSystemListView)
|
||||
&& !_SelectCurrentMap(fUserListView))
|
||||
fUserListView->Select(0L);
|
||||
|
||||
Unlock();
|
||||
}
|
||||
|
||||
|
||||
@@ -138,116 +151,6 @@ KeymapWindow::~KeymapWindow(void)
|
||||
}
|
||||
|
||||
|
||||
BMenuBar*
|
||||
KeymapWindow::_CreateMenu()
|
||||
{
|
||||
BMenuBar* menuBar = new BMenuBar(Bounds(), "menubar");
|
||||
BMenuItem* currentItem;
|
||||
|
||||
// Create the File menu
|
||||
BMenu* menu = new BMenu("File");
|
||||
menu->AddItem(new BMenuItem("Open" B_UTF8_ELLIPSIS,
|
||||
new BMessage(kMsgMenuFileOpen), 'O'));
|
||||
menu->AddSeparatorItem();
|
||||
currentItem = new BMenuItem("Save",
|
||||
new BMessage(kMsgMenuFileSave), 'S');
|
||||
currentItem->SetEnabled(false);
|
||||
menu->AddItem(currentItem);
|
||||
menu->AddItem(new BMenuItem("Save As" B_UTF8_ELLIPSIS,
|
||||
new BMessage(kMsgMenuFileSaveAs)));
|
||||
menu->AddSeparatorItem();
|
||||
menu->AddItem(new BMenuItem("Quit",
|
||||
new BMessage(B_QUIT_REQUESTED), 'Q'));
|
||||
menuBar->AddItem(menu);
|
||||
|
||||
#if 0
|
||||
// Create the Edit menu
|
||||
menu = new BMenu("Edit");
|
||||
currentItem = new BMenuItem("Undo",
|
||||
new BMessage(kMsgMenuEditUndo), 'Z');
|
||||
currentItem->SetEnabled(false);
|
||||
menu->AddItem(currentItem);
|
||||
menu->AddSeparatorItem();
|
||||
menu->AddItem(new BMenuItem( "Cut",
|
||||
new BMessage(kMsgMenuEditCut), 'X'));
|
||||
menu->AddItem(new BMenuItem( "Copy",
|
||||
new BMessage(kMsgMenuEditCopy), 'C'));
|
||||
menu->AddItem(new BMenuItem( "Paste",
|
||||
new BMessage(kMsgMenuEditPaste), 'V'));
|
||||
menu->AddItem(new BMenuItem( "Clear",
|
||||
new BMessage(kMsgMenuEditClear)));
|
||||
menu->AddSeparatorItem();
|
||||
menu->AddItem(new BMenuItem( "Select All",
|
||||
new BMessage(kMsgMenuEditSelectAll), 'A'));
|
||||
menuBar->AddItem(menu);
|
||||
|
||||
// Create the Font menu
|
||||
fFontMenu = new BMenu("Font");
|
||||
fFontMenu->SetRadioMode(true);
|
||||
int32 numFamilies = count_font_families();
|
||||
font_family family, current_family;
|
||||
font_style current_style;
|
||||
uint32 flags;
|
||||
|
||||
be_plain_font->GetFamilyAndStyle(¤t_family, ¤t_style);
|
||||
|
||||
for (int32 i = 0; i < numFamilies; i++) {
|
||||
if (get_font_family(i, &family, &flags) == B_OK) {
|
||||
BMenuItem *item =
|
||||
new BMenuItem(family, new BMessage(kMsgMenuFontChanged));
|
||||
fFontMenu->AddItem(item);
|
||||
if (strcmp(family, current_family) == 0)
|
||||
item->SetMarked(true);
|
||||
}
|
||||
}
|
||||
menuBar->AddItem(fFontMenu);
|
||||
#endif
|
||||
|
||||
return menuBar;
|
||||
}
|
||||
|
||||
|
||||
BView*
|
||||
KeymapWindow::_CreateMapLists()
|
||||
{
|
||||
// The System list
|
||||
BStringView* systemLabel = new BStringView("system", "System:");
|
||||
fSystemListView = new BListView("systemList");
|
||||
fSystemListView->SetSelectionMessage(new BMessage(kMsgSystemMapSelected));
|
||||
|
||||
BScrollView* systemScroller = new BScrollView("systemScrollList",
|
||||
fSystemListView, 0, false, true);
|
||||
|
||||
// The User list
|
||||
BStringView* userLabel = new BStringView("user", "User:");
|
||||
|
||||
fUserListView = new BListView("userList");
|
||||
fUserListView->SetSelectionMessage(new BMessage(kMsgUserMapSelected));
|
||||
BScrollView* userScroller = new BScrollView("userScrollList",
|
||||
fUserListView, 0, false, true);
|
||||
|
||||
// '(Current)'
|
||||
KeymapListItem *currentKeymapItem
|
||||
= static_cast<KeymapListItem*>(fUserListView->FirstItem());
|
||||
if (currentKeymapItem != NULL)
|
||||
fUserListView->AddItem(currentKeymapItem);
|
||||
|
||||
// Saved keymaps
|
||||
|
||||
_FillSystemMaps();
|
||||
_FillUserMaps();
|
||||
|
||||
_SetListViewSize(fSystemListView);
|
||||
_SetListViewSize(fUserListView);
|
||||
|
||||
return BGroupLayoutBuilder(B_VERTICAL)
|
||||
.Add(systemLabel)
|
||||
.Add(systemScroller, 3)
|
||||
.Add(userLabel)
|
||||
.Add(userScroller);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
KeymapWindow::QuitRequested()
|
||||
{
|
||||
@@ -274,6 +177,9 @@ KeymapWindow::MessageReceived(BMessage* message)
|
||||
break;
|
||||
}
|
||||
|
||||
case B_MIME_DATA:
|
||||
break;
|
||||
|
||||
case B_SAVE_REQUESTED:
|
||||
{
|
||||
entry_ref ref;
|
||||
@@ -309,17 +215,17 @@ KeymapWindow::MessageReceived(BMessage* message)
|
||||
fMapView->MessageReceived(message);
|
||||
break;
|
||||
#endif
|
||||
#if 0
|
||||
case kMsgMenuFontChanged:
|
||||
{
|
||||
BMenuItem *item = fFontMenu->FindMarked();
|
||||
if (item != NULL) {
|
||||
fMapView->SetFontFamily(item->Label());
|
||||
fMapView->Invalidate();
|
||||
BFont font;
|
||||
font.SetFamilyAndStyle(item->Label(), NULL);
|
||||
fKeyboardLayoutView->SetFont(font);
|
||||
fTextControl->TextView()->SetFontAndColor(&font);
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
case kMsgSystemMapSelected:
|
||||
{
|
||||
@@ -383,6 +289,119 @@ KeymapWindow::MessageReceived(BMessage* message)
|
||||
}
|
||||
|
||||
|
||||
BMenuBar*
|
||||
KeymapWindow::_CreateMenu()
|
||||
{
|
||||
BMenuBar* menuBar = new BMenuBar(Bounds(), "menubar");
|
||||
BMenuItem* item;
|
||||
|
||||
// Create the File menu
|
||||
BMenu* menu = new BMenu("File");
|
||||
menu->AddItem(new BMenuItem("Open" B_UTF8_ELLIPSIS,
|
||||
new BMessage(kMsgMenuFileOpen), 'O'));
|
||||
menu->AddSeparatorItem();
|
||||
item = new BMenuItem("Save", new BMessage(kMsgMenuFileSave), 'S');
|
||||
item->SetEnabled(false);
|
||||
menu->AddItem(item);
|
||||
menu->AddItem(new BMenuItem("Save As" B_UTF8_ELLIPSIS,
|
||||
new BMessage(kMsgMenuFileSaveAs)));
|
||||
menu->AddSeparatorItem();
|
||||
menu->AddItem(new BMenuItem("Quit",
|
||||
new BMessage(B_QUIT_REQUESTED), 'Q'));
|
||||
menuBar->AddItem(menu);
|
||||
|
||||
// Create keyboard layout menu
|
||||
menu = new BMenu("Layout");
|
||||
menu->AddItem(item = new BMenuItem(
|
||||
fKeyboardLayoutView->GetKeyboardLayout()->Name(), NULL));
|
||||
item->SetMarked(true);
|
||||
menuBar->AddItem(menu);
|
||||
#if 0
|
||||
// Create the Edit menu
|
||||
menu = new BMenu("Edit");
|
||||
currentItem = new BMenuItem("Undo",
|
||||
new BMessage(kMsgMenuEditUndo), 'Z');
|
||||
currentItem->SetEnabled(false);
|
||||
menu->AddItem(currentItem);
|
||||
menu->AddSeparatorItem();
|
||||
menu->AddItem(new BMenuItem( "Cut",
|
||||
new BMessage(kMsgMenuEditCut), 'X'));
|
||||
menu->AddItem(new BMenuItem( "Copy",
|
||||
new BMessage(kMsgMenuEditCopy), 'C'));
|
||||
menu->AddItem(new BMenuItem( "Paste",
|
||||
new BMessage(kMsgMenuEditPaste), 'V'));
|
||||
menu->AddItem(new BMenuItem( "Clear",
|
||||
new BMessage(kMsgMenuEditClear)));
|
||||
menu->AddSeparatorItem();
|
||||
menu->AddItem(new BMenuItem( "Select All",
|
||||
new BMessage(kMsgMenuEditSelectAll), 'A'));
|
||||
menuBar->AddItem(menu);
|
||||
#endif
|
||||
|
||||
// Create the Font menu
|
||||
fFontMenu = new BMenu("Font");
|
||||
fFontMenu->SetRadioMode(true);
|
||||
int32 numFamilies = count_font_families();
|
||||
font_family family, currentFamily;
|
||||
font_style currentStyle;
|
||||
uint32 flags;
|
||||
|
||||
be_plain_font->GetFamilyAndStyle(¤tFamily, ¤tStyle);
|
||||
|
||||
for (int32 i = 0; i < numFamilies; i++) {
|
||||
if (get_font_family(i, &family, &flags) == B_OK) {
|
||||
BMenuItem *item =
|
||||
new BMenuItem(family, new BMessage(kMsgMenuFontChanged));
|
||||
fFontMenu->AddItem(item);
|
||||
|
||||
if (!strcmp(family, currentFamily))
|
||||
item->SetMarked(true);
|
||||
}
|
||||
}
|
||||
menuBar->AddItem(fFontMenu);
|
||||
|
||||
return menuBar;
|
||||
}
|
||||
|
||||
|
||||
BView*
|
||||
KeymapWindow::_CreateMapLists()
|
||||
{
|
||||
// The System list
|
||||
fSystemListView = new BListView("systemList");
|
||||
fSystemListView->SetSelectionMessage(new BMessage(kMsgSystemMapSelected));
|
||||
|
||||
BScrollView* systemScroller = new BScrollView("systemScrollList",
|
||||
fSystemListView, 0, false, true);
|
||||
|
||||
// The User list
|
||||
fUserListView = new BListView("userList");
|
||||
fUserListView->SetSelectionMessage(new BMessage(kMsgUserMapSelected));
|
||||
BScrollView* userScroller = new BScrollView("userScrollList",
|
||||
fUserListView, 0, false, true);
|
||||
|
||||
// '(Current)'
|
||||
KeymapListItem *currentKeymapItem
|
||||
= static_cast<KeymapListItem*>(fUserListView->FirstItem());
|
||||
if (currentKeymapItem != NULL)
|
||||
fUserListView->AddItem(currentKeymapItem);
|
||||
|
||||
// Saved keymaps
|
||||
|
||||
_FillSystemMaps();
|
||||
_FillUserMaps();
|
||||
|
||||
_SetListViewSize(fSystemListView);
|
||||
_SetListViewSize(fUserListView);
|
||||
|
||||
return BGroupLayoutBuilder(B_VERTICAL)
|
||||
.Add(new BStringView("system", "System:"))
|
||||
.Add(systemScroller, 3)
|
||||
.Add(new BStringView("user", "User:"))
|
||||
.Add(userScroller);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
KeymapWindow::_UpdateButtons()
|
||||
{
|
||||
|
||||
@@ -18,9 +18,10 @@
|
||||
#include <Window.h>
|
||||
|
||||
#include "Keymap.h"
|
||||
#include "KeymapTextView.h"
|
||||
|
||||
class BMenu;
|
||||
class BMenuBar;
|
||||
class BTextControl;
|
||||
class KeyboardLayoutView;
|
||||
class KeymapListItem;
|
||||
|
||||
@@ -37,9 +38,10 @@ protected:
|
||||
BMenuBar* _CreateMenu();
|
||||
BView* _CreateMapLists();
|
||||
|
||||
void _UpdateButtons();
|
||||
|
||||
void _UseKeymap();
|
||||
void _RevertKeymap();
|
||||
void _UpdateButtons();
|
||||
|
||||
void _FillSystemMaps();
|
||||
void _FillUserMaps();
|
||||
@@ -52,8 +54,9 @@ protected:
|
||||
BListView* fUserListView;
|
||||
BButton* fUseButton;
|
||||
BButton* fRevertButton;
|
||||
//BMenu* fFontMenu;
|
||||
BMenu* fFontMenu;
|
||||
KeyboardLayoutView* fKeyboardLayoutView;
|
||||
BTextControl* fTextControl;
|
||||
|
||||
Keymap fCurrentMap;
|
||||
Keymap fPreviousMap;
|
||||
|
||||
Reference in New Issue
Block a user