* Add capability to load other keyboard layouts from disk. It even works :-)
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29714 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -31,7 +31,7 @@ KeyboardLayout::KeyboardLayout()
|
|||||||
fKeyCapacity(0),
|
fKeyCapacity(0),
|
||||||
fIndicators(5, true)
|
fIndicators(5, true)
|
||||||
{
|
{
|
||||||
_SetDefault();
|
SetDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -102,9 +102,19 @@ KeyboardLayout::IndexForModifier(int32 modifier)
|
|||||||
|
|
||||||
status_t
|
status_t
|
||||||
KeyboardLayout::Load(const char* path)
|
KeyboardLayout::Load(const char* path)
|
||||||
|
{
|
||||||
|
entry_ref ref;
|
||||||
|
get_ref_for_path(path, &ref);
|
||||||
|
|
||||||
|
return Load(ref);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
KeyboardLayout::Load(entry_ref& ref)
|
||||||
{
|
{
|
||||||
BFile file;
|
BFile file;
|
||||||
status_t status = file.SetTo(path, B_READ_ONLY);
|
status_t status = file.SetTo(&ref, B_READ_ONLY);
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
@@ -142,7 +152,7 @@ KeyboardLayout::Load(const char* path)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
KeyboardLayout::_SetDefault()
|
KeyboardLayout::SetDefault()
|
||||||
{
|
{
|
||||||
#if 1
|
#if 1
|
||||||
static const char* kDefaultLayout104 = "name = Generic 104-key\n"
|
static const char* kDefaultLayout104 = "name = Generic 104-key\n"
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#include <Entry.h>
|
||||||
#include <ObjectList.h>
|
#include <ObjectList.h>
|
||||||
#include <Point.h>
|
#include <Point.h>
|
||||||
#include <Rect.h>
|
#include <Rect.h>
|
||||||
@@ -55,7 +56,10 @@ public:
|
|||||||
int32 IndexForModifier(int32 modifier);
|
int32 IndexForModifier(int32 modifier);
|
||||||
|
|
||||||
status_t Load(const char* path);
|
status_t Load(const char* path);
|
||||||
|
status_t Load(entry_ref& ref);
|
||||||
|
|
||||||
|
void SetDefault();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum parse_mode {
|
enum parse_mode {
|
||||||
kPairs,
|
kPairs,
|
||||||
@@ -69,7 +73,6 @@ private:
|
|||||||
int32 line;
|
int32 line;
|
||||||
};
|
};
|
||||||
|
|
||||||
void _SetDefault();
|
|
||||||
void _FreeKeys();
|
void _FreeKeys();
|
||||||
void _Error(const parse_state& state,
|
void _Error(const parse_state& state,
|
||||||
const char* reason, ...);
|
const char* reason, ...);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ static const uint32 kMsgMenuFileOpen = 'mMFO';
|
|||||||
static const uint32 kMsgMenuFileSave = 'mMFS';
|
static const uint32 kMsgMenuFileSave = 'mMFS';
|
||||||
static const uint32 kMsgMenuFileSaveAs = 'mMFA';
|
static const uint32 kMsgMenuFileSaveAs = 'mMFA';
|
||||||
|
|
||||||
static const uint32 kMsgMenuEditUndo = 'mMEU';
|
static const uint32 kChangeKeyboardLayout = 'cKyL';
|
||||||
|
|
||||||
static const uint32 kMsgMenuFontChanged = 'mMFC';
|
static const uint32 kMsgMenuFontChanged = 'mMFC';
|
||||||
|
|
||||||
@@ -211,6 +211,24 @@ KeymapWindow::MessageReceived(BMessage* message)
|
|||||||
fSavePanel->Show();
|
fSavePanel->Show();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case kChangeKeyboardLayout:
|
||||||
|
{
|
||||||
|
entry_ref ref;
|
||||||
|
if (message->FindRef("ref", &ref) == B_OK
|
||||||
|
&& fKeyboardLayoutView->GetKeyboardLayout()->Load(ref)
|
||||||
|
== B_OK) {
|
||||||
|
fKeyboardLayoutView->SetKeyboardLayout(
|
||||||
|
fKeyboardLayoutView->GetKeyboardLayout());
|
||||||
|
} else {
|
||||||
|
fKeyboardLayoutView->GetKeyboardLayout()->SetDefault();
|
||||||
|
fLayoutMenu->ItemAt(0)->SetMarked(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
fKeyboardLayoutView->SetKeyboardLayout(
|
||||||
|
fKeyboardLayoutView->GetKeyboardLayout());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case kMsgMenuFontChanged:
|
case kMsgMenuFontChanged:
|
||||||
{
|
{
|
||||||
BMenuItem *item = fFontMenu->FindMarked();
|
BMenuItem *item = fFontMenu->FindMarked();
|
||||||
@@ -308,32 +326,15 @@ KeymapWindow::_CreateMenu()
|
|||||||
menuBar->AddItem(menu);
|
menuBar->AddItem(menu);
|
||||||
|
|
||||||
// Create keyboard layout menu
|
// Create keyboard layout menu
|
||||||
menu = new BMenu("Layout");
|
fLayoutMenu = new BMenu("Layout");
|
||||||
menu->AddItem(item = new BMenuItem(
|
fLayoutMenu->SetRadioMode(true);
|
||||||
fKeyboardLayoutView->GetKeyboardLayout()->Name(), NULL));
|
fLayoutMenu->AddItem(item = new BMenuItem(
|
||||||
|
fKeyboardLayoutView->GetKeyboardLayout()->Name(),
|
||||||
|
new BMessage(kChangeKeyboardLayout)));
|
||||||
item->SetMarked(true);
|
item->SetMarked(true);
|
||||||
menuBar->AddItem(menu);
|
|
||||||
#if 0
|
_AddKeyboardLayouts(fLayoutMenu);
|
||||||
// Create the Edit menu
|
menuBar->AddItem(fLayoutMenu);
|
||||||
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
|
// Create the Font menu
|
||||||
fFontMenu = new BMenu("Font");
|
fFontMenu = new BMenu("Font");
|
||||||
@@ -377,12 +378,6 @@ KeymapWindow::_CreateMapLists()
|
|||||||
BScrollView* userScroller = new BScrollView("userScrollList",
|
BScrollView* userScroller = new BScrollView("userScrollList",
|
||||||
fUserListView, 0, false, true);
|
fUserListView, 0, false, true);
|
||||||
|
|
||||||
// '(Current)'
|
|
||||||
KeymapListItem* currentKeymapItem
|
|
||||||
= static_cast<KeymapListItem*>(fUserListView->FirstItem());
|
|
||||||
if (currentKeymapItem != NULL)
|
|
||||||
fUserListView->AddItem(currentKeymapItem);
|
|
||||||
|
|
||||||
// Saved keymaps
|
// Saved keymaps
|
||||||
|
|
||||||
_FillSystemMaps();
|
_FillSystemMaps();
|
||||||
@@ -399,6 +394,40 @@ KeymapWindow::_CreateMapLists()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
KeymapWindow::_AddKeyboardLayouts(BMenu* menu)
|
||||||
|
{
|
||||||
|
directory_which dataDirectories[] = {
|
||||||
|
B_USER_DATA_DIRECTORY,
|
||||||
|
B_COMMON_DATA_DIRECTORY,
|
||||||
|
B_BEOS_DATA_DIRECTORY
|
||||||
|
};
|
||||||
|
|
||||||
|
for (uint32 i = 0;
|
||||||
|
i < sizeof(dataDirectories) / sizeof(dataDirectories[0]); i++) {
|
||||||
|
BPath path;
|
||||||
|
if (find_directory(dataDirectories[i], &path) != B_OK)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
path.Append("KeyboardLayouts");
|
||||||
|
|
||||||
|
BDirectory directory;
|
||||||
|
if (directory.SetTo(path.Path()) == B_OK) {
|
||||||
|
entry_ref ref;
|
||||||
|
while (directory.GetNextRef(&ref) == B_OK) {
|
||||||
|
if (menu->FindItem(ref.name) != NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
BMessage* message = new BMessage(kChangeKeyboardLayout);
|
||||||
|
message->AddRef("ref", &ref);
|
||||||
|
|
||||||
|
menu->AddItem(new BMenuItem(ref.name, message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
KeymapWindow::_UpdateButtons()
|
KeymapWindow::_UpdateButtons()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
BMenuBar* _CreateMenu();
|
BMenuBar* _CreateMenu();
|
||||||
BView* _CreateMapLists();
|
BView* _CreateMapLists();
|
||||||
|
void _AddKeyboardLayouts(BMenu* menu);
|
||||||
|
|
||||||
void _UpdateButtons();
|
void _UpdateButtons();
|
||||||
|
|
||||||
@@ -56,6 +57,7 @@ protected:
|
|||||||
BListView* fUserListView;
|
BListView* fUserListView;
|
||||||
BButton* fUseButton;
|
BButton* fUseButton;
|
||||||
BButton* fRevertButton;
|
BButton* fRevertButton;
|
||||||
|
BMenu* fLayoutMenu;
|
||||||
BMenu* fFontMenu;
|
BMenu* fFontMenu;
|
||||||
KeyboardLayoutView* fKeyboardLayoutView;
|
KeyboardLayoutView* fKeyboardLayoutView;
|
||||||
BTextControl* fTextControl;
|
BTextControl* fTextControl;
|
||||||
|
|||||||
Reference in New Issue
Block a user