From e4aad26fec2e5ff3e807e54c88892592198ce29e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 24 Mar 2009 22:12:31 +0000 Subject: [PATCH] * While the new stuff isn't really ready for prime time, I've switched over to it now (also to get some comments). It already looks better than the old one, at least. * The KeymapWindow is now using our layout engine. * Removed the old MapView. * Do you think the text view is necessary? And the ability to switch the font? (I've removed both for now, comments welcome) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29684 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/preferences/keymap/Jamfile | 2 + src/preferences/keymap/KeymapWindow.cpp | 1551 ++++------------------- src/preferences/keymap/KeymapWindow.h | 120 +- 3 files changed, 255 insertions(+), 1418 deletions(-) diff --git a/src/preferences/keymap/Jamfile b/src/preferences/keymap/Jamfile index 0152f84323..5b568b96df 100644 --- a/src/preferences/keymap/Jamfile +++ b/src/preferences/keymap/Jamfile @@ -5,6 +5,8 @@ SetSubDirSupportedPlatformsBeOSCompatible ; UsePrivateHeaders interface ; Preference Keymap : + KeyboardLayout.cpp + KeyboardLayoutView.cpp KeymapApplication.cpp KeymapWindow.cpp KeymapListItem.cpp diff --git a/src/preferences/keymap/KeymapWindow.cpp b/src/preferences/keymap/KeymapWindow.cpp index cb3ea6aff4..23c3afb1b6 100644 --- a/src/preferences/keymap/KeymapWindow.cpp +++ b/src/preferences/keymap/KeymapWindow.cpp @@ -1,36 +1,36 @@ /* - * Copyright 2004-2008 Haiku Inc. All rights reserved. + * Copyright 2004-2009 Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Sandor Vroemisse * Jérôme Duval * Alexandre Deckner, alex@zappotek.com + * Axel Dörfler, axeld@pinc-software.de. */ +#include "KeymapWindow.h" + +#include + #include -#include -#include -#include #include -#include -#include #include #include -#include +#include #include +#include #include #include -#include +#include #include #include -#include -#include -#include -#include "KeymapWindow.h" + +#include "KeyboardLayoutView.h" #include "KeymapListItem.h" #include "KeymapApplication.h" + static const uint32 kMsgMenuFileOpen = 'mMFO'; static const uint32 kMsgMenuFileSave = 'mMFS'; static const uint32 kMsgMenuFileSaveAs = 'mMFA'; @@ -46,52 +46,57 @@ static const uint32 kMsgUserMapSelected = 'UmST'; static const uint32 kMsgUseKeymap = 'UkyM'; static const uint32 kMsgRevertKeymap = 'Rvrt'; -KeymapWindow::KeymapWindow() - : BWindow(BRect(80, 25, 750, 280), "Keymap", B_TITLED_WINDOW, - B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS ) -{ - fFirstTime = true; - - // Add the menu bar - BMenuBar *menubar = AddMenuBar(); - // The view to hold all but the menu bar - BRect bounds = Bounds(); - bounds.top = menubar->Bounds().bottom + 1; - BBox *placeholderView = new BBox(bounds, "placeholderView", - B_FOLLOW_ALL); - placeholderView->SetBorder(B_NO_BORDER); - AddChild(placeholderView); - - // Create the Maps box and contents - AddMaps(placeholderView); - - fMapView = new MapView(BRect(205, 15, 655, 189), "mapView", &fCurrentMap); - placeholderView->AddChild(fMapView); - +KeymapWindow::KeymapWindow() + : BWindow(BRect(80, 50, 880, 380), "Keymap", B_TITLED_WINDOW, + B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS), + fFirstTime(true) +{ + SetLayout(new BGroupLayout(B_VERTICAL)); + + fKeyboardLayoutView = new KeyboardLayoutView("layout"); + fKeyboardLayoutView->SetKeymap(&fCurrentMap); + + fUseButton = new BButton("useButton", "Use", new BMessage(kMsgUseKeymap)); + fRevertButton = new BButton("revertButton", "Revert", + new BMessage(kMsgRevertKeymap)); + + // controls pane + AddChild(BGroupLayoutBuilder(B_VERTICAL) + .Add(_CreateMenu()) + .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10) + .Add(_CreateMapLists(), 0.25) + .Add(BGroupLayoutBuilder(B_VERTICAL, 10) + .Add(fKeyboardLayoutView) + .AddGlue(0.0) + .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10) + .AddGlue(0.0) + .Add(fUseButton) + .Add(fRevertButton))) + .SetInsets(10, 10, 10, 10))); + +#if 0 BMenuItem *item = fFontMenu->FindMarked(); if (item) { fMapView->SetFontFamily(item->Label()); } - - // The 'Use' button - fUseButton = new BButton(BRect(582, 200, 655, 220), "useButton", "Use", - new BMessage(kMsgUseKeymap)); - placeholderView->AddChild(fUseButton); - - // The 'Revert' button - fRevertButton = new BButton(BRect(497, 200, 570, 220), "revertButton", - "Revert", new BMessage(kMsgRevertKeymap)); - placeholderView->AddChild(fRevertButton); - UpdateButtons(); - +#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); + + _UpdateButtons(); + BPath path; find_directory(B_USER_SETTINGS_DIRECTORY, &path); path.Append("Keymap"); - + entry_ref ref; get_ref_for_path(path.Path(), &ref); - + BDirectory userKeymapsDir(&ref); if (userKeymapsDir.InitCheck() != B_OK) { create_directory(path.Path(), S_IRWXU | S_IRWXG | S_IRWXO); @@ -102,6 +107,27 @@ KeymapWindow::KeymapWindow() B_FILE_NODE, false, NULL); fSavePanel = new BFilePanel(B_SAVE_PANEL, &messenger, &ref, B_FILE_NODE, false, NULL); + + BScreen screen(this); + + float width = Frame().Width(); + float height = Frame().Height(); + + // Make sure we can fit on screen + if (screen.Frame().Width() < Frame().Width()) + width = screen.Frame().Width(); + if (screen.Frame().Height() < Frame().Height()) + height = screen.Frame().Height(); + + // See if we can use a larger default size + if (screen.Frame().Width() > 1200) { + width = 1000; + height = 400; + } + + // TODO: store and restore position and size! + ResizeTo(width, height); + MoveTo(BAlert::AlertPosition(width, height)); } @@ -112,20 +138,14 @@ KeymapWindow::~KeymapWindow(void) } -BMenuBar * -KeymapWindow::AddMenuBar() +BMenuBar* +KeymapWindow::_CreateMenu() { - BRect bounds; - BMenu *menu; - BMenuItem *currentItem; - BMenuBar *menubar; + BMenuBar* menuBar = new BMenuBar(Bounds(), "menubar"); + BMenuItem* currentItem; - bounds = Bounds(); - menubar = new BMenuBar(bounds, "menubar"); - AddChild(menubar); - // Create the File menu - menu = new BMenu("File"); + BMenu* menu = new BMenu("File"); menu->AddItem(new BMenuItem("Open" B_UTF8_ELLIPSIS, new BMessage(kMsgMenuFileOpen), 'O')); menu->AddSeparatorItem(); @@ -138,8 +158,9 @@ KeymapWindow::AddMenuBar() menu->AddSeparatorItem(); menu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q')); - menubar->AddItem(menu); + menuBar->AddItem(menu); +#if 0 // Create the Edit menu menu = new BMenu("Edit"); currentItem = new BMenuItem("Undo", @@ -158,8 +179,8 @@ KeymapWindow::AddMenuBar() menu->AddSeparatorItem(); menu->AddItem(new BMenuItem( "Select All", new BMessage(kMsgMenuEditSelectAll), 'A')); - menubar->AddItem(menu); - + menuBar->AddItem(menu); + // Create the Font menu fFontMenu = new BMenu("Font"); fFontMenu->SetRadioMode(true); @@ -167,10 +188,10 @@ KeymapWindow::AddMenuBar() 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++ ) + + for (int32 i = 0; i < numFamilies; i++) { if (get_font_family(i, &family, &flags) == B_OK) { BMenuItem *item = new BMenuItem(family, new BMessage(kMsgMenuFontChanged)); @@ -178,48 +199,52 @@ KeymapWindow::AddMenuBar() if (strcmp(family, current_family) == 0) item->SetMarked(true); } - menubar->AddItem(fFontMenu); - - return menubar; + } + menuBar->AddItem(fFontMenu); +#endif + + return menuBar; } -void -KeymapWindow::AddMaps(BView *placeholderView) +BView* +KeymapWindow::_CreateMapLists() { // The System list - BStringView *systemLabel = new BStringView(BRect(13, 5, 143, 28), "system", "System:"); - placeholderView->AddChild(systemLabel); - - BRect bounds = BRect(13, 27, 173, 130); - fSystemListView = new BListView(bounds, "systemList"); - - placeholderView->AddChild(new BScrollView("systemScrollList", fSystemListView, - B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, false, true)); + BStringView* systemLabel = new BStringView("system", "System:"); + fSystemListView = new BListView("systemList"); fSystemListView->SetSelectionMessage(new BMessage(kMsgSystemMapSelected)); - // The User list - BStringView *userLabel = new BStringView(BRect(13, 135, 143, 153), "user", "User:"); - placeholderView->AddChild(userLabel); + 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); - bounds = BRect(13, 155, 173, 225); - fUserListView = new BListView(bounds, "userList"); // '(Current)' - KeymapListItem *currentKeymapItem = static_cast(fUserListView->FirstItem()); + KeymapListItem *currentKeymapItem + = static_cast(fUserListView->FirstItem()); if (currentKeymapItem != NULL) fUserListView->AddItem(currentKeymapItem); - // Saved keymaps - placeholderView->AddChild(new BScrollView("userScrollList", fUserListView, - B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, false, true)); - fUserListView->SetSelectionMessage(new BMessage(kMsgUserMapSelected)); - - FillSystemMaps(); - FillUserMaps(); - // try and find the current map name in the two list views (if the name was read at all) - if (!SelectCurrentMap(fSystemListView)) - if (!SelectCurrentMap(fUserListView)) - fUserListView->Select(0L); + // Saved keymaps + + _FillSystemMaps(); + _FillUserMaps(); + + _SetListViewSize(fSystemListView); + _SetListViewSize(fUserListView); + + return BGroupLayoutBuilder(B_VERTICAL) + .Add(systemLabel) + .Add(systemScroller, 3) + .Add(userLabel) + .Add(userScroller); } @@ -234,7 +259,7 @@ KeymapWindow::QuitRequested() void KeymapWindow::MessageReceived(BMessage* message) { - switch(message->what) { + switch (message->what) { case B_SIMPLE_DATA: case B_REFS_RECEIVED: { @@ -243,27 +268,28 @@ KeymapWindow::MessageReceived(BMessage* message) while (message->FindRef("refs", i++, &ref) == B_OK) { fCurrentMap.Load(ref); } - fMapView->Invalidate(); + fKeyboardLayoutView->SetKeymap(&fCurrentMap); fSystemListView->DeselectAll(); fUserListView->DeselectAll(); - } break; + } + case B_SAVE_REQUESTED: { entry_ref ref; const char *name; - if ((message->FindRef("directory", &ref) == B_OK) - && (message->FindString("name", &name) == B_OK)) { - + if (message->FindRef("directory", &ref) == B_OK + && message->FindString("name", &name) == B_OK) { BDirectory directory(&ref); BEntry entry(&directory, name); entry.GetRef(&ref); fCurrentMap.Save(ref); - - FillUserMaps(); + + _FillUserMaps(); } - } break; + } + case kMsgMenuFileOpen: fOpenPanel->Show(); break; @@ -272,6 +298,8 @@ KeymapWindow::MessageReceived(BMessage* message) case kMsgMenuFileSaveAs: fSavePanel->Show(); break; + +#if 0 case kMsgMenuEditUndo: case kMsgMenuEditCut: case kMsgMenuEditCopy: @@ -280,19 +308,24 @@ KeymapWindow::MessageReceived(BMessage* message) case kMsgMenuEditSelectAll: fMapView->MessageReceived(message); break; +#endif +#if 0 case kMsgMenuFontChanged: { BMenuItem *item = fFontMenu->FindMarked(); - if (item) { + if (item != NULL) { fMapView->SetFontFamily(item->Label()); fMapView->Invalidate(); } - } break; + } +#endif + case kMsgSystemMapSelected: { KeymapListItem *keymapListItem = - static_cast(fSystemListView->ItemAt(fSystemListView->CurrentSelection())); + static_cast(fSystemListView->ItemAt( + fSystemListView->CurrentSelection())); if (keymapListItem) { fCurrentMap.Load(keymapListItem->KeymapEntry()); @@ -302,43 +335,47 @@ KeymapWindow::MessageReceived(BMessage* message) fFirstTime = false; } - fMapView->Invalidate(); - + fKeyboardLayoutView->SetKeymap(&fCurrentMap); + // Deselect item in other BListView fUserListView->DeselectAll(); - UpdateButtons(); + _UpdateButtons(); } - } break; + } + case kMsgUserMapSelected: { KeymapListItem *keymapListItem = - static_cast(fUserListView->ItemAt(fUserListView->CurrentSelection())); - if (keymapListItem) { + static_cast(fUserListView->ItemAt( + fUserListView->CurrentSelection())); + if (keymapListItem != NULL) { fCurrentMap.Load(keymapListItem->KeymapEntry()); - + if (fFirstTime) { fPreviousMap.Load(keymapListItem->KeymapEntry()); fAppliedMap.Load(keymapListItem->KeymapEntry()); fFirstTime = false; } - - fMapView->Invalidate(); - + + fKeyboardLayoutView->SetKeymap(&fCurrentMap); + // Deselect item in other BListView fSystemListView->DeselectAll(); - UpdateButtons(); + _UpdateButtons(); } - } break; + } + case kMsgUseKeymap: - UseKeymap(); - UpdateButtons(); + _UseKeymap(); + _UpdateButtons(); break; case kMsgRevertKeymap: - RevertKeymap(); - UpdateButtons(); + _RevertKeymap(); + _UpdateButtons(); break; + default: BWindow::MessageReceived(message); break; @@ -346,8 +383,8 @@ KeymapWindow::MessageReceived(BMessage* message) } - void -KeymapWindow::UpdateButtons() +void +KeymapWindow::_UpdateButtons() { fUseButton->SetEnabled(!fCurrentMap.Equals(fAppliedMap)); fRevertButton->SetEnabled(!fCurrentMap.Equals(fPreviousMap)); @@ -355,7 +392,7 @@ KeymapWindow::UpdateButtons() void -KeymapWindow::RevertKeymap() +KeymapWindow::_RevertKeymap() { //saves previous map to the Key_map file @@ -373,24 +410,25 @@ KeymapWindow::RevertKeymap() printf("error when saving : %s", strerror(err)); return; } + fPreviousMap.Use(); fAppliedMap.Load(ref); - - fCurrentMapName = GetActiveKeymapName(); - - if (!SelectCurrentMap(fSystemListView)) - if (!SelectCurrentMap(fUserListView)) - fUserListView->Select(0L); + + fCurrentMapName = _GetActiveKeymapName(); + + if (!_SelectCurrentMap(fSystemListView) + && !_SelectCurrentMap(fUserListView)) + fUserListView->Select(0L); } void -KeymapWindow::UseKeymap() +KeymapWindow::_UseKeymap() { BPath path; if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) return; - + path.Append("Key_map"); entry_ref ref; @@ -404,12 +442,12 @@ KeymapWindow::UseKeymap() fCurrentMap.Use(); fAppliedMap.Load(ref); - fCurrentMapName = GetActiveKeymapName(); + fCurrentMapName = _GetActiveKeymapName(); } void -KeymapWindow::FillSystemMaps() +KeymapWindow::_FillSystemMaps() { BListItem *item; while ((item = fSystemListView->RemoveItem(static_cast(0)))) @@ -424,15 +462,16 @@ KeymapWindow::FillSystemMaps() BDirectory directory; entry_ref ref; - if (directory.SetTo(path.Path()) == B_OK) - while( directory.GetNextRef(&ref) == B_OK ) { + if (directory.SetTo(path.Path()) == B_OK) { + while (directory.GetNextRef(&ref) == B_OK) { fSystemListView->AddItem(new KeymapListItem(ref)); } + } } void -KeymapWindow::FillUserMaps() +KeymapWindow::_FillUserMaps() { BListItem *item; while ((item = fUserListView->RemoveItem(static_cast(0)))) @@ -449,37 +488,52 @@ KeymapWindow::FillUserMaps() fUserListView->AddItem(new KeymapListItem(ref, "(Current)")); - fCurrentMapName = GetActiveKeymapName(); + fCurrentMapName = _GetActiveKeymapName(); if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) return; - + path.Append("Keymap"); - + BDirectory directory; - - if (directory.SetTo(path.Path()) == B_OK) - while( directory.GetNextRef(&ref) == B_OK ) { + if (directory.SetTo(path.Path()) == B_OK) { + while (directory.GetNextRef(&ref) == B_OK) { fUserListView->AddItem(new KeymapListItem(ref)); } + } +} + + +void +KeymapWindow::_SetListViewSize(BListView* listView) +{ + float minWidth = 0; + for (int32 i = 0; i < listView->CountItems(); i++) { + BStringItem* item = (BStringItem*)listView->ItemAt(i); + float width = listView->StringWidth(item->Text()); + if (width > minWidth) + minWidth = width; + } + + listView->SetExplicitMinSize(BSize(minWidth + 8, 32)); } BString -KeymapWindow::GetActiveKeymapName() +KeymapWindow::_GetActiveKeymapName() { - BString mapName = "(Current)"; //safe default + BString mapName = "(Current)"; // safe default BPath path; if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) return mapName; - + path.Append("Key_map"); entry_ref ref; get_ref_for_path(path.Path(), &ref); BNode node(&ref); - + if (node.InitCheck() == B_OK) node.ReadAttrString("keymap:name", &mapName); @@ -488,1196 +542,19 @@ KeymapWindow::GetActiveKeymapName() bool -KeymapWindow::SelectCurrentMap(BListView *view) +KeymapWindow::_SelectCurrentMap(BListView* view) { - bool found = false; - if (fCurrentMapName.Length() > 0) { - for (int32 i = 0; i < view->CountItems(); i++) { - BStringItem *current = dynamic_cast(view->ItemAt(i)); - if (current && (fCurrentMapName == current->Text())) { - found = true; - view->Select(i); - view->ScrollToSelection(); - break; - } - } - } - return found; -} + if (fCurrentMapName.Length() <= 0) + return false; - -MapView::MapView(BRect rect, const char *name, Keymap* keymap) - : BControl(rect, name, NULL, NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW), - fCurrentFont(*be_plain_font), - fCurrentMap(keymap), - fCurrentMouseKey(0) -{ - // TODO: Properly handle font sensitivity in drawing the keys. - // This at least prevents the app from looking horrible until the font sensitivity for this app - // can be done the Right Way. - if (fCurrentFont.Size() > 14) - fCurrentFont.SetSize(14); - - BRect frameRect = BRect(14, 16, Bounds().right - 12, 30); - BRect textRect = frameRect; - textRect.OffsetTo(B_ORIGIN); - textRect.InsetBy(1, 1); - fTextView = new KeymapTextView(frameRect, "testzone", textRect, - B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_FRAME_EVENTS); - fTextView->MakeEditable(true); - fTextView->MakeSelectable(true); - - AddChild(fTextView); - - fBitmap = new BBitmap(Bounds(), B_RGB32, true, false); - fOffscreenView = new BView(Bounds(), "off_view", 0, 0); - - fBitmap->Lock(); - fBitmap->AddChild(fOffscreenView); - fBitmap->Unlock(); - - for (uint32 j = 0; j < 128; j++) - fKeysToDraw[j] = false; - - BRect keyRect = BRect(11, 50, 29, 68); - uint32 i = 1; - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - - // Fx keys - i++; - keyRect.OffsetBySelf(36, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - - i++; - keyRect.OffsetBySelf(27, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - - i++; - keyRect.OffsetBySelf(27, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - - // Pause, PrintScreen, ... - i++; - keyRect.OffsetBySelf(35, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - - // 1st line : numbers and backspace - i++; - keyRect = BRect(11, 78, 29, 96); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - keyRect.right += 18; - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - keyRect.left += 18; - - // Insert, pg up ... - i++; - keyRect.OffsetBySelf(35, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - - // 2nd line : tab and azerty ... - i = 0x26; - keyRect = BRect(11, 96, 38, 114); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(27, 0); - keyRect.right -= 9; - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - keyRect.right += 9; - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - keyRect.left += 9; - - // Suppr, pg down ... - i++; - keyRect.OffsetBySelf(35, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - - // 3rd line : caps and qsdfg ... - i = 0x3b; - keyRect = BRect(11, 114, 47, 132); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(36, 0); - keyRect.right -= 18; - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - keyRect.right += 18; - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - keyRect.left += 18; - - // 4th line : shift and wxcv ... - i = 0x4b; - keyRect = BRect(11, 132, 56, 150); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(45, 0); - keyRect.right -= 27; - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - keyRect.right += 27; - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - keyRect.left += 27; - - //5th line : Ctrl, Alt, Space ... - i = 0x5c; - keyRect = BRect(11, 150, 38, 168); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(27, 0); - keyRect.OffsetBySelf(26, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(27, 0); - keyRect.right += 92; - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.right -= 92; - keyRect.OffsetBySelf(92, 0); - keyRect.OffsetBySelf(27, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(26, 0); - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - - // Arrows - i++; - keyRect = BRect(298, 150, 316, 168); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i = 0x57; - keyRect.OffsetBySelf(-18, -18); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - - // numkeys - i = 0x22; - keyRect = BRect(369, 78, 387, 96); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i = 0x37; - keyRect.OffsetBySelf(-54, 18); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - keyRect.bottom += 18; - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i = 0x48; - keyRect.bottom -= 18; - keyRect.OffsetBySelf(-54, 18); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i = 0x58; - keyRect.OffsetBySelf(-36, 18); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.OffsetBySelf(18, 0); - keyRect.bottom += 18; - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i = 0x64; - keyRect.bottom -= 18; - keyRect.OffsetBySelf(-54, 18); - keyRect.right += 18; - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - i++; - keyRect.right -= 18; - keyRect.OffsetBySelf(36, 0); - fKeysRect[i] = keyRect; - fKeysToDraw[i] = true; - - for (uint32 j = 0; j < 128; j++) - fKeysVertical[j] = false; - - fKeysVertical[0x5e] = true; - - fActiveDeadKey = 0; - - for (int8 j = 0; j < 16; j++) - fOldKeyInfo.key_states[j] = 0; - fOldKeyInfo.modifiers = 0; -} - - -MapView::~MapView() -{ - delete fBitmap; -} - - -void -MapView::_InitOffscreen() -{ - if (fBitmap->Lock()) { - _DrawBackground(); - fOffscreenView->Sync(); - fBitmap->Unlock(); - } -} - - -void -MapView::AttachedToWindow() -{ - BControl::AttachedToWindow(); - - SetEventMask(B_KEYBOARD_EVENTS, 0); - SetViewColor(B_TRANSPARENT_COLOR); - fTextView->SetViewColor(255, 255, 255); - _InitOffscreen(); -} - - -void -MapView::_DrawBackground(){ - BRect r = fOffscreenView->Bounds(); - fOffscreenView->SetHighColor(0, 0, 0); - fOffscreenView->StrokeRect(r); - - r.InsetBySelf(1, 1); - fOffscreenView->SetHighColor(168, 168, 168); - fOffscreenView->StrokeRect(r); - fOffscreenView->SetHighColor(80, 80, 80); - fOffscreenView->StrokeLine(BPoint(r.left + 2, r.bottom), r.RightBottom()); - fOffscreenView->StrokeLine(r.RightTop()); - - r.InsetBySelf(1, 1); - fOffscreenView->SetHighColor(255, 255, 255); - fOffscreenView->StrokeRect(r); - fOffscreenView->SetHighColor(112, 112, 112); - fOffscreenView->StrokeLine(BPoint(r.left + 1, r.bottom), r.RightBottom()); - fOffscreenView->StrokeLine(r.RightTop()); - - r.InsetBySelf(1, 1); - fOffscreenView->SetHighColor(168, 168, 168); - fOffscreenView->FillRect(r); - - fOffscreenView->SetHighColor(255, 255, 255); - fOffscreenView->FillRect(BRect(r.right - 1, r.bottom - 1, r.right, r.bottom)); - fOffscreenView->SetHighColor(184, 184, 184); - fOffscreenView->StrokeLine(BPoint(r.right - 9, r.bottom), BPoint(r.right - 2, r.bottom)); - fOffscreenView->StrokeLine(BPoint(r.right, r.bottom - 9), BPoint(r.right, r.bottom - 2)); - - // Esc key - _DrawBorder(fOffscreenView, BRect(10, 49, 30, 69)); - - // Fx keys - _DrawBorder(fOffscreenView, BRect(46, 49, 120, 69)); - - _DrawBorder(fOffscreenView, BRect(127, 49, 201, 69)); - - _DrawBorder(fOffscreenView, BRect(208, 49, 282, 69)); - - // Pause, PrintScreen, ... - _DrawBorder(fOffscreenView, BRect(297, 49, 353, 69)); - - // Insert, pg up ... - _DrawBorder(fOffscreenView, BRect(297, 77, 353, 115)); - - fOffscreenView->SetHighColor(80, 80, 80); - fOffscreenView->StrokeLine(BPoint(10, 169), BPoint(10, 77)); - fOffscreenView->StrokeLine(BPoint(282, 77)); - fOffscreenView->SetHighColor(255, 255, 255); - fOffscreenView->StrokeLine(BPoint(282, 169)); - fOffscreenView->StrokeLine(BPoint(253, 169)); - fOffscreenView->SetHighColor(80, 80, 80); - fOffscreenView->StrokeLine(BPoint(253, 151)); - fOffscreenView->SetHighColor(255, 255, 255); - fOffscreenView->StrokeLine(BPoint(238, 151)); - fOffscreenView->StrokeLine(BPoint(238, 169)); - fOffscreenView->StrokeLine(BPoint(63, 169)); - fOffscreenView->SetHighColor(80, 80, 80); - fOffscreenView->StrokeLine(BPoint(63, 151)); - fOffscreenView->SetHighColor(255, 255, 255); - fOffscreenView->StrokeLine(BPoint(39, 151)); - fOffscreenView->StrokeLine(BPoint(39, 169)); - fOffscreenView->StrokeLine(BPoint(11, 169)); - - // Arrows - fOffscreenView->SetHighColor(80, 80, 80); - fOffscreenView->StrokeLine(BPoint(297, 169), BPoint(297, 149)); - fOffscreenView->StrokeLine(BPoint(315, 149)); - fOffscreenView->StrokeLine(BPoint(315, 131)); - fOffscreenView->StrokeLine(BPoint(335, 131)); - fOffscreenView->StrokeLine(BPoint(336, 149), BPoint(353, 149)); - fOffscreenView->SetHighColor(255, 255, 255); - fOffscreenView->StrokeLine(BPoint(335, 132), BPoint(335, 149)); - fOffscreenView->StrokeLine(BPoint(353, 150), BPoint(353, 169)); - fOffscreenView->StrokeLine(BPoint(298, 169)); - - // numkeys - _DrawBorder(fOffscreenView, BRect(368, 77, 442, 169)); - - _DrawLocksBackground(); - - // the line separator - r = BRect(11, 40, 353, 43); - fOffscreenView->SetHighColor(255, 255, 255); - fOffscreenView->StrokeLine(r.LeftBottom(), r.LeftTop()); - fOffscreenView->StrokeLine(r.RightTop()); - fOffscreenView->SetHighColor(80, 80, 80); - fOffscreenView->StrokeLine(r.RightBottom()); - fOffscreenView->StrokeLine(r.LeftBottom()); - r.OffsetBySelf(2, 4); - r.bottom = r.top + 1; - fOffscreenView->SetHighColor(136, 136, 136); - fOffscreenView->FillRect(r); - fOffscreenView->FillRect(BRect(354, 41, 355, 43)); - - // around the textview - fOffscreenView->SetHighColor(0, 0, 0); - r = BRect(11, 13, Bounds().right - 11, 31); - fOffscreenView->StrokeLine(r.LeftBottom(), r.LeftTop()); - fOffscreenView->StrokeLine(r.RightTop()); - fOffscreenView->SetHighColor(80, 80, 80); - fOffscreenView->StrokeLine(r.LeftBottom() + BPoint(1, 0), - r.LeftTop() + BPoint(1, 1)); - fOffscreenView->StrokeLine(r.RightTop() + BPoint(0,1)); - fOffscreenView->SetHighColor(136, 136, 136); - fOffscreenView->StrokeLine(r.LeftBottom() + BPoint(2, -1), - r.LeftTop() + BPoint(2, 2)); - fOffscreenView->StrokeLine(r.RightTop()+BPoint(0, 2)); - fOffscreenView->StrokeLine(r.LeftBottom()+BPoint(1, 0), - r.LeftBottom() + BPoint(1, 0)); - fOffscreenView->SetHighColor(255, 255, 255); - fOffscreenView->StrokeLine(r.RightTop() + BPoint(0, 1), r.RightBottom()); - fOffscreenView->StrokeLine(r.LeftBottom() + BPoint(2, 0)); - - _DrawKeysBackground(); - -} - - -void -MapView::Draw(BRect rect) -{ - // draw the background - if (!fBitmap->Lock()) - return; - - if (fOffscreenView->Bounds().Intersects(rect)) { - BRegion region(rect); - ConstrainClippingRegion(®ion); - DrawBitmapAsync(fBitmap, B_ORIGIN); - ConstrainClippingRegion(NULL); - } - - fBitmap->Unlock(); - - // draw symbols and lights - for (uint32 i = 1; i <= 128; i++) - if (fKeysToDraw[i] && rect.Intersects(fKeysRect[i])) - _DrawKey(i); - - if (rect.Intersects(BRect(368, 49, 442, 69))) - _DrawLocksLights(); -} - - -void -MapView::_DrawLocksBackground() -{ - _DrawBorder(fOffscreenView, BRect(368, 49, 442, 69)); - - escapement_delta delta; - delta.nonspace = 0.0; - BFont font(be_plain_font); - font.SetSize(8.0); - font.SetFlags(B_DISABLE_ANTIALIASING); - font.SetSpacing(B_CHAR_SPACING); - fOffscreenView->SetFont(&font); - BRect lightRect = BRect(372, 53, 386, 56); - - fOffscreenView->SetHighColor(80, 80, 80); - fOffscreenView->StrokeLine(lightRect.LeftBottom(), lightRect.RightBottom()); - fOffscreenView->StrokeLine(lightRect.RightTop()); - fOffscreenView->SetHighColor(255, 255, 255); - fOffscreenView->StrokeLine(BPoint(lightRect.right - 1, lightRect.top), - lightRect.LeftTop()); - fOffscreenView->StrokeLine(BPoint(lightRect.left, lightRect.bottom - 1)); - fOffscreenView->SetHighColor(0, 55, 0); - fOffscreenView->FillRect(lightRect.InsetByCopy(1, 1)); - fOffscreenView->SetHighColor(64, 64, 64); - fOffscreenView->DrawString("num", BPoint(lightRect.left - 2, 65), &delta); - - lightRect.OffsetBy(26, 0); - fOffscreenView->SetHighColor(80, 80, 80); - fOffscreenView->StrokeLine(lightRect.LeftBottom(), lightRect.RightBottom()); - fOffscreenView->StrokeLine(lightRect.RightTop()); - fOffscreenView->SetHighColor(255, 255, 255); - fOffscreenView->StrokeLine(BPoint(lightRect.right - 1, lightRect.top), - lightRect.LeftTop()); - fOffscreenView->StrokeLine(BPoint(lightRect.left, lightRect.bottom - 1)); - fOffscreenView->SetHighColor(0, 55, 0); - fOffscreenView->FillRect(lightRect.InsetByCopy(1, 1)); - fOffscreenView->SetHighColor(64, 64, 64); - fOffscreenView->DrawString("caps", BPoint(lightRect.left - 2, 65), &delta); - - lightRect.OffsetBy(26, 0); - fOffscreenView->SetHighColor(80, 80, 80); - fOffscreenView->StrokeLine(lightRect.LeftBottom(), lightRect.RightBottom()); - fOffscreenView->StrokeLine(lightRect.RightTop()); - fOffscreenView->SetHighColor(255, 255, 255); - fOffscreenView->StrokeLine(BPoint(lightRect.right - 1, lightRect.top), - lightRect.LeftTop()); - fOffscreenView->StrokeLine(BPoint(lightRect.left, lightRect.bottom - 1)); - fOffscreenView->SetHighColor(0, 55, 0); - fOffscreenView->FillRect(lightRect.InsetByCopy(1, 1)); - fOffscreenView->SetHighColor(64, 64, 64); - fOffscreenView->DrawString("scroll", BPoint(lightRect.left - 4, 65), &delta); -} - - -void MapView::_DrawLocksLights() -{ - BRect lightRect = BRect(372, 53, 386, 56); - lightRect.InsetBy(1, 1); - - SetHighColor(0, 55, 0); - if (fOldKeyInfo.modifiers & B_NUM_LOCK) - SetHighColor(0, 178, 0); - FillRect(lightRect); - - lightRect.OffsetBy(26, 0); - SetHighColor(0, 55, 0); - if (fOldKeyInfo.modifiers & B_CAPS_LOCK) - SetHighColor(0, 178, 0); - FillRect(lightRect); - - lightRect.OffsetBy(26, 0); - SetHighColor(0, 55, 0); - if (fOldKeyInfo.modifiers & B_SCROLL_LOCK) - SetHighColor(0, 178, 0); - FillRect(lightRect); -} - - -void -MapView::_InvalidateKeys() -{ - Invalidate(); -} - - -void -MapView::_InvalidateKey(uint32 keyCode) -{ - Invalidate(fKeysRect[keyCode]); - -} - - -void -MapView::_DrawKeysBackground() -{ - for (uint32 keyCode = 1; keyCode <= 128; keyCode++){ - - BRect r = fKeysRect[keyCode]; - if (!r.IsValid()) - return; - fOffscreenView->SetHighColor(0, 0, 0); - fOffscreenView->StrokeRect(r); - - bool vertical = fKeysVertical[keyCode]; - int32 deadKey = fCurrentMap->IsDeadKey(keyCode, fOldKeyInfo.modifiers); - bool secondDeadKey = fCurrentMap->IsDeadSecondKey(keyCode, - fOldKeyInfo.modifiers, fActiveDeadKey); - - r.InsetBySelf(1, 1); - if (!secondDeadKey && deadKey == 0) { - fOffscreenView->SetHighColor(64, 64, 64); - fOffscreenView->StrokeRect(r); - - fOffscreenView->BeginLineArray(14); - rgb_color color1 = {200, 200, 200}; - fOffscreenView->AddLine(BPoint(r.left, r.bottom - 1), r.LeftTop(), - color1); - fOffscreenView->AddLine(r.LeftTop(), BPoint(r.left+3, r.top), - color1); - rgb_color color2 = {184, 184, 184}; - fOffscreenView->AddLine(BPoint(r.left + 3, r.top), - BPoint(r.left + 6, r.top), color2); - rgb_color color3 = {168, 168, 168}; - fOffscreenView->AddLine(BPoint(r.left + 6, r.top), - BPoint(r.left + 9, r.top), color3); - rgb_color color4 = {152, 152, 152}; - fOffscreenView->AddLine(BPoint(r.left + 9, r.top), - BPoint(r.right - 1, r.top), color4); - - r.InsetBySelf(1,1); - fOffscreenView->SetHighColor(255, 255, 255); - fOffscreenView->StrokeRect(r); - - rgb_color color6 = {96, 96, 96}; - fOffscreenView->AddLine(r.LeftBottom(), r.RightBottom(), color6); - rgb_color color5 = {160, 160, 160}; - fOffscreenView->AddLine(r.LeftBottom(), r.LeftBottom(), color5); - rgb_color color7 = {64, 64, 64}; - fOffscreenView->AddLine(r.RightBottom(), - BPoint(r.right, r.bottom - 1), color7); - fOffscreenView->AddLine(BPoint(r.right, r.bottom - 1), - BPoint(r.right, r.top - 1), color6); - fOffscreenView->AddLine(BPoint(r.right, r.top - 1), r.RightTop(), - color5); - rgb_color color8 = {255, 255, 255}; - fOffscreenView->AddLine(BPoint(r.left + 1, r.bottom - 1), - BPoint(r.left + 2, r.bottom - 1), color8); - fOffscreenView->AddLine(BPoint(r.left + 2, r.bottom - 1), - BPoint(r.right - 1, r.bottom - 1), color1); - fOffscreenView->AddLine(BPoint(r.right - 1, r.bottom - 1), - BPoint(r.right - 1, r.bottom - 2), color5); - fOffscreenView->AddLine(BPoint(r.right - 1, r.bottom - 2), - BPoint(r.right - 1, r.top + 1), color1); - fOffscreenView->EndLineArray(); - } - - r.InsetBySelf(1, 1); - r.bottom -= 1; - BRect fillRect = r; - - if (!vertical) { - int32 w1 = 4; - int32 w2 = 3; - if (fKeysRect[keyCode].Width() > 20) { - w1 = 6; - w2 = 6; - } - - fillRect.right = fillRect.left + w1; - fOffscreenView->SetHighColor(152, 152, 152); - fOffscreenView->FillRect(fillRect); - fillRect.left += w1; - fillRect.right = fillRect.left + w2; - fOffscreenView->SetHighColor(168, 168, 168); - fOffscreenView->FillRect(fillRect); - fillRect.left += w2; - fillRect.right = r.right - 1; - fOffscreenView->SetHighColor(184, 184, 184); - fOffscreenView->FillRect(fillRect); - } else { - fOffscreenView->SetHighColor(200, 200, 200); - fillRect.right -= 1; - fillRect.bottom = fillRect.top + 2; - fOffscreenView->FillRect(fillRect); - fOffscreenView->SetHighColor(184, 184, 184); - fillRect.OffsetBySelf(0, 3); - fOffscreenView->FillRect(fillRect); - fOffscreenView->SetHighColor(168, 168, 168); - fillRect.OffsetBySelf(0, 3); - fOffscreenView->FillRect(fillRect); - fOffscreenView->SetHighColor(152, 152, 152); - fillRect.OffsetBySelf(0, 3); - fOffscreenView->FillRect(fillRect); - } - } - -} - - -void -MapView::_DrawKey(uint32 keyCode) -{ - BRect r = fKeysRect[keyCode]; - if (!r.IsValid()) - return; - - bool pressed = (fOldKeyInfo.key_states[keyCode >> 3] & (1 << (7 - keyCode % 8))) || (keyCode == fCurrentMouseKey); - int32 deadKey = fCurrentMap->IsDeadKey(keyCode, fOldKeyInfo.modifiers); - bool secondDeadKey = fCurrentMap->IsDeadSecondKey(keyCode, fOldKeyInfo.modifiers, fActiveDeadKey); - - if (!pressed) { - r.InsetBySelf(1, 1); - if (secondDeadKey) { - SetHighColor(255, 0, 0); - StrokeRect(r); - r.InsetBySelf(1, 1); - StrokeRect(r); - } else if (deadKey > 0) { - SetHighColor(255, 255, 0); - StrokeRect(r); - r.InsetBySelf(1, 1); - StrokeRect(r); - } - } else { - r.InsetBySelf(1, 1); - - if (secondDeadKey) { - SetHighColor(255, 0, 0); - StrokeRect(r); - r.InsetBySelf(1, 1); - StrokeRect(r); - } else if (deadKey > 0) { - SetHighColor(255, 255, 0); - StrokeRect(r); - r.InsetBySelf(1, 1); - StrokeRect(r); - } else { - SetHighColor(48, 48, 48); - StrokeRect(r); - - BeginLineArray(2); - rgb_color color1 = {136, 136, 136}; - AddLine(BPoint(r.left + 1, r.bottom), r.RightBottom(), color1); - AddLine(r.RightBottom(), BPoint(r.right, r.top + 1), color1); - EndLineArray(); - - r.InsetBySelf(1, 1); - SetHighColor(72, 72, 72); - StrokeRect(r); - - BeginLineArray(4); - rgb_color color2 = {48, 48, 48}; - AddLine(r.LeftTop(), r.LeftTop(), color2); - rgb_color color3 = {152, 152, 152}; - AddLine(BPoint(r.left + 1, r.bottom), r.RightBottom(), color3); - AddLine(r.RightBottom(), r.RightTop(), color3); - rgb_color color4 = {160, 160, 160}; - AddLine(r.RightTop(), r.RightTop(), color4); - EndLineArray(); - } - - r.InsetBySelf(1, 1); - SetHighColor(112, 112, 112); - FillRect(r); - SetHighColor(136, 136, 136); - StrokeLine(r.LeftTop(), r.LeftTop()); - } - - char *str = NULL; - int32 numBytes; - - fCurrentMap->GetChars(keyCode, fOldKeyInfo.modifiers, fActiveDeadKey, &str, &numBytes); - if (str) { - bool hasGlyphs; - if (deadKey > 0) { - delete[] str; - switch (deadKey) { - case 1: str = strdup("'"); break; - case 2: str = strdup("`"); break; - case 3: str = strdup("^"); break; - case 4: str = strdup("\""); break; - case 5: str = strdup("~"); break; - } - } - fCurrentFont.GetHasGlyphs(str, 1, &hasGlyphs); - - if (hasGlyphs) { - SetFont(&fCurrentFont); - SetHighColor(0, 0, 0); - SetLowColor(160, 160, 160); - BPoint point = fKeysRect[keyCode].LeftBottom(); - point.x += 5; - point.y -= 5; - if (pressed) { - point.y += 1; - SetLowColor(112, 112, 112); - } - DrawString(str, point); - } - delete[] str; - } -} - - -void -MapView::_DrawBorder(BView *view, const BRect& rect) -{ - rgb_color gray = {80, 80, 80}; - rgb_color white = {255, 255, 255}; - - view->BeginLineArray(4); - view->AddLine(rect.LeftTop(), rect.LeftBottom(), gray); - view->AddLine(rect.LeftTop(), rect.RightTop(), gray); - view->AddLine(BPoint(rect.left + 1, rect.bottom), rect.RightBottom(), white); - view->AddLine(rect.RightBottom(), BPoint(rect.right, rect.top + 1), white); - view->EndLineArray(); -} - - -void -MapView::MessageReceived(BMessage *msg) -{ - switch (msg->what) { - case kMsgMenuEditUndo: - fTextView->Undo(be_clipboard); - break; - case kMsgMenuEditCut: - fTextView->Cut(be_clipboard); - break; - case kMsgMenuEditCopy: - fTextView->Copy(be_clipboard); - break; - case kMsgMenuEditPaste: - fTextView->Paste(be_clipboard); - break; - case kMsgMenuEditClear: - fTextView->Clear(); - break; - case kMsgMenuEditSelectAll: - fTextView->SelectAll(); - break; - case B_KEY_DOWN: - case B_KEY_UP: - case B_UNMAPPED_KEY_DOWN: - case B_UNMAPPED_KEY_UP: - case B_MODIFIERS_CHANGED: { - key_info info; - const uint8 *states; - ssize_t size; - - if ((msg->FindData("states", B_UINT8_TYPE, reinterpret_cast(&states), &size) != B_OK) - || (msg->FindInt32("modifiers", reinterpret_cast(&info.modifiers)) != B_OK)) - break; - - if (fOldKeyInfo.modifiers != info.modifiers) { - fOldKeyInfo.modifiers = info.modifiers; - for (int8 i = 0; i < 16; i++) - fOldKeyInfo.key_states[i] = states[i]; - _InvalidateKeys(); - _DrawLocksLights(); - } else { - - int32 keyCode = -1; - for (int8 i = 0; i < 16; i++) - if (fOldKeyInfo.key_states[i] != states[i]) { - uint8 stbits = fOldKeyInfo.key_states[i] ^ states[i]; - fOldKeyInfo.key_states[i] = states[i]; - for (int8 j = 7; stbits; j--, stbits >>= 1) - if (stbits & 1) { - keyCode = i * 8 + j; - _InvalidateKey(keyCode); - } - } - - if (keyCode < 0) - for (int8 i = 0; i < 16; i++) { - uint8 stbits = states[i]; - for (int8 j = 7; stbits; j--, stbits >>= 1) - if (stbits & 1) { - keyCode = i * 8 + j; - if (!fCurrentMap->IsModifierKey(keyCode)) { - i = 16; - break; - } - } - } - - if (Window()->IsActive() - && msg->what == B_KEY_DOWN) { - char *str = NULL; - int32 numBytes; - if (fActiveDeadKey) { - fCurrentMap->GetChars(keyCode, fOldKeyInfo.modifiers, fActiveDeadKey, &str, &numBytes); - if (numBytes > 0) { - fTextView->FakeKeyDown(str, numBytes); - } - fActiveDeadKey = 0; - _InvalidateKeys(); - } else { - fCurrentMap->GetChars(keyCode, fOldKeyInfo.modifiers, fActiveDeadKey, &str, &numBytes); - fActiveDeadKey = fCurrentMap->IsDeadKey(keyCode, fOldKeyInfo.modifiers); - if (fActiveDeadKey) - _InvalidateKeys(); - else if (numBytes > 0) { - fTextView->FakeKeyDown(str, numBytes); - } - } - delete[] str; - } - } - break; - } - default: - BControl::MessageReceived(msg); - } -} - - -void -MapView::KeyDown(const char* bytes, int32 numBytes) -{ - MessageReceived(Window()->CurrentMessage()); -} - - -void -MapView::KeyUp(const char* bytes, int32 numBytes) -{ - MessageReceived(Window()->CurrentMessage()); -} - - -void -MapView::MouseDown(BPoint point) -{ - uint32 buttons; - GetMouse(&point, &buttons); - if (buttons & B_PRIMARY_MOUSE_BUTTON) { - fCurrentMouseKey = 0; - for (int32 i = 0; i < 128; i++) { - if (fKeysRect[i].IsValid() && fKeysRect[i].Contains(point)) { - fCurrentMouseKey = i; - _DrawKey(fCurrentMouseKey); - char *str = NULL; - int32 numBytes; - fCurrentMap->GetChars(fCurrentMouseKey, fOldKeyInfo.modifiers, fActiveDeadKey, &str, &numBytes); - if (numBytes > 0) - fTextView->FakeKeyDown(str, numBytes); - - delete[] str; - SetTracking(true); - SetMouseEventMask(B_POINTER_EVENTS, - B_LOCK_WINDOW_FOCUS | B_NO_POINTER_HISTORY); - break; - } + for (int32 i = 0; i < view->CountItems(); i++) { + BStringItem* current = dynamic_cast(view->ItemAt(i)); + if (current != NULL && fCurrentMapName == current->Text()) { + view->Select(i); + view->ScrollToSelection(); + return true; } } -} - - -void -MapView::MouseUp(BPoint point) -{ - if (IsTracking()) - SetTracking(false); - uint32 value = fCurrentMouseKey; - fCurrentMouseKey = 0; - _InvalidateKey(value); -} - - -void -MapView::MouseMoved(BPoint point, uint32 transit, const BMessage *msg) -{ - if (IsTracking()) { - uint32 value = fCurrentMouseKey; - for (int32 i = 0; i < 128; i++) { - if (fKeysRect[i].Contains(point) && !fKeysRect[value].Contains(point)) { - fCurrentMouseKey = i; - _InvalidateKey(value); - _InvalidateKey(fCurrentMouseKey); - char *str = NULL; - int32 numBytes; - fCurrentMap->GetChars(fCurrentMouseKey, fOldKeyInfo.modifiers, fActiveDeadKey, &str, &numBytes); - if (numBytes > 0) { - fTextView->FakeKeyDown(str, numBytes); - delete[] str; - } - break; - } - } - } - BControl::MouseMoved(point, transit, msg); -} - - -void -MapView::SetFontFamily(const font_family family) -{ - fCurrentFont.SetFamilyAndStyle(family, NULL); - fTextView->SetFontAndColor(&fCurrentFont); + + return false; } diff --git a/src/preferences/keymap/KeymapWindow.h b/src/preferences/keymap/KeymapWindow.h index 9bb6abf242..7a4e4647c5 100644 --- a/src/preferences/keymap/KeymapWindow.h +++ b/src/preferences/keymap/KeymapWindow.h @@ -1,110 +1,68 @@ /* - * Copyright 2004-2008 Haiku Inc. All rights reserved. + * Copyright 2004-2009 Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Sandor Vroemisse * Jérôme Duval * Alexandre Deckner, alex@zappotek.com + * Axel Dörfler, axeld@pinc-software.de. */ - #ifndef KEYMAP_WINDOW_H #define KEYMAP_WINDOW_H -#include + #include #include -#include #include #include #include "Keymap.h" #include "KeymapTextView.h" +class BMenuBar; +class KeyboardLayoutView; class KeymapListItem; -class BBitmap; - -class MapView : public BControl -{ -public: - MapView(BRect rect, const char *name, Keymap *keymap); - ~MapView(); - - void Draw(BRect rect); - void AttachedToWindow(); - void KeyDown(const char* bytes, int32 numBytes); - void KeyUp(const char* bytes, int32 numBytes); - void MessageReceived(BMessage *msg); - void SetFontFamily(const font_family family); - void MouseDown(BPoint point); - void MouseUp(BPoint point); - void MouseMoved(BPoint point, uint32 transit, const BMessage *msg); - -private: - void _InvalidateKey(uint32 keyCode); - void _InvalidateKeys(); - void _DrawKey(uint32 keyCode); - void _DrawBackground(); - void _DrawKeysBackground(); - void _DrawLocksBackground(); - void _DrawBorder(BView *view, const BRect &borderRect); - void _DrawLocksLights(); - void _InitOffscreen(); - - BBitmap *fBitmap; - BView *fOffscreenView; - - key_info fOldKeyInfo; - BRect fKeysRect[128]; - bool fKeysVertical[128]; - bool fKeysToDraw[128]; - uint8 fKeyState[16]; - BFont fCurrentFont; - - Keymap *fCurrentMap; - KeymapTextView *fTextView; - uint32 fCurrentMouseKey; - uint8 fActiveDeadKey; // 0 : none, 1 : acute , ... -}; class KeymapWindow : public BWindow { public: - KeymapWindow(); - ~KeymapWindow(); - bool QuitRequested(); - void MessageReceived( BMessage* message ); + KeymapWindow(); + ~KeymapWindow(); + + virtual bool QuitRequested(); + virtual void MessageReceived(BMessage* message); protected: - BMenuBar *AddMenuBar(); - void AddMaps(BView *placeholderView); - void UseKeymap(); - void RevertKeymap(); - void UpdateButtons(); - - void FillSystemMaps(); - void FillUserMaps(); - - bool SelectCurrentMap(BListView *list); - BString GetActiveKeymapName(); + BMenuBar* _CreateMenu(); + BView* _CreateMapLists(); - BListView *fSystemListView; - BListView *fUserListView; - // the map that's currently highlighted - BButton *fUseButton; - BButton *fRevertButton; - BMenu *fFontMenu; - - MapView *fMapView; - - Keymap fCurrentMap; - Keymap fPreviousMap; - Keymap fAppliedMap; - bool fFirstTime; - BString fCurrentMapName; - - BFilePanel *fOpenPanel; // the file panel to open - BFilePanel *fSavePanel; // the file panel to save + void _UseKeymap(); + void _RevertKeymap(); + void _UpdateButtons(); + + void _FillSystemMaps(); + void _FillUserMaps(); + void _SetListViewSize(BListView* listView); + + bool _SelectCurrentMap(BListView *list); + BString _GetActiveKeymapName(); + + BListView* fSystemListView; + BListView* fUserListView; + BButton* fUseButton; + BButton* fRevertButton; + //BMenu* fFontMenu; + KeyboardLayoutView* fKeyboardLayoutView; + + Keymap fCurrentMap; + Keymap fPreviousMap; + Keymap fAppliedMap; + bool fFirstTime; + BString fCurrentMapName; + + BFilePanel* fOpenPanel; + BFilePanel* fSavePanel; }; -#endif // KEYMAP_WINDOW_H +#endif // KEYMAP_WINDOW_H