diff --git a/src/prefs/keymap/Jamfile b/src/prefs/keymap/Jamfile index 38384c415d..feacd5d7f1 100644 --- a/src/prefs/keymap/Jamfile +++ b/src/prefs/keymap/Jamfile @@ -5,5 +5,6 @@ AddResources Keymap : Keymap.rdef ; Preference Keymap : KeymapApplication.cpp KeymapWindow.cpp - KeymapListItem.cpp + KeymapListItem.cpp + Keymap.cpp : be ; diff --git a/src/prefs/keymap/Keymap.cpp b/src/prefs/keymap/Keymap.cpp new file mode 100644 index 0000000000..a1d53207c9 --- /dev/null +++ b/src/prefs/keymap/Keymap.cpp @@ -0,0 +1,142 @@ +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +// +// Copyright (c) 2004, Haiku +// +// This software is part of the Haiku distribution and is covered +// by the Haiku license. +// +// +// File: Keymap.cpp +// Author: Sandor Vroemisse, Jérôme Duval +// Description: Keymap Preferences +// Created : July 12, 2004 +// +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ + +#include "Keymap.h" +#include +#include +#include +#include + +static void +print_key( char *chars, int32 offset ) +{ + int size = chars[offset++]; + + switch( size ) { + case 0: + // Not mapped + printf( "N/A" ); + break; + + case 1: + // 1-byte UTF-8/ASCII character + printf( "%c", chars[offset] ); + break; + + default: + // 2-, 3-, or 4-byte UTF-8 character + { + char *str = new char[size + 1]; + strncpy( str, &(chars[offset]), size ); + str[size] = 0; + printf( "%s", str ); + delete [] str; + } + break; + } + + printf( "\t" ); +} + + +void +Keymap::GetChars(int32 keyCode, uint32 modifiers, char **chars) +{ + int32 offset = 0; + switch (modifiers & 0xff) { + case 0: offset = fKeys.normal_map[keyCode]; break; + case B_SHIFT_KEY: offset = fKeys.shift_map[keyCode]; break; + case B_CAPS_LOCK: offset = fKeys.caps_map[keyCode]; break; + case B_CAPS_LOCK|B_SHIFT_KEY: offset = fKeys.caps_shift_map[keyCode]; break; + case B_OPTION_KEY: offset = fKeys.option_map[keyCode]; break; + case B_OPTION_KEY|B_SHIFT_KEY: offset = fKeys.option_shift_map[keyCode]; break; + case B_OPTION_KEY|B_CAPS_LOCK: offset = fKeys.option_caps_map[keyCode]; break; + case B_OPTION_KEY|B_SHIFT_KEY|B_CAPS_LOCK: offset = fKeys.option_caps_shift_map[keyCode]; break; + case B_CONTROL_KEY: offset = fKeys.control_map[keyCode]; break; + } + + int size = fChars[offset++]; + + switch( size ) { + case 0: + // Not mapped + *chars = NULL; + break; + default: + // 1-, 2-, 3-, or 4-byte UTF-8 character + { + char *str = *chars = new char[size + 1]; + strncpy(str, &(fChars[offset]), size ); + str[size] = 0; + } + break; + } +} + + +void +Keymap::DumpKeymap() +{ + // Print a chart of the normal, shift, option, and option+shift + // keys. + printf( "Key #\tNormal\tShift\tCaps\tC+S\tOption\tO+S\tO+C\tO+C+S\tControl\n" ); + for( int idx = 0; idx < 128; idx++ ) { + printf( " 0x%x\t", idx ); + print_key( fChars, fKeys.normal_map[idx] ); + print_key( fChars, fKeys.shift_map[idx] ); + print_key( fChars, fKeys.caps_map[idx] ); + print_key( fChars, fKeys.caps_shift_map[idx] ); + print_key( fChars, fKeys.option_map[idx] ); + print_key( fChars, fKeys.option_shift_map[idx] ); + print_key( fChars, fKeys.option_caps_map[idx] ); + print_key( fChars, fKeys.option_caps_shift_map[idx] ); + print_key( fChars, fKeys.control_map[idx] ); + printf( "\n" ); + } + +} + + +status_t +Keymap::Load(entry_ref &ref) +{ + status_t err; + + BFile file(&ref, B_READ_ONLY); + if ((err = file.InitCheck()) != B_OK) { + printf("error %s\n", strerror(err)); + return err; + } + + if (file.Read(&fKeys, sizeof(fKeys)) < (ssize_t)sizeof(fKeys)) { + return B_BAD_VALUE; + } + + for (uint32 i=0; i +#include + +class Keymap +{ +public: + status_t Load(entry_ref &ref); + void DumpKeymap(); + void GetChars(int32 keyCode, uint32 modifiers, char **chars); +private: + char *fChars; + key_map fKeys; +}; + + +#endif //KEYMAP_H diff --git a/src/prefs/keymap/KeymapApplication.cpp b/src/prefs/keymap/KeymapApplication.cpp index 953f7f4ab6..582854d1ba 100644 --- a/src/prefs/keymap/KeymapApplication.cpp +++ b/src/prefs/keymap/KeymapApplication.cpp @@ -1,7 +1,24 @@ -#include -#include -#include -#include +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +// +// Copyright (c) 2004, Haiku +// +// This software is part of the Haiku distribution and is covered +// by the Haiku license. +// +// +// File: KeymapApplication.cpp +// Author: Sandor Vroemisse, Jérôme Duval +// Description: Keymap Preferences +// Created : July 12, 2004 +// +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ + +#include +#include +#include +#include +#include +#include #if DEBUG #include #include @@ -27,67 +44,11 @@ void KeymapApplication::MessageReceived( BMessage * message ) } -/* - * Returns a BList containing BEntry objects - * representing the systems' keymap files - */ -BList* KeymapApplication::SystemMaps() -{ - // TODO: find a constant containing this path and use that instead - return EntryList( "/boot/beos/etc/Keymap" ); -} - -BList* KeymapApplication::UserMaps() -{ - // TODO: find a constant containing this path and use that instead - return EntryList( "/boot/home/config/settings/Keymap" ); -} - -BList* KeymapApplication::EntryList( char *directoryPath ) -{ - BList *entryList; - BDirectory *directory; - BEntry *currentEntry; - entryList = new BList(); - directory = new BDirectory(); - if( directory->SetTo( directoryPath ) == B_OK ) - // put each files' name in the list - while( true ) { - currentEntry = new BEntry(); - if( directory->GetNextEntry( currentEntry, true ) != B_OK ) { - delete currentEntry; - break; - } - entryList->AddItem( currentEntry ); - #if DEBUG - char name[B_FILE_NAME_LENGTH]; - currentEntry->GetName( name ); - printf("Found: %s\n",name); - #endif //DEBUG - } - else { - // something went wrong; no system keymaps today - // TODO: catch error codes and act appropriately - - } - delete directory; - - return entryList; -} - -BEntry* KeymapApplication::CurrentMap() -{ - BEntry *entry; - - // TODO: find a constant containing this path and use that instead - entry = new BEntry( "/boot/home/config/settings/Key_map" ); - return entry; -} - -bool KeymapApplication::UseKeymap( BEntry *keymap ) +/*bool +KeymapApplication::UseKeymap( BEntry *keymap ) { // Copies keymap to ~/config/settings/key_map BFile *inFile; BFile *outFile; @@ -132,14 +93,18 @@ bool KeymapApplication::UseKeymap( BEntry *keymap ) return true; } -bool KeymapApplication::IsValidKeymap( BFile *inFile ) + +bool +KeymapApplication::IsValidKeymap( BFile *inFile ) { // TODO: implement this thing return true; } -int KeymapApplication::Copy( BFile *original, BFile *copy ) + +int +KeymapApplication::Copy( BFile *original, BFile *copy ) { char *buffer[ COPY_BUFFER_SIZE ]; int offset = 0; @@ -169,9 +134,11 @@ int KeymapApplication::Copy( BFile *original, BFile *copy ) } return errorCode; -} +}*/ -int KeymapApplication::NotifyInputServer() + +int +KeymapApplication::NotifyInputServer() { // This took me days to find out. Go figure. // Be didn't need to restart the thing - they prolly used @@ -182,10 +149,11 @@ int KeymapApplication::NotifyInputServer() } -int main () +int +main () { new KeymapApplication; be_app->Run(); delete be_app; - return 0; + return B_OK; } diff --git a/src/prefs/keymap/KeymapApplication.h b/src/prefs/keymap/KeymapApplication.h index 09d3e65ade..527bd2a130 100644 --- a/src/prefs/keymap/KeymapApplication.h +++ b/src/prefs/keymap/KeymapApplication.h @@ -1,12 +1,24 @@ -#ifndef OBOS_KEYMAP_APPLICATION_H -#define OBOS_KEYMAP_APPLICATION_H +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +// +// Copyright (c) 2004, Haiku +// +// This software is part of the Haiku distribution and is covered +// by the Haiku license. +// +// +// File: KeymapApplication.h +// Author: Sandor Vroemisse, Jérôme Duval +// Description: Keymap Preferences +// Created : July 12, 2004 +// +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ + +#ifndef KEYMAP_APPLICATION_H +#define KEYMAP_APPLICATION_H #include -#include #define APP_SIGNATURE "application/x-vnd.OpenBeOS-Keymap" -#define COPY_BUFFER_SIZE 1 * 1024 - class KeymapWindow; @@ -14,19 +26,15 @@ class KeymapApplication : public BApplication { public: KeymapApplication(); void MessageReceived(BMessage *message); - BList* SystemMaps(); - BList* UserMaps(); - BEntry* CurrentMap(); + bool UseKeymap( BEntry *keymap ); protected: KeymapWindow *fWindow; - BList* EntryList( char *directoryPath ); bool IsValidKeymap( BFile *inFile ); - int Copy( BFile *original, BFile *copy ); int NotifyInputServer(); }; -#endif // OBOS_KEYMAP_APPLICATION_H +#endif // KEYMAP_APPLICATION_H diff --git a/src/prefs/keymap/KeymapListItem.cpp b/src/prefs/keymap/KeymapListItem.cpp index 496b0b1fb4..4b238c46cb 100644 --- a/src/prefs/keymap/KeymapListItem.cpp +++ b/src/prefs/keymap/KeymapListItem.cpp @@ -1,3 +1,18 @@ +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +// +// Copyright (c) 2004, Haiku +// +// This software is part of the Haiku distribution and is covered +// by the Haiku license. +// +// +// File: KeymapListItem.cpp +// Author: Sandor Vroemisse, Jérôme Duval +// Description: Keymap Preferences +// Created : July 12, 2004 +// +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ + /* * A BStringItem modified such that it holds * the BEntry object it corresponds with @@ -6,23 +21,8 @@ #include "KeymapListItem.h" -KeymapListItem::KeymapListItem( BEntry *keymap ) - : BStringItem( "" ) +KeymapListItem::KeymapListItem( entry_ref &keymap, const char* name ) + : BStringItem( name ? name : keymap.name ), + fKeymap(keymap) { - char name[B_FILE_NAME_LENGTH]; - - fKeymap = keymap; - keymap->GetName( name ); - - SetText( name ); -} - -KeymapListItem::~KeymapListItem() -{ - delete fKeymap; -} - -BEntry* KeymapListItem::KeymapEntry() -{ - return fKeymap; } diff --git a/src/prefs/keymap/KeymapListItem.h b/src/prefs/keymap/KeymapListItem.h index 5d1325e0a8..934b888d92 100644 --- a/src/prefs/keymap/KeymapListItem.h +++ b/src/prefs/keymap/KeymapListItem.h @@ -1,24 +1,36 @@ +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +// +// Copyright (c) 2004, Haiku +// +// This software is part of the Haiku distribution and is covered +// by the Haiku license. +// +// +// File: KeymapListItem.h +// Author: Sandor Vroemisse, Jérôme Duval +// Description: Keymap Preferences +// Created : July 12, 2004 +// +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ + /* * A BStringItem modified such that it holds * the BEntry object it corresponds with */ -#ifndef OBOS_KEYMAP_LIST_ITEM_H -#define OBOS_KEYMAP_LIST_ITEM_H - -#include -#include +#ifndef KEYMAP_LIST_ITEM_H +#define KEYMAP_LIST_ITEM_H +#include +#include class KeymapListItem : public BStringItem { public: - KeymapListItem( BEntry *keymap ); - ~KeymapListItem(); - BEntry *KeymapEntry(); + KeymapListItem( entry_ref &keymap, const char* name = NULL); + entry_ref & KeymapEntry() { return fKeymap; }; protected: - BEntry *fKeymap; - + entry_ref fKeymap; }; -#endif //OBOS_KEYMAP_LIST_ITEM_H +#endif //KEYMAP_LIST_ITEM_H diff --git a/src/prefs/keymap/KeymapWindow.cpp b/src/prefs/keymap/KeymapWindow.cpp index 711196199b..e25b8eda5b 100644 --- a/src/prefs/keymap/KeymapWindow.cpp +++ b/src/prefs/keymap/KeymapWindow.cpp @@ -1,13 +1,32 @@ +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +// +// Copyright (c) 2004, Haiku +// +// This software is part of the Haiku distribution and is covered +// by the Haiku license. +// +// +// File: KeymapWindow.cpp +// Author: Sandor Vroemisse, Jérôme Duval +// Description: Keymap Preferences +// Created : July 12, 2004 +// +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ + #include #include #include #include #include +#include +#include #include #include #include +#include #include #include +#include #include #include "KeymapWindow.h" #include "KeymapListItem.h" @@ -32,41 +51,38 @@ KeymapWindow::KeymapWindow( BRect frame ) : BWindow( frame, WINDOW_TITLE, B_TITLED_WINDOW, B_NOT_ZOOMABLE|B_NOT_RESIZABLE|B_ASYNCHRONOUS_CONTROLS ) { - rgb_color tempColor; - BRect bounds = Bounds(); - BMenuBar *menubar; - - fApplication = (KeymapApplication*) be_app; - fSelectedMap = fApplication->CurrentMap(); - // Add the menu bar - menubar = AddMenuBar(); + BMenuBar *menubar = AddMenuBar(); // The view to hold all but the menu bar + BRect bounds = Bounds(); bounds.top = menubar->Bounds().bottom + 1; - fPlaceholderView = new BView( bounds, "placeholderView", + BView *placeholderView = new BView( bounds, "placeholderView", B_FOLLOW_NONE, 0 ); - tempColor = ui_color( B_MENU_BACKGROUND_COLOR ); - fPlaceholderView->SetViewColor( tempColor ); - AddChild( fPlaceholderView ); + placeholderView->SetViewColor(ui_color(B_MENU_BACKGROUND_COLOR)); + AddChild( placeholderView ); // Create the Maps box and contents - AddMaps(); + AddMaps(placeholderView); + + fMapView = new MapView(BRect(149,29,601,209), "mapView", &fCurrentMap); + AddChild(fMapView); + + BMenuItem *item = fFontMenu->FindMarked(); + if (item) { + fMapView->SetFontFamily(item->Label()); + } // The 'Use' button - bounds.Set( 527,200, 600,220 ); - fUseButton = new BButton( bounds, "useButton", "Use", + fUseButton = new BButton(BRect(527,200, 600,220), "useButton", "Use", new BMessage( USE_KEYMAP )); - fPlaceholderView->AddChild( fUseButton ); + placeholderView->AddChild( fUseButton ); // The 'Revert' button - bounds.Set( 442,200, 515,220 ); - fRevertButton = new BButton( bounds, "revertButton", "Revert", + fRevertButton = new BButton(BRect(442,200, 515,220), "revertButton", "Revert", new BMessage( REVERT )); - fPlaceholderView->AddChild( fRevertButton ); - - fMapView = new MapView(BRect(149,29,601,209), "mapView"); - AddChild(fMapView); + placeholderView->AddChild( fRevertButton ); + } @@ -120,7 +136,8 @@ KeymapWindow::AddMenuBar() menubar->AddItem( menu ); // Create the Font menu - menu = new BMenu( "Font" ); + fFontMenu = new BMenu( "Font" ); + fFontMenu->SetRadioMode(true); int32 numFamilies = count_font_families(); font_family family, current_family; font_style current_style; @@ -128,113 +145,70 @@ KeymapWindow::AddMenuBar() 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( MENU_FONT_CHANGED)); - menu->AddItem(item); + fFontMenu->AddItem(item); if(strcmp(family, current_family) == 0) item->SetMarked(true); } - menubar->AddItem( menu ); + menubar->AddItem( fFontMenu ); return menubar; } void -KeymapWindow::AddMaps() +KeymapWindow::AddMaps(BView *placeholderView) { // The Maps box BRect bounds = BRect(9,11,140,226); BBox *mapsBox = new BBox(bounds); mapsBox->SetLabel("Maps"); - fPlaceholderView->AddChild( mapsBox ); + placeholderView->AddChild( mapsBox ); // The System list BStringView *systemLabel = new BStringView(BRect(13,13,113,33), "system", "System"); mapsBox->AddChild(systemLabel); bounds = BRect( 13,35, 103,105 ); - BList *entryList = fApplication->SystemMaps(); fSystemListView = new BListView( bounds, "systemList" ); - BList *listItems = ListItemsFromEntryList( entryList ); - fSystemListView->AddList( listItems ); + mapsBox->AddChild( new BScrollView( "systemScrollList", fSystemListView, B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, false, true )); fSystemListView->SetSelectionMessage( new BMessage( SYSTEM_MAP_SELECTED )); - delete listItems; - delete entryList; // The User list BStringView *userLabel = new BStringView(BRect(13,110,113,128), "user", "User"); mapsBox->AddChild(userLabel); bounds = BRect(13,130,103,200); - entryList = fApplication->UserMaps(); fUserListView = new BListView( bounds, "userList" ); // '(Current)' - KeymapListItem *currentKeymapItem = ItemFromEntry( fApplication->CurrentMap() ); + KeymapListItem *currentKeymapItem = (KeymapListItem*)fUserListView->FirstItem(); if( currentKeymapItem != NULL ) fUserListView->AddItem( currentKeymapItem ); // Saved keymaps - listItems = ListItemsFromEntryList( entryList ); - fUserListView->AddList( listItems ); mapsBox->AddChild( new BScrollView( "systemScrollList", fUserListView, B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, false, true )); fUserListView->SetSelectionMessage( new BMessage( USER_MAP_SELECTED )); - delete listItems; - delete entryList; -} - - -BList* -KeymapWindow::ListItemsFromEntryList( BList * entryList) -{ - BEntry *currentEntry; - BList *listItems; - int nrItems; - #ifdef DEBUG - char name[B_FILE_NAME_LENGTH]; - #endif //DEBUG - - listItems = new BList(); - nrItems = entryList->CountItems(); - for( int index=0; indexItemAt( index ); - listItems->AddItem( new KeymapListItem( currentEntry )); - - #ifdef DEBUG - currentEntry->GetName( name ); - printf("New list item: %s\n",name); - #endif //DEBUG - } - - return listItems; -} - - -KeymapListItem* -KeymapWindow::ItemFromEntry( BEntry *entry ) -{ - KeymapListItem *item; - - if( entry->Exists() ) { - item = new KeymapListItem( entry ); - item->SetText( "(Current)" ); - } - else - item = NULL; - - return item; + FillSystemMaps(); + + FillUserMaps(); + + fUserListView->Select(0); + fCurrentMap.Load(((KeymapListItem*)fUserListView->FirstItem())->KeymapEntry()); } bool KeymapWindow::QuitRequested() { + if (!IsActive()) + return false; be_app->PostMessage( B_QUIT_REQUESTED ); return true; } @@ -262,49 +236,46 @@ KeymapWindow::MessageReceived( BMessage* message ) break; case MENU_EDIT_SELECT_ALL: break; + case MENU_FONT_CHANGED: + { + BMenuItem *item = fFontMenu->FindMarked(); + if (item) { + fMapView->SetFontFamily(item->Label()); + fMapView->Invalidate(); + } + } + break; case SYSTEM_MAP_SELECTED: - HandleSystemMapSelected( message ); + { + KeymapListItem *keymapListItem = + (KeymapListItem*)fSystemListView->ItemAt(fSystemListView->CurrentSelection()); + if (keymapListItem) { + fCurrentMap.Load(keymapListItem->KeymapEntry()); + fMapView->Invalidate(); + + // Deselect item in other BListView + fUserListView->DeselectAll(); + } + } break; case USER_MAP_SELECTED: - HandleUserMapSelected( message ); + { + KeymapListItem *keymapListItem = + (KeymapListItem*)fUserListView->ItemAt(fUserListView->CurrentSelection()); + if (keymapListItem) { + fCurrentMap.Load(keymapListItem->KeymapEntry()); + fMapView->Invalidate(); + + // Deselect item in other BListView + fSystemListView->DeselectAll(); + } + } break; case USE_KEYMAP: UseKeymap(); break; case REVERT: // do nothing, just like the original 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; - bool need_update = false; - - if ((message->FindData("states", 'UBYT', (const void **)&states, &size)==B_OK) - && (message->FindInt32("modifiers", (int32 *)&info.modifiers) == B_OK)) { - if (fMapView->fOldKeyInfo.modifiers != info.modifiers) { - need_update = true; - } - - for (int8 i=0; i<16; i++) - if (fMapView->fOldKeyInfo.key_states[i] != states[i]) { - need_update = true; - break; - } - - if (need_update) { - fMapView->fOldKeyInfo.modifiers = info.modifiers; - for (int8 j=0; j<16; j++) - fMapView->fOldKeyInfo.key_states[j] = states[j]; - fMapView->Invalidate(); - } - } - break; - } default: BWindow::MessageReceived( message ); break; @@ -312,72 +283,438 @@ KeymapWindow::MessageReceived( BMessage* message ) } -void -KeymapWindow::HandleSystemMapSelected( BMessage *selectionMessage ) -{ - HandleMapSelected( selectionMessage, fSystemListView, fUserListView ); -} - - -void -KeymapWindow::HandleUserMapSelected( BMessage *selectionMessage ) -{ - HandleMapSelected( selectionMessage, fUserListView, fSystemListView ); -} - - -void -KeymapWindow::HandleMapSelected( BMessage *selectionMessage, - BListView * selectedView, BListView * otherView ) -{ - int32 index; - KeymapListItem *keymapListItem; - - // Anything selected? - index = selectedView->CurrentSelection( 0 ); - if( index < 0 ) { - #if DEBUG - printf("index<0; HandleMapSelected ends here.\n"); - - #endif //DEBUG - return; - } - - // Store selected map in fSelectedMap - keymapListItem = (KeymapListItem*)selectedView->ItemAt( index ); - if( keymapListItem == NULL ) - return; - fSelectedMap = keymapListItem->KeymapEntry(); - #if DEBUG - char name[B_FILE_NAME_LENGTH]; - fSelectedMap->GetName( name ); - printf("fSelectedMap has been set to %s\n",name); - #endif //DEBUG - - // Deselect item in other BListView - otherView->DeselectAll(); -} - - void KeymapWindow::UseKeymap() { - if( fSelectedMap != NULL ) - fApplication->UseKeymap( fSelectedMap ); - else { - // There is no keymap selected! - BAlert *alert; - alert = new BAlert( "w>noKeymap", "No keymap has been selected", "Bummer", - NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT ); - alert->Go(); - } + //TODO } -MapView::MapView(BRect rect, const char *name) - : BView(rect, name, B_FOLLOW_LEFT|B_FOLLOW_TOP, B_WILL_DRAW) +void +KeymapWindow::FillSystemMaps() { + BPath path; + if (find_directory(B_BEOS_ETC_DIRECTORY, &path)!=B_OK) + return; + + path.Append("Keymap"); + + BDirectory directory; + entry_ref ref; + + if (directory.SetTo(path.Path()) == B_OK) + while( directory.GetNextRef(&ref) == B_OK ) { + fSystemListView->AddItem(new KeymapListItem(ref)); + } +} + +void +KeymapWindow::FillUserMaps() +{ + BPath path; + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path)!=B_OK) + return; + + path.Append("Key_map"); + + entry_ref ref; + get_ref_for_path(path.Path(), &ref); + + fUserListView->AddItem(new KeymapListItem(ref, "(Current)")); + + 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 ) { + fUserListView->AddItem(new KeymapListItem(ref)); + } +} + + +BEntry* +KeymapWindow::CurrentMap() +{ + return NULL; +} + + +MapView::MapView(BRect rect, const char *name, Keymap* keymap) + : BView(rect, name, B_FOLLOW_LEFT|B_FOLLOW_TOP, B_WILL_DRAW), + fCurrentFont(*be_plain_font), + fCurrentMap(keymap) +{ + BRect keyRect = BRect(11,50,29,68); + int32 i = 1; + fKeysRect[i] = keyRect; + + // Fx keys + i++; + keyRect.OffsetBySelf(36,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + + i++; + keyRect.OffsetBySelf(27,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + + i++; + keyRect.OffsetBySelf(27,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + + // Pause, PrintScreen, ... + i++; + keyRect.OffsetBySelf(35,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + + // 1st line : numbers and backspace + i++; + keyRect = BRect(11,78,29,96); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + keyRect.right += 18; + fKeysRect[i] = keyRect; + keyRect.left += 18; + + // Insert, pg up ... + i++; + keyRect.OffsetBySelf(35,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + + // 2nd line : tab and azerty ... + i = 0x26; + keyRect = BRect(11,96,38,114); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(27,0); + keyRect.right -= 9; + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + keyRect.right += 9; + fKeysRect[i] = keyRect; + keyRect.left += 9; + + // Suppr, pg down ... + i++; + keyRect.OffsetBySelf(35,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + + // 3rd line : caps and qsdfg ... + i = 0x3b; + keyRect = BRect(11,114,47,132); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(36,0); + keyRect.right -= 18; + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + keyRect.right += 18; + fKeysRect[i] = keyRect; + keyRect.left += 18; + + // 4th line : shift and wxcv ... + i = 0x4b; + keyRect = BRect(11,132,56,150); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(45,0); + keyRect.right -= 27; + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + keyRect.right += 27; + fKeysRect[i] = keyRect; + keyRect.left += 27; + + //5th line : Ctrl, Alt, Space ... + i = 0x5c; + keyRect = BRect(11,150,38,168); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(27,0); + keyRect.OffsetBySelf(26,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(27,0); + keyRect.right += 92; + fKeysRect[i] = keyRect; + i++; + keyRect.right -= 92; + keyRect.OffsetBySelf(92,0); + keyRect.OffsetBySelf(27,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(26,0); + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + + // Arrows + i++; + keyRect = BRect(298,150,316,168); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i = 0x57; + keyRect.OffsetBySelf(-18,-18); + fKeysRect[i] = keyRect; + + // numkeys + i = 0x22; + keyRect = BRect(369,78,387,96); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i = 0x37; + keyRect.OffsetBySelf(-54, 18); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + keyRect.bottom += 18; + fKeysRect[i] = keyRect; + i = 0x48; + keyRect.bottom -= 18; + keyRect.OffsetBySelf(-54, 18); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i = 0x58; + keyRect.OffsetBySelf(-36, 18); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + fKeysRect[i] = keyRect; + i++; + keyRect.OffsetBySelf(18,0); + keyRect.bottom += 18; + fKeysRect[i] = keyRect; + i = 0x64; + keyRect.bottom -= 18; + keyRect.OffsetBySelf(-54, 18); + keyRect.right += 18; + fKeysRect[i] = keyRect; + i++; + keyRect.right -= 18; + keyRect.OffsetBySelf(36,0); + fKeysRect[i] = keyRect; + + for (uint8 j = 0; j<128; j++) + fKeysVertical[j] = false; + + fKeysVertical[0x5e] = true; + + BRect frameRect = BRect(14, 16, Bounds().right-12, 30); + BRect textRect = frameRect; + textRect.OffsetTo(B_ORIGIN); + textRect.InsetBy(1,1); + fTextView = new BTextView(frameRect, "testzone", textRect, + B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_FRAME_EVENTS); + fTextView->MakeEditable(true); + fTextView->MakeSelectable(true); + fTextView->SetViewColor(255,255,255); + AddChild(fTextView); + } @@ -420,296 +757,126 @@ MapView::Draw(BRect rect) StrokeLine(BPoint(r.right, r.bottom-9), BPoint(r.right, r.bottom-2)); int32 i = 1; -#define isPressed(i) (fOldKeyInfo.key_states[i>>3] & (1 << (7 - i%8)) ) // Esc key - BRect keyRect = BRect(11,50,29,68); - DrawKey(keyRect, isPressed(i)); + DrawKey(i); - DrawBorder(keyRect.InsetByCopy(-1, -1)); + DrawBorder(BRect(10,49,30,69)); // Fx keys - i++; - keyRect.OffsetBySelf(36,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + + DrawBorder(BRect(46, 49, 120, 69)); - DrawBorder(BRect(keyRect.left - 55, 49, keyRect.right + 1, 69)); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + + DrawBorder(BRect(127, 49, 201, 69)); - i++; - keyRect.OffsetBySelf(27,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - - DrawBorder(BRect(keyRect.left - 55, 49, keyRect.right + 1, 69)); - - i++; - keyRect.OffsetBySelf(27,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - - DrawBorder(BRect(keyRect.left - 55, 49, keyRect.right + 1, 69)); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + + DrawBorder(BRect(208, 49, 282, 69)); // Pause, PrintScreen, ... - i++; - keyRect.OffsetBySelf(35,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - - DrawBorder(BRect(keyRect.left - 37, 49, keyRect.right + 1, 69)); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + + DrawBorder(BRect(297, 49, 353, 69)); // 1st line : numbers and backspace - i++; - keyRect = BRect(11,78,29,96); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - keyRect.right += 18; - DrawKey(keyRect, isPressed(i)); - keyRect.left += 18; - + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + // Insert, pg up ... - i++; - keyRect.OffsetBySelf(35,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(0x20)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(0x21)); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); - DrawBorder(BRect(keyRect.left - 37, 77, keyRect.right + 1, 115)); + DrawBorder(BRect(297, 77, 353, 115)); // 2nd line : tab and azerty ... i = 0x26; - keyRect = BRect(11,96,38,114); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(27,0); - keyRect.right -= 9; - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - keyRect.right += 9; - DrawKey(keyRect, isPressed(i)); - keyRect.left += 9; + DrawKey(i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); // Suppr, pg down ... - i++; - keyRect.OffsetBySelf(35,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + // 3rd line : caps and qsdfg ... i = 0x3b; - keyRect = BRect(11,114,47,132); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(36,0); - keyRect.right -= 18; - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - keyRect.right += 18; - DrawKey(keyRect, isPressed(i)); - keyRect.left += 18; + DrawKey(i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + // 4th line : shift and wxcv ... i = 0x4b; - keyRect = BRect(11,132,56,150); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(45,0); - keyRect.right -= 27; - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - keyRect.right += 27; - DrawKey(keyRect, isPressed(i)); - keyRect.left += 27; + DrawKey(i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + //5th line : Ctrl, Alt, Space ... i = 0x5c; - keyRect = BRect(11,150,38,168); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(27,0); - keyRect.OffsetBySelf(26,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(27,0); - keyRect.right += 92; - DrawKey(keyRect, isPressed(i), true); - i++; - keyRect.right -= 92; - keyRect.OffsetBySelf(92,0); - keyRect.OffsetBySelf(27,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(26,0); - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); + DrawKey(i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); SetHighColor(80,80,80); StrokeLine(BPoint(10,169), BPoint(10,77)); @@ -731,18 +898,12 @@ MapView::Draw(BRect rect) StrokeLine(BPoint(11,169)); // Arrows - i++; - keyRect = BRect(298,150,316,168); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + i = 0x57; - keyRect.OffsetBySelf(-18,-18); - DrawKey(keyRect, isPressed(i)); + DrawKey(i); SetHighColor(80,80,80); StrokeLine(BPoint(297,169), BPoint(297,149)); @@ -757,64 +918,33 @@ MapView::Draw(BRect rect) // numkeys i = 0x22; - keyRect = BRect(369,78,387,96); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i = 0x37; - keyRect.OffsetBySelf(-54, 18); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - keyRect.bottom += 18; - DrawKey(keyRect, isPressed(i)); - i = 0x48; - keyRect.bottom -= 18; - keyRect.OffsetBySelf(-54, 18); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i = 0x58; - keyRect.OffsetBySelf(-36, 18); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.OffsetBySelf(18,0); - keyRect.bottom += 18; - DrawKey(keyRect, isPressed(i)); - i = 0x64; - keyRect.bottom -= 18; - keyRect.OffsetBySelf(-54, 18); - keyRect.right += 18; - DrawKey(keyRect, isPressed(i)); - i++; - keyRect.right -= 18; - keyRect.OffsetBySelf(36,0); - DrawKey(keyRect, isPressed(i)); + DrawKey(i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); - DrawBorder(BRect(keyRect.left - 37, 77, keyRect.right + 19, 169)); + i = 0x37; + DrawKey(i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + + i = 0x48; + DrawKey(i); + DrawKey(++i); + DrawKey(++i); + + i = 0x58; + DrawKey(i); + DrawKey(++i); + DrawKey(++i); + DrawKey(++i); + + i = 0x64; + DrawKey(i); + DrawKey(++i); + + DrawBorder(BRect(368, 77, 442, 169)); // lights #define isLighted(i) (fOldKeyInfo.modifiers & i) @@ -885,17 +1015,35 @@ MapView::Draw(BRect rect) FillRect(r); FillRect(BRect(354,41,355,43)); + // around the textview + SetHighColor(0,0,0); + r = BRect(11, 13, Bounds().right-11, 31); + StrokeLine(r.LeftBottom(), r.LeftTop()); + StrokeLine(r.RightTop()); + SetHighColor(80,80,80); + StrokeLine(r.LeftBottom()+BPoint(1,0), r.LeftTop()+BPoint(1,1)); + StrokeLine(r.RightTop()+BPoint(0,1)); + SetHighColor(136,136,136); + StrokeLine(r.LeftBottom()+BPoint(2,-1), r.LeftTop()+BPoint(2,2)); + StrokeLine(r.RightTop()+BPoint(0,2)); + StrokeLine(r.LeftBottom()+BPoint(1,0), r.LeftBottom()+BPoint(1,0)); + SetHighColor(255,255,255); + StrokeLine(r.RightTop()+BPoint(0,1), r.RightBottom()); + StrokeLine(r.LeftBottom()+BPoint(2,0)); BView::Draw(rect); } void -MapView::DrawKey(BRect rect, bool pressed, bool vertical) +MapView::DrawKey(int32 keyCode) { - BRect r = rect; + BRect r = fKeysRect[keyCode]; SetHighColor(0,0,0); StrokeRect(r); + bool pressed = (fOldKeyInfo.key_states[keyCode>>3] & (1 << (7 - keyCode%8))); + bool vertical = fKeysVertical[keyCode]; + if (!pressed) { r.InsetBySelf(1,1); SetHighColor(64,64,64); @@ -940,7 +1088,7 @@ MapView::DrawKey(BRect rect, bool pressed, bool vertical) if (!vertical) { int32 w1 = 4; int32 w2 = 3; - if(rect.Width() > 20) { + if(fKeysRect[keyCode].Width() > 20) { w1 = 6; w2 = 6; } @@ -975,20 +1123,26 @@ MapView::DrawKey(BRect rect, bool pressed, bool vertical) r.InsetBySelf(1,1); SetHighColor(48,48,48); StrokeRect(r); - SetHighColor(136,136,136); - StrokeLine(BPoint(r.left+1, r.bottom), r.RightBottom()); - StrokeLine(BPoint(r.right, r.top+1)); + + 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); - SetHighColor(48,48,48); - StrokeLine(r.LeftTop(), r.LeftTop()); - SetHighColor(152,152,152); - StrokeLine(BPoint(r.left+1, r.bottom), r.RightBottom()); - StrokeLine(r.RightTop()); - SetHighColor(160,160,160); - StrokeLine(r.RightTop()); + + 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); @@ -997,17 +1151,39 @@ MapView::DrawKey(BRect rect, bool pressed, bool vertical) StrokeLine(r.LeftTop(), r.LeftTop()); } + + char *str; + fCurrentMap->GetChars(keyCode, fOldKeyInfo.modifiers, &str); + if (str) { + bool hasGlyphs; + fCurrentFont.GetHasGlyphs(str, 1, &hasGlyphs); + if (hasGlyphs) { + SetFont(&fCurrentFont); + SetDrawingMode(B_OP_COPY); + SetHighColor(0,0,0); + SetLowColor(184,184,184); + BPoint point = fKeysRect[keyCode].LeftBottom(); + point.x += 4; + point.y -= 5; + DrawString(str, point); + SetDrawingMode(B_OP_OVER); + } + } } void -MapView::DrawBorder(BRect borderRect) +MapView::DrawBorder(BRect bRect) { - SetHighColor(80,80,80); - StrokeRect(borderRect); - SetHighColor(255,255,255); - StrokeLine(BPoint(borderRect.left + 1, borderRect.bottom), borderRect.RightBottom()); - StrokeLine(BPoint(borderRect.right, borderRect.top + 1)); + rgb_color gray = {80,80,80}; + rgb_color white = {255,255,255}; + + BeginLineArray(4); + AddLine(bRect.LeftTop(), bRect.LeftBottom(), gray); + AddLine(bRect.LeftTop(), bRect.RightTop(), gray); + AddLine(BPoint(bRect.left + 1, bRect.bottom), bRect.RightBottom(), white); + AddLine(bRect.RightBottom(), BPoint(bRect.right, bRect.top + 1), white); + EndLineArray(); } @@ -1023,27 +1199,28 @@ MapView::MessageReceived(BMessage *msg) key_info info; const uint8 *states; ssize_t size; - bool need_update = false; if ((msg->FindData("states", 'UBYT', (const void **)&states, &size)==B_OK) && (msg->FindInt32("modifiers", (int32 *)&info.modifiers) == B_OK)) { if (fOldKeyInfo.modifiers != info.modifiers) { - need_update = true; - } - - for (int8 i=0; i<16; i++) - if (fOldKeyInfo.key_states[i] != states[i]) { - need_update = true; - break; - } - - if (need_update) { fOldKeyInfo.modifiers = info.modifiers; - for (int8 j=0; j<16; j++) - fOldKeyInfo.key_states[j] = states[j]; + for (int8 i=0; i<16; i++) + fOldKeyInfo.key_states[i] = states[i]; Invalidate(); - } + } else { + + 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) + DrawKey(i*8 + j); + + } + } } + break; } default: diff --git a/src/prefs/keymap/KeymapWindow.h b/src/prefs/keymap/KeymapWindow.h index a3a4cfaf2a..7e9537d663 100644 --- a/src/prefs/keymap/KeymapWindow.h +++ b/src/prefs/keymap/KeymapWindow.h @@ -1,15 +1,27 @@ -#ifndef OBOS_KEYMAP_WINDOW_H -#define OBOS_KEYMAP_WINDOW_H +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ +// +// Copyright (c) 2004, Haiku +// +// This software is part of the Haiku distribution and is covered +// by the Haiku license. +// +// +// File: KeymapWindow.h +// Author: Sandor Vroemisse, Jérôme Duval +// Description: Keymap Preferences +// Created : July 12, 2004 +// +// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ + +#ifndef KEYMAP_WINDOW_H +#define KEYMAP_WINDOW_H #include #include #include +#include "Keymap.h" -#if !DEBUG - #define WINDOW_TITLE "Keymap" -#else - #define WINDOW_TITLE "OBOS Keymap" -#endif //DEBUG +#define WINDOW_TITLE "Keymap" #define WINDOW_LEFT_TOP_POSITION BPoint( 80, 25 ) #define WINDOW_DIMENSIONS BRect( 0,0, 612,256 ) @@ -19,17 +31,24 @@ class KeymapApplication; class MapView : public BView { public: - MapView(BRect rect, const char *name); + MapView(BRect rect, const char *name, Keymap *keymap); void Draw(BRect rect); - void DrawKey(BRect rect, bool pressed, bool vertical = false); + void DrawKey(int32 keyCode); void DrawBorder(BRect borderRect); - //void Pulse(); 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) {fCurrentFont.SetFamilyAndStyle(family, NULL); }; +private: key_info fOldKeyInfo; + BRect fKeysRect[128]; + bool fKeysVertical[128]; + uint8 fKeyState[16]; + BFont fCurrentFont; + + Keymap *fCurrentMap; + BTextView *fTextView; }; @@ -38,31 +57,28 @@ public: KeymapWindow( BRect frame ); bool QuitRequested(); void MessageReceived( BMessage* message ); - //void AllAttached(); protected: - KeymapApplication *fApplication; - BView *fPlaceholderView; BListView *fSystemListView; BListView *fUserListView; // the map that's currently highlighted - BEntry *fSelectedMap; BButton *fUseButton; BButton *fRevertButton; - const char *title; + BMenu *fFontMenu; MapView *fMapView; - BMenuBar *AddMenuBar(); - void AddMaps(); - BList *ListItemsFromEntryList( BList * entryList); - KeymapListItem* ItemFromEntry( BEntry *entry ); - void HandleSystemMapSelected( BMessage* ); - void HandleUserMapSelected( BMessage* ); - void HandleMapSelected( BMessage *selectionMessage, - BListView * selectedView, BListView * otherView ); - void UseKeymap(); - + BMenuBar *AddMenuBar(); + void AddMaps(BView *placeholderView); + //KeymapListItem* ItemFromEntry( BEntry *entry ); + void UseKeymap(); + + void FillSystemMaps(); + void FillUserMaps(); + + BEntry* CurrentMap(); + + Keymap fCurrentMap; }; -#endif // OBOS_KEYMAP_WINDOW_H +#endif // KEYMAP_WINDOW_H