diff --git a/src/preferences/shortcuts/MetaKeyStateMap.cpp b/src/preferences/shortcuts/MetaKeyStateMap.cpp index 76b36bcd48..fa23f836ec 100644 --- a/src/preferences/shortcuts/MetaKeyStateMap.cpp +++ b/src/preferences/shortcuts/MetaKeyStateMap.cpp @@ -1,5 +1,6 @@ /* - * Copyright 1999-2009 Haiku Inc. All rights reserved. + * Copyright 1999-2009 Jeremy Friesner + * Copyright 2009 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -89,4 +90,3 @@ MetaKeyStateMap::GetName() const { return fKeyName; } - diff --git a/src/preferences/shortcuts/MetaKeyStateMap.h b/src/preferences/shortcuts/MetaKeyStateMap.h index bd2b316a6a..0e57488a67 100644 --- a/src/preferences/shortcuts/MetaKeyStateMap.h +++ b/src/preferences/shortcuts/MetaKeyStateMap.h @@ -1,12 +1,13 @@ /* - * Copyright 1999-2009 Haiku Inc. All rights reserved. + * Copyright 1999-2009 Jeremy Friesner + * Copyright 2009 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Jeremy Friesner */ -#ifndef MetaKeyStateMap_h -#define MetaKeyStateMap_h +#ifndef META_KEY_STATE_MAP_H +#define META_KEY_STATE_MAP_H #include @@ -21,7 +22,6 @@ class BitFieldTester; // description strings and qualifier bit-chords that go with them. class MetaKeyStateMap { public: - // Note: You MUST call SetInfo() directly after using this ctor! MetaKeyStateMap(); @@ -65,5 +65,4 @@ private: }; -#endif - +#endif // META_KEY_STATE_MAP_H diff --git a/src/preferences/shortcuts/Shortcuts.rdef b/src/preferences/shortcuts/Shortcuts.rdef index fa548a4d6d..2224a08c65 100644 --- a/src/preferences/shortcuts/Shortcuts.rdef +++ b/src/preferences/shortcuts/Shortcuts.rdef @@ -16,7 +16,7 @@ resource app_version { internal = 0, short_info = "Shortcuts", - long_info = "Shortcuts ©1999-2009 Jeremy Friesner ©2009 Haiku Inc." + long_info = "Shortcuts ©1999-2009 Jeremy Friesner ©2009-2014 Haiku, Inc." }; resource vector_icon { diff --git a/src/preferences/shortcuts/ShortcutsApp.cpp b/src/preferences/shortcuts/ShortcutsApp.cpp index 8d8ff2d7c2..79f67fc66a 100644 --- a/src/preferences/shortcuts/ShortcutsApp.cpp +++ b/src/preferences/shortcuts/ShortcutsApp.cpp @@ -1,12 +1,13 @@ /* - * Copyright 1999-2010 Haiku Inc. All rights reserved. + * Copyright 1999-2009 Jeremy Friesner + * Copyright 2009-2010 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Jeremy Friesner * Fredrik Modéen */ - + #include "ShortcutsApp.h" @@ -35,5 +36,5 @@ ShortcutsApp::ReadyToRun() ShortcutsApp::~ShortcutsApp() -{ +{ } diff --git a/src/preferences/shortcuts/ShortcutsApp.h b/src/preferences/shortcuts/ShortcutsApp.h index 19b90319d1..c0ad7b2170 100644 --- a/src/preferences/shortcuts/ShortcutsApp.h +++ b/src/preferences/shortcuts/ShortcutsApp.h @@ -1,13 +1,14 @@ /* - * Copyright 1999-2009 Haiku Inc. All rights reserved. + * Copyright 1999-2009 Jeremy Friesner + * Copyright 2009-2010 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Jeremy Friesner - * Fredrik Modéen + * Fredrik Modéen */ -#ifndef ShortcutsApp_h -#define ShortcutsApp_h +#ifndef SHORTCUTS_APP_H +#define SHORTCUTS_APP_H #include @@ -21,5 +22,4 @@ public: }; -#endif - +#endif // SHORTCUTS_APP_H diff --git a/src/preferences/shortcuts/ShortcutsSpec.cpp b/src/preferences/shortcuts/ShortcutsSpec.cpp index d7f5ca51bc..41917c4d8c 100644 --- a/src/preferences/shortcuts/ShortcutsSpec.cpp +++ b/src/preferences/shortcuts/ShortcutsSpec.cpp @@ -1,12 +1,12 @@ /* - * Copyright 1999-2010 Haiku Inc. All rights reserved. + * Copyright 1999-2009 Jeremy Friesner + * Copyright 2009-2010 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Jeremy Friesner */ - #include "ShortcutsSpec.h" #include @@ -227,7 +227,8 @@ ShortcutsSpec::ShortcutsSpec(BMessage* from) void ShortcutsSpec::SetCommand(const char* command) { - delete[] fCommand; // out with the old (if any)... + delete[] fCommand; + // out with the old (if any)... fCommandLen = strlen(command) + 1; fCommandNul = fCommandLen - 1; fCommand = new char[fCommandLen]; @@ -342,7 +343,8 @@ void ShortcutsSpec::DrawItemColumn(BView* owner, BRect item_column_rect, int32 column_index, bool columnSelected, bool complete) { - const float STRING_COLUMN_LEFT_MARGIN = 25.0f; // 16 for the icon,+9 empty + const float STRING_COLUMN_LEFT_MARGIN = 25.0f; + // 16 for the icon, +9 empty rgb_color color; bool selected = IsSelected(); @@ -406,8 +408,8 @@ ShortcutsSpec::DrawItemColumn(BView* owner, BRect item_column_rect, _CacheViewFont(owner); // How about I draw a nice "key" background for this one? - BRect textRect(point.x - KEY_MARGIN, (point.y-sFontHeight) - KEY_MARGIN - , point.x + textWidth + KEY_MARGIN - 2.0f, point.y + KEY_MARGIN); + BRect textRect(point.x - KEY_MARGIN, (point.y - sFontHeight) - KEY_MARGIN, + point.x + textWidth + KEY_MARGIN - 2.0f, point.y + KEY_MARGIN); if (column_index == KEY_COLUMN_INDEX) lowColor = ReallyLightPurple; @@ -547,7 +549,7 @@ ShortcutsSpec::ProcessColumnTextString(int whichColumn, const char* string) bool ShortcutsSpec::_AttemptTabCompletion() { - bool ret = false; + bool result = false; int32 argc; char** argv = ParseArgvFromString(fCommand, argc); @@ -555,11 +557,11 @@ ShortcutsSpec::_AttemptTabCompletion() // Try to complete the path partially expressed in the last argument! char* arg = argv[argc - 1]; char* fileFragment = strrchr(arg, '/'); - if (fileFragment) { + if (fileFragment != NULL) { const char* directoryName = (fileFragment == arg) ? "/" : arg; *fileFragment = '\0'; fileFragment++; - int fragLen = strlen(fileFragment); + int fragmentLength = strlen(fileFragment); BDirectory dir(directoryName); if (dir.InitCheck() == B_NO_ERROR) { @@ -573,7 +575,7 @@ ShortcutsSpec::_AttemptTabCompletion() while (dir.GetNextEntry(&nextEnt) == B_NO_ERROR) { if (nextEnt.GetPath(&nextPath) == B_NO_ERROR) { char* filePath = strrchr(nextPath.Path(), '/') + 1; - if (strncmp(filePath, fileFragment, fragLen) == 0) { + if (strncmp(filePath, fileFragment, fragmentLength) == 0) { int len = strlen(filePath); if (len > maxEntryLen) maxEntryLen = len; @@ -586,13 +588,13 @@ ShortcutsSpec::_AttemptTabCompletion() // Now slowly extend our keyword to its full length, counting // numbers of matches at each step. If the match list length - // is 1, we can use that whole entry. If it's greater than one - // , we can use just the match length. + // is 1, we can use that whole entry. If it's greater than one, + // we can use just the match length. int matchLen = matchList.CountItems(); if (matchLen > 0) { int i; BString result(fileFragment); - for (i = fragLen; i < maxEntryLen; i++) { + for (i = fragmentLength; i < maxEntryLen; i++) { // See if all the matching entries have the same letter // in the next position... if so, we can go farther. char commonLetter = '\0'; @@ -615,7 +617,7 @@ ShortcutsSpec::_AttemptTabCompletion() result.Append(commonLetter, 1); } - // Free all the strings we allocated + // free all the strings we allocated for (int k = 0; k < matchLen; k++) delete [] ((char*)matchList.ItemAt(k)); @@ -637,10 +639,10 @@ ShortcutsSpec::_AttemptTabCompletion() // Remove any trailing slash... const char* fileStr = file.String(); - if (fileStr[strlen(fileStr)-1] == '/') + if (fileStr[strlen(fileStr) - 1] == '/') file.RemoveLast("/"); - // And re-append it iff the file is a dir. + // and re-append it iff the file is a dir. BDirectory testFileAsDir(file.String()); if ((strcmp(file.String(), "/") != 0) && (testFileAsDir.InitCheck() == B_NO_ERROR)) @@ -649,14 +651,15 @@ ShortcutsSpec::_AttemptTabCompletion() wholeLine += file; SetCommand(wholeLine.String()); - ret = true; + result = true; } } *(fileFragment - 1) = '/'; } } FreeArgv(argv); - return ret; + + return result; } @@ -664,13 +667,14 @@ bool ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes, int32 key) { - bool ret = false; + bool result = false; + switch(whichColumn) { case KEY_COLUMN_INDEX: if (key > -1) { if ((int32)fKey != key) { fKey = key; - ret = true; + result = true; } } break; @@ -684,18 +688,18 @@ ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes, // trim a char off the string fCommand[fCommandNul - 1] = '\0'; fCommandNul--; // note new nul position - ret = true; + result = true; _UpdateIconBitmap(); } - break; + break; case B_TAB: if (_AttemptTabCompletion()) { _UpdateIconBitmap(); - ret = true; + result = true; } else beep(); - break; + break; default: { @@ -722,7 +726,7 @@ ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes, // Here we should be guaranteed enough room. strncat(fCommand, bytes, fCommandLen); fCommandNul += newCharLen; - ret = true; + result = true; _UpdateIconBitmap(); } } @@ -731,72 +735,73 @@ ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes, } default: - if ((whichColumn >= 0) && (whichColumn < NUM_META_COLUMNS)) { - MetaKeyStateMap * map = &sMetaMaps[whichColumn]; - int curState = fMetaCellStateIndex[whichColumn]; - int origState = curState; - int numStates = map->GetNumStates(); + if (whichColumn < 0 || whichColumn >= NUM_META_COLUMNS) + break; - switch(bytes[0]) + MetaKeyStateMap * map = &sMetaMaps[whichColumn]; + int curState = fMetaCellStateIndex[whichColumn]; + int origState = curState; + int numStates = map->GetNumStates(); + + switch(bytes[0]) { + case B_RETURN: + // cycle to the previous state + curState = (curState + numStates - 1) % numStates; + break; + + case B_SPACE: + // cycle to the next state + curState = (curState + 1) % numStates; + break; + + default: { - case B_RETURN: - // cycle to the previous state - curState = (curState + numStates - 1) % numStates; - break; + // Go to the state starting with the given letter, if + // any + char letter = bytes[0]; + if (islower(letter)) + letter = toupper(letter); // convert to upper case - case B_SPACE: - // cycle to the next state - curState = (curState + 1) % numStates; - break; + if ((letter == B_BACKSPACE) || (letter == B_DELETE)) + letter = '('; + // so space bar will blank out an entry - default: - { - // Go to the state starting with the given letter, if - // any - char letter = bytes[0]; - if (islower(letter)) - letter = toupper(letter); // convert to upper case + for (int i = 0; i < numStates; i++) { + const char* desc = map->GetNthStateDesc(i); - if ((letter == B_BACKSPACE) || (letter == B_DELETE)) - letter = '('; - // so space bar will blank out an entry - - for (int i = 0; i < numStates; i++) { - const char* desc = map->GetNthStateDesc(i); - - if (desc) { - if (desc[0] == letter) { - curState = i; - break; - } - } else - printf(B_TRANSLATE("Error, NULL state description?\n")); + if (desc) { + if (desc[0] == letter) { + curState = i; + break; + } + } else { + puts(B_TRANSLATE( + "Error, NULL state description?")); } - break; } } - fMetaCellStateIndex[whichColumn] = curState; - - if (curState != origState) - ret = true; } - break; + fMetaCellStateIndex[whichColumn] = curState; + + if (curState != origState) + result = true; } - return ret; + return result; } int -ShortcutsSpec::MyCompare(const CLVListItem* a_Item1, const CLVListItem* a_Item2, - int32 KeyColumn) +ShortcutsSpec::CLVListItemCompare(const CLVListItem* firstItem, + const CLVListItem* secondItem, int32 keyColumn) { - ShortcutsSpec* left = (ShortcutsSpec*) a_Item1; - ShortcutsSpec* right = (ShortcutsSpec*) a_Item2; + ShortcutsSpec* left = (ShortcutsSpec*) firstItem; + ShortcutsSpec* right = (ShortcutsSpec*) secondItem; - int ret = strcmp(left->GetCellText(KeyColumn), - right->GetCellText(KeyColumn)); - return (ret > 0) ? 1 : ((ret == 0) ? 0 : -1); + int result = strcmp(left->GetCellText(keyColumn), + right->GetCellText(keyColumn)); + + return result > 0 ? 1 : (result == 0 ? 0 : -1); } @@ -821,13 +826,14 @@ ShortcutsSpec::_UpdateIconBitmap() { BString firstWord = ParseArgvZeroFromString(fCommand); - // Only need to change if the first word has changed... + // we only need to change if the first word has changed... if (fLastBitmapName == NULL || firstWord.Length() == 0 || firstWord.Compare(fLastBitmapName)) { if (firstWord.ByteAt(0) == '*') fBitmapValid = IsValidActuatorName(&firstWord.String()[1]); else { - fBitmapValid = false; // default till we prove otherwise! + fBitmapValid = false; + // default until we prove otherwise if (firstWord.Length() > 0) { delete [] fLastBitmapName; @@ -873,4 +879,3 @@ ShortcutsSpec::_InitModifierNames() "Name for modifier on keyboard"); #endif } - diff --git a/src/preferences/shortcuts/ShortcutsSpec.h b/src/preferences/shortcuts/ShortcutsSpec.h index 0dbfc91756..289656e999 100644 --- a/src/preferences/shortcuts/ShortcutsSpec.h +++ b/src/preferences/shortcuts/ShortcutsSpec.h @@ -1,12 +1,13 @@ /* - * Copyright 1999-2009 Haiku Inc. All rights reserved. + * Copyright 1999-2009 Jeremy Friesner + * Copyright 2009-2010 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Jeremy Friesner */ -#ifndef ShortcutsSpec_h -#define ShortcutsSpec_h +#ifndef SHORTCUTS_SPEC_H +#define SHORTCUTS_SPEC_H #include @@ -19,11 +20,12 @@ class CommandActuator; class MetaKeyStateMap; -MetaKeyStateMap & GetNthKeyMap(int which); +MetaKeyStateMap& GetNthKeyMap(int which); -/* Objects of this class represent one hotkey "entry" in the preferences - * ListView. Each ShortcutsSpec contains the info necessary to generate both - * the proper GUI display, and the proper BitFieldTester and CommandActuator +/* + * Objects of this class represent one hotkey "entry" in the preferences + * ListView. Each ShortcutsSpec contains the info necessary to generate both + * the proper GUI display, and the proper BitFieldTester and CommandActuator * object for the ShortcutsCatcher add-on to use. */ class ShortcutsSpec : public CLVListItem { @@ -36,36 +38,36 @@ public: ~ShortcutsSpec(); virtual status_t Archive(BMessage* into, bool deep = true) const; - virtual void Pulse(BView* owner); - static BArchivable* Instantiate(BMessage* from); - void Update(BView* owner, const BFont* font); - const char* GetCellText(int whichColumn) const; + virtual void Pulse(BView* owner); + static BArchivable* Instantiate(BMessage* from); + void Update(BView* owner, const BFont* font); + const char* GetCellText(int whichColumn) const; void SetCommand(const char* commandStr); - + virtual void DrawItemColumn(BView* owner, BRect item_column_rect, int32 column_index, bool columnSelected, bool complete); - static int MyCompare(const CLVListItem* a_Item1, - const CLVListItem* a_Item2, int32 KeyColumn); + static int CLVListItemCompare(const CLVListItem* firstItem, + const CLVListItem* secondItem, int32 keyColumn); // Returns the name of the Nth Column. static const char* GetColumnName(int index); // Update this spec's state in response to a keystroke to the given // column. Returns true iff a change occurred. - bool ProcessColumnKeyStroke(int whichColumn, + bool ProcessColumnKeyStroke(int whichColumn, const char* bytes, int32 key); // Same as ProcessColumnKeyStroke, but for a mouse click instead. bool ProcessColumnMouseClick(int whichColumn); // Same as ProcessColumnKeyStroke, but for a text string instead. - bool ProcessColumnTextString(int whichColumn, + bool ProcessColumnTextString(int whichColumn, const char* string); - int32 GetSelectedColumn() const {return fSelectedColumn;} - void SetSelectedColumn(int32 i) {fSelectedColumn = i;} + int32 GetSelectedColumn() const { return fSelectedColumn; } + void SetSelectedColumn(int32 i) { fSelectedColumn = i; } // default layout of columns is set in here. enum { @@ -81,20 +83,20 @@ public: private: void _CacheViewFont(BView* owner); bool _AttemptTabCompletion(); - + // call this to ensure the icon is up-to-date void _UpdateIconBitmap(); char* fCommand; - uint32 fCommandLen; // number of bytes in fCommand buffer - uint32 fCommandNul; // index of the NUL byte in fCommand - float fTextOffset; - + uint32 fCommandLen; // number of bytes in fCommand buffer + uint32 fCommandNul; // index of the NUL byte in fCommand + float fTextOffset; + // icon for associated program. Invalid if none available. - BBitmap fBitmap; - + BBitmap fBitmap; + char* fLastBitmapName; - bool fBitmapValid; + bool fBitmapValid; uint32 fKey; int32 fMetaCellStateIndex[NUM_META_COLUMNS]; BPoint fCursorPt1; @@ -112,5 +114,5 @@ private: static const char* sCommandName; }; -#endif +#endif // SHORTCUTS_SPEC_H diff --git a/src/preferences/shortcuts/ShortcutsWindow.cpp b/src/preferences/shortcuts/ShortcutsWindow.cpp index dd2803937c..953daaa468 100644 --- a/src/preferences/shortcuts/ShortcutsWindow.cpp +++ b/src/preferences/shortcuts/ShortcutsWindow.cpp @@ -1,5 +1,6 @@ /* - * Copyright 1999-2010 Haiku Inc. All rights reserved. + * Copyright 1999-2009 Jeremy Friesner + * Copyright 2009-2010 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -50,14 +51,14 @@ #define MAX_WIDTH 10000 #define MAX_HEIGHT 10000 // SetSizeLimits does not provide a mechanism for specifying an - // unrestricted maximum. 10,000 seems to be the most common value used + // unrestricted maximum. 10,000 seems to be the most common value used // in other Haiku system applications. #define WINDOW_SETTINGS_FILE_NAME "Shortcuts_window_settings" // Because the "shortcuts_settings" file (SHORTCUTS_SETTING_FILE_NAME) is // already used as a communications method between this configurator and // the "shortcut_catcher" input_server filter, it should not be overloaded - // with window position information. Instead, a separate file is used. + // with window position information, instead, a separate file is used. #undef B_TRANSLATION_CONTEXT #define B_TRANSLATION_CONTEXT "ShortcutsWindow" @@ -66,18 +67,18 @@ #define WARNING "Shortcuts warning" -// Creates a pop-up-menu that reflects the possible states of the specified +// Creates a pop-up-menu that reflects the possible states of the specified // meta-key. static BPopUpMenu* -CreateMetaPopUp(int col) +CreateMetaPopUp(int column) { - MetaKeyStateMap& map = GetNthKeyMap(col); - BPopUpMenu * popup = new BPopUpMenu(NULL, false); - int numStates = map.GetNumStates(); - - for (int i = 0; i < numStates; i++) + MetaKeyStateMap& map = GetNthKeyMap(column); + BPopUpMenu* popup = new BPopUpMenu(NULL, false); + int stateCount = map.GetNumStates(); + + for (int i = 0; i < stateCount; i++) popup->AddItem(new BMenuItem(map.GetNthStateDesc(i), NULL)); - + return popup; } @@ -90,10 +91,10 @@ CreateKeysPopUp() int numKeys = GetNumKeyIndices(); for (int i = 0; i < numKeys; i++) { const char* next = GetKeyName(i); - - if (next) + if (next != NULL) popup->AddItem(new BMenuItem(next, NULL)); } + return popup; } @@ -102,14 +103,14 @@ ShortcutsWindow::ShortcutsWindow() : BWindow(BRect(0, 0, 0, 0), B_TRANSLATE_SYSTEM_NAME("Shortcuts"), B_TITLED_WINDOW, 0L), - fSavePanel(NULL), - fOpenPanel(NULL), - fSelectPanel(NULL), - fKeySetModified(false), + fSavePanel(NULL), + fOpenPanel(NULL), + fSelectPanel(NULL), + fKeySetModified(false), fLastOpenWasAppend(false) { ShortcutsSpec::InitializeMetaMaps(); - + float spacing = be_control_look->DefaultItemSpacing(); BView* top = new BView(Bounds(), NULL, B_FOLLOW_ALL_SIDES, 0); @@ -194,7 +195,7 @@ ShortcutsWindow::ShortcutsWindow() minListWidth += 323.0 + 1; minListWidth += B_V_SCROLL_BAR_WIDTH; - fColumnListView->SetSortFunction(ShortcutsSpec::MyCompare); + fColumnListView->SetSortFunction(ShortcutsSpec::CLVListItemCompare); top->AddChild(containerView); fColumnListView->SetSelectionMessage(new BMessage(HOTKEY_ITEM_SELECTED)); @@ -250,19 +251,20 @@ ShortcutsWindow::ShortcutsWindow() // is a behind-the-scenes file that the user will never see or // interact with. BFile windowSettingsFile(&windowSettingsRef, B_READ_ONLY); - BMessage loadMsg; - if (loadMsg.Unflatten(&windowSettingsFile) == B_OK) - _LoadWindowSettings(loadMsg); + BMessage loadMessage; + if (loadMessage.Unflatten(&windowSettingsFile) == B_OK) + _LoadWindowSettings(loadMessage); } entry_ref keySetRef; if (_GetSettingsFile(&keySetRef)) { - BMessage msg(B_REFS_RECEIVED); - msg.AddRef("refs", &keySetRef); - msg.AddString("startupRef", "please"); - PostMessage(&msg); - // Tell ourselves to load this file if it exists. + BMessage message(B_REFS_RECEIVED); + message.AddRef("refs", &keySetRef); + message.AddString("startupRef", "please"); + PostMessage(&message); + // tell ourselves to load this file if it exists } + Show(); } @@ -279,10 +281,10 @@ ShortcutsWindow::~ShortcutsWindow() bool ShortcutsWindow::QuitRequested() { - bool ret = true; + bool result = true; if (fKeySetModified) { - BAlert* alert = new BAlert(WARNING, + BAlert* alert = new BAlert(WARNING, B_TRANSLATE("Save changes before closing?"), B_TRANSLATE("Cancel"), B_TRANSLATE("Don't save"), B_TRANSLATE("Save")); @@ -291,11 +293,11 @@ ShortcutsWindow::QuitRequested() alert->SetShortcut(2, 's'); switch(alert->Go()) { case 0: - ret = false; + result = false; break; case 1: - ret = true; + result = true; break; case 2: @@ -309,17 +311,17 @@ ShortcutsWindow::QuitRequested() B_TRANSLATE("Oh no")); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->Go(); - ret = true; //quit anyway + result = true; //quit anyway } } else { PostMessage(SAVE_KEYSET); - ret = false; + result = false; } break; } } - if (ret) { + if (result) { fColumnListView->DeselectAll(); // Save the window position. @@ -329,8 +331,8 @@ ShortcutsWindow::QuitRequested() _SaveWindowSettings(entry); } } - - return ret; + + return result; } @@ -358,41 +360,43 @@ ShortcutsWindow::_SaveKeySet(BEntry& saveEntry) if (saveTo.InitCheck() != B_OK) return false; - BMessage saveMsg; + BMessage saveMessage; for (int i = 0; i < fColumnListView->CountItems(); i++) { BMessage next; - if (((ShortcutsSpec*)fColumnListView->ItemAt(i))->Archive(&next) - == B_OK) - saveMsg.AddMessage("spec", &next); - else + if (((ShortcutsSpec*)fColumnListView->ItemAt(i))->Archive(&next) + == B_OK) { + saveMessage.AddMessage("spec", &next); + } else printf("Error archiving ShortcutsSpec #%i!\n", i); } - - bool ret = (saveMsg.Flatten(&saveTo) == B_OK); - - if (ret) { + + bool result = (saveMessage.Flatten(&saveTo) == B_OK); + + if (result) { fKeySetModified = false; fSaveButton->SetEnabled(false); } - return ret; + return result; } // Appends new entries from the file specified in the "spec" entry of -// (loadMsg). Returns true iff successful. +// (loadMessage). Returns true iff successful. bool -ShortcutsWindow::_LoadKeySet(const BMessage& loadMsg) +ShortcutsWindow::_LoadKeySet(const BMessage& loadMessage) { int i = 0; - BMessage msg; - while (loadMsg.FindMessage("spec", i++, &msg) == B_OK) { - ShortcutsSpec* spec = (ShortcutsSpec*)ShortcutsSpec::Instantiate(&msg); - if (spec != NULL) + BMessage message; + while (loadMessage.FindMessage("spec", i++, &message) == B_OK) { + ShortcutsSpec* spec + = (ShortcutsSpec*)ShortcutsSpec::Instantiate(&message); + if (spec != NULL) fColumnListView->AddItem(spec); - else + else printf("_LoadKeySet: Error parsing spec!\n"); } + return true; } @@ -432,20 +436,20 @@ ShortcutsWindow::_SaveWindowSettings(BEntry& saveEntry) } -// Loads the application settings file from (loadMsg) and resizes the interface -// to match the previously saved settings. Because this is a non-essential -// file, errors are ignored when loading the settings. +// Loads the application settings file from (loadMessage) and resizes +// the interface to match the previously saved settings. Because this +// is a non-essential file, errors are ignored when loading the settings. void -ShortcutsWindow::_LoadWindowSettings(const BMessage& loadMsg) +ShortcutsWindow::_LoadWindowSettings(const BMessage& loadMessage) { BRect frame; - if (loadMsg.FindRect("window frame", &frame) == B_OK) { - // Ensure the frame does not resize below the computed minimum. + if (loadMessage.FindRect("window frame", &frame) == B_OK) { + // ensure the frame does not resize below the computed minimum. float width = max_c(Bounds().right, frame.right - frame.left); float height = max_c(Bounds().bottom, frame.bottom - frame.top); ResizeTo(width, height); - // Ensure the frame is not placed outside of the screen. + // ensure the frame is not placed outside of the screen. BScreen screen(this); float left = min_c(screen.Frame().right - width, frame.left); float top = min_c(screen.Frame().bottom - height, frame.top); @@ -455,13 +459,13 @@ ShortcutsWindow::_LoadWindowSettings(const BMessage& loadMsg) for (int i = 0; i < fColumnListView->CountColumns(); i++) { CLVColumn* column = fColumnListView->ColumnAt(i); float columnWidth; - if (loadMsg.FindFloat("column width", i, &columnWidth) == B_OK) + if (loadMessage.FindFloat("column width", i, &columnWidth) == B_OK) column->SetWidth(max_c(column->Width(), columnWidth)); } } -// Creates a new entry and adds it to the GUI. (defaultCommand) will be the +// Creates a new entry and adds it to the GUI. (defaultCommand) will be the // text in the entry, or NULL if no text is desired. void ShortcutsWindow::_AddNewSpec(const char* defaultCommand) @@ -476,7 +480,7 @@ ShortcutsWindow::_AddNewSpec(const char* defaultCommand) if (defaultCommand) spec->SetCommand(defaultCommand); - } else + } else spec = new ShortcutsSpec(defaultCommand ? defaultCommand : ""); fColumnListView->AddItem(spec); @@ -486,26 +490,27 @@ ShortcutsWindow::_AddNewSpec(const char* defaultCommand) void -ShortcutsWindow::MessageReceived(BMessage* msg) +ShortcutsWindow::MessageReceived(BMessage* message) { - switch(msg->what) { - case OPEN_KEYSET: - case APPEND_KEYSET: - fLastOpenWasAppend = (msg->what == APPEND_KEYSET); - if (fOpenPanel) + switch(message->what) { + case OPEN_KEYSET: + case APPEND_KEYSET: + fLastOpenWasAppend = (message->what == APPEND_KEYSET); + if (fOpenPanel) fOpenPanel->Show(); else { - BMessenger m(this); - fOpenPanel = new BFilePanel(B_OPEN_PANEL, &m, NULL, 0, false); + BMessenger messenger(this); + fOpenPanel = new BFilePanel(B_OPEN_PANEL, &messenger, NULL, + 0, false); fOpenPanel->Show(); } fOpenPanel->SetButtonLabel(B_DEFAULT_BUTTON, fLastOpenWasAppend ? B_TRANSLATE("Append") : B_TRANSLATE("Open")); break; + // send a message to myself, to get me to reload the settings file case REVERT_KEYSET: { - // Send a message to myself, to get me to reload the settings file fLastOpenWasAppend = false; BMessage reload(B_REFS_RECEIVED); entry_ref eref; @@ -516,13 +521,13 @@ ShortcutsWindow::MessageReceived(BMessage* msg) break; } - // Respond to drag-and-drop messages here + // respond to drag-and-drop messages here case B_SIMPLE_DATA: { int i = 0; entry_ref ref; - while (msg->FindRef("refs", i++, &ref) == B_OK) { + while (message->FindRef("refs", i++, &ref) == B_OK) { BEntry entry(&ref); if (entry.InitCheck() == B_OK) { BPath path(&entry); @@ -538,13 +543,13 @@ ShortcutsWindow::MessageReceived(BMessage* msg) break; } - // Respond to FileRequester's messages here + // respond to FileRequester's messages here case B_REFS_RECEIVED: { // Find file ref entry_ref ref; - bool isStartMsg = msg->HasString("startupRef"); - if (msg->FindRef("refs", &ref) == B_OK) { + bool isStartMsg = message->HasString("startupRef"); + if (message->FindRef("refs", &ref) == B_OK) { // load the file into (fileMsg) BMessage fileMsg; { @@ -579,7 +584,7 @@ ShortcutsWindow::MessageReceived(BMessage* msg) if (isStartMsg) fLastSaved = BEntry(&ref); fSaveButton->SetEnabled(isStartMsg == false); - // If we just loaded in the Shortcuts settings file, then + // If we just loaded in the Shortcuts settings file, then // no need to tell the user to save on exit. entry_ref eref; _GetSettingsFile(&eref); @@ -596,22 +601,20 @@ ShortcutsWindow::MessageReceived(BMessage* msg) break; } - // These messages come from the pop-up menu of the Applications column + // these messages come from the pop-up menu of the Applications column case SELECT_APPLICATION: { int csel = fColumnListView->CurrentSelection(); if (csel >= 0) { entry_ref aref; - if (msg->FindRef("refs", &aref) == B_OK) { + if (message->FindRef("refs", &aref) == B_OK) { BEntry ent(&aref); if (ent.InitCheck() == B_OK) { BPath path; - if ((ent.GetPath(&path) == B_OK) - && (((ShortcutsSpec *) - fColumnListView->ItemAt(csel))-> - ProcessColumnTextString(ShortcutsSpec:: - STRING_COLUMN_INDEX, path.Path()))) { - + if ((ent.GetPath(&path) == B_OK) + && (((ShortcutsSpec*)fColumnListView->ItemAt(csel))-> + ProcessColumnTextString(ShortcutsSpec::STRING_COLUMN_INDEX, + path.Path()))) { fColumnListView->InvalidateItem(csel); _MarkKeySetModified(); } @@ -625,21 +628,23 @@ ShortcutsWindow::MessageReceived(BMessage* msg) { bool showSaveError = false; - const char * name; + const char* name; entry_ref entry; - if ((msg->FindString("name", &name) == B_OK) - && (msg->FindRef("directory", &entry) == B_OK)) { + if ((message->FindString("name", &name) == B_OK) + && (message->FindRef("directory", &entry) == B_OK)) { BDirectory dir(&entry); BEntry saveTo(&dir, name, true); - showSaveError = ((saveTo.InitCheck() != B_OK) - || (_SaveKeySet(saveTo) == false)); + showSaveError = ((saveTo.InitCheck() != B_OK) + || (_SaveKeySet(saveTo) == false)); } else if (fLastSaved.InitCheck() == B_OK) { // We've saved this before, save over previous file. showSaveError = (_SaveKeySet(fLastSaved) == false); - } else PostMessage(SAVE_KEYSET_AS); // open the save requester... + } else + PostMessage(SAVE_KEYSET_AS); + // open the save requester... if (showSaveError) { - BAlert* alert = new BAlert(ERROR, + BAlert* alert = new BAlert(ERROR, B_TRANSLATE("Shortcuts wasn't able to save your keyset."), B_TRANSLATE("OK")); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); @@ -653,10 +658,10 @@ ShortcutsWindow::MessageReceived(BMessage* msg) if (fSavePanel) fSavePanel->Show(); else { - BMessage msg(SAVE_KEYSET); + BMessage message(SAVE_KEYSET); BMessenger messenger(this); - fSavePanel = new BFilePanel(B_SAVE_PANEL, &messenger, NULL, 0, - false, &msg); + fSavePanel = new BFilePanel(B_SAVE_PANEL, &messenger, NULL, 0, + false, &message); fSavePanel->Show(); } break; @@ -698,7 +703,7 @@ ShortcutsWindow::MessageReceived(BMessage* msg) case HOTKEY_ITEM_SELECTED: { int32 index = -1; - msg->FindInt32("index", &index); + message->FindInt32("index", &index); bool validItem = (index >= 0); fRemoveButton->SetEnabled(validItem); break; @@ -709,8 +714,8 @@ ShortcutsWindow::MessageReceived(BMessage* msg) { int32 row, column; - if ((msg->FindInt32("row", &row) == B_OK) - && (msg->FindInt32("column", &column) == B_OK)) { + if ((message->FindInt32("row", &row) == B_OK) + && (message->FindInt32("column", &column) == B_OK)) { int32 key; const char* bytes; @@ -719,27 +724,27 @@ ShortcutsWindow::MessageReceived(BMessage* msg) fColumnListView->ItemAt(row); bool repaintNeeded = false; // default - if (msg->HasInt32("mouseClick")) { + if (message->HasInt32("mouseClick")) { repaintNeeded = item->ProcessColumnMouseClick(column); - } else if ((msg->FindString("bytes", &bytes) == B_OK) - && (msg->FindInt32("key", &key) == B_OK)) { + } else if ((message->FindString("bytes", &bytes) == B_OK) + && (message->FindInt32("key", &key) == B_OK)) { repaintNeeded = item->ProcessColumnKeyStroke(column, bytes, key); - } else if (msg->FindInt32("unmappedkey", &key) == + } else if (message->FindInt32("unmappedkey", &key) == B_OK) { repaintNeeded = ((column == item->KEY_COLUMN_INDEX) && ((key > 0xFF) || (GetKeyName(key) != NULL)) && (item->ProcessColumnKeyStroke(column, NULL, key))); - } else if (msg->FindString("text", &bytes) == B_OK) { + } else if (message->FindString("text", &bytes) == B_OK) { if ((bytes[0] == '(')&&(bytes[1] == 'C')) { if (fSelectPanel) fSelectPanel->Show(); else { - BMessage msg(SELECT_APPLICATION); + BMessage message(SELECT_APPLICATION); BMessenger m(this); fSelectPanel = new BFilePanel(B_OPEN_PANEL, &m, - NULL, 0, false, &msg); + NULL, 0, false, &message); fSelectPanel->Show(); } fSelectPanel->SetButtonLabel(B_DEFAULT_BUTTON, @@ -760,7 +765,7 @@ ShortcutsWindow::MessageReceived(BMessage* msg) } default: - BWindow::MessageReceived(msg); + BWindow::MessageReceived(message); break; } } @@ -788,9 +793,9 @@ ShortcutsWindow::Quit() void -ShortcutsWindow::DispatchMessage(BMessage* msg, BHandler* handler) +ShortcutsWindow::DispatchMessage(BMessage* message, BHandler* handler) { - switch(msg->what) { + switch(message->what) { case B_COPY: case B_CUT: if (be_clipboard->Lock()) { @@ -808,7 +813,7 @@ ShortcutsWindow::DispatchMessage(BMessage* msg, BHandler* handler) strlen(spec->GetCellText(column))); be_clipboard->Commit(); - if (msg->what == B_CUT) { + if (message->what == B_CUT) { spec->ProcessColumnTextString(column, ""); _MarkKeySetModified(); fColumnListView->InvalidateItem(row); @@ -824,13 +829,13 @@ ShortcutsWindow::DispatchMessage(BMessage* msg, BHandler* handler) BMessage* data = be_clipboard->Data(); const char* text; ssize_t textLen; - if (data->FindData("text/plain", B_MIME_TYPE, (const void**) + if (data->FindData("text/plain", B_MIME_TYPE, (const void**) &text, &textLen) == B_OK) { - int32 row = fColumnListView->CurrentSelection(); + int32 row = fColumnListView->CurrentSelection(); int32 column = fColumnListView->GetSelectedColumn(); if ((row >= 0) && (column == ShortcutsSpec::STRING_COLUMN_INDEX)) { - ShortcutsSpec* spec = (ShortcutsSpec*) + ShortcutsSpec* spec = (ShortcutsSpec*) fColumnListView->ItemAt(row); if (spec) { for (ssize_t i = 0; i < textLen; i++) { @@ -847,8 +852,7 @@ ShortcutsWindow::DispatchMessage(BMessage* msg, BHandler* handler) break; default: - BWindow::DispatchMessage(msg, handler); + BWindow::DispatchMessage(message, handler); break; } } - diff --git a/src/preferences/shortcuts/ShortcutsWindow.h b/src/preferences/shortcuts/ShortcutsWindow.h index db12b0de78..792ec2ddb8 100644 --- a/src/preferences/shortcuts/ShortcutsWindow.h +++ b/src/preferences/shortcuts/ShortcutsWindow.h @@ -1,12 +1,13 @@ /* - * Copyright 1999-2009 Haiku Inc. All rights reserved. + * Copyright 1999-2009 Jeremy Friesner + * Copyright 2009-2010 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Jeremy Friesner */ -#ifndef ShortcutsWindow_h -#define ShortcutsWindow_h +#ifndef SHORTCUTS_WINDOW_H +#define SHORTCUTS_WINDOW_H #include @@ -14,6 +15,7 @@ #include "ColumnListView.h" + class BButton; class BFilePanel; class BMessage; @@ -24,61 +26,66 @@ public: ShortcutsWindow(); ~ShortcutsWindow(); - virtual void DispatchMessage(BMessage* msg, BHandler* handler); - virtual void Quit(); - virtual void MessageReceived(BMessage* msg); - virtual bool QuitRequested(); + virtual void DispatchMessage(BMessage* message, + BHandler* handler); + virtual void Quit(); + virtual void MessageReceived(BMessage* message); + virtual bool QuitRequested(); // BMessage 'what' codes, representing commands understood by this Window. enum { ADD_HOTKEY_ITEM = 'SpKy', // Add a new hotkey entry to the GUI list. REMOVE_HOTKEY_ITEM, // Remove a hotkey entry from the GUI list. - HOTKEY_ITEM_SELECTED, // Give the "focus bar" to the specified + HOTKEY_ITEM_SELECTED, // Give the "focus bar" to the specified // entry. - HOTKEY_ITEM_MODIFIED, // Update the state of an entry to reflect + HOTKEY_ITEM_MODIFIED, // Update the state of an entry to reflect // user's changes. - OPEN_KEYSET, // Bring up a File requester to load new + OPEN_KEYSET, // Bring up a File requester to load new // settings. - APPEND_KEYSET, // Bring up a File requester to append + APPEND_KEYSET, // Bring up a File requester to append // settings. - REVERT_KEYSET, // Dump the current state and re-read + REVERT_KEYSET, // Dump the current state and re-read // settings from disk. SAVE_KEYSET, // Save the current settings to disk - SAVE_KEYSET_AS, // Bring up a File requester to save + SAVE_KEYSET_AS, // Bring up a File requester to save // current settings. - SELECT_APPLICATION, // Set the current entry to point to the + SELECT_APPLICATION, // Set the current entry to point to the // given file. }; + private: BMenuItem* _CreateActuatorPresetMenuItem(const char* label) const; void _AddNewSpec(const char* defaultCommand); void _MarkKeySetModified(); - bool _LoadKeySet(const BMessage& loadMsg); + bool _LoadKeySet(const BMessage& loadMessage); bool _SaveKeySet(BEntry& saveEntry); bool _GetSettingsFile(entry_ref* ref); - void _LoadWindowSettings(const BMessage& loadMsg); + void _LoadWindowSettings( + const BMessage& loadMessage); void _SaveWindowSettings(BEntry& saveEntry); bool _GetWindowSettingsFile(entry_ref* ref); - BButton* fAddButton; - BButton* fRemoveButton; - BButton* fSaveButton; - ColumnListView* fColumnListView; - BFilePanel* fSavePanel; // for saving settings - BFilePanel* fOpenPanel; // for loading settings - BFilePanel* fSelectPanel; // for selecting apps to launch - + BButton* fAddButton; + BButton* fRemoveButton; + BButton* fSaveButton; + ColumnListView* fColumnListView; + BFilePanel* fSavePanel; + // for saving settings + BFilePanel* fOpenPanel; + // for loading settings + BFilePanel* fSelectPanel; + // for selecting apps to launch + // Points to the settings file to save to - BEntry fLastSaved; - + BEntry fLastSaved; + // true iff changes were made since last load or save bool fKeySetModified; - + // true iff the file-requester's ref should be appended to current - bool fLastOpenWasAppend; + bool fLastOpenWasAppend; }; -#endif - +#endif // SHORTCUTS_WINDOW_H diff --git a/src/preferences/shortcuts/clv/CLVColumn.cpp b/src/preferences/shortcuts/clv/CLVColumn.cpp index ed88dc2976..1b3e635e80 100644 --- a/src/preferences/shortcuts/clv/CLVColumn.cpp +++ b/src/preferences/shortcuts/clv/CLVColumn.cpp @@ -1,211 +1,228 @@ -//Column list header source file +/* + * Copyright 1999-2009 Jeremy Friesner + * Copyright 2009-2014 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jeremy Friesner + * John Scipione, jscipione@gmail.com + */ -//****************************************************************************************************** -//**** PROJECT HEADER FILES -//****************************************************************************************************** #define CLVColumn_CPP + #include + #include "CLVColumn.h" #include "ColumnListView.h" #include "CLVColumnLabelView.h" -//****************************************************************************************************** -//**** CLVColumn CLASS DEFINITION -//****************************************************************************************************** -CLVColumn::CLVColumn(const char* label,BPopUpMenu * popup,float width,uint32 flags,float min_width) +CLVColumn::CLVColumn(const char* label, BPopUpMenu* popup, float width, + uint32 flags, float minWidth) { - fPopup = popup; + fPopup = popup; - if(flags & CLV_EXPANDER) - { + if (flags & CLV_EXPANDER) { label = NULL; width = 20.0; - min_width = 20.0; - flags &= CLV_NOT_MOVABLE | CLV_LOCK_AT_BEGINNING | CLV_HIDDEN | CLV_LOCK_WITH_RIGHT; + minWidth = 20.0; + flags &= CLV_NOT_MOVABLE | CLV_LOCK_AT_BEGINNING | CLV_HIDDEN + | CLV_LOCK_WITH_RIGHT; flags |= CLV_EXPANDER | CLV_NOT_RESIZABLE | CLV_MERGE_WITH_RIGHT; } - if(min_width < 4.0) - min_width = 4.0; - if(width < min_width) - width = min_width; - if(label) - { - fLabel = new char[strlen(label)+1]; - strcpy((char*)fLabel,label); - } - else + + if (minWidth < 4.0) + minWidth = 4.0; + + if (width < minWidth) + width = minWidth; + + if (label != NULL) { + fLabel = new char[strlen(label) + 1]; + strcpy((char*)fLabel, label); + } else fLabel = NULL; + fWidth = width; - fMinWidth = min_width; + fMinWidth = minWidth; fFlags = flags; fPushedByExpander = false; fParent = NULL; - fSortMode = NoSort; + fSortMode = SORT_MODE_NONE; } CLVColumn::~CLVColumn() { - delete [] fLabel; - if(fParent) fParent->RemoveColumn(this); - delete fPopup; + delete[] fLabel; + if (fParent != NULL) + fParent->RemoveColumn(this); + + delete fPopup; } -float CLVColumn::Width() const +float +CLVColumn::Width() const { return fWidth; } -void CLVColumn::SetWidth(float width) +void +CLVColumn::SetWidth(float width) { if(width < fMinWidth) width = fMinWidth; - if(width != fWidth) - { - float OldWidth = fWidth; + + if(width != fWidth) { + float oldWidth = fWidth; fWidth = width; - if(IsShown() && fParent) - { - BWindow* ParentWindow = fParent->Window(); - if(ParentWindow) - ParentWindow->Lock(); - //Figure out the area after this column to scroll + if (IsShown() && fParent != NULL) { + BWindow* parentWindow = fParent->Window(); + if (parentWindow != NULL) + parentWindow->Lock(); + + // figure out the area after this column to scroll BRect ColumnViewBounds = fParent->fColumnLabelView->Bounds(); BRect MainViewBounds = fParent->Bounds(); - BRect SourceArea = ColumnViewBounds; - SourceArea.left = fColumnEnd+1.0; - BRect DestArea = SourceArea; - float Delta = width-OldWidth; - DestArea.left += Delta; - DestArea.right += Delta; + BRect sourceArea = ColumnViewBounds; + sourceArea.left = fColumnEnd + 1.0; + BRect destArea = sourceArea; + float delta = width-oldWidth; + destArea.left += delta; + destArea.right += delta; float LimitShift; - if(DestArea.right > ColumnViewBounds.right) - { - LimitShift = DestArea.right-ColumnViewBounds.right; - DestArea.right -= LimitShift; - SourceArea.right -= LimitShift; + if (destArea.right > ColumnViewBounds.right) { + LimitShift = destArea.right-ColumnViewBounds.right; + destArea.right -= LimitShift; + sourceArea.right -= LimitShift; } - if(DestArea.left < ColumnViewBounds.left) - { - LimitShift = ColumnViewBounds.left - DestArea.left; - DestArea.left += LimitShift; - SourceArea.left += LimitShift; + if (destArea.left < ColumnViewBounds.left) { + LimitShift = ColumnViewBounds.left - destArea.left; + destArea.left += LimitShift; + sourceArea.left += LimitShift; } - //Scroll the area that is being shifted - if(ParentWindow) - ParentWindow->UpdateIfNeeded(); - fParent->fColumnLabelView->CopyBits(SourceArea,DestArea); - SourceArea.top = MainViewBounds.top; - SourceArea.bottom = MainViewBounds.bottom; - DestArea.top = MainViewBounds.top; - DestArea.bottom = MainViewBounds.bottom; - fParent->CopyBits(SourceArea,DestArea); - //Invalidate the region that got revealed - DestArea = ColumnViewBounds; - if(width > OldWidth) - { - DestArea.left = fColumnEnd+1.0; - DestArea.right = fColumnEnd+Delta; + // scroll the area that is being shifted + if(parentWindow) + parentWindow->UpdateIfNeeded(); + + fParent->fColumnLabelView->CopyBits(sourceArea, destArea); + sourceArea.top = MainViewBounds.top; + sourceArea.bottom = MainViewBounds.bottom; + destArea.top = MainViewBounds.top; + destArea.bottom = MainViewBounds.bottom; + fParent->CopyBits(sourceArea, destArea); + + // invalidate the region that got revealed + destArea = ColumnViewBounds; + if (width > oldWidth) { + destArea.left = fColumnEnd + 1.0; + destArea.right = fColumnEnd + delta; + } else { + destArea.left = ColumnViewBounds.right + delta + 1.0; + destArea.right = ColumnViewBounds.right; } + fParent->fColumnLabelView->Invalidate(destArea); + destArea.top = MainViewBounds.top; + destArea.bottom = MainViewBounds.bottom; + fParent->Invalidate(destArea); + + // invalidate the old or new resize handle as necessary + destArea = ColumnViewBounds; + if (width > oldWidth) + destArea.left = fColumnEnd; else - { - DestArea.left = ColumnViewBounds.right+Delta+1.0; - DestArea.right = ColumnViewBounds.right; - } - fParent->fColumnLabelView->Invalidate(DestArea); - DestArea.top = MainViewBounds.top; - DestArea.bottom = MainViewBounds.bottom; - fParent->Invalidate(DestArea); + destArea.left = fColumnEnd + delta; - //Invalidate the old or new resize handle as necessary - DestArea = ColumnViewBounds; - if(width > OldWidth) - DestArea.left = fColumnEnd; - else - DestArea.left = fColumnEnd + Delta; - DestArea.right = DestArea.left; - fParent->fColumnLabelView->Invalidate(DestArea); + destArea.right = destArea.left; + fParent->fColumnLabelView->Invalidate(destArea); - //Update the column sizes, positions and group positions - fParent->UpdateColumnSizesDataRectSizeScrollBars(); + // update the column sizes, positions and group positions + fParent->ShiftDragGroup(); fParent->fColumnLabelView->UpdateDragGroups(); - if(ParentWindow) - ParentWindow->Unlock(); + if(parentWindow) + parentWindow->Unlock(); + } + if (fParent != NULL) { + fParent->ColumnWidthChanged(fParent->fColumnList.IndexOf(this), + fWidth); } - if(fParent) - fParent->ColumnWidthChanged(fParent->fColumnList.IndexOf(this),fWidth); } } -uint32 CLVColumn::Flags() const +uint32 +CLVColumn::Flags() const { return fFlags; } -bool CLVColumn::IsShown() const +bool +CLVColumn::IsShown() const { - if(fFlags & CLV_HIDDEN) + if ((fFlags & CLV_HIDDEN) != 0) return false; else return true; } -void CLVColumn::SetShown(bool Shown) +void +CLVColumn::SetShown(bool show) { bool shown = IsShown(); - if(shown != Shown) - { - if(Shown) + if (shown != show) { + if (show) fFlags &= 0xFFFFFFFF^CLV_HIDDEN; else fFlags |= CLV_HIDDEN; - if(fParent) - { - float UpdateLeft = fColumnBegin; - BWindow* ParentWindow = fParent->Window(); - if(ParentWindow) - ParentWindow->Lock(); - fParent->UpdateColumnSizesDataRectSizeScrollBars(); + + if (fParent != NULL) { + float updateLeft = fColumnBegin; + BWindow* parentWindow = fParent->Window(); + if (parentWindow != NULL) + parentWindow->Lock(); + + fParent->ShiftDragGroup(); fParent->fColumnLabelView->UpdateDragGroups(); - if(Shown) - UpdateLeft = fColumnBegin; - BRect Area = fParent->fColumnLabelView->Bounds(); - Area.left = UpdateLeft; - fParent->fColumnLabelView->Invalidate(Area); - Area = fParent->Bounds(); - Area.left = UpdateLeft; - fParent->Invalidate(Area); - if(fFlags & CLV_EXPANDER) - { - if(!Shown) + if (show) + updateLeft = fColumnBegin; + + BRect area = fParent->fColumnLabelView->Bounds(); + area.left = updateLeft; + fParent->fColumnLabelView->Invalidate(area); + area = fParent->Bounds(); + area.left = updateLeft; + fParent->Invalidate(area); + if ((fFlags & CLV_EXPANDER) != 0) { + if (!show) fParent->fExpanderColumn = -1; else fParent->fExpanderColumn = fParent->IndexOfColumn(this); } - if(ParentWindow) - ParentWindow->Unlock(); + if (parentWindow != NULL) + parentWindow->Unlock(); } } } -CLVSortMode CLVColumn::SortMode() const +CLVSortMode +CLVColumn::SortMode() const { return fSortMode; } -void CLVColumn::SetSortMode(CLVSortMode mode) + +void +CLVColumn::SetSortMode(CLVSortMode mode) { - if(fParent) - fParent->SetSortMode(fParent->IndexOfColumn(this),mode); + if (fParent != NULL) + fParent->SetSortMode(fParent->IndexOfColumn(this), mode); else fSortMode = mode; } diff --git a/src/preferences/shortcuts/clv/CLVColumn.h b/src/preferences/shortcuts/clv/CLVColumn.h index 89e809d45c..2b77288a6d 100644 --- a/src/preferences/shortcuts/clv/CLVColumn.h +++ b/src/preferences/shortcuts/clv/CLVColumn.h @@ -1,107 +1,118 @@ -#ifndef CLVColumn_h -#define CLVColumn_h +/* + * Copyright 1999-2009 Jeremy Friesner + * Copyright 2009-2014 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jeremy Friesner + * John Scipione, jscipione@gmail.com + */ +#ifndef CLV_COLUMN_H +#define CLV_COLUMN_H + #include #include -//****************************************************************************************************** -//**** PROJECT HEADER FILES AND CLASS NAME DECLARATIONS -//****************************************************************************************************** + +// flags +enum { + CLV_SORT_KEYABLE = 0x00000001, + // Can be used as the sorting key + CLV_NOT_MOVABLE = 0x00000002, + // Column can't be moved by user + CLV_NOT_RESIZABLE = 0x00000004, + // Column can't be resized by user + CLV_LOCK_AT_BEGINNING = 0x00000008, + // Movable columns may not be placed or moved by the user + // into a position before this one + CLV_LOCK_AT_END = 0x00000010, + // Movable columns may not be placed or moved by the user + // into a position after this one + CLV_HIDDEN = 0x00000020, + // This column is hidden initially + CLV_MERGE_WITH_RIGHT = 0x00000040, + // Merge this column label with the one that follows it. + CLV_LOCK_WITH_RIGHT = 0x00000080, + // Lock this column to the one that follows it such that + // if the column to the right is moved by the user, this + // one will move with it and vice versa + CLV_EXPANDER = 0x00000100, + // Column contains an expander. You may only use one + // expander in a ColumnListView, and an expander may not be + // added to a non-hierarchal ColumnListView. It may not + // have a label. Its width is automatically set to 20.0. + // The only flags that affect it are CLV_NOT_MOVABLE, + // CLV_LOCK_AT_BEGINNING, CLV_NOT_SHOWN and + // CLV_LOCK_WITH_RIGHT. The others are set for you: + // CLV_NOT_RESIZABLE | CLV_MERGE_WITH_RIGHT + CLV_PUSH_PASS = 0x00000200 + // Causes this column, if pushed by an expander to the + // left, to pass that push on and also push the next + // column to the right. +}; + +enum CLVSortMode { + SORT_MODE_ASCENDING, + SORT_MODE_DESCENDING, + SORT_MODE_NONE +}; + + class ColumnListView; class CLVColumn; class CLVListItem; -//****************************************************************************************************** -//**** CONSTANTS -//****************************************************************************************************** -//Flags -enum -{ - CLV_SORT_KEYABLE = 0x00000001, //Can be used as the sorting key - CLV_NOT_MOVABLE = 0x00000002, //Column can't be moved by user - CLV_NOT_RESIZABLE = 0x00000004, //Column can't be resized by user - CLV_LOCK_AT_BEGINNING = 0x00000008, //Movable columns may not be placed or moved by the user - //into a position before this one - CLV_LOCK_AT_END = 0x00000010, //Movable columns may not be placed or moved by the user - //into a position after this one - CLV_HIDDEN = 0x00000020, //This column is hidden initially - CLV_MERGE_WITH_RIGHT = 0x00000040, //Merge this column label with the one that follows it. - CLV_LOCK_WITH_RIGHT = 0x00000080, //Lock this column to the one that follows it such that - //if the column to the right is moved by the user, this - //one will move with it and vice versa - CLV_EXPANDER = 0x00000100, //Column contains an expander. You may only use one - //expander in a ColumnListView, and an expander may not be - //added to a non-hierarchal ColumnListView. It may not - //have a label. Its width is automatically set to 20.0. - //The only flags that affect it are CLV_NOT_MOVABLE, - //CLV_LOCK_AT_BEGINNING, CLV_NOT_SHOWN and - //CLV_LOCK_WITH_RIGHT. The others are set for you: - //CLV_NOT_RESIZABLE | CLV_MERGE_WITH_RIGHT - CLV_PUSH_PASS = 0x00000200 //Causes this column, if pushed by an expander to the - //left, to pass that push on and also push the next -}; //column to the right. +class CLVColumn { +public: + CLVColumn(const char* label, + BPopUpMenu* popup = NULL, + float width = 20.0, uint32 flags = 0L, + float min_width = 20.0); + virtual ~CLVColumn(); -enum CLVSortMode -{ - Ascending, - Descending, - NoSort -}; + // Archival stuff + /* Not implemented yet + CLVColumn(BMessage* archive); + static CLVColumn* Instantiate(BMessage* data); + virtual status_t Archive(BMessage* data, bool deep = true) const; + */ + // Functions + float Width() const; + virtual void SetWidth(float width); + // Can be overridden to detect changes to the column width + // however since you are probably overriding ColumnListView + // and dealing with an array of columns anyway, it is + // probably more useful to override + // ColumnListView::ColumnWidthChanged to detect changes to + // column widths + uint32 Flags() const; + bool IsShown() const; + void SetShown(bool show); + CLVSortMode SortMode() const; + void SetSortMode(CLVSortMode mode); + const char* GetLabel() const { return fLabel; } + BPopUpMenu* GetPopup() { return fPopup; } -//****************************************************************************************************** -//**** ColumnListView CLASS DECLARATION -//****************************************************************************************************** -class CLVColumn -{ - public: - //Constructor and destructor - CLVColumn( const char* label, - BPopUpMenu * popup = NULL, - float width = 20.0, - uint32 flags = 0L, - float min_width = 20.0); - virtual ~CLVColumn(); - - //Archival stuff - /* Not implemented yet - CLVColumn(BMessage* archive); - static CLVColumn* Instantiate(BMessage* data); - virtual status_t Archive(BMessage* data, bool deep = true) const; - */ - - //Functions - float Width() const; - virtual void SetWidth(float width); //Can be overridden to detect changes to the column width - //however since you are probably overriding - //ColumnListView and dealing with an array of columns - //anyway, it is probably more useful to override - //ColumnListView::ColumnWidthChanged to detect changes to - //column widths - uint32 Flags() const; - bool IsShown() const; - void SetShown(bool shown); - CLVSortMode SortMode() const; - void SetSortMode(CLVSortMode mode); - const char * GetLabel() const {return fLabel;} - BPopUpMenu * GetPopup() {return fPopup;} - - private: +private: friend class ColumnListView; friend class CLVColumnLabelView; friend class CLVListItem; - const char *fLabel; - float fWidth; - float fMinWidth; - float fColumnBegin; - float fColumnEnd; - uint32 fFlags; - bool fPushedByExpander; - CLVSortMode fSortMode; - ColumnListView* fParent; - BPopUpMenu * fPopup; // added by jaf + const char* fLabel; + float fWidth; + float fMinWidth; + float fColumnBegin; + float fColumnEnd; + uint32 fFlags; + bool fPushedByExpander; + CLVSortMode fSortMode; + ColumnListView* fParent; + BPopUpMenu* fPopup; + // added by jaf }; -#endif + +#endif // CLV_COLUMN_H diff --git a/src/preferences/shortcuts/clv/CLVColumnLabelView.cpp b/src/preferences/shortcuts/clv/CLVColumnLabelView.cpp index e1ea8cc3b6..3567bce34d 100644 --- a/src/preferences/shortcuts/clv/CLVColumnLabelView.cpp +++ b/src/preferences/shortcuts/clv/CLVColumnLabelView.cpp @@ -1,24 +1,30 @@ -//ColumnLabelView class source file +/* + * Copyright 1999-2009 Jeremy Friesner + * Copyright 2009-2014 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jeremy Friesner + * John Scipione, jscipione@gmail.com + */ -//****************************************************************************************************** -//**** PROJECT HEADER FILES -//****************************************************************************************************** #define CLVColumnLabelView_CPP + #include "CLVColumnLabelView.h" #include "ColumnListView.h" #include "CLVColumn.h" #include "MouseWatcher.h" -//****************************************************************************************************** -//**** FUNCTION DEFINITIONS -//****************************************************************************************************** -CLVColumnLabelView::CLVColumnLabelView(BRect Bounds,ColumnListView* parent,const BFont* Font) -: BView(Bounds,NULL,B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP,B_WILL_DRAW|B_FRAME_EVENTS), -fDragGroups(10) +CLVColumnLabelView::CLVColumnLabelView(BRect frame, ColumnListView* parent, + const BFont* font) + : + BView(frame, NULL, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, + B_WILL_DRAW | B_FRAME_EVENTS), + fDragGroupsList(10) { - SetFont(Font); + SetFont(font); SetViewColor(BeBackgroundGrey); SetLowColor(BeBackgroundGrey); SetHighColor(Black); @@ -27,726 +33,778 @@ fDragGroups(10) fColumnClicked = NULL; fColumnDragging = false; fColumnResizing = false; - font_height FontAttributes; - Font->GetHeight(&FontAttributes); - fFontAscent = ceil(FontAttributes.ascent); + font_height fontAttributes; + font->GetHeight(&fontAttributes); + fFontAscent = ceil(fontAttributes.ascent); } CLVColumnLabelView::~CLVColumnLabelView() { - int32 NumberOfGroups = fDragGroups.CountItems(); - for(int32 Counter = 0; Counter < NumberOfGroups; Counter++) - fDragGroups.RemoveItem(int32(0)); + int32 groupCount = fDragGroupsList.CountItems(); + for (int32 i = 0; i < groupCount; i++) + fDragGroupsList.RemoveItem(int32(0)); } -void CLVColumnLabelView::Draw(BRect UpdateRect) +void +CLVColumnLabelView::Draw(BRect updateRect) { - BRegion ClippingRegion; - GetClippingRegion(&ClippingRegion); - BRect ViewBounds = Bounds(); + BRegion clippingRegion; + GetClippingRegion(&clippingRegion); + BRect bounds = Bounds(); - //Draw each column label in turn - float ColumnBegin = 0.0; - float ColumnEnd = -1.0; - bool MergeWithLeft = false; - int32 NumberOfColumns = fDisplayList->CountItems(); - BPoint Start,Stop; - for(int32 ColumnDraw = 0; ColumnDraw < NumberOfColumns; ColumnDraw++) - { - CLVColumn* ThisColumn = (CLVColumn*)fDisplayList->ItemAt(ColumnDraw); - if(ThisColumn->IsShown()) - { - //Figure out where this column is - ColumnBegin = ThisColumn->fColumnBegin; - ColumnEnd = ThisColumn->fColumnEnd; - //Start by figuring out if this column will merge with a shown column to the right - bool MergeWithRight = false; - if(ThisColumn->fFlags & CLV_MERGE_WITH_RIGHT) - { - for(int32 ColumnCounter = ColumnDraw+1; ColumnCounter < NumberOfColumns; - ColumnCounter++) - { - CLVColumn* NextColumn = (CLVColumn*)fDisplayList->ItemAt(ColumnCounter); - if(NextColumn->IsShown()) - { - //The next column is shown - MergeWithRight = true; + // draw each column label in turn + float columnBegin = 0.0; + float columnEnd = -1.0; + bool shouldMergeWithLeft = false; + int32 columnCount = fDisplayList->CountItems(); + BPoint startingPoint; + BPoint stoppingPoint; + for (int32 i = 0; i < columnCount; i++) { + CLVColumn* column = (CLVColumn*)fDisplayList->ItemAt(i); + if (column->IsShown()) { + // figure out where this column is + columnBegin = column->fColumnBegin; + columnEnd = column->fColumnEnd; + // start by figuring out if this column will merge + // with a shown column to the right + bool shouldMergeWithRight = false; + if ((column->fFlags & CLV_MERGE_WITH_RIGHT) != 0) { + for (int32 j = i + 1; j < columnCount; j++) { + CLVColumn* nextColumn = (CLVColumn*)fDisplayList->ItemAt(j); + if (nextColumn->IsShown()) { + // next column is shown + shouldMergeWithRight = true; + break; + } else if ((nextColumn->fFlags & CLV_MERGE_WITH_RIGHT) + == 0) { + // next column is not shown and doesn't + // pass on the merge break; } - else if(!(NextColumn->fFlags & CLV_MERGE_WITH_RIGHT)) - //The next column is not shown and doesn't pass on the merge - break; } } - if(ClippingRegion.Intersects(BRect(ColumnBegin,ViewBounds.top,ColumnEnd, - ViewBounds.bottom))) - { - //Need to draw this column + + if (clippingRegion.Intersects(BRect(columnBegin, + bounds.top, columnEnd, bounds.bottom))) { + // need to draw this column BeginLineArray(4); - //Top line - Start.Set(ColumnBegin,ViewBounds.top); - Stop.Set(ColumnEnd-1.0,ViewBounds.top); - if(MergeWithRight && !(ThisColumn == fColumnClicked && fColumnResizing)) - Stop.x = ColumnEnd; - AddLine(Start,Stop,BeHighlight); - //Left line - if(!MergeWithLeft) - AddLine(BPoint(ColumnBegin,ViewBounds.top+1.0), - BPoint(ColumnBegin,ViewBounds.bottom),BeHighlight); - //Bottom line - Start.Set(ColumnBegin+1.0,ViewBounds.bottom); - if(MergeWithLeft) - Start.x = ColumnBegin; - Stop.Set(ColumnEnd-1.0,ViewBounds.bottom); - if(MergeWithRight && !(ThisColumn == fColumnClicked && fColumnResizing)) - Stop.x = ColumnEnd; - AddLine(Start,Stop,BeShadow); - //Right line - if(ThisColumn == fColumnClicked && fColumnResizing) - AddLine(BPoint(ColumnEnd,ViewBounds.top),BPoint(ColumnEnd,ViewBounds.bottom), - BeFocusBlue); - else if(!MergeWithRight) - AddLine(BPoint(ColumnEnd,ViewBounds.top),BPoint(ColumnEnd,ViewBounds.bottom), - BeShadow); + + // top line + startingPoint.Set(columnBegin, bounds.top); + stoppingPoint.Set(columnEnd - 1.0, bounds.top); + if (shouldMergeWithRight && !(column == fColumnClicked + && fColumnResizing)) { + stoppingPoint.x = columnEnd; + } + AddLine(startingPoint, stoppingPoint, BeHighlight); + + // left line + if (!shouldMergeWithLeft) { + AddLine(BPoint(columnBegin, bounds.top + 1.0), + BPoint(columnBegin, bounds.bottom), BeHighlight); + } + + // bottom line + startingPoint.Set(columnBegin + 1.0, bounds.bottom); + if (shouldMergeWithLeft) + startingPoint.x = columnBegin; + + stoppingPoint.Set(columnEnd - 1.0, bounds.bottom); + if (shouldMergeWithRight && !(column == fColumnClicked + && fColumnResizing)) { + stoppingPoint.x = columnEnd; + } + AddLine(startingPoint, stoppingPoint, BeShadow); + + // right line + if (column == fColumnClicked && fColumnResizing) { + AddLine(BPoint(columnEnd, bounds.top), + BPoint(columnEnd, bounds.bottom), BeFocusBlue); + } else if (!shouldMergeWithRight) { + AddLine(BPoint(columnEnd, bounds.top), + BPoint(columnEnd, bounds.bottom), BeShadow); + } EndLineArray(); - //Add the label - if(ThisColumn->fLabel) - { - //Limit the clipping region to the interior of the box - BRegion TextRegion; - TextRegion.Include(BRect(ColumnBegin+1.0,ViewBounds.top+1.0,ColumnEnd-1.0, - ViewBounds.bottom-1.0)); - ConstrainClippingRegion(&TextRegion); + // add the label + if (column->fLabel != NULL) { + // limit the clipping region to the interior of the box + BRegion textRegion; + textRegion.Include(BRect(columnBegin + 1.0, + bounds.top + 1.0, columnEnd - 1.0, + bounds.bottom - 1.0)); + ConstrainClippingRegion(&textRegion); - //Draw the label - if(ThisColumn == fColumnClicked && !fColumnResizing) + // draw the label + if (column == fColumnClicked && !fColumnResizing) SetHighColor(BeFocusBlue); + SetDrawingMode(B_OP_OVER); - DrawString(ThisColumn->fLabel,BPoint(ColumnBegin+9.0,ViewBounds.top+2.0+fFontAscent)); + DrawString(column->fLabel, + BPoint(columnBegin + 9.0, + bounds.top + 2.0 + fFontAscent)); SetDrawingMode(B_OP_COPY); - //Underline if this is a selected sort column - if(fParent->fSortKeyList.HasItem(ThisColumn) && ThisColumn->fSortMode != NoSort) - { - float Width = StringWidth(ThisColumn->fLabel); - StrokeLine(BPoint(ColumnBegin+8.0,ViewBounds.top+2.0+fFontAscent+2.0), - BPoint(ColumnBegin+8.0+Width,ViewBounds.top+2.0+fFontAscent+2.0)); + // underline if this is a selected sort column + if (fParent->fSortKeyList.HasItem(column) + && column->fSortMode != SORT_MODE_NONE) { + float Width = StringWidth(column->fLabel); + StrokeLine(BPoint(columnBegin + 8.0, + bounds.top + 2.0 + fFontAscent + 2.0), + BPoint(columnBegin + 8.0 + Width, + bounds.top + 2.0 + fFontAscent + 2.0)); } - if(ThisColumn == fColumnClicked && !fColumnResizing) + if (column == fColumnClicked && !fColumnResizing) SetHighColor(Black); - //Restore the clipping region + // restore the clipping region ConstrainClippingRegion(NULL); } } - //Set MergeWithLeft flag for the next column to the appropriate state - MergeWithLeft = MergeWithRight; + + // set shouldMergeWithLeft flag for the next column to + // the appropriate state + shouldMergeWithLeft = shouldMergeWithRight; } } - //Add highlight and shadow to the region after the columns if necessary - if(ColumnEnd < ViewBounds.right) - { - ColumnBegin = ColumnEnd+1.0; - if(ClippingRegion.Intersects(BRect(ColumnEnd+1.0,ViewBounds.top,ViewBounds.right, - ViewBounds.bottom))) - { + // add highlight and shadow to the region after the columns if necessary + if (columnEnd < bounds.right) { + columnBegin = columnEnd + 1.0; + + if (clippingRegion.Intersects(BRect(columnEnd + 1.0, + bounds.top, bounds.right, bounds.bottom))) { BeginLineArray(3); - //Top line - AddLine(BPoint(ColumnBegin,ViewBounds.top),BPoint(ViewBounds.right,ViewBounds.top), - BeHighlight); - //Left line - AddLine(BPoint(ColumnBegin,ViewBounds.top+1.0),BPoint(ColumnBegin,ViewBounds.bottom), - BeHighlight); - //Bottom line - Start.Set(ColumnBegin+1.0,ViewBounds.bottom); - if(MergeWithLeft) - Start.x = ColumnBegin; - Stop.Set(ViewBounds.right,ViewBounds.bottom); - AddLine(Start,Stop,BeShadow); + + // top line + AddLine(BPoint(columnBegin, bounds.top), + BPoint(bounds.right, bounds.top), BeHighlight); + + // left line + AddLine(BPoint(columnBegin, bounds.top + 1.0), + BPoint(columnBegin, bounds.bottom), BeHighlight); + + // bottom line + startingPoint.Set(columnBegin + 1.0, bounds.bottom); + if (shouldMergeWithLeft) + startingPoint.x = columnBegin; + + stoppingPoint.Set(bounds.right, bounds.bottom); + AddLine(startingPoint, stoppingPoint, BeShadow); EndLineArray(); } } - //Draw the dragging box if necessary - if(fColumnClicked && fColumnDragging) - { - float DragOutlineLeft = fPreviousMousePos.x-fDragBoxMouseHoldOffset; - float GroupBegin = ((CLVDragGroup*)fDragGroups.ItemAt(fDragGroup))->GroupBegin; - if(DragOutlineLeft < GroupBegin && fSnapGroupBefore == -1) - DragOutlineLeft = GroupBegin; - if(DragOutlineLeft > GroupBegin && fSnapGroupAfter == -1) - DragOutlineLeft = GroupBegin; - float DragOutlineRight = DragOutlineLeft + fDragBoxWidth; + // draw the dragging box if necessary + if (fColumnClicked && fColumnDragging) { + float dragOutlineLeft = fPreviousMousePosition.x + - fDragBoxMouseHoldOffset; + float groupBegin = ((CLVDragGroup*)fDragGroupsList.ItemAt( + fDragGroupIndex))->groupBeginIndex; + if (dragOutlineLeft < groupBegin && fSnapGroupBeforeIndex == -1) + dragOutlineLeft = groupBegin; + + if (dragOutlineLeft > groupBegin && fSnapGroupAfterIndex == -1) + dragOutlineLeft = groupBegin; + + float DragOutlineRight = dragOutlineLeft + fDragBoxWidth; + BeginLineArray(4); - AddLine(BPoint(DragOutlineLeft,ViewBounds.top),BPoint(DragOutlineRight, - ViewBounds.top),BeFocusBlue); - AddLine(BPoint(DragOutlineLeft,ViewBounds.bottom),BPoint(DragOutlineRight, - ViewBounds.bottom),BeFocusBlue); - AddLine(BPoint(DragOutlineLeft,ViewBounds.top+1.0),BPoint(DragOutlineLeft, - ViewBounds.bottom-1.0),BeFocusBlue); - AddLine(BPoint(DragOutlineRight,ViewBounds.top+1.0),BPoint(DragOutlineRight, - ViewBounds.bottom-1.0),BeFocusBlue); + AddLine(BPoint(dragOutlineLeft, bounds.top), + BPoint(DragOutlineRight, bounds.top), BeFocusBlue); + AddLine(BPoint(dragOutlineLeft, bounds.bottom), + BPoint(DragOutlineRight, bounds.bottom), BeFocusBlue); + AddLine(BPoint(dragOutlineLeft, bounds.top + 1.0), + BPoint(dragOutlineLeft, bounds.bottom - 1.0), BeFocusBlue); + AddLine(BPoint(DragOutlineRight, bounds.top + 1.0), + BPoint(DragOutlineRight, bounds.bottom - 1.0), BeFocusBlue); EndLineArray(); - fPrevDragOutlineLeft = DragOutlineLeft; - fPrevDragOutlineRight = DragOutlineRight; + + fPreviousDragOutlineLeft = dragOutlineLeft; + fPreviousDragOutlineRight = DragOutlineRight; } } -void CLVColumnLabelView::MouseDown(BPoint Point) +void +CLVColumnLabelView::MouseDown(BPoint where) { - //Only pay attention to primary mouse button - bool WatchMouse = false; - BPoint MousePos; - uint32 Buttons; - GetMouse(&MousePos,&Buttons); - if(Buttons == B_PRIMARY_MOUSE_BUTTON) - { - BRect ViewBounds = Bounds(); + // pay attention only to primary mouse button + bool shouldWatchMouse = false; + BPoint mousePosition; + uint32 buttons; + GetMouse(&mousePosition, &buttons); + if (buttons == B_PRIMARY_MOUSE_BUTTON) { + BRect bounds = Bounds(); - //Make sure no other column was already clicked. If so, just discard the old one and redraw the - //view - if(fColumnClicked != NULL) - { + // Make sure no other column was already clicked. + // If so, just discard the old one and redraw the view. + if (fColumnClicked != NULL) { Invalidate(); fColumnClicked = NULL; } - //Find the column that the user clicked, if any - bool GrabbedResizeTab = false; - int32 NumberOfColumns = fDisplayList->CountItems(); - int32 ColumnFind; - CLVColumn* ThisColumn = NULL; - for(ColumnFind = 0; ColumnFind < NumberOfColumns; ColumnFind++) - { - ThisColumn = (CLVColumn*)fDisplayList->ItemAt(ColumnFind); - if(ThisColumn->IsShown()) - { - float ColumnBegin = ThisColumn->fColumnBegin; - float ColumnEnd = ThisColumn->fColumnEnd; - if ((Point.x >= ColumnBegin && Point.x <= ColumnEnd) || - ((ColumnFind == NumberOfColumns-1)&&(Point.x >= ColumnBegin))) // anything after the rightmost column can drag... jaf - { - const float resizeTolerance = 5.0f; // jaf is too clumsy to click on a 2 pixel space. :) + // find the column that the user clicked, if any + bool didGrabResizeTab = false; + int32 columnCount = fDisplayList->CountItems(); + int32 i; + CLVColumn* column = NULL; + for (i = 0; i < columnCount; i++) { + column = (CLVColumn*)fDisplayList->ItemAt(i); + if (column->IsShown()) { + float columnBegin = column->fColumnBegin; + float columnEnd = column->fColumnEnd; + if ((where.x >= columnBegin && where.x <= columnEnd) + || ((i == columnCount - 1) && (where.x >= columnBegin))) { + // anything after the rightmost column can drag... jaf + const float resizeTolerance = 5.0f; + // jaf is too clumsy to click on a 2 pixel space. :) - //User clicked in this column - if(Point.x <= ColumnBegin+resizeTolerance) - { - //User clicked the resize tab preceding this column - for(ColumnFind--; ColumnFind >= 0; ColumnFind--) - { - ThisColumn = (CLVColumn*)fDisplayList->ItemAt(ColumnFind); - if(ThisColumn->IsShown()) - { - GrabbedResizeTab = true; + // user clicked in this column + if (where.x <= columnBegin + resizeTolerance) { + // user clicked the resize tab preceding this column + for (i--; i >= 0; i--) { + column = (CLVColumn*)fDisplayList->ItemAt(i); + if (column->IsShown()) { + didGrabResizeTab = true; break; } } - } - else if(Point.x >= ColumnEnd-resizeTolerance) - { - //User clicked the resize tab for (after) this column - GrabbedResizeTab = true; - } - else - { - //The user clicked in this column - fColumnClicked = (CLVColumn*)fDisplayList->ItemAt(ColumnFind); + } else if (where.x >= columnEnd-resizeTolerance) { + // user clicked the resize tab for (after) this column + didGrabResizeTab = true; + } else { + // user clicked in this column + fColumnClicked = (CLVColumn*)fDisplayList->ItemAt(i); fColumnResizing = false; - fPreviousMousePos = Point; - fMouseClickedPos = Point; + fPreviousMousePosition = where; + fMouseClickedPosition = where; fColumnDragging = false; SetSnapMinMax(); - fDragBoxMouseHoldOffset = Point.x- - ((CLVDragGroup*)fDragGroups.ItemAt(fDragGroup))->GroupBegin; - Invalidate(BRect(ColumnBegin+1.0,ViewBounds.top+1.0,ColumnEnd-1.0, - ViewBounds.bottom-1.0)); + fDragBoxMouseHoldOffset = where.x + - ((CLVDragGroup*)fDragGroupsList.ItemAt( + fDragGroupIndex))->groupBeginIndex; - //Start watching the mouse - WatchMouse = true; + Invalidate(BRect(columnBegin + 1.0, + bounds.top + 1.0, columnEnd - 1.0, + bounds.bottom - 1.0)); + + // start watching the mouse + shouldWatchMouse = true; } break; } } } - if(GrabbedResizeTab) - { - //The user grabbed a resize tab. See if resizing of this column is allowed - if(!(ThisColumn->fFlags & CLV_NOT_RESIZABLE)) - { - fColumnClicked = (CLVColumn*)fDisplayList->ItemAt(ColumnFind); - fColumnResizing = true; - fPreviousMousePos = Point; - fMouseClickedPos = Point; - fColumnDragging = false; - fResizeMouseHoldOffset = Point.x-fColumnClicked->fColumnEnd; - Invalidate(BRect(fColumnClicked->fColumnEnd,ViewBounds.top,ThisColumn->fColumnEnd, - ViewBounds.bottom)); - //Start watching the mouse - WatchMouse = true; + if (didGrabResizeTab) { + // user grabbed a resize tab, check to see if + // resizing this column is allowed + if ((column->fFlags & CLV_NOT_RESIZABLE) == 0) { + fColumnClicked = (CLVColumn*)fDisplayList->ItemAt(i); + fColumnResizing = true; + fPreviousMousePosition = where; + fMouseClickedPosition = where; + fColumnDragging = false; + fResizeMouseHoldOffset = where.x - fColumnClicked->fColumnEnd; + Invalidate(BRect(fColumnClicked->fColumnEnd, bounds.top, + column->fColumnEnd, bounds.bottom)); + + // start watching the mouse + shouldWatchMouse = true; } } } - if(WatchMouse) - { + + if (shouldWatchMouse) { thread_id MouseWatcherThread = StartMouseWatcher(this); - if(MouseWatcherThread == B_NO_MORE_THREADS || MouseWatcherThread == B_NO_MEMORY) + if (MouseWatcherThread == B_NO_MORE_THREADS + || MouseWatcherThread == B_NO_MEMORY) { fColumnClicked = NULL; + } } } -void CLVColumnLabelView::MessageReceived(BMessage *message) +void +CLVColumnLabelView::MessageReceived(BMessage* message) { - if(message->what != MW_MOUSE_MOVED && message->what != MW_MOUSE_DOWN && message->what != MW_MOUSE_UP) + if (message->what != MW_MOUSE_MOVED && message->what != MW_MOUSE_DOWN + && message->what != MW_MOUSE_UP) { BView::MessageReceived(message); - else if(fColumnClicked != NULL) - { - BPoint MousePos; - message->FindPoint("where",&MousePos); - uint32 Buttons; - message->FindInt32("buttons",(int32*)&Buttons); - uint32 Modifiers; - message->FindInt32("modifiers",(int32*)&Modifiers); - BRect ViewBounds; - ViewBounds = Bounds(); - uint32 ColumnFlags = fColumnClicked->Flags(); - if(Buttons == B_PRIMARY_MOUSE_BUTTON) - { - //Mouse is still held down - if(!fColumnResizing) - { - //User is clicking or dragging - if((MousePos.xfMouseClickedPos.x+2.0) && - !fColumnDragging) - { - //User is initiating a drag - if(fTheDragGroup->Flags & CLV_NOT_MOVABLE) - { - //Not allowed to drag this column - terminate the click - Invalidate(BRect(fColumnClicked->fColumnBegin,ViewBounds.top, - fColumnClicked->fColumnEnd,ViewBounds.bottom)); + } else if (fColumnClicked != NULL) { + BPoint mousePosition; + message->FindPoint("where", &mousePosition); + uint32 buttons; + message->FindInt32("buttons", (int32*)&buttons); + uint32 modifiers; + message->FindInt32("modifiers", (int32*)&modifiers); + BRect bounds; + bounds = Bounds(); + uint32 columnFlags = fColumnClicked->Flags(); + if (buttons == B_PRIMARY_MOUSE_BUTTON) { + // mouse is still held down + if (!fColumnResizing) { + // user is clicking or dragging + if ((mousePosition.x < fMouseClickedPosition.x - 2.0 + || mousePosition.x > fMouseClickedPosition.x + 2.0) + && !fColumnDragging) { + // user is initiating a drag + if ((fDragGroup->flags & CLV_NOT_MOVABLE) != 0) { + // not allowed to drag this column - terminate the click + Invalidate(BRect(fColumnClicked->fColumnBegin, + bounds.top, fColumnClicked->fColumnEnd, + bounds.bottom)); fColumnClicked = NULL; - } - else - { - //Actually initiate a drag + } else { + // actually initiate a drag fColumnDragging = true; - fPrevDragOutlineLeft = -1.0; - fPrevDragOutlineRight = -1.0; + fPreviousDragOutlineLeft = -1.0; + fPreviousDragOutlineRight = -1.0; } } - //Now deal with dragging - if(fColumnDragging) - { - //User is dragging - if(MousePos.xfPreviousMousePos.x) - { - //Mouse moved since I last checked - ViewBounds = Bounds(); + // now deal with dragging + if (fColumnDragging) { + // user is dragging + if (mousePosition.x < fPreviousMousePosition.x + || mousePosition.x > fPreviousMousePosition.x) { + // mouse moved since I last checked + bounds = Bounds(); - bool ColumnSnapped; - do - { - //Live dragging of columns - ColumnSnapped = false; - float ColumnsUpdateLeft = 0; - float ColumnsUpdateRight = 0; + bool hasColumnSnapped; + do { + // live dragging of columns + hasColumnSnapped = false; + float columnsUpdateLeft = 0; + float columnsUpdateRight = 0; float MainViewUpdateLeft = 0; float MainViewUpdateRight = 0; - CLVColumn* LastSwapColumn = NULL; - if(fSnapMin != -1.0 && MousePos.x < fSnapMin) - { - //Shift the group left - ColumnsUpdateLeft = fTheShownGroupBefore->GroupBegin; - ColumnsUpdateRight = fTheDragGroup->GroupEnd; - MainViewUpdateLeft = ColumnsUpdateLeft; - MainViewUpdateRight = ColumnsUpdateRight; - LastSwapColumn = fTheShownGroupBefore->LastColumnShown; - if(fTheDragGroup->LastColumnShown->fFlags & CLV_MERGE_WITH_RIGHT) - ColumnsUpdateRight += 1.0; - else if(fTheShownGroupBefore->LastColumnShown->fFlags & CLV_MERGE_WITH_RIGHT) - ColumnsUpdateRight += 1.0; - ShiftDragGroup(fSnapGroupBefore); - ColumnSnapped = true; + CLVColumn* lastSwapColumn = NULL; + if (fSnapMin != -1.0 + && mousePosition.x < fSnapMin) { + // shift the group left + columnsUpdateLeft + = fShownGroupBefore->groupBeginIndex; + columnsUpdateRight = fDragGroup->groupEndIndex; + MainViewUpdateLeft = columnsUpdateLeft; + MainViewUpdateRight = columnsUpdateRight; + lastSwapColumn + = fShownGroupBefore->lastColumnShown; + if ((fDragGroup->lastColumnShown->fFlags + & CLV_MERGE_WITH_RIGHT) != 0) { + columnsUpdateRight += 1.0; + } else if ((fShownGroupBefore-> + lastColumnShown->fFlags + & CLV_MERGE_WITH_RIGHT) != 0) { + columnsUpdateRight += 1.0; + } + + ShiftDragGroup(fSnapGroupBeforeIndex); + hasColumnSnapped = true; } - if(fSnapMax != -1.0 && MousePos.x > fSnapMax) - { - //Shift the group right - ColumnsUpdateLeft = fTheDragGroup->GroupBegin; - ColumnsUpdateRight = fTheShownGroupAfter->GroupEnd; - MainViewUpdateLeft = ColumnsUpdateLeft; - MainViewUpdateRight = ColumnsUpdateRight; - LastSwapColumn = fTheDragGroup->LastColumnShown; - if(fTheDragGroup->LastColumnShown->fFlags & CLV_MERGE_WITH_RIGHT) - ColumnsUpdateRight += 1.0; - else if(fTheShownGroupAfter->LastColumnShown->fFlags & CLV_MERGE_WITH_RIGHT) - ColumnsUpdateRight += 1.0; - ShiftDragGroup(fSnapGroupAfter+1); - ColumnSnapped = true; + + if (fSnapMax != -1.0 + && mousePosition.x > fSnapMax) { + // shift the group right + columnsUpdateLeft = fDragGroup->groupBeginIndex; + columnsUpdateRight + = fShownGroupAfter->groupEndIndex; + MainViewUpdateLeft = columnsUpdateLeft; + MainViewUpdateRight = columnsUpdateRight; + lastSwapColumn = fDragGroup->lastColumnShown; + if ((fDragGroup->lastColumnShown->fFlags + & CLV_MERGE_WITH_RIGHT) != 0) { + columnsUpdateRight += 1.0; + } else if ((fShownGroupAfter + ->lastColumnShown->fFlags + & CLV_MERGE_WITH_RIGHT) != 0) { + columnsUpdateRight += 1.0; + } + ShiftDragGroup(fSnapGroupAfterIndex + 1); + hasColumnSnapped = true; } - if(ColumnSnapped) - { - //Redraw the snapped column labels - Invalidate(BRect(ColumnsUpdateLeft,ViewBounds.top,ColumnsUpdateRight, - ViewBounds.bottom)); - BRect MainViewBounds = fParent->Bounds(); - //Modify MainViewUpdateRight if more columns are pushed by expanders - if(LastSwapColumn->fFlags & CLV_EXPANDER || - (LastSwapColumn->fPushedByExpander && (LastSwapColumn->fFlags & - CLV_PUSH_PASS))) - { - int32 NumberOfColumns = fDisplayList->CountItems(); - for(int32 ColumnCounter = fDisplayList->IndexOf(LastSwapColumn)+1; - ColumnCounter < NumberOfColumns; ColumnCounter++) - { - CLVColumn* ThisColumn = - (CLVColumn*)fDisplayList->ItemAt(ColumnCounter); - if(ThisColumn->IsShown()) - { - if(ThisColumn->fPushedByExpander) - MainViewUpdateRight = ThisColumn->fColumnEnd; + + if (hasColumnSnapped) { + // redraw the snapped column labels + Invalidate(BRect(columnsUpdateLeft, + bounds.top, columnsUpdateRight, + bounds.bottom)); + BRect mainBounds = fParent->Bounds(); + // modify MainViewUpdateRight if more + // columns are pushed by expanders + if ((lastSwapColumn->fFlags & CLV_EXPANDER) != 0 + || (lastSwapColumn->fPushedByExpander + && ((lastSwapColumn->fFlags & CLV_PUSH_PASS) + != 0))) { + int32 columnCount + = fDisplayList->CountItems(); + for (int32 j = fDisplayList->IndexOf( + lastSwapColumn) + 1; + j < columnCount; j++) { + CLVColumn* column = + (CLVColumn*)fDisplayList->ItemAt(j); + if (column->IsShown()) { + if (column->fPushedByExpander) + MainViewUpdateRight + = column->fColumnEnd; else break; } } } - fParent->Invalidate(BRect(MainViewUpdateLeft,MainViewBounds.top, - MainViewUpdateRight,MainViewBounds.bottom)); + fParent->Invalidate(BRect(MainViewUpdateLeft, + mainBounds.top, MainViewUpdateRight, + mainBounds.bottom)); } - }while(ColumnSnapped); - //Erase and redraw the drag rectangle but not the interior to avoid label flicker - float Min = fPrevDragOutlineLeft; - float Max = fPrevDragOutlineRight; - float Min2 = MousePos.x-fDragBoxMouseHoldOffset; - float GroupBegin = ((CLVDragGroup*)fDragGroups.ItemAt(fDragGroup))->GroupBegin; - if(Min2 < GroupBegin && fSnapGroupBefore == -1) - Min2 = GroupBegin; - if(Min2 > GroupBegin && fSnapGroupAfter == -1) - Min2 = GroupBegin; - float Max2 = Min2 + fDragBoxWidth; + } while (hasColumnSnapped); + // erase and redraw the drag rectangle but not the + // interior to avoid label flicker + float min = fPreviousDragOutlineLeft; + float max = fPreviousDragOutlineRight; + float min2 = mousePosition.x - fDragBoxMouseHoldOffset; + float groupBegin = ((CLVDragGroup*)fDragGroupsList.ItemAt( + fDragGroupIndex))->groupBeginIndex; + if (min2 < groupBegin && fSnapGroupBeforeIndex == -1) + min2 = groupBegin; + + if (min2 > groupBegin && fSnapGroupAfterIndex == -1) + min2 = groupBegin; + + float max2 = min2 + fDragBoxWidth; float Temp; - if(Min2 < Min || Min == -1.0) - {Temp = Min2;Min2 = Min;Min = Temp;} - if(Max2 > Max || Max == -1.0) - {Temp = Max2;Max2 = Max;Max = Temp;} - Invalidate(BRect(Min,ViewBounds.top+1.0,Min,ViewBounds.bottom-1.0)); - if(Min2 != -1.0) - Invalidate(BRect(Min2,ViewBounds.top+1.0,Min2,ViewBounds.bottom-1.0)); - Invalidate(BRect(Max,ViewBounds.top+1.0,Max,ViewBounds.bottom-1.0)); - if(Max2 != -1.0) - Invalidate(BRect(Max2,ViewBounds.top+1.0,Max2,ViewBounds.bottom-1.0)); - Invalidate(BRect(Min,ViewBounds.top,Max,ViewBounds.top)); - Invalidate(BRect(Min,ViewBounds.bottom,Max,ViewBounds.bottom)); + if (min2 < min || min == -1.0) { + Temp = min2; + min2 = min; + min = Temp; + } + + if (max2 > max || max == -1.0) { + Temp = max2; + max2 = max; + max = Temp; + } + Invalidate(BRect(min, bounds.top + 1.0, min, + bounds.bottom - 1.0)); + if (min2 != -1.0) { + Invalidate(BRect(min2, bounds.top + 1.0, min2, + bounds.bottom - 1.0)); + } + Invalidate(BRect(max, bounds.top + 1.0, max, + bounds.bottom - 1.0)); + if (max2 != -1.0) { + Invalidate(BRect(max2, bounds.top + 1.0, max2, + bounds.bottom - 1.0)); + } + Invalidate(BRect(min, bounds.top, max, bounds.top)); + Invalidate(BRect(min, bounds.bottom, max, + bounds.bottom)); + } + } + } else { + // user is resizing the column + if (mousePosition.x < fPreviousMousePosition.x + || mousePosition.x > fPreviousMousePosition.x) { + float newWidth = mousePosition.x - fResizeMouseHoldOffset + - fColumnClicked->fColumnBegin; + if (newWidth < fColumnClicked->fMinWidth) + newWidth = fColumnClicked->fMinWidth; + + if (newWidth != fColumnClicked->fWidth) { + fColumnClicked->SetWidth(newWidth); + fParent->ColumnWidthChanged(fParent->IndexOfColumn( + fColumnClicked), newWidth); } } } - else - { - //User is resizing the column - if(MousePos.xfPreviousMousePos.x) - { - float NewWidth = MousePos.x - fResizeMouseHoldOffset - fColumnClicked->fColumnBegin; - if(NewWidth < fColumnClicked->fMinWidth) - NewWidth = fColumnClicked->fMinWidth; - if(NewWidth != fColumnClicked->fWidth) - { - fColumnClicked->SetWidth(NewWidth); - fParent->ColumnWidthChanged(fParent->IndexOfColumn(fColumnClicked),NewWidth); - } - } - } - } - else if(Buttons == 0) - { - //Mouse button was released - if(!fColumnDragging && !fColumnResizing) - { - //Column was clicked - if(ColumnFlags&CLV_SORT_KEYABLE) - { - //The column is a "sortable" column - if(!(Modifiers&B_SHIFT_KEY)) - { - //The user wants to select it as the main sorting column - if(fParent->fSortKeyList.ItemAt(0) == fColumnClicked) - //The column was already selected; switch sort modes - fParent->ReverseSortMode(fParent->fColumnList.IndexOf(fColumnClicked)); - else + } else if (buttons == 0) { + // mouse button was released + if (!fColumnDragging && !fColumnResizing) { + // column was clicked + if ((columnFlags & CLV_SORT_KEYABLE) != 0) { + // column is a "sortable" column + if ((modifiers & B_SHIFT_KEY) == 0) { + // user wants to select it as the main sorting column + if (fParent->fSortKeyList.ItemAt(0) == fColumnClicked) { + // column was already selected; switch sort modes + fParent->ReverseSortMode( + fParent->fColumnList.IndexOf(fColumnClicked)); + } else { //The user selected this column for sorting - fParent->SetSortKey(fParent->fColumnList.IndexOf(fColumnClicked)); - } - else - { - //The user wants to add it as a secondary sorting column - if(fParent->fSortKeyList.HasItem(fColumnClicked)) - //The column was already selected; switch sort modes - fParent->ReverseSortMode(fParent->fColumnList.IndexOf(fColumnClicked)); - else - //The user selected this column for sorting - fParent->AddSortKey(fParent->fColumnList.IndexOf(fColumnClicked)); + fParent->SetSortKey( + fParent->fColumnList.IndexOf(fColumnClicked)); + } + } else { + // user wants to add it as a secondary sorting column + if (fParent->fSortKeyList.HasItem(fColumnClicked)) { + // column was already selected; switch sort modes + fParent->ReverseSortMode( + fParent->fColumnList.IndexOf(fColumnClicked)); + } else { + // user selected this column for sorting + fParent->AddSortKey( + fParent->fColumnList.IndexOf(fColumnClicked)); + } } } + } else if (fColumnDragging) { + // column was dragging; erase the drag box but not + // the interior to avoid label flicker + Invalidate(BRect(fPreviousDragOutlineLeft, bounds.top + 1.0, + fPreviousDragOutlineLeft, bounds.bottom - 1.0)); + Invalidate(BRect(fPreviousDragOutlineRight, bounds.top + 1.0, + fPreviousDragOutlineRight, bounds.bottom - 1.0)); + Invalidate(BRect(fPreviousDragOutlineLeft, bounds.top, + fPreviousDragOutlineRight, bounds.top)); + Invalidate(BRect(fPreviousDragOutlineLeft, bounds.bottom, + fPreviousDragOutlineRight, bounds.bottom)); + } else { + // column was resizing; erase the drag tab + Invalidate(BRect(fColumnClicked->fColumnEnd, + bounds.top, fColumnClicked->fColumnEnd, + bounds.bottom)); } - else if(fColumnDragging) - { - //Column was dragging; erase the drag box but not the interior to avoid label flicker - Invalidate(BRect(fPrevDragOutlineLeft,ViewBounds.top+1.0, - fPrevDragOutlineLeft,ViewBounds.bottom-1.0)); - Invalidate(BRect(fPrevDragOutlineRight,ViewBounds.top+1.0, - fPrevDragOutlineRight,ViewBounds.bottom-1.0)); - Invalidate(BRect(fPrevDragOutlineLeft,ViewBounds.top, - fPrevDragOutlineRight,ViewBounds.top)); - Invalidate(BRect(fPrevDragOutlineLeft,ViewBounds.bottom, - fPrevDragOutlineRight,ViewBounds.bottom)); - } - else - //Column was resizing; erase the drag tab - Invalidate(BRect(fColumnClicked->fColumnEnd,ViewBounds.top,fColumnClicked->fColumnEnd, - ViewBounds.bottom)); - //Unhighlight the label and forget the column - Invalidate(BRect(fColumnClicked->fColumnBegin+1.0,ViewBounds.top+1.0, - fColumnClicked->fColumnEnd-1.0,ViewBounds.bottom-1.0)); + + // unhighlight the label and forget the column + Invalidate(BRect(fColumnClicked->fColumnBegin + 1.0, + bounds.top + 1.0, fColumnClicked->fColumnEnd - 1.0, + bounds.bottom - 1.0)); + fColumnClicked = NULL; + fColumnDragging = false; + fColumnResizing = false; + } else { + // unused button combination, unhighlight the label and + // forget the column + Invalidate(BRect(fColumnClicked->fColumnBegin + 1.0, + bounds.top + 1.0, fColumnClicked->fColumnEnd - 1.0, + bounds.bottom - 1.0)); fColumnClicked = NULL; fColumnDragging = false; fColumnResizing = false; } - else - { - //Unused button combination - //Unhighlight the label and forget the column - Invalidate(BRect(fColumnClicked->fColumnBegin+1.0,ViewBounds.top+1.0, - fColumnClicked->fColumnEnd-1.0,ViewBounds.bottom-1.0)); - fColumnClicked = NULL; - fColumnDragging = false; - fColumnResizing = false; - } - fPreviousMousePos = MousePos; + + fPreviousMousePosition = mousePosition; } } -void CLVColumnLabelView::ShiftDragGroup(int32 NewPos) -//Shift the drag group into a new position +// Shift the drag group into a new position +void +CLVColumnLabelView::ShiftDragGroup(int32 newPosition) { - int32 NumberOfGroups = fDragGroups.CountItems(); - int32 GroupCounter; - CLVDragGroup* ThisGroup; - int32 ColumnCounter; - BList NewDisplayList; + int32 groupCount = fDragGroupsList.CountItems(); + CLVDragGroup* group; + BList newDisplayList; //Copy the groups up to the new position - for(GroupCounter = 0; GroupCounter < NewPos; GroupCounter++) - { - if(GroupCounter != fDragGroup) - { - ThisGroup = (CLVDragGroup*)fDragGroups.ItemAt(GroupCounter); - for(ColumnCounter = ThisGroup->GroupStartDispListIndex; ColumnCounter <= - ThisGroup->GroupStopDispListIndex; ColumnCounter++) - NewDisplayList.AddItem(fDisplayList->ItemAt(ColumnCounter)); - } - } - //Copy the group into the new position - ThisGroup = (CLVDragGroup*)fDragGroups.ItemAt(fDragGroup); - for(ColumnCounter = ThisGroup->GroupStartDispListIndex; ColumnCounter <= - ThisGroup->GroupStopDispListIndex; ColumnCounter++) - NewDisplayList.AddItem(fDisplayList->ItemAt(ColumnCounter)); - //Copy the rest of the groups, but skip the dragging group - for(GroupCounter = NewPos; GroupCounter < NumberOfGroups; GroupCounter++) - { - if(GroupCounter != fDragGroup) - { - ThisGroup = (CLVDragGroup*)fDragGroups.ItemAt(GroupCounter); - for(ColumnCounter = ThisGroup->GroupStartDispListIndex; ColumnCounter <= - ThisGroup->GroupStopDispListIndex; ColumnCounter++) - NewDisplayList.AddItem(fDisplayList->ItemAt(ColumnCounter)); + for (int32 i = 0; i < newPosition; i++) { + if (i != fDragGroupIndex) { + group = (CLVDragGroup*)fDragGroupsList.ItemAt(i); + for (int32 j = group->groupStartDisplayListIndex; + j <= group->groupStopDisplayListIndex; j++) { + newDisplayList.AddItem(fDisplayList->ItemAt(j)); + } } } - //Set the new order - *fDisplayList = NewDisplayList; + // copy the group into the new position + group = (CLVDragGroup*)fDragGroupsList.ItemAt(fDragGroupIndex); + for (int32 j = group->groupStartDisplayListIndex; + j <= group->groupStopDisplayListIndex; j++) { + newDisplayList.AddItem(fDisplayList->ItemAt(j)); + } - //Update columns and drag groups - fParent->UpdateColumnSizesDataRectSizeScrollBars(); + // copy the rest of the groups, but skip the dragging group + for (int32 i = newPosition; i < groupCount; i++) { + if (i != fDragGroupIndex) { + group = (CLVDragGroup*)fDragGroupsList.ItemAt(i); + for (int32 j = group->groupStartDisplayListIndex; + j <= group->groupStopDisplayListIndex; j++) { + newDisplayList.AddItem(fDisplayList->ItemAt(j)); + } + } + } + + // set the new order + *fDisplayList = newDisplayList; + + // update columns and drag groups + fParent->ShiftDragGroup(); UpdateDragGroups(); SetSnapMinMax(); - //Inform the program that the display order changed - int32* NewOrder = fParent->DisplayOrder(); - fParent->DisplayOrderChanged(NewOrder); - delete[] NewOrder; + // inform the program that the display order changed + int32* newOrder = fParent->DisplayOrder(); + fParent->DisplayOrderChanged(newOrder); + delete[] newOrder; } -void CLVColumnLabelView::UpdateDragGroups() +// Make a copy of the DragGroups list, use it to store +// the CLVDragGroup's for recycling. +void +CLVColumnLabelView::UpdateDragGroups() { - //Make a copy of the DragGroups list. Use it to store the CLVDragGroup's for recycling - BList TempList(fDragGroups); - fDragGroups.MakeEmpty(); - int32 NumberOfColumns = fDisplayList->CountItems(); - bool ContinueGroup = false; + BList tempList(fDragGroupsList); + fDragGroupsList.MakeEmpty(); + int32 columnCount = fDisplayList->CountItems(); + bool shouldContinueGroup = false; CLVDragGroup* CurrentGroup = NULL; - for(int32 Counter = 0; Counter < NumberOfColumns; Counter++) - { - CLVColumn* CurrentColumn = (CLVColumn*)fDisplayList->ItemAt(Counter); - if(!ContinueGroup) - { - //Recycle or obtain a new CLVDragGroup - CurrentGroup = (CLVDragGroup*)TempList.RemoveItem(int32(0)); - if(CurrentGroup == NULL) + + for (int32 i = 0; i < columnCount; i++) { + CLVColumn* CurrentColumn = (CLVColumn*)fDisplayList->ItemAt(i); + if (!shouldContinueGroup) { + // recycle or obtain a new CLVDragGroup + CurrentGroup = (CLVDragGroup*)tempList.RemoveItem(int32(0)); + if (CurrentGroup == NULL) CurrentGroup = new CLVDragGroup; - //Add the CLVDragGroup to the DragGroups list - fDragGroups.AddItem(CurrentGroup); - //Set up the new DragGroup - CurrentGroup->GroupStartDispListIndex = Counter; - CurrentGroup->GroupStopDispListIndex = Counter; - CurrentGroup->Flags = 0; - if(CurrentColumn->IsShown()) - { - CurrentGroup->GroupBegin = CurrentColumn->fColumnBegin; - CurrentGroup->GroupEnd = CurrentColumn->fColumnEnd; - CurrentGroup->LastColumnShown = CurrentColumn; - CurrentGroup->Shown = true; - if(CurrentColumn->fFlags & CLV_LOCK_AT_BEGINNING) - CurrentGroup->AllLockBeginning = true; + + // add the CLVDragGroup to the DragGroups list + fDragGroupsList.AddItem(CurrentGroup); + // set up the new DragGroup + CurrentGroup->groupStartDisplayListIndex = i; + CurrentGroup->groupStopDisplayListIndex = i; + CurrentGroup->flags = 0; + + if (CurrentColumn->IsShown()) { + CurrentGroup->groupBeginIndex = CurrentColumn->fColumnBegin; + CurrentGroup->groupEndIndex = CurrentColumn->fColumnEnd; + CurrentGroup->lastColumnShown = CurrentColumn; + CurrentGroup->isShown = true; + if (CurrentColumn->fFlags & CLV_LOCK_AT_BEGINNING) + CurrentGroup->isAllLockBeginning = true; else - CurrentGroup->AllLockBeginning = false; - if(CurrentColumn->fFlags & CLV_LOCK_AT_END) - CurrentGroup->AllLockEnd = true; + CurrentGroup->isAllLockBeginning = false; + + if (CurrentColumn->fFlags & CLV_LOCK_AT_END) + CurrentGroup->isAllLockEnd = true; else - CurrentGroup->AllLockEnd = false; + CurrentGroup->isAllLockEnd = false; + } else { + CurrentGroup->groupBeginIndex = -1.0; + CurrentGroup->groupEndIndex = -1.0; + CurrentGroup->lastColumnShown = NULL; + CurrentGroup->isShown = false; + if (CurrentColumn->fFlags & CLV_LOCK_AT_BEGINNING) + CurrentGroup->isAllLockBeginning = true; + else + CurrentGroup->isAllLockBeginning = false; + if (CurrentColumn->fFlags & CLV_LOCK_AT_END) + CurrentGroup->isAllLockEnd = true; + else + CurrentGroup->isAllLockEnd = false; } - else - { - CurrentGroup->GroupBegin = -1.0; - CurrentGroup->GroupEnd = -1.0; - CurrentGroup->LastColumnShown = NULL; - CurrentGroup->Shown = false; - if(CurrentColumn->fFlags & CLV_LOCK_AT_BEGINNING) - CurrentGroup->AllLockBeginning = true; - else - CurrentGroup->AllLockBeginning = false; - if(CurrentColumn->fFlags & CLV_LOCK_AT_END) - CurrentGroup->AllLockEnd = true; - else - CurrentGroup->AllLockEnd = false; + } else { + // add this column to the current DragGroup + CurrentGroup->groupStopDisplayListIndex = i; + if (CurrentColumn->IsShown()) { + if (CurrentGroup->groupBeginIndex == -1.0) + CurrentGroup->groupBeginIndex = CurrentColumn->fColumnBegin; + CurrentGroup->groupEndIndex = CurrentColumn->fColumnEnd; + CurrentGroup->lastColumnShown = CurrentColumn; + CurrentGroup->isShown = true; } + if ((CurrentColumn->fFlags & CLV_LOCK_AT_BEGINNING) == 0) + CurrentGroup->isAllLockBeginning = false; + if ((CurrentColumn->fFlags & CLV_LOCK_AT_END) == 0) + CurrentGroup->isAllLockEnd = false; } + + CurrentGroup->flags = CurrentColumn->fFlags + & (CLV_NOT_MOVABLE | CLV_LOCK_AT_BEGINNING + | CLV_LOCK_AT_END); + // see if I should add more columns to this group + if (CurrentColumn->fFlags & CLV_LOCK_WITH_RIGHT) + shouldContinueGroup = true; else - { - //Add this column to the current DragGroup - CurrentGroup->GroupStopDispListIndex = Counter; - if(CurrentColumn->IsShown()) - { - if(CurrentGroup->GroupBegin == -1.0) - CurrentGroup->GroupBegin = CurrentColumn->fColumnBegin; - CurrentGroup->GroupEnd = CurrentColumn->fColumnEnd; - CurrentGroup->LastColumnShown = CurrentColumn; - CurrentGroup->Shown = true; - } - if(!(CurrentColumn->fFlags & CLV_LOCK_AT_BEGINNING)) - CurrentGroup->AllLockBeginning = false; - if(!(CurrentColumn->fFlags & CLV_LOCK_AT_END)) - CurrentGroup->AllLockEnd = false; - } - CurrentGroup->Flags |= CurrentColumn->fFlags & (CLV_NOT_MOVABLE|CLV_LOCK_AT_BEGINNING| - CLV_LOCK_AT_END); - //See if I should add more columns to this group - if(CurrentColumn->fFlags & CLV_LOCK_WITH_RIGHT) - ContinueGroup = true; - else - ContinueGroup = false; + shouldContinueGroup = false; } - //If any unused groups remain in TempList, delete them - while((CurrentGroup = (CLVDragGroup*)TempList.RemoveItem(int32(0))) != NULL) + // if any unused groups remain in tempList, delete them + while ((CurrentGroup = (CLVDragGroup*)tempList.RemoveItem(int32(0))) + != NULL) { delete CurrentGroup; + } } -void CLVColumnLabelView::SetSnapMinMax() +// find the column group that the user is dragging and the shown +// group before it +void +CLVColumnLabelView::SetSnapMinMax() { - //Find the column group that the user is dragging and the shown group before it - int32 NumberOfGroups = fDragGroups.CountItems(); - int32 ColumnCount; - fDragGroup = -1; - fTheShownGroupBefore = NULL; - fSnapGroupBefore = -1; - CLVDragGroup* ThisGroup; - int32 GroupCounter; - for(GroupCounter = 0; GroupCounter < NumberOfGroups; GroupCounter++) - { - ThisGroup = (CLVDragGroup*)fDragGroups.ItemAt(GroupCounter); - for(ColumnCount = ThisGroup->GroupStartDispListIndex; ColumnCount <= - ThisGroup->GroupStopDispListIndex; ColumnCount++) - if(fDisplayList->ItemAt(ColumnCount) == fColumnClicked) - { - fDragGroup = GroupCounter; - fTheDragGroup = ThisGroup; + int32 groupCount = fDragGroupsList.CountItems(); + int32 columnCount; + fDragGroupIndex = -1; + fShownGroupBefore = NULL; + fSnapGroupBeforeIndex = -1; + CLVDragGroup* group; + for (int32 i = 0; i < groupCount; i++) { + group = (CLVDragGroup*)fDragGroupsList.ItemAt(i); + for (columnCount = group->groupStartDisplayListIndex; + columnCount <= group->groupStopDisplayListIndex; columnCount++) { + if (fDisplayList->ItemAt(columnCount) == fColumnClicked) { + fDragGroupIndex = i; + fDragGroup = group; break; } - if(fDragGroup != -1) + } + + if (fDragGroupIndex != -1) break; - else if(ThisGroup->Shown) - { - fTheShownGroupBefore = ThisGroup; - fSnapGroupBefore = GroupCounter; + else if (group->isShown) { + fShownGroupBefore = group; + fSnapGroupBeforeIndex = i; } } - //Find the position of shown group after the one that the user is dragging - fTheShownGroupAfter = NULL; - fSnapGroupAfter = -1; - for(GroupCounter = fDragGroup+1; GroupCounter < NumberOfGroups; GroupCounter++) - { - ThisGroup = (CLVDragGroup*)fDragGroups.ItemAt(GroupCounter); - if(ThisGroup->Shown) - { - fTheShownGroupAfter = ThisGroup; - fSnapGroupAfter = GroupCounter; + // find the position of shown group after the one that the user is dragging + fShownGroupAfter = NULL; + fSnapGroupAfterIndex = -1; + for (int32 i = fDragGroupIndex + 1; i < groupCount; i++) { + group = (CLVDragGroup*)fDragGroupsList.ItemAt(i); + if (group->isShown) { + fShownGroupAfter = group; + fSnapGroupAfterIndex = i; break; } } - //See if it can actually snap in the given direction - if(fSnapGroupBefore != -1) - { - if(fTheShownGroupBefore->Flags & CLV_LOCK_AT_BEGINNING) - if(!fTheDragGroup->AllLockBeginning) - fSnapGroupBefore = -1; - if(fTheDragGroup->Flags & CLV_LOCK_AT_END) - if(!fTheShownGroupBefore->AllLockEnd) - fSnapGroupBefore = -1; + // see if it can actually snap in the given direction + if (fSnapGroupBeforeIndex != -1) { + if ((fShownGroupBefore->flags & CLV_LOCK_AT_BEGINNING) != 0 + && !fDragGroup->isAllLockBeginning) { + fSnapGroupBeforeIndex = -1; + } + if ((fDragGroup->flags & CLV_LOCK_AT_END) != 0 + && !fShownGroupBefore->isAllLockEnd) { + fSnapGroupBeforeIndex = -1; + } } - if(fSnapGroupAfter != -1) - { - if(fTheShownGroupAfter->Flags & CLV_LOCK_AT_END) - if(!fTheDragGroup->AllLockEnd) - fSnapGroupAfter = -1; - if(fTheDragGroup->Flags & CLV_LOCK_AT_BEGINNING) - if(!fTheShownGroupAfter->AllLockBeginning) - fSnapGroupAfter = -1; + if (fSnapGroupAfterIndex != -1) { + if (fShownGroupAfter->flags & CLV_LOCK_AT_END + && !fDragGroup->isAllLockEnd) { + fSnapGroupAfterIndex = -1; + } + if (fDragGroup->flags & CLV_LOCK_AT_BEGINNING + && !fShownGroupAfter->isAllLockBeginning) { + fSnapGroupAfterIndex = -1; + } } - //Find the minumum and maximum positions for the group to snap + // find the minumum and maximum positions for the group to snap fSnapMin = -1.0; fSnapMax = -1.0; - fDragBoxWidth = fTheDragGroup->GroupEnd-fTheDragGroup->GroupBegin; - if(fSnapGroupBefore != -1) - { - fSnapMin = fTheShownGroupBefore->GroupBegin + fDragBoxWidth; - if(fSnapMin > fTheShownGroupBefore->GroupEnd) - fSnapMin = fTheShownGroupBefore->GroupEnd; + fDragBoxWidth = fDragGroup->groupEndIndex - fDragGroup->groupBeginIndex; + if (fSnapGroupBeforeIndex != -1) { + fSnapMin = fShownGroupBefore->groupBeginIndex + fDragBoxWidth; + if (fSnapMin > fShownGroupBefore->groupEndIndex) + fSnapMin = fShownGroupBefore->groupEndIndex; } - if(fSnapGroupAfter != -1) - { - fSnapMax = fTheShownGroupAfter->GroupEnd - fDragBoxWidth; - if(fSnapMax < fTheShownGroupAfter->GroupBegin) - fSnapMax = fTheShownGroupAfter->GroupBegin; + if (fSnapGroupAfterIndex != -1){ + fSnapMax = fShownGroupAfter->groupEndIndex - fDragBoxWidth; + if (fSnapMax < fShownGroupAfter->groupBeginIndex) + fSnapMax = fShownGroupAfter->groupBeginIndex; } } diff --git a/src/preferences/shortcuts/clv/CLVColumnLabelView.h b/src/preferences/shortcuts/clv/CLVColumnLabelView.h index 159adb1f22..2adf0f7540 100644 --- a/src/preferences/shortcuts/clv/CLVColumnLabelView.h +++ b/src/preferences/shortcuts/clv/CLVColumnLabelView.h @@ -1,76 +1,97 @@ -#ifndef CLVColumnLabelView_h -#define CLVColumnLabelView_h +/* + * Copyright 1999-2009 Jeremy Friesner + * Copyright 2009-2014 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jeremy Friesner + * John Scipione, jscipione@gmail.com + */ +#ifndef CLV_COLUMN_LABEL_VIEW_H +#define CLV_COLUMN_LABEL_VIEW_H + #include #include -//****************************************************************************************************** -//**** PROJECT HEADER FILES AND CLASS NAME DECLARATIONS -//****************************************************************************************************** + class ColumnListView; class CLVColumn; -//****************************************************************************************************** -//**** CLASS AND STRUCTURE DECLARATIONS, ASSOCIATED CONSTANTS AND STATIC FUNCTIONS -//****************************************************************************************************** struct CLVDragGroup { - int32 GroupStartDispListIndex; //Indices in the column display list where this group starts - int32 GroupStopDispListIndex; //and finishes - float GroupBegin,GroupEnd; //-1.0 if whole group is hidden - CLVColumn* LastColumnShown; - bool AllLockBeginning; - bool AllLockEnd; - bool Shown; //False if none of the columns in this group are shown - uint32 Flags; //Uses CLV_NOT_MOVABLE, CLV_LOCK_AT_BEGINNING, CLV_LOCK_AT_END + int32 groupStartDisplayListIndex; + // indices in the column display list where this group starts + int32 groupStopDisplayListIndex; + // and finishes + float groupBeginIndex; + // -1.0 if whole group is hidden + float groupEndIndex; + // -1.0 if whole group is hidden + CLVColumn* lastColumnShown; + bool isAllLockBeginning; + bool isAllLockEnd; + bool isShown; + // false if none of the columns in this group are shown + uint32 flags; + // Uses CLV_NOT_MOVABLE, CLV_LOCK_AT_BEGINNING, CLV_LOCK_AT_END }; class CLVColumnLabelView : public BView { - public: - //Constructor and destructor - CLVColumnLabelView(BRect Bounds,ColumnListView* Parent,const BFont* Font); - ~CLVColumnLabelView(); +public: + CLVColumnLabelView(BRect frame, + ColumnListView* parent, + const BFont* font); + ~CLVColumnLabelView(); - //BView overrides - void Draw(BRect UpdateRect); - void MouseDown(BPoint Point); - void MessageReceived(BMessage *message); + // BView overrides + void Draw(BRect UpdateRect); + void MouseDown(BPoint Point); + void MessageReceived(BMessage* message); - private: +private: friend class ColumnListView; friend class CLVColumn; - float fFontAscent; - BList* fDisplayList; + void ShiftDragGroup(int32 newPosition); + void UpdateDragGroups(); + void SetSnapMinMax(); - //Column select and drag stuff - CLVColumn* fColumnClicked; - BPoint fPreviousMousePos; - BPoint fMouseClickedPos; - bool fColumnDragging; - bool fColumnResizing; - BList fDragGroups; //Groups of CLVColumns that must drag together - int32 fDragGroup; //Index into DragGroups of the group being dragged by user - CLVDragGroup* fTheDragGroup; - CLVDragGroup* fTheShownGroupBefore; - CLVDragGroup* fTheShownGroupAfter; - int32 fSnapGroupBefore, //Index into DragGroups of TheShownGroupBefore and - fSnapGroupAfter; //TheShownGroupAfter, if the group the user is dragging is - //allowed to snap there, otherwise -1 - float fDragBoxMouseHoldOffset,fResizeMouseHoldOffset; - float fDragBoxWidth; //Can include multiple columns; depends on CLV_LOCK_WITH_RIGHT - float fPrevDragOutlineLeft,fPrevDragOutlineRight; - float fSnapMin,fSnapMax; //-1.0 indicates the column can't snap in the given direction - ColumnListView* fParent; + float fFontAscent; + BList* fDisplayList; - //Private functions - void ShiftDragGroup(int32 NewPos); - void UpdateDragGroups(); - void SetSnapMinMax(); + // column select and drag stuff + CLVColumn* fColumnClicked; + BPoint fPreviousMousePosition; + BPoint fMouseClickedPosition; + bool fColumnDragging; + bool fColumnResizing; + BList fDragGroupsList; + // groups of CLVColumns that must drag together + int32 fDragGroupIndex; + // index into DragGroups of the group being dragged by user + CLVDragGroup* fDragGroup; + CLVDragGroup* fShownGroupBefore; + CLVDragGroup* fShownGroupAfter; + int32 fSnapGroupBeforeIndex; + int32 fSnapGroupAfterIndex; + // index into DragGroups of fShownGroupBefore and + // fShownGroupAfter, if the group the user is dragging is + // allowed to snap there, otherwise -1 + float fDragBoxMouseHoldOffset; + float fResizeMouseHoldOffset; + float fDragBoxWidth; + // can include multiple columns; depends on CLV_LOCK_WITH_RIGHT + float fPreviousDragOutlineLeft; + float fPreviousDragOutlineRight; + float fSnapMin; + float fSnapMax; + // -1.0 indicates the column can't snap in the given direction + ColumnListView* fParent; }; -#endif +#endif // CLV_COLUMN_LABEL_VIEW_H diff --git a/src/preferences/shortcuts/clv/CLVListItem.cpp b/src/preferences/shortcuts/clv/CLVListItem.cpp index 2060f765d7..a7bfc67530 100644 --- a/src/preferences/shortcuts/clv/CLVListItem.cpp +++ b/src/preferences/shortcuts/clv/CLVListItem.cpp @@ -1,11 +1,18 @@ -//CLVListItem source file +/* + * Copyright 1999-2009 Jeremy Friesner + * Copyright 2009-2014 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jeremy Friesner + * John Scipione, jscipione@gmail.com + */ -//****************************************************************************************************** -//**** PROJECT HEADER FILES -//****************************************************************************************************** #define CLVListItem_CPP + #include + #include "CLVListItem.h" #include "ColumnListView.h" #include "CLVColumn.h" @@ -13,162 +20,185 @@ #include "InterfaceKit.h" -//****************************************************************************************************** -//**** CLVItem CLASS DEFINITION -//****************************************************************************************************** -CLVListItem::CLVListItem(uint32 level, bool superitem, bool expanded, float minheight) -: BListItem(level, expanded), -fExpanderButtonRect(-1.0,-1.0,-1.0,-1.0), -fExpanderColumnRect(-1.0,-1.0,-1.0,-1.0), -_selectedColumn(-1) + +CLVListItem::CLVListItem(uint32 level, bool superitem, bool expanded, + float minheight) + : + BListItem(level, expanded), + fExpanderButtonRect(-1.0, -1.0, -1.0, -1.0), + fExpanderColumnRect(-1.0, -1.0, -1.0, -1.0), + fSelectedColumn(-1) { - fSuperItem = superitem; + fIsSuperItem = superitem; fOutlineLevel = level; fMinHeight = minheight; } CLVListItem::~CLVListItem() -{ } - - -bool CLVListItem::IsSuperItem() const { - return fSuperItem; } -void CLVListItem::SetSuperItem(bool superitem) +bool +CLVListItem::IsSuperItem() const { - fSuperItem = superitem; + return fIsSuperItem; } -uint32 CLVListItem::OutlineLevel() const +void +CLVListItem::SetSuperItem(bool superitem) +{ + fIsSuperItem = superitem; +} + + +uint32 +CLVListItem::OutlineLevel() const { return fOutlineLevel; } -void CLVListItem::SetOutlineLevel(uint32 level) + +void +CLVListItem::SetOutlineLevel(uint32 level) { fOutlineLevel = level; } -void CLVListItem::Pulse(BView * owner) + +void +CLVListItem::Pulse(BView* owner) { - // empty } -void CLVListItem::DrawItem(BView* owner, BRect itemRect, bool complete) +void +CLVListItem::DrawItem(BView* owner, BRect itemRect, bool complete) { - BList* DisplayList = &((ColumnListView*)owner)->fColumnDisplayList; - int32 NumberOfColumns = DisplayList->CountItems(); + BList* displayList = &((ColumnListView*)owner)->fColumnDisplayList; + int32 columnCount = displayList->CountItems(); float PushMax = itemRect.right; - CLVColumn* ThisColumn; - BRect ThisColumnRect = itemRect; - float ExpanderDelta = OutlineLevel() * 20.0; - //Figure out what the limit is for expanders pushing other columns - for(int32 Counter = 0; Counter < NumberOfColumns; Counter++) - { - ThisColumn = (CLVColumn*)DisplayList->ItemAt(Counter); - if((ThisColumn->fFlags & CLV_EXPANDER) || ThisColumn->fPushedByExpander) - PushMax = ThisColumn->fColumnEnd; + CLVColumn* column; + BRect columnRect = itemRect; + float expanderDelta = OutlineLevel() * 20.0; + // figure out what the limit is for expanders pushing other columns + for (int32 i = 0; i < columnCount; i++) { + column = (CLVColumn*)displayList->ItemAt(i); + if((column->fFlags & CLV_EXPANDER) || column->fPushedByExpander) + PushMax = column->fColumnEnd; } + BRegion ClippingRegion; - if(!complete) + if (!complete) owner->GetClippingRegion(&ClippingRegion); else ClippingRegion.Set(itemRect); + float LastColumnEnd = -1.0; - //Draw the columns - for(int32 Counter = 0; Counter < NumberOfColumns; Counter++) - { - ThisColumn = (CLVColumn*)DisplayList->ItemAt(Counter); - if(!ThisColumn->IsShown()) + // draw the columns + for (int32 Counter = 0; Counter < columnCount; Counter++) { + column = (CLVColumn*)displayList->ItemAt(Counter); + if(!column->IsShown()) continue; - ThisColumnRect.left = ThisColumn->fColumnBegin; - ThisColumnRect.right = LastColumnEnd = ThisColumn->fColumnEnd; - float Shift = 0.0; - if((ThisColumn->fFlags & CLV_EXPANDER) || ThisColumn->fPushedByExpander) - Shift = ExpanderDelta; - if(ThisColumn->fFlags & CLV_EXPANDER) - { - ThisColumnRect.right += Shift; - if(ThisColumnRect.right > PushMax) - ThisColumnRect.right = PushMax; - fExpanderColumnRect = ThisColumnRect; - if(ClippingRegion.Intersects(ThisColumnRect)) - { - //Give the programmer a chance to do his kind of highlighting if the item is selected - int32 actualIndex = ((ColumnListView*)owner)->fColumnList.IndexOf(ThisColumn); - DrawItemColumn(owner, ThisColumnRect, actualIndex, (_selectedColumn == actualIndex), complete); - if(fSuperItem) - { - //Draw the expander, clip manually - float TopOffset = ceil((ThisColumnRect.bottom-ThisColumnRect.top-10.0)/2.0); - float LeftOffset = ThisColumn->fColumnEnd + Shift - 3.0 - 10.0; - float RightClip = LeftOffset + 10.0 - ThisColumnRect.right; - if(RightClip < 0.0) - RightClip = 0.0; - BBitmap* Arrow; - if(IsExpanded()) - Arrow = &((ColumnListView*)owner)->fDownArrow; + + columnRect.left = column->fColumnBegin; + columnRect.right = LastColumnEnd = column->fColumnEnd; + float shift = 0.0; + if ((column->fFlags & CLV_EXPANDER) || column->fPushedByExpander) + shift = expanderDelta; + + if (column->fFlags & CLV_EXPANDER) { + columnRect.right += shift; + if(columnRect.right > PushMax) + columnRect.right = PushMax; + + fExpanderColumnRect = columnRect; + if (ClippingRegion.Intersects(columnRect)) { + // give the programmer a chance to do his kind of + // highlighting if the item is selected + int32 actualIndex + = ((ColumnListView*)owner)->fColumnList.IndexOf(column); + DrawItemColumn(owner, columnRect, actualIndex, + (fSelectedColumn == actualIndex), complete); + if (fIsSuperItem) { + // draw the expander, clip manually + float top + = ceilf((columnRect.bottom-columnRect.top - 10.0) + / 2.0); + float left = column->fColumnEnd + shift - 3.0 - 10.0; + float rightClip = left + 10.0 - columnRect.right; + if (rightClip < 0.0) + rightClip = 0.0; + + BBitmap* arrow; + if (IsExpanded()) + arrow = &((ColumnListView*)owner)->fDownArrow; else - Arrow = &((ColumnListView*)owner)->fRightArrow; - if(LeftOffset <= ThisColumnRect.right) - { - fExpanderButtonRect.Set(LeftOffset,ThisColumnRect.top+TopOffset, - LeftOffset+10.0-RightClip,ThisColumnRect.top+TopOffset+10.0); + arrow = &((ColumnListView*)owner)->fRightArrow; + + if (left <= columnRect.right) { + fExpanderButtonRect.Set(left, columnRect.top + top, + left + 10.0 - rightClip, columnRect.top + top + 10.0); owner->SetDrawingMode(B_OP_OVER); - owner->DrawBitmap(Arrow, BRect(0.0,0.0,10.0-RightClip,10.0),fExpanderButtonRect); + owner->DrawBitmap(arrow, + BRect(0.0, 0.0, 10.0 - rightClip, 10.0), + fExpanderButtonRect); owner->SetDrawingMode(B_OP_COPY); - } - else - fExpanderButtonRect.Set(-1.0,-1.0,-1.0,-1.0); + } else + fExpanderButtonRect.Set(-1.0, -1.0, -1.0, -1.0); } } - } - else - { - ThisColumnRect.left += Shift; - ThisColumnRect.right += Shift; - if(Shift > 0.0 && ThisColumnRect.right > PushMax) - ThisColumnRect.right = PushMax; - if(ThisColumnRect.right >= ThisColumnRect.left && ClippingRegion.Intersects(ThisColumnRect)) + } else { + columnRect.left += shift; + columnRect.right += shift; + if (shift > 0.0 && columnRect.right > PushMax) + columnRect.right = PushMax; + + if (columnRect.right >= columnRect.left + && ClippingRegion.Intersects(columnRect)) { - int32 actualIndex = ((ColumnListView*)owner)->fColumnList.IndexOf(ThisColumn); - DrawItemColumn(owner, ThisColumnRect, actualIndex, (_selectedColumn == actualIndex), complete); + int32 actualIndex + = ((ColumnListView*)owner)->fColumnList.IndexOf(column); + DrawItemColumn(owner, columnRect, actualIndex, + (fSelectedColumn == actualIndex), complete); } } } - //Fill the area after all the columns (so the select highlight goes all the way across) - ThisColumnRect.left = LastColumnEnd + 1.0; - ThisColumnRect.right = owner->Bounds().right; - if(ThisColumnRect.left <= ThisColumnRect.right && ClippingRegion.Intersects(ThisColumnRect)) - { - DrawItemColumn(owner, ThisColumnRect,-1, false, complete); + + // fill the area after all the columns (so the select highlight goes + // all the way across) + columnRect.left = LastColumnEnd + 1.0; + columnRect.right = owner->Bounds().right; + if (columnRect.left <= columnRect.right + && ClippingRegion.Intersects(columnRect)) { + DrawItemColumn(owner, columnRect, -1, false, complete); } } -float CLVListItem::ExpanderShift(int32 column_index, BView* owner) +float +CLVListItem::ExpanderShift(int32 columnIndex, BView* owner) { - BList* DisplayList = &((ColumnListView*)owner)->fColumnDisplayList; - CLVColumn* ThisColumn = (CLVColumn*)DisplayList->ItemAt(column_index); - float ExpanderDelta = OutlineLevel() * 20.0; - if(!ThisColumn->fPushedByExpander) - ExpanderDelta = 0.0; - return ExpanderDelta; + BList* displayList = &((ColumnListView*)owner)->fColumnDisplayList; + CLVColumn* column = (CLVColumn*)displayList->ItemAt(columnIndex); + float expanderDelta = OutlineLevel() * 20.0f; + if (!column->fPushedByExpander) + expanderDelta = 0.0; + + return expanderDelta; } -void CLVListItem::Update(BView* owner, const BFont* font) +void +CLVListItem::Update(BView* owner, const BFont* font) { - BListItem::Update(owner,font); - float ItemHeight = Height(); - if(ItemHeight < fMinHeight) - ItemHeight = fMinHeight; + BListItem::Update(owner, font); + float itemHeight = Height(); + if (itemHeight < fMinHeight) + itemHeight = fMinHeight; + SetWidth(((ColumnListView*)owner)->fPageWidth); - SetHeight(ItemHeight); + SetHeight(itemHeight); } diff --git a/src/preferences/shortcuts/clv/CLVListItem.h b/src/preferences/shortcuts/clv/CLVListItem.h index 4ce55e68b9..f2d0db49eb 100644 --- a/src/preferences/shortcuts/clv/CLVListItem.h +++ b/src/preferences/shortcuts/clv/CLVListItem.h @@ -1,63 +1,82 @@ -#ifndef CLVListItem_h -#define CLVListItem_h +/* + * Copyright 1999-2009 Jeremy Friesner + * Copyright 2009-2014 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jeremy Friesner + * John Scipione, jscipione@gmail.com + */ +#ifndef CLV_LIST_ITEM_H +#define CLV_LIST_ITEM_H + #include -//****************************************************************************************************** -//**** PROJECT HEADER FILES AND CLASS NAME DECLARATIONS -//****************************************************************************************************** + class ColumnListView; -//****************************************************************************************************** -//**** CLVItem CLASS DECLARATION -//****************************************************************************************************** class CLVListItem : public BListItem { - public: - //Constructor and destructor - CLVListItem(uint32 level = 0, bool superitem = false, bool expanded = false, float minheight = 0.0); - virtual ~CLVListItem(); +public: + CLVListItem(uint32 level = 0, + bool superitem = false, + bool expanded = false, + float minheight = 0.0); + virtual ~CLVListItem(); //Archival stuff /* Not implemented yet - CLVItem(BMessage* archive); - static CLVItem* Instantiate(BMessage* data); - virtual status_t Archive(BMessage* data, bool deep = true) const; + CLVItem(BMessage* archive); + static CLVItem* Instantiate(BMessage* data); + virtual status_t Archive(BMessage* data, bool deep = true) + const; */ - - virtual void DrawItemColumn(BView* owner, BRect item_column_rect, int32 column_index, bool columnSelected, - bool complete) = 0; //column_index (0-N) is based on the order in which the columns were added - //to the ColumnListView, not the display order. An index of -1 indicates - //that the program needs to draw a blank area beyond the last column. The - //main purpose is to allow the highlighting bar to continue all the way to - //the end of the ColumnListView, even after the end of the last column. - - virtual void DrawItem(BView* owner, BRect itemRect, bool complete); - //In general, you don't need or want to override DrawItem(). - float ExpanderShift(int32 column_index, BView* owner); - virtual void Update(BView* owner, const BFont* font); - bool IsSuperItem() const; - void SetSuperItem(bool superitem); - uint32 OutlineLevel() const; - void SetOutlineLevel(uint32 level); - virtual void Pulse(BView * owner); // Called periodically when this item is selected. - - int32 GetSelectedColumn() const {return _selectedColumn;} - void SetSelectedColumn(int32 i) {_selectedColumn = i;} - + virtual void DrawItemColumn(BView* owner, + BRect columnRect, + int32 columnIndex, + bool columnSelected, + bool complete) = 0; + // columnIndex (0-N) is based on the order in which the columns + // were added to the ColumnListView, not the display order. + // An index of -1 indicates that the program needs to draw a blank + // area beyond the last column. The main purpose is to allow the + // highlighting bar to continue all the way to the end of the' + // ColumnListView, even after the end of the last column. + + virtual void DrawItem(BView* owner, BRect itemRect, + bool complete); + // In general, you don't need or want to override DrawItem(). + float ExpanderShift(int32 columnIndex, + BView* owner); + virtual void Update(BView* owner, const BFont* font); + bool IsSuperItem() const; + void SetSuperItem(bool superitem); + uint32 OutlineLevel() const; + void SetOutlineLevel(uint32 level); + + virtual void Pulse(BView* owner); + // Called periodically when this item is selected. + + int32 GetSelectedColumn() const + { return fSelectedColumn; } + void SetSelectedColumn(int32 i) + { fSelectedColumn = i; } + private: friend class ColumnListView; - bool fSuperItem; - uint32 fOutlineLevel; - float fMinHeight; - BRect fExpanderButtonRect; - BRect fExpanderColumnRect; - BList* fSortingContextBList; - ColumnListView* fSortingContextCLV; - int32 _selectedColumn; + bool fIsSuperItem; + uint32 fOutlineLevel; + float fMinHeight; + BRect fExpanderButtonRect; + BRect fExpanderColumnRect; + BList* fSortingContextBList; + ColumnListView* fSortingContextCLV; + int32 fSelectedColumn; }; -#endif + +#endif // CLV_LIST_ITEM_H diff --git a/src/preferences/shortcuts/clv/Colors.h b/src/preferences/shortcuts/clv/Colors.h index 62979032ca..276607a743 100644 --- a/src/preferences/shortcuts/clv/Colors.h +++ b/src/preferences/shortcuts/clv/Colors.h @@ -1,45 +1,54 @@ -#ifndef JColors_h -#define JColors_h +/* + * Copyright 1999-2009 Jeremy Friesner + * Copyright 2009-2014 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jeremy Friesner + * John Scipione, jscipione@gmail.com + */ +#ifndef J_COLORS_H +#define J_COLORS_H -//Useful until be gets around to making these sorts of things -//globals akin to be_plain_font, etc. -#include +// useful until be gets around to making these sorts of things +// globals akin to be_plain_font, etc. +#include -//Be standard UI colors -const rgb_color BeBackgroundGrey = {216,216,216, 255}; -const rgb_color BeInactiveControlGrey = {240,240,240, 255}; -const rgb_color BeFocusBlue = {0, 0, 229, 255}; -const rgb_color BeHighlight = {255,255,255, 255}; -const rgb_color BeShadow = {152,152,152, 255}; -const rgb_color BeDarkShadow = {108,108,108, 255}; -const rgb_color BeLightShadow = {194,194,194, 255}; -const rgb_color BeButtonGrey = {232,232,232, 255}; -const rgb_color BeInactiveGrey = {127,127,127, 255}; -const rgb_color BeListSelectGrey = {178,178,178, 255}; -const rgb_color BeTitleBarYellow = {255,203,0, 255}; +// Be standard UI colors +const rgb_color BeBackgroundGrey = { 216, 216, 216, 255 }; +const rgb_color BeInactiveControlGrey = { 240, 240, 240, 255 }; +const rgb_color BeFocusBlue = { 0, 0, 229, 255 }; +const rgb_color BeHighlight = { 255, 255, 255, 255 }; +const rgb_color BeShadow = { 152, 152, 152, 255 }; +const rgb_color BeDarkShadow = { 108, 108, 108, 255 }; +const rgb_color BeLightShadow = { 194, 194, 194, 255 }; +const rgb_color BeButtonGrey = { 232, 232, 232, 255 }; +const rgb_color BeInactiveGrey = { 127, 127, 127, 255 }; +const rgb_color BeListSelectGrey = { 178, 178, 178, 255 }; +const rgb_color BeTitleBarYellow = { 255, 203, 0, 255 }; -//Other colors -const rgb_color Black = {0, 0, 0, 255}; -const rgb_color White = {255,255,255, 255}; -const rgb_color Red = {255,0, 0, 255}; -const rgb_color Green = {0, 167,0, 255}; -const rgb_color LightGreen = {90, 240,90, 255}; -const rgb_color Blue = {49, 61, 225, 255}; -const rgb_color LightBlue = {64, 162,255, 255}; -const rgb_color Purple = {144,64, 221, 255}; -const rgb_color LightPurple = {166,74, 255, 255}; -const rgb_color Lavender = {193,122,255, 255}; -const rgb_color Yellow = {255,203,0, 255}; -const rgb_color Orange = {255,163,0, 255}; -const rgb_color Flesh = {255,231,186, 255}; -const rgb_color Tan = {208,182,121, 255}; -const rgb_color Brown = {154,110,45, 255}; -const rgb_color LightMetallicBlue = {143,166,240, 255}; -const rgb_color MedMetallicBlue = {75, 96, 154, 255}; -const rgb_color DarkMetallicBlue = {78, 89, 126, 255}; +// Other colors +const rgb_color Black = { 0, 0, 0, 255 }; +const rgb_color White = { 255, 255, 255, 255 }; +const rgb_color Red = { 255, 0, 0, 255 }; +const rgb_color Green = { 0, 167, 0, 255 }; +const rgb_color LightGreen = { 90, 240, 90, 255 }; +const rgb_color Blue = { 49, 61, 225, 255 }; +const rgb_color LightBlue = { 64, 162, 255, 255 }; +const rgb_color Purple = { 144, 64, 221, 255 }; +const rgb_color LightPurple = { 166, 74, 255, 255 }; +const rgb_color Lavender = { 193, 122, 255, 255 }; +const rgb_color Yellow = { 255, 203, 0, 255 }; +const rgb_color Orange = { 255, 163, 0, 255 }; +const rgb_color Flesh = { 255, 231, 186, 255 }; +const rgb_color Tan = { 208, 182, 121, 255 }; +const rgb_color Brown = { 154, 110, 45, 255 }; +const rgb_color LightMetallicBlue = { 143, 166, 240, 255 }; +const rgb_color MedMetallicBlue = { 75, 96, 154, 255 }; +const rgb_color DarkMetallicBlue = { 78, 89, 126, 255 }; -const rgb_color ReallyLightPurple = {255,210,255, 255}; -const rgb_color LightYellow = {255,255,210, 255}; +const rgb_color ReallyLightPurple = { 255, 210, 255, 255 }; +const rgb_color LightYellow = { 255, 255, 210, 255 }; -#endif +#endif // J_COLORS_H diff --git a/src/preferences/shortcuts/clv/ColumnListView.cpp b/src/preferences/shortcuts/clv/ColumnListView.cpp index bc7f496ab9..9c175ec315 100644 --- a/src/preferences/shortcuts/clv/ColumnListView.cpp +++ b/src/preferences/shortcuts/clv/ColumnListView.cpp @@ -1,10 +1,16 @@ -//Column list view source file +/* + * Copyright 1999-2009 Jeremy Friesner + * Copyright 2009-2014 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jeremy Friesner + * John Scipione, jscipione@gmail.com + */ -//****************************************************************************************************** -//**** PROJECT HEADER FILES -//****************************************************************************************************** #define ColumnListView_CPP + #include "ColumnListView.h" #include "CLVColumnLabelView.h" #include "CLVColumn.h" @@ -13,11 +19,8 @@ #include #include -//****************************************************************************************************** -//**** BITMAPS -//****************************************************************************************************** -uint8 CLVRightArrowData[132] = -{ + +uint8 CLVRightArrowData[132] = { 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x12, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, @@ -30,8 +33,8 @@ uint8 CLVRightArrowData[132] = 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; -uint8 CLVDownArrowData[132] = -{ + +uint8 CLVDownArrowData[132] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, @@ -46,38 +49,44 @@ uint8 CLVDownArrowData[132] = }; -//****************************************************************************************************** -//**** ColumnListView CLASS DEFINITION -//****************************************************************************************************** class CLVContainerView : public BScrollView { - public: - CLVContainerView(char* name, BView* target, uint32 resizingMode, uint32 flags, bool horizontal, - bool vertical, border_style border); - ~CLVContainerView(); - bool IsBeingDestroyed; +public: + CLVContainerView(char* name, BView* target, + uint32 resizingMode, uint32 flags, + bool horizontal, bool vertical, + border_style border); + virtual ~CLVContainerView(); + + bool IsBeingDestroyed() const + { return fIsBeingDestroyed; }; + +private: + bool fIsBeingDestroyed; }; -CLVContainerView::CLVContainerView(char* name, BView* target, uint32 resizingMode, uint32 flags, - bool horizontal, bool vertical, border_style border) +CLVContainerView::CLVContainerView(char* name, BView* target, + uint32 resizingMode, uint32 flags, bool horizontal, bool vertical, + border_style border) : - BScrollView(name, target, resizingMode, flags, horizontal, vertical, border) + BScrollView(name, target, resizingMode, flags, horizontal, vertical, + border) { - IsBeingDestroyed = false; -}; + fIsBeingDestroyed = false; +} CLVContainerView::~CLVContainerView() { - IsBeingDestroyed = true; + fIsBeingDestroyed = true; } -ColumnListView::ColumnListView(BRect frame, BScrollView **containerView, - const char *name, uint32 resizingMode, uint32 flags, list_view_type type, +ColumnListView::ColumnListView(BRect frame, BScrollView** containerView, + const char* name, uint32 resizingMode, uint32 flags, list_view_type type, bool hierarchical, bool horizontal, bool vertical, border_style border, - const BFont *labelFont) + const BFont* labelFont) : BListView(frame, name, type, B_FOLLOW_ALL_SIDES, flags | B_PULSE_NEEDED), fHierarchical(hierarchical), @@ -91,10 +100,10 @@ ColumnListView::ColumnListView(BRect frame, BScrollView **containerView, fRightArrow(BRect(0, 0, 10, 10), B_RGBA32, CLVRightArrowData, false, false), fDownArrow(BRect(0, 0, 10, 10), B_RGBA32, CLVDownArrowData, false, false), fFullItemList(32), - _selectedColumn(-1), - _editMessage(NULL) + fSelectedColumn(-1), + fEditMessage(NULL) { - //Create the column titles bar view + // create the column titles bar view font_height fontAttributes; labelFont->GetHeight(&fontAttributes); float fLabelFontHeight = ceil(fontAttributes.ascent) @@ -103,56 +112,60 @@ ColumnListView::ColumnListView(BRect frame, BScrollView **containerView, fColumnLabelView = new CLVColumnLabelView(BRect(frame.left, frame.top, frame.right, columnLabelViewBottom), this, labelFont); - //Create the container view + // create the container view CreateContainer(horizontal, vertical, border, resizingMode, flags); *containerView = fScrollView; - //Complete the setup - UpdateColumnSizesDataRectSizeScrollBars(); + // complete the setup + ShiftDragGroup(); fColumnLabelView->UpdateDragGroups(); fExpanderColumn = -1; - fCompare = NULL; + fCompareFunction = NULL; } ColumnListView::~ColumnListView() { - //Delete all list columns + // delete all list columns int32 ColumnCount = fColumnList.CountItems(); - for(int32 Counter = ColumnCount-1; Counter >= 0; Counter--) - { - CLVColumn* Item = (CLVColumn*)fColumnList.RemoveItem(Counter); - if(Item) - delete Item; + for (int32 i = ColumnCount - 1; i >= 0; i--) { + CLVColumn* item = (CLVColumn*)fColumnList.RemoveItem(i); + if (item != NULL) + delete item; } - //Remove and delete the container view if necessary - if(!fScrollView->IsBeingDestroyed) - { + + // remove and delete the container view if necessary + if (!fScrollView->IsBeingDestroyed()) { fScrollView->RemoveChild(this); delete fScrollView; } - delete _editMessage; + delete fEditMessage; } -void ColumnListView::CreateContainer(bool horizontal, bool vertical, border_style border, - uint32 ResizingMode, uint32 flags) +void +ColumnListView::CreateContainer(bool horizontal, bool vertical, + border_style border, uint32 resizingMode, uint32 flags) { - BRect ViewFrame = Frame(); - BRect LabelsFrame = fColumnLabelView->Frame(); + BRect frame = Frame(); + BRect labelsFrame = fColumnLabelView->Frame(); - fScrollView = new CLVContainerView(NULL,this,ResizingMode,flags,horizontal,vertical,border); - BRect NewFrame = Frame(); - //Resize the main view to make room for the CLVColumnLabelView - ResizeTo(ViewFrame.right-ViewFrame.left,ViewFrame.bottom-LabelsFrame.bottom-1.0); - MoveTo(NewFrame.left,NewFrame.top+(LabelsFrame.bottom-LabelsFrame.top+1.0)); - fColumnLabelView->MoveTo(NewFrame.left,NewFrame.top); + fScrollView = new CLVContainerView(NULL, this, resizingMode, flags, + horizontal, vertical, border); + BRect newFrame = Frame(); + // resize the main view to make room for the CLVColumnLabelView + ResizeTo(frame.right - frame.left, frame.bottom - + labelsFrame.bottom - 1.0); + MoveTo(newFrame.left, newFrame.top + + (labelsFrame.bottom - labelsFrame.top + 1.0)); + fColumnLabelView->MoveTo(newFrame.left, newFrame.top); - //Add the ColumnLabelView + // add the ColumnLabelView fScrollView->AddChild(fColumnLabelView); - //Remove and re-add the BListView so that it will draw after the CLVColumnLabelView + // remove and re-add the BListView so that it will draw after + // the CLVColumnLabelView fScrollView->RemoveChild(this); fScrollView->AddChild(this); @@ -160,1625 +173,1770 @@ void ColumnListView::CreateContainer(bool horizontal, bool vertical, border_styl } -void ColumnListView::AddScrollViewCorner() +void +ColumnListView::AddScrollViewCorner() { - BPoint FarCorner = fScrollView->Bounds().RightBottom(); - fFillerView = new ScrollViewCorner(FarCorner.x-B_V_SCROLL_BAR_WIDTH,FarCorner.y-B_H_SCROLL_BAR_HEIGHT); + BPoint farCorner = fScrollView->Bounds().RightBottom(); + fFillerView = new ScrollViewCorner(farCorner.x - B_V_SCROLL_BAR_WIDTH, + farCorner.y - B_H_SCROLL_BAR_HEIGHT); fScrollView->AddChild(fFillerView); } -void ColumnListView::UpdateColumnSizesDataRectSizeScrollBars() +void +ColumnListView::ShiftDragGroup() { - //Figure out the width - float ColumnBegin; - float ColumnEnd = -1.0; + // figure out the width + float columnBegin; + float columnEnd = -1.0; fDataWidth = 0.0; - bool NextPushedByExpander = false; - int32 NumberOfColumns = fColumnDisplayList.CountItems(); - for(int32 Counter = 0; Counter < NumberOfColumns; Counter++) - { - CLVColumn* Column = (CLVColumn*)fColumnDisplayList.ItemAt(Counter); - if(NextPushedByExpander) - Column->fPushedByExpander = true; + bool nextPushedByExpander = false; + int32 columnCount = fColumnDisplayList.CountItems(); + for (int32 i = 0; i < columnCount; i++) { + CLVColumn* column = (CLVColumn*)fColumnDisplayList.ItemAt(i); + if (nextPushedByExpander) + column->fPushedByExpander = true; else - Column->fPushedByExpander = false; - if(Column->IsShown()) - { - float ColumnWidth = Column->Width(); - ColumnBegin = ColumnEnd + 1.0; - ColumnEnd = ColumnBegin + ColumnWidth; - Column->fColumnBegin = ColumnBegin; - Column->fColumnEnd = ColumnEnd; - fDataWidth = Column->fColumnEnd; - if(NextPushedByExpander) - if(!(Column->fFlags & CLV_PUSH_PASS)) - NextPushedByExpander = false; - if(Column->fFlags & CLV_EXPANDER) - //Set the next column to be pushed - NextPushedByExpander = true; + column->fPushedByExpander = false; + + if (column->IsShown()) { + float columnWidth = column->Width(); + columnBegin = columnEnd + 1.0; + columnEnd = columnBegin + columnWidth; + column->fColumnBegin = columnBegin; + column->fColumnEnd = columnEnd; + fDataWidth = column->fColumnEnd; + if (nextPushedByExpander && !(column->fFlags & CLV_PUSH_PASS)) + nextPushedByExpander = false; + + if (column->fFlags & CLV_EXPANDER) { + // set the next column to be pushed + nextPushedByExpander = true; + } } } - //Figure out the height + // figure out the height fDataHeight = 0.0; - int32 NumberOfItems = CountItems(); - for(int32 Counter2 = 0; Counter2 < NumberOfItems; Counter2++) - fDataHeight += ItemAt(Counter2)->Height()+1.0; - if(NumberOfItems > 0) + int32 itemCount = CountItems(); + for (int32 i = 0; i < itemCount; i++) + fDataHeight += ItemAt(i)->Height() + 1.0; + + if (itemCount > 0) fDataHeight -= 1.0; - //Update the scroll bars + // update the scroll bars UpdateScrollBars(); } -void ColumnListView::UpdateScrollBars() +void +ColumnListView::UpdateScrollBars() { - if(fScrollView) - { - //Figure out the bounds and scroll if necessary - BRect ViewBounds; - float DeltaX,DeltaY; - do - { - ViewBounds = Bounds(); + if (fScrollView != NULL) { + // figure out the bounds and scroll if necessary + BRect bounds; + float deltaX; + float deltaY; + do { + bounds = Bounds(); //Figure out the width of the page rectangle fPageWidth = fDataWidth; fPageHeight = fDataHeight; //If view runs past the end, make more visible at the beginning - DeltaX = 0.0; - if(ViewBounds.right > fDataWidth && ViewBounds.left > 0) - { - DeltaX = ViewBounds.right-fDataWidth; - if(DeltaX > ViewBounds.left) - DeltaX = ViewBounds.left; + deltaX = 0.0; + if (bounds.right > fDataWidth && bounds.left > 0) { + deltaX = bounds.right - fDataWidth; + if (deltaX > bounds.left) + deltaX = bounds.left; } - DeltaY = 0.0; - if(ViewBounds.bottom > fDataHeight && ViewBounds.top > 0) - { - DeltaY = ViewBounds.bottom-fDataHeight; - if(DeltaY > ViewBounds.top) - DeltaY = ViewBounds.top; + deltaY = 0.0; + if (bounds.bottom > fDataHeight && bounds.top > 0) { + deltaY = bounds.bottom - fDataHeight; + if (deltaY > bounds.top) + deltaY = bounds.top; } - if(DeltaX != 0.0 || DeltaY != 0.0) - { - ScrollTo(BPoint(ViewBounds.left-DeltaX,ViewBounds.top-DeltaY)); - ViewBounds = Bounds(); + if (deltaX != 0.0 || deltaY != 0.0) { + ScrollTo(BPoint(bounds.left - deltaX, bounds.top - deltaY)); + bounds = Bounds(); } - if(ViewBounds.right-ViewBounds.left > fDataWidth) - fPageWidth = ViewBounds.right; - if(ViewBounds.bottom-ViewBounds.top > fDataHeight) - fPageHeight = ViewBounds.bottom; - }while(DeltaX != 0.0 || DeltaY != 0.0); + if (bounds.right-bounds.left > fDataWidth) + fPageWidth = bounds.right; - //Figure out the ratio of the bounds rectangle width or height to the page rectangle width or height - float WidthProp = (ViewBounds.right-ViewBounds.left)/fPageWidth; - float HeightProp = (ViewBounds.bottom-ViewBounds.top)/fPageHeight; + if (bounds.bottom-bounds.top > fDataHeight) + fPageHeight = bounds.bottom; + } while (deltaX != 0.0 || deltaY != 0.0); - BScrollBar* HScrollBar = fScrollView->ScrollBar(B_HORIZONTAL); - BScrollBar* VScrollBar = fScrollView->ScrollBar(B_VERTICAL); - //Set the scroll bar ranges and proportions. If the whole document is visible, inactivate the - //slider - if(HScrollBar) - { - if(WidthProp >= 1.0 && ViewBounds.left == 0.0) - HScrollBar->SetRange(0.0,0.0); - else - HScrollBar->SetRange(0.0,fPageWidth-(ViewBounds.right-ViewBounds.left)); - HScrollBar->SetProportion(WidthProp); - //Set the step values - HScrollBar->SetSteps(20.0,ViewBounds.right-ViewBounds.left); + // figure out the ratio of the bounds rectangle width or height + // to the page rectangle width or height + float widthRatio = (bounds.right - bounds.left) / fPageWidth; + float heightRatio = (bounds.bottom - bounds.top) / fPageHeight; + + BScrollBar* horizontalScrollBar = fScrollView->ScrollBar(B_HORIZONTAL); + BScrollBar* verticalScrollBar = fScrollView->ScrollBar(B_VERTICAL); + // set the scroll bar ranges and proportions. If the whole document + // is visible, inactivate the slider + if (horizontalScrollBar != NULL) { + if (widthRatio >= 1.0 && bounds.left == 0.0) + horizontalScrollBar->SetRange(0.0, 0.0); + else { + horizontalScrollBar->SetRange(0.0, fPageWidth + - (bounds.right - bounds.left)); + } + horizontalScrollBar->SetProportion(widthRatio); + // set the step values + horizontalScrollBar->SetSteps(20.0, bounds.right - bounds.left); } - if(VScrollBar) - { - if(HeightProp >= 1.0 && ViewBounds.top == 0.0) - { - VScrollBar->SetRange(0.0,0.0); - if(fFillerView) + + if (verticalScrollBar != NULL) { + if (heightRatio >= 1.0 && bounds.top == 0.0) { + verticalScrollBar->SetRange(0.0, 0.0); + if (fFillerView) fFillerView->SetViewColor(BeInactiveControlGrey); - } - else - { - VScrollBar->SetRange(0.0,fPageHeight-(ViewBounds.bottom-ViewBounds.top)); - if(fFillerView) + } else { + verticalScrollBar->SetRange(0.0, + fPageHeight - (bounds.bottom-bounds.top)); + if (fFillerView != NULL) fFillerView->SetViewColor(BeBackgroundGrey); } - VScrollBar->SetProportion(HeightProp); + verticalScrollBar->SetProportion(heightRatio); } } } -void ColumnListView::ColumnsChanged() +void +ColumnListView::ColumnsChanged() { - //Any previous column dragging/resizing will get corrupted, so deselect - if(fColumnLabelView->fColumnClicked) + // any previous column dragging/resizing will get corrupted, so deselect + if (fColumnLabelView->fColumnClicked) fColumnLabelView->fColumnClicked = NULL; - //Update the internal sizes and grouping of the columns and sizes of drag groups - UpdateColumnSizesDataRectSizeScrollBars(); + // update the internal sizes and grouping of the columns and sizes + // of drag groups + ShiftDragGroup(); fColumnLabelView->UpdateDragGroups(); fColumnLabelView->Invalidate(); Invalidate(); } -bool ColumnListView::AddColumn(CLVColumn* Column) -//Adds a column to the ColumnListView at the end of the list. Returns true if successful. +// Adds a column to the ColumnListView at the end of the list. +// Returns true if successful. +bool +ColumnListView::AddColumn(CLVColumn* column) { - int32 NumberOfColumns = fColumnList.CountItems(); - int32 DisplayIndex = NumberOfColumns; + int32 columnCount = fColumnList.CountItems(); + int32 displayIndex = columnCount; - //Make sure a second Expander is not being added - if(Column->fFlags & CLV_EXPANDER) - { - if(!fHierarchical) + // make sure a second Expander is not being added + if ((column->fFlags & CLV_EXPANDER) != 0) { + if (!fHierarchical) return false; - for(int32 Counter = 0; Counter < NumberOfColumns; Counter++) - if(((CLVColumn*)fColumnList.ItemAt(Counter))->fFlags & CLV_EXPANDER) + + for (int32 i = 0; i < columnCount; i++) { + if ((((CLVColumn*)fColumnList.ItemAt(i))->fFlags & CLV_EXPANDER) + != 0) { return false; - if(Column->IsShown()) - fExpanderColumn = NumberOfColumns; + } + } + + if (column->IsShown()) + fExpanderColumn = columnCount; } - //Make sure this column hasn't already been added to another ColumnListView - if(Column->fParent != NULL) + // make sure this column hasn't already been added to another ColumnListView + if (column->fParent != NULL) return false; - BWindow* ParentWindow = Window(); - if(ParentWindow) - ParentWindow->Lock(); - //Check if this should be locked at the beginning or end, and adjust its position if necessary - if(!Column->Flags() & CLV_LOCK_AT_END) - { - bool Repeat; - if(Column->Flags() & CLV_LOCK_AT_BEGINNING) - { - //Move it to the beginning, after the last CLV_LOCK_AT_BEGINNING item - DisplayIndex = 0; - Repeat = true; - while(Repeat && DisplayIndex < NumberOfColumns) - { - Repeat = false; - CLVColumn* LastColumn = (CLVColumn*)fColumnDisplayList.ItemAt(DisplayIndex); - if(LastColumn->Flags() & CLV_LOCK_AT_BEGINNING) - { - DisplayIndex++; - Repeat = true; + BWindow* parentWindow = Window(); + if (parentWindow != NULL) + parentWindow->Lock(); + + // check if this should be locked at the beginning or end, and adjust + // its position if necessary + if ((column->Flags() & CLV_LOCK_AT_END) == 0) { + bool shouldRepeat; + if ((column->Flags() & CLV_LOCK_AT_BEGINNING) != 0) { + // move it to the beginning, after the last + // CLV_LOCK_AT_BEGINNING item + displayIndex = 0; + shouldRepeat = true; + while (shouldRepeat && displayIndex < columnCount) { + shouldRepeat = false; + CLVColumn* lastColumn + = (CLVColumn*)fColumnDisplayList.ItemAt(displayIndex); + if ((lastColumn->Flags() & CLV_LOCK_AT_BEGINNING) != 0) { + displayIndex++; + shouldRepeat = true; } } - } - else - { - //Make sure it isn't after a CLV_LOCK_AT_END item - Repeat = true; - while(Repeat && DisplayIndex > 0) + } else { + // make sure it isn't after a CLV_LOCK_AT_END item + shouldRepeat = true; + while (shouldRepeat && displayIndex > 0) { - Repeat = false; - CLVColumn* LastColumn = (CLVColumn*)fColumnDisplayList.ItemAt(DisplayIndex-1); - if(LastColumn->Flags() & CLV_LOCK_AT_END) - { - DisplayIndex--; - Repeat = true; + shouldRepeat = false; + CLVColumn* lastColumn + = (CLVColumn*)fColumnDisplayList.ItemAt(displayIndex - 1); + if ((lastColumn->Flags() & CLV_LOCK_AT_END) != 0) { + displayIndex--; + shouldRepeat = true; } } } } - //Add the column to the display list in the appropriate position - fColumnDisplayList.AddItem(Column, DisplayIndex); + // add the column to the display list in the appropriate position + fColumnDisplayList.AddItem(column, displayIndex); - //Add the column to the end of the column list - fColumnList.AddItem(Column); + // add the column to the end of the column list + fColumnList.AddItem(column); - //Tell the column it belongs to me now - Column->fParent = this; + // tell the column it belongs to me now + column->fParent = this; - //Set the scroll bars and tell views to update + // set the scroll bars and tell views to update ColumnsChanged(); - if(ParentWindow) - ParentWindow->Unlock(); + if (parentWindow != NULL) + parentWindow->Unlock(); + return true; } -bool ColumnListView::AddColumnList(BList* NewColumns) -//Adds a BList of CLVColumn's to the ColumnListView at the position specified, or at the end of the list -//if AtIndex == -1. Returns true if successful. +// Adds a BList of CLVColumn's to the ColumnListView at the position specified, +// or at the end of the list if AtIndex == -1. Returns true if successful. +bool +ColumnListView::AddColumnList(BList* newColumns) { - int32 NumberOfColumns = int32(fColumnList.CountItems()); - int32 NumberOfColumnsToAdd = int32(NewColumns->CountItems()); + int32 columnCount = int32(fColumnList.CountItems()); + int32 columnCountToAdd = int32(newColumns->CountItems()); - //Make sure a second CLVExpander is not being added - int32 Counter; - int32 NumberOfExpanders = 0; - for(Counter = 0; Counter < NumberOfColumns; Counter++) - if(((CLVColumn*)fColumnList.ItemAt(Counter))->fFlags & CLV_EXPANDER) - NumberOfExpanders++; - int32 SetfExpanderColumnTo = -1; - for(Counter = 0; Counter < NumberOfColumnsToAdd; Counter++) - { - CLVColumn* ThisColumn = (CLVColumn*)NewColumns->ItemAt(Counter); - if(ThisColumn->fFlags & CLV_EXPANDER) - { - NumberOfExpanders++; - if(ThisColumn->IsShown()) - SetfExpanderColumnTo = NumberOfColumns + Counter; + // make sure a second CLVExpander is not being added + int32 expanderCount = 0; + for (int32 i = 0; i < columnCount; i++) { + if ((((CLVColumn*)fColumnList.ItemAt(i))->fFlags & CLV_EXPANDER) != 0) + expanderCount++; + } + + int32 expandercolumnIndex = -1; + for (int32 i = 0; i < columnCountToAdd; i++) { + CLVColumn* current = (CLVColumn*)newColumns->ItemAt(i); + if ((current->fFlags & CLV_EXPANDER) != 0) { + expanderCount++; + if (current->IsShown()) + expandercolumnIndex = columnCount + i; } } - if(NumberOfExpanders != 0 && !fHierarchical) - return false; - if(NumberOfExpanders > 1) - return false; - if(SetfExpanderColumnTo != -1) - fExpanderColumn = SetfExpanderColumnTo; - //Make sure none of these columns have already been added to a ColumnListView - for(Counter = 0; Counter < NumberOfColumnsToAdd; Counter++) - if(((CLVColumn*)NewColumns->ItemAt(Counter))->fParent != NULL) + if (expanderCount != 0 && !fHierarchical) + return false; + + if (expanderCount > 1) + return false; + + if (expandercolumnIndex != -1) + fExpanderColumn = expandercolumnIndex; + + // make sure none of these columns have already been added + // to a ColumnListView + for (int32 i = 0; i < columnCountToAdd; i++) { + if (((CLVColumn*)newColumns->ItemAt(i))->fParent != NULL) return false; - //Make sure none of these columns are being added twice - for(Counter = 0; Counter < NumberOfColumnsToAdd-1; Counter++) - for(int32 Counter2 = Counter+1; Counter2 < NumberOfColumnsToAdd; Counter2++) - if(NewColumns->ItemAt(Counter) == NewColumns->ItemAt(Counter2)) - return false; + } - BWindow* ParentWindow = Window(); - if(ParentWindow) - ParentWindow->Lock(); - for(Counter = 0; Counter < NumberOfColumnsToAdd; Counter++) - { - CLVColumn* Column = (CLVColumn*)NewColumns->ItemAt(Counter); - //Check if this should be locked at the beginning or end, and adjust its position if necessary - int32 DisplayIndex = NumberOfColumns; - if(!Column->Flags() & CLV_LOCK_AT_END) - { - bool Repeat; - if(Column->Flags() & CLV_LOCK_AT_BEGINNING) - { - //Move it to the beginning, after the last CLV_LOCK_AT_BEGINNING item - DisplayIndex = 0; - Repeat = true; - while(Repeat && DisplayIndex < NumberOfColumns) - { - Repeat = false; - CLVColumn* LastColumn = (CLVColumn*)fColumnDisplayList.ItemAt(DisplayIndex); - if(LastColumn->Flags() & CLV_LOCK_AT_BEGINNING) - { - DisplayIndex++; - Repeat = true; + // make sure none of these columns are being added twice + for (int32 i = 0; i < columnCountToAdd - 1; i++) { + for (int32 j = i + 1; j < columnCountToAdd; j++) { + if (newColumns->ItemAt(i) == newColumns->ItemAt(j)) + return false; + } + } + + BWindow* parentWindow = Window(); + if (parentWindow != NULL) + parentWindow->Lock(); + + for (int32 i = 0; i < columnCountToAdd; i++) { + CLVColumn* column = (CLVColumn*)newColumns->ItemAt(i); + // check if this should be locked at the beginning or end, + // and adjust its position if necessary + int32 displayIndex = columnCount; + if ((column->Flags() & CLV_LOCK_AT_END) == 0) { + bool shouldRepeat; + if ((column->Flags() & CLV_LOCK_AT_BEGINNING) != 0) { + // move it to the beginning, after the last + // CLV_LOCK_AT_BEGINNING item + displayIndex = 0; + shouldRepeat = true; + while (shouldRepeat && displayIndex < columnCount) { + shouldRepeat = false; + CLVColumn* lastColumn + = (CLVColumn*)fColumnDisplayList.ItemAt(displayIndex); + if ((lastColumn->Flags() & CLV_LOCK_AT_BEGINNING) != 0) { + displayIndex++; + shouldRepeat = true; } } - } - else - { - //Make sure it isn't after a CLV_LOCK_AT_END item - Repeat = true; - while(Repeat && DisplayIndex > 0) - { - Repeat = false; - CLVColumn* LastColumn = (CLVColumn*)fColumnDisplayList.ItemAt(DisplayIndex-1); - if(LastColumn->Flags() & CLV_LOCK_AT_END) - { - DisplayIndex--; - Repeat = true; + } else { + // make sure it isn't after a CLV_LOCK_AT_END item + shouldRepeat = true; + while (shouldRepeat && displayIndex > 0) { + shouldRepeat = false; + CLVColumn* lastColumn + = (CLVColumn*)fColumnDisplayList.ItemAt( + displayIndex - 1); + if ((lastColumn->Flags() & CLV_LOCK_AT_END) != 0) { + displayIndex--; + shouldRepeat = true; } } } } - //Add the column to the display list in the appropriate position - fColumnDisplayList.AddItem(Column, DisplayIndex); + // add the column to the display list in the appropriate position + fColumnDisplayList.AddItem(column, displayIndex); - //Tell the column it belongs to me now - Column->fParent = this; + // tell the column it belongs to me now + column->fParent = this; - NumberOfColumns++; + columnCount++; } - //Add the columns to the end of the column list - fColumnList.AddList(NewColumns); + // add the columns to the end of the column list + fColumnList.AddList(newColumns); - //Set the scroll bars and tell views to update + // set the scroll bars and tell views to update ColumnsChanged(); - if(ParentWindow) - ParentWindow->Unlock(); + if (parentWindow != NULL) + parentWindow->Unlock(); + return true; } -bool ColumnListView::RemoveColumn(CLVColumn* Column) -//Removes a CLVColumn from the ColumnListView. Returns true if successful. +// Removes a CLVColumn from the ColumnListView. +// Returns true if successful. +bool +ColumnListView::RemoveColumn(CLVColumn* column) { - if(!fColumnList.HasItem(Column)) + if (!fColumnList.HasItem(column)) return false; - int32 ColumnIndex = fSortKeyList.IndexOf(Column); - if(ColumnIndex >= 0) - fSortKeyList.RemoveItem(ColumnIndex); - if(Column->fFlags & CLV_EXPANDER) + int32 columnIndex = fSortKeyList.IndexOf(column); + if (columnIndex >= 0) + fSortKeyList.RemoveItem(columnIndex); + + if ((column->fFlags & CLV_EXPANDER) != 0) fExpanderColumn = -1; - BWindow* ParentWindow = Window(); - if(ParentWindow) - ParentWindow->Lock(); - //Remove Column from the column and display lists - fColumnDisplayList.RemoveItem(Column); - fColumnList.RemoveItem(Column); + BWindow* parentWindow = Window(); + if (parentWindow != NULL) + parentWindow->Lock(); - //Tell the column it has been removed - Column->fParent = NULL; + // remove column from the column and display lists + fColumnDisplayList.RemoveItem(column); + fColumnList.RemoveItem(column); - //Set the scroll bars and tell views to update + //tell the column it has been removed + column->fParent = NULL; + + // set the scroll bars and tell views to update ColumnsChanged(); - if(ParentWindow) - ParentWindow->Unlock(); + if (parentWindow != NULL) + parentWindow->Unlock(); + return true; } -bool ColumnListView::RemoveColumns(CLVColumn* Column, int32 Count) -//Finds Column in ColumnList and removes Count columns and their data from the view and its items +// Finds column in columnList and removes Count columns and their data +// from the view and its items. +bool +ColumnListView::RemoveColumns(CLVColumn* column, int32 count) { - BWindow* ParentWindow = Window(); - if(ParentWindow) - ParentWindow->Lock(); - int32 ColumnIndex = fColumnList.IndexOf(Column); - if(ColumnIndex < 0) - { - if(ParentWindow) - ParentWindow->Unlock(); - return false; - } - if(ColumnIndex + Count >= fColumnList.CountItems()) - { - if(ParentWindow) - ParentWindow->Unlock(); + BWindow* parentWindow = Window(); + if (parentWindow != NULL) + parentWindow->Lock(); + + int32 columnIndex = fColumnList.IndexOf(column); + if (columnIndex < 0) { + if (parentWindow != NULL) + parentWindow->Unlock(); + return false; } - //Remove columns from the column and display lists - for(int32 Counter = ColumnIndex; Counter < ColumnIndex+Count; Counter++) - { - CLVColumn* ThisColumn = (CLVColumn*)fColumnList.ItemAt(Counter); - fColumnDisplayList.RemoveItem(ThisColumn); + if (columnIndex + count >= fColumnList.CountItems()) { + if (parentWindow != NULL) + parentWindow->Unlock(); - int32 SortIndex = fSortKeyList.IndexOf(Column); - if(SortIndex >= 0) - fSortKeyList.RemoveItem(SortIndex); + return false; + } - if(ThisColumn->fFlags & CLV_EXPANDER) + for (int32 i = columnIndex; i < columnIndex + count; i++) { + // remove columns from the column and display lists + CLVColumn* current = (CLVColumn*)fColumnList.ItemAt(i); + fColumnDisplayList.RemoveItem(current); + + int32 sortIndex = fSortKeyList.IndexOf(column); + if (sortIndex >= 0) + fSortKeyList.RemoveItem(sortIndex); + + if ((current->fFlags & CLV_EXPANDER) != 0) fExpanderColumn = -1; - //Tell the column it has been removed - ThisColumn->fParent = NULL; + // tell the column it has been removed + current->fParent = NULL; } - fColumnList.RemoveItems(ColumnIndex,Count); + fColumnList.RemoveItems(columnIndex, count); - //Set the scroll bars and tell views to update + // set the scroll bars and tell views to update ColumnsChanged(); - if(ParentWindow) - ParentWindow->Unlock(); + if (parentWindow != NULL) + parentWindow->Unlock(); + return true; } -void ColumnListView :: SetEditMessage(BMessage * newMsg, BMessenger target) +void +ColumnListView::SetEditMessage(BMessage* message, BMessenger target) { - delete _editMessage; - _editMessage = newMsg; - _editTarget = target; + delete fEditMessage; + fEditMessage = message; + fEditTarget = target; } -void ColumnListView :: KeyDown(const char * bytes, int32 numBytes) + +void +ColumnListView::KeyDown(const char* bytes, int32 numBytes) { - int colDiff = 0; - bool metaKeysPressed = false; + int colDiff = 0; + bool metaKeysPressed = false; - // Find out if any meta-keys are pressed - int32 q; - if (Window()->CurrentMessage()->FindInt32("modifiers", &q) == B_NO_ERROR) - { - metaKeysPressed = ((q & (B_SHIFT_KEY | B_COMMAND_KEY | B_CONTROL_KEY | B_OPTION_KEY)) != 0); - } + // find out if any meta-keys are pressed + int32 q; + if (Window()->CurrentMessage()->FindInt32("modifiers", &q) == B_NO_ERROR) { + metaKeysPressed = ((q & (B_SHIFT_KEY | B_COMMAND_KEY | B_CONTROL_KEY + | B_OPTION_KEY)) != 0); + } - if (numBytes > 0) - { - switch (*bytes) - { - case B_LEFT_ARROW: - if (metaKeysPressed == false) - { - colDiff = -1; - break; - } + if (numBytes > 0) { + switch (*bytes) + { + case B_LEFT_ARROW: + if (metaKeysPressed == false) + { + colDiff = -1; + break; + } - case B_RIGHT_ARROW: - if (metaKeysPressed == false) - { - colDiff = 1; - break; - } + case B_RIGHT_ARROW: + if (metaKeysPressed == false) + { + colDiff = 1; + break; + } - case B_UP_ARROW: - case B_DOWN_ARROW: - if (metaKeysPressed == false) - { - BListView::KeyDown(bytes, numBytes); - break; - } + case B_UP_ARROW: + case B_DOWN_ARROW: + if (metaKeysPressed == false) + { + BListView::KeyDown(bytes, numBytes); + break; + } - default: - if (_editMessage != NULL) - { - BMessage temp(*_editMessage); - temp.AddInt32("column", _selectedColumn); - temp.AddInt32("row", CurrentSelection()); - temp.AddString("bytes", bytes); + default: + if (fEditMessage != NULL) + { + BMessage temp(*fEditMessage); + temp.AddInt32("column", fSelectedColumn); + temp.AddInt32("row", CurrentSelection()); + temp.AddString("bytes", bytes); - int32 key; - if (Window()->CurrentMessage()->FindInt32("key", &key) == B_NO_ERROR) temp.AddInt32("key", key); + int32 key; + if (Window()->CurrentMessage()->FindInt32("key", &key) + == B_NO_ERROR) { + temp.AddInt32("key", key); + } - _editTarget.SendMessage(&temp); - } - break; - } - } + fEditTarget.SendMessage(&temp); + } + break; + } + } - if (colDiff != 0) - { - // We need to move the highlighted column by (colDiff) columns, if possible. - int numDisplayColumns = fColumnDisplayList.CountItems(); + if (colDiff != 0) { + // we need to move the highlighted column by (colDiff) columns + // if possible. + int displayColumnCount = fColumnDisplayList.CountItems(); + int currentColumn = fSelectedColumn; + // currentColumn is an ACTUAL index. + if (currentColumn == -1) { + // no current column selected? + currentColumn = (colDiff > 0) ? GetActualIndexOf(0) + : GetActualIndexOf(displayColumnCount-1); + // go to an edge + } else { + // go to the display column adjacent to the current column's + // display column. + int32 currentDisplayIndex = GetDisplayIndexOf(currentColumn); + if (currentDisplayIndex < 0) + currentDisplayIndex = 0; - int curColumn = _selectedColumn; // curColumn is an ACTUAL index. - if (curColumn == -1) // no current column selected? - { - curColumn = (colDiff > 0) ? GetActualIndexOf(0) : GetActualIndexOf(numDisplayColumns-1); // go to an edge - } - else - { - // Go to the display column adjacent to the current column's display column. - int32 currentDisplayIndex = GetDisplayIndexOf(curColumn); - if (currentDisplayIndex < 0) currentDisplayIndex = 0; - currentDisplayIndex += colDiff; + currentDisplayIndex += colDiff; - if (currentDisplayIndex < 0) currentDisplayIndex = numDisplayColumns - 1; - if (currentDisplayIndex >= numDisplayColumns) currentDisplayIndex = 0; - curColumn = GetActualIndexOf(currentDisplayIndex); - } - SetSelectedColumnIndex(curColumn); - } + if (currentDisplayIndex < 0) + currentDisplayIndex = displayColumnCount - 1; + + if (currentDisplayIndex >= displayColumnCount) + currentDisplayIndex = 0; + + currentColumn = GetActualIndexOf(currentDisplayIndex); + } + + SetSelectedColumnIndex(currentColumn); + } } -int32 ColumnListView::CountColumns() const + +int32 +ColumnListView::CountColumns() const { return fColumnList.CountItems(); } -int32 ColumnListView::IndexOfColumn(CLVColumn* column) const +int32 +ColumnListView::IndexOfColumn(CLVColumn* column) const { return fColumnList.IndexOf(column); } -CLVColumn* ColumnListView::ColumnAt(int32 column_index) const +CLVColumn* +ColumnListView::ColumnAt(int32 columnIndex) const { - return (CLVColumn*)fColumnList.ItemAt(column_index); + return (CLVColumn*)fColumnList.ItemAt(columnIndex); } -CLVColumn* ColumnListView::ColumnAt(BPoint point) const -{ - for (int i=0; i= col->fColumnBegin)&&(point.x <= col->fColumnEnd)) return col; - } - return NULL; -} -bool ColumnListView::SetDisplayOrder(const int32* ColumnOrder) -//Sets the display order using a BList of CLVColumn's +CLVColumn* +ColumnListView::ColumnAt(BPoint point) const { - BWindow* ParentWindow = Window(); - if(ParentWindow) - ParentWindow->Lock(); - //Add the items to the display list in order - fColumnDisplayList.MakeEmpty(); - int32 ColumnsToSet = fColumnList.CountItems(); - for(int32 Counter = 0; Counter < ColumnsToSet; Counter++) - { - if(ColumnOrder[Counter] >= ColumnsToSet) - { - if(ParentWindow) - ParentWindow->Unlock(); - return false; - } - for(int32 Counter2 = 0; Counter2 < Counter; Counter2++) - if(ColumnOrder[Counter] == ColumnOrder[Counter2]) - { - if(ParentWindow) - ParentWindow->Unlock(); - return false; - } - fColumnDisplayList.AddItem(fColumnList.ItemAt(ColumnOrder[Counter])); + int32 columnCount = fColumnList.CountItems(); + for (int32 i = 0; i < columnCount; i++) { + CLVColumn* col = (CLVColumn*)fColumnList.ItemAt(i); + if ((point.x >= col->fColumnBegin) && (point.x <= col->fColumnEnd)) + return col; } - //Update everything about the columns + return NULL; +} + + +//Sets the display order using a BList of CLVColumn's +bool +ColumnListView::SetDisplayOrder(const int32* ColumnOrder) +{ + BWindow* parentWindow = Window(); + if (parentWindow != NULL) + parentWindow->Lock(); + + // add the items to the display list in order + fColumnDisplayList.MakeEmpty(); + int32 columnCount = fColumnList.CountItems(); + for (int32 i = 0; i < columnCount; i++) { + if (ColumnOrder[i] >= columnCount) { + if (parentWindow != NULL) + parentWindow->Unlock(); + + return false; + } + + for (int32 j = 0; j < i; j++) { + if (ColumnOrder[i] == ColumnOrder[j]) { + if (parentWindow != NULL) + parentWindow->Unlock(); + + return false; + } + } + fColumnDisplayList.AddItem(fColumnList.ItemAt(ColumnOrder[i])); + } + + // update everything about the columns ColumnsChanged(); - //Let the program know that the display order changed. - if(ParentWindow) - ParentWindow->Unlock(); + // let the program know that the display order changed. + if (parentWindow != NULL) + parentWindow->Unlock(); + DisplayOrderChanged(ColumnOrder); + return true; } -void ColumnListView::ColumnWidthChanged(int32 ColumnIndex, float NewWidth) +void +ColumnListView::ColumnWidthChanged(int32 columnIndex, float newWidth) { - Invalidate(); + Invalidate(); } -void ColumnListView::DisplayOrderChanged(const int32* order) -{ } - - -int32* ColumnListView::DisplayOrder() const +void +ColumnListView::DisplayOrderChanged(const int32* order) { - int32 ColumnsInList = fColumnList.CountItems(); - int32* ReturnList = new int32[ColumnsInList]; - BWindow* ParentWindow = Window(); - if(ParentWindow) - ParentWindow->Lock(); - for(int32 Counter = 0; Counter < ColumnsInList; Counter++) - ReturnList[Counter] = int32(fColumnList.IndexOf(fColumnDisplayList.ItemAt(Counter))); - if(ParentWindow) - ParentWindow->Unlock(); - return ReturnList; } -void ColumnListView::SetSortKey(int32 ColumnIndex) +int32* +ColumnListView::DisplayOrder() const { - CLVColumn* Column; - if(ColumnIndex >= 0) - { - Column = (CLVColumn*)fColumnList.ItemAt(ColumnIndex); - if(!(Column->Flags()&CLV_SORT_KEYABLE)) + int32 columnCount = fColumnList.CountItems(); + int32* list = new int32[columnCount]; + BWindow* parentWindow = Window(); + if (parentWindow != NULL) + parentWindow->Lock(); + + for (int32 i = 0; i < columnCount; i++) + list[i] = int32(fColumnList.IndexOf(fColumnDisplayList.ItemAt(i))); + + if (parentWindow != NULL) + parentWindow->Unlock(); + + return list; +} + + +void +ColumnListView::SetSortKey(int32 columnIndex) +{ + CLVColumn* column; + if (columnIndex >= 0) { + column = (CLVColumn*)fColumnList.ItemAt(columnIndex); + if ((column->Flags() & CLV_SORT_KEYABLE) == 0) return; - } - else - Column = NULL; - if(fSortKeyList.ItemAt(0) != Column || Column == NULL) - { - BWindow* ParentWindow = Window(); - if(ParentWindow) - ParentWindow->Lock(); - BRect LabelBounds = fColumnLabelView->Bounds(); - //Need to remove old sort keys and erase all the old underlines - int32 SortKeyCount = fSortKeyList.CountItems(); - for(int32 Counter = 0; Counter < SortKeyCount; Counter++) - { - CLVColumn* UnderlineColumn = (CLVColumn*)fSortKeyList.ItemAt(Counter); - if(UnderlineColumn->fSortMode != NoSort) - fColumnLabelView->Invalidate(BRect(UnderlineColumn->fColumnBegin,LabelBounds.top, - UnderlineColumn->fColumnEnd,LabelBounds.bottom)); + } else + column = NULL; + + if (fSortKeyList.ItemAt(0) != column || column == NULL) { + BWindow* parentWindow = Window(); + if (parentWindow != NULL) + parentWindow->Lock(); + + BRect labelBounds = fColumnLabelView->Bounds(); + // need to remove old sort keys and erase all the old underlines + int32 sortKeyCount = fSortKeyList.CountItems(); + for (int32 i = 0; i < sortKeyCount; i++) { + CLVColumn* underlineColumn = (CLVColumn*)fSortKeyList.ItemAt(i); + if (underlineColumn->fSortMode != SORT_MODE_NONE) { + fColumnLabelView->Invalidate( + BRect(underlineColumn->fColumnBegin, + labelBounds.top, underlineColumn->fColumnEnd, + labelBounds.bottom)); + } } fSortKeyList.MakeEmpty(); - if(Column) - { - fSortKeyList.AddItem(Column); - if(Column->fSortMode == NoSort) - SetSortMode(ColumnIndex,Ascending); + if (column != NULL) { + fSortKeyList.AddItem(column); + if (column->fSortMode == SORT_MODE_NONE) + SetSortMode(columnIndex, SORT_MODE_ASCENDING); + SortItems(); - //Need to draw new underline - fColumnLabelView->Invalidate(BRect(Column->fColumnBegin,LabelBounds.top,Column->fColumnEnd, - LabelBounds.bottom)); + // need to draw new underline + fColumnLabelView->Invalidate(BRect(column->fColumnBegin, + labelBounds.top, column->fColumnEnd, labelBounds.bottom)); } - if(ParentWindow) - ParentWindow->Unlock(); + if (parentWindow != NULL) + parentWindow->Unlock(); } } -void ColumnListView::AddSortKey(int32 ColumnIndex) +void +ColumnListView::AddSortKey(int32 columnIndex) { - CLVColumn* Column; - if(ColumnIndex >= 0) - { - Column = (CLVColumn*)fColumnList.ItemAt(ColumnIndex); - if(!(Column->Flags()&CLV_SORT_KEYABLE)) + CLVColumn* column; + if (columnIndex >= 0) { + column = (CLVColumn*)fColumnList.ItemAt(columnIndex); + if ((column->Flags() & CLV_SORT_KEYABLE) == 0) return; - } - else - Column = NULL; - if(Column && !fSortKeyList.HasItem(Column)) - { - BWindow* ParentWindow = Window(); - if(ParentWindow) - ParentWindow->Lock(); - BRect LabelBounds = fColumnLabelView->Bounds(); - fSortKeyList.AddItem(Column); - if(Column->fSortMode == NoSort) - SetSortMode(ColumnIndex,Ascending); + } else + column = NULL; + + if (column != NULL && !fSortKeyList.HasItem(column)) { + BWindow* parentWindow = Window(); + if (parentWindow != NULL) + parentWindow->Lock(); + + BRect labelBounds = fColumnLabelView->Bounds(); + fSortKeyList.AddItem(column); + if (column->fSortMode == SORT_MODE_NONE) + SetSortMode(columnIndex, SORT_MODE_ASCENDING); + SortItems(); - //Need to draw new underline - fColumnLabelView->Invalidate(BRect(Column->fColumnBegin,LabelBounds.top,Column->fColumnEnd, - LabelBounds.bottom)); - if(ParentWindow) - ParentWindow->Unlock(); + + // need to draw new underline + fColumnLabelView->Invalidate(BRect(column->fColumnBegin, + labelBounds.top, column->fColumnEnd, labelBounds.bottom)); + + if (parentWindow != NULL) + parentWindow->Unlock(); } } -void ColumnListView::SetSortMode(int32 ColumnIndex,CLVSortMode Mode) +void +ColumnListView::SetSortMode(int32 columnIndex, CLVSortMode sortMode) { - CLVColumn* Column; - if(ColumnIndex >= 0) - { - Column = (CLVColumn*)fColumnList.ItemAt(ColumnIndex); - if(!(Column->Flags()&CLV_SORT_KEYABLE)) + CLVColumn* column; + if (columnIndex >= 0) { + column = (CLVColumn*)fColumnList.ItemAt(columnIndex); + if ((column->Flags() & CLV_SORT_KEYABLE) == 0) return; - } - else + } else return; - if(Column->fSortMode != Mode) - { - BWindow* ParentWindow = Window(); - if(ParentWindow) - ParentWindow->Lock(); - BRect LabelBounds = fColumnLabelView->Bounds(); - Column->fSortMode = Mode; - if(Mode == NoSort && fSortKeyList.HasItem(Column)) - fSortKeyList.RemoveItem(Column); + + if (column->fSortMode != sortMode) { + BWindow* parentWindow = Window(); + if (parentWindow != NULL) + parentWindow->Lock(); + + BRect labelBounds = fColumnLabelView->Bounds(); + column->fSortMode = sortMode; + if (sortMode == SORT_MODE_NONE && fSortKeyList.HasItem(column)) + fSortKeyList.RemoveItem(column); + SortItems(); - //Need to draw or erase underline - fColumnLabelView->Invalidate(BRect(Column->fColumnBegin,LabelBounds.top,Column->fColumnEnd, - LabelBounds.bottom)); - if(ParentWindow) - ParentWindow->Unlock(); + // need to draw or erase underline + + fColumnLabelView->Invalidate(BRect(column->fColumnBegin, + labelBounds.top, column->fColumnEnd, labelBounds.bottom)); + if (parentWindow != NULL) + parentWindow->Unlock(); } } -void ColumnListView::ReverseSortMode(int32 ColumnIndex) +void +ColumnListView::ReverseSortMode(int32 columnIndex) { - CLVColumn* Column; - if(ColumnIndex >= 0) - { - Column = (CLVColumn*)fColumnList.ItemAt(ColumnIndex); - if(!(Column->Flags()&CLV_SORT_KEYABLE)) + CLVColumn* column; + if (columnIndex >= 0) { + column = (CLVColumn*)fColumnList.ItemAt(columnIndex); + if ((column->Flags() & CLV_SORT_KEYABLE) == 0) return; - } - else + } else return; - if(Column->fSortMode == Ascending) - SetSortMode(ColumnIndex,Descending); - else if(Column->fSortMode == Descending) - SetSortMode(ColumnIndex,NoSort); - else if(Column->fSortMode == NoSort) - SetSortMode(ColumnIndex,Ascending); + + if (column->fSortMode == SORT_MODE_ASCENDING) + SetSortMode(columnIndex, SORT_MODE_DESCENDING); + else if (column->fSortMode == SORT_MODE_DESCENDING) + SetSortMode(columnIndex, SORT_MODE_NONE); + else if (column->fSortMode == SORT_MODE_NONE) + SetSortMode(columnIndex, SORT_MODE_ASCENDING); } -int32 ColumnListView::Sorting(int32* SortKeys, CLVSortMode* SortModes) const +int32 +ColumnListView::Sorting(int32* sortKeys, CLVSortMode* sortModes) const { - BWindow* ParentWindow = Window(); - if(ParentWindow) - ParentWindow->Lock(); - int32 NumberOfKeys = fSortKeyList.CountItems(); - for(int32 Counter = 0; Counter < NumberOfKeys; Counter++) - { - CLVColumn* Column = (CLVColumn*)fSortKeyList.ItemAt(Counter); - SortKeys[Counter] = IndexOfColumn(Column); - SortModes[Counter] = Column->SortMode(); + BWindow* parentWindow = Window(); + if (parentWindow != NULL) + parentWindow->Lock(); + + int32 keyCount = fSortKeyList.CountItems(); + for (int32 i = 0; i < keyCount; i++) { + CLVColumn* Column = (CLVColumn*)fSortKeyList.ItemAt(i); + sortKeys[i] = IndexOfColumn(Column); + sortModes[i] = Column->SortMode(); } - if(ParentWindow) - ParentWindow->Unlock(); - return NumberOfKeys; + + if (parentWindow != NULL) + parentWindow->Unlock(); + + return keyCount; } -void ColumnListView :: Pulse() +void +ColumnListView::Pulse() { - int32 curSel = CurrentSelection(); - if (curSel >= 0) - { - CLVListItem * item = (CLVListItem *) ItemAt(curSel); - item->Pulse(this); - } + int32 curSel = CurrentSelection(); + if (curSel >= 0) { + CLVListItem* item = (CLVListItem*) ItemAt(curSel); + item->Pulse(this); + } } -void ColumnListView::SetSorting(int32 NumberOfKeys, int32* SortKeys, CLVSortMode* SortModes) -{ - BWindow* ParentWindow = Window(); - if(ParentWindow) - ParentWindow->Lock(); - //Need to remove old sort keys and erase all the old underlines - BRect LabelBounds = fColumnLabelView->Bounds(); - int32 SortKeyCount = fSortKeyList.CountItems(); - for(int32 Counter = 0; Counter < SortKeyCount; Counter++) - { - CLVColumn* UnderlineColumn = (CLVColumn*)fSortKeyList.ItemAt(Counter); - if(UnderlineColumn->fSortMode != NoSort) - fColumnLabelView->Invalidate(BRect(UnderlineColumn->fColumnBegin,LabelBounds.top, - UnderlineColumn->fColumnEnd,LabelBounds.bottom)); +void +ColumnListView::SetSorting(int32 keyCount, int32* sortKeys, + CLVSortMode* sortModes) +{ + BWindow* parentWindow = Window(); + if (parentWindow != NULL) + parentWindow->Lock(); + + // need to remove old sort keys and erase all the old underlines + BRect labelBounds = fColumnLabelView->Bounds(); + int32 sortKeyCount = fSortKeyList.CountItems(); + for (int32 i = 0; i < sortKeyCount; i++) { + CLVColumn* underlineColumn = (CLVColumn*)fSortKeyList.ItemAt(i); + if (underlineColumn->fSortMode != SORT_MODE_NONE) { + fColumnLabelView->Invalidate(BRect(underlineColumn->fColumnBegin, + labelBounds.top, underlineColumn->fColumnEnd, + labelBounds.bottom)); + } } fSortKeyList.MakeEmpty(); - for(int32 Counter = 0; Counter < NumberOfKeys; Counter++) - { - if(Counter == 0) - SetSortKey(SortKeys[0]); + for (int32 i = 0; i < keyCount; i++) { + if (i == 0) + SetSortKey(sortKeys[0]); else - AddSortKey(SortKeys[Counter]); - SetSortMode(SortKeys[Counter],SortModes[Counter]); + AddSortKey(sortKeys[i]); + + SetSortMode(sortKeys[i], sortModes[i]); } - if(ParentWindow) - ParentWindow->Unlock(); -} - -void ColumnListView::FrameResized(float width, float height) -{ - UpdateColumnSizesDataRectSizeScrollBars(); - uint32 NumberOfItems = CountItems(); - BFont Font; - GetFont(&Font); - for(uint32 Counter = 0; Counter < NumberOfItems; Counter++) - ItemAt(Counter)->Update(this,&Font); - BListView::FrameResized(width,height); + if (parentWindow != NULL) + parentWindow->Unlock(); } -void ColumnListView::AttachedToWindow() -//Hack to work around app_server bug +void +ColumnListView::FrameResized(float newWidth, float newHeight) { + ShiftDragGroup(); + uint32 itemCount = CountItems(); + BFont font; + GetFont(&font); + for (uint32 i = 0; i < itemCount; i++) + ItemAt(i)->Update(this, &font); + + BListView::FrameResized(newWidth, newHeight); +} + + +void +ColumnListView::AttachedToWindow() +{ + // Hack to work around app_server bug BListView::AttachedToWindow(); - UpdateColumnSizesDataRectSizeScrollBars(); + ShiftDragGroup(); } -void ColumnListView::ScrollTo(BPoint point) +void +ColumnListView::ScrollTo(BPoint point) { BListView::ScrollTo(point); - fColumnLabelView->ScrollTo(BPoint(point.x,0.0)); + fColumnLabelView->ScrollTo(BPoint(point.x, 0.0)); } -int32 ColumnListView::GetActualIndexOf(int32 displayIndex) const +int32 +ColumnListView::GetActualIndexOf(int32 displayIndex) const { - if ((displayIndex < 0)||(displayIndex >= fColumnDisplayList.CountItems())) return -1; - return (int32) fColumnList.IndexOf(fColumnDisplayList.ItemAt(displayIndex)); + if ((displayIndex < 0) || (displayIndex >= fColumnDisplayList.CountItems())) + return -1; + + return (int32)fColumnList.IndexOf(fColumnDisplayList.ItemAt(displayIndex)); } -int32 ColumnListView::GetDisplayIndexOf(int32 realIndex) const + +int32 +ColumnListView::GetDisplayIndexOf(int32 realIndex) const { - if ((realIndex < 0)||(realIndex >= fColumnList.CountItems())) return -1; - return (int32) fColumnDisplayList.IndexOf(fColumnList.ItemAt(realIndex)); + if ((realIndex < 0) || (realIndex >= fColumnList.CountItems())) + return -1; + + return (int32)fColumnDisplayList.IndexOf(fColumnList.ItemAt(realIndex)); } -// Set a new (actual) column index as the selected index. Call with arg -1 to unselect all. -// Gotta change the _selectedColumn on all entries. There is -// undoubtedly a more efficient way to do this! --jaf -void ColumnListView :: SetSelectedColumnIndex(int32 col) + +// Set a new (actual) column index as the selected index. +// Call with arg -1 to unselect all. +// Gotta change the fSelectedColumn on all entries. +// There is undoubtedly a more efficient way to do this! --jaf +void +ColumnListView :: SetSelectedColumnIndex(int32 col) { - if (_selectedColumn != col) - { - _selectedColumn = col; + if (fSelectedColumn != col) { + fSelectedColumn = col; - int numRows = fFullItemList.CountItems(); - for (int j=0; j_selectedColumn = _selectedColumn; + int32 numRows = fFullItemList.CountItems(); + for (int32 j = 0; j < numRows; j++) { + ((CLVListItem *)fFullItemList.ItemAt(j))->fSelectedColumn + = fSelectedColumn; + } - // Update current row if necessary. - int32 selectedIndex = CurrentSelection(); - if (selectedIndex != -1) InvalidateItem(selectedIndex); + // update current row if necessary + int32 selectedIndex = CurrentSelection(); + if (selectedIndex != -1) + InvalidateItem(selectedIndex); } } -void ColumnListView::MouseDown(BPoint point) +void +ColumnListView::MouseDown(BPoint point) { - int prevColumn = _selectedColumn; - int32 numberOfColumns = fColumnDisplayList.CountItems(); + int prevColumn = fSelectedColumn; + int32 columnCount = fColumnDisplayList.CountItems(); float xleft = point.x; - for(int32 Counter = 0; Counter < numberOfColumns; Counter++) - { - CLVColumn* Column = (CLVColumn*)fColumnDisplayList.ItemAt(Counter); - if(Column->IsShown()) - { - if (xleft > 0) - { - xleft -= Column->Width(); - if (xleft <= 0) - { - SetSelectedColumnIndex(GetActualIndexOf(Counter)); - break; - } + for (int32 i = 0; i < columnCount; i++) { + CLVColumn* column = (CLVColumn*)fColumnDisplayList.ItemAt(i); + if (column->IsShown()) { + if (xleft > 0) { + xleft -= column->Width(); + if (xleft <= 0) { + SetSelectedColumnIndex(GetActualIndexOf(i)); + break; + } } } } - int32 ItemIndex = IndexOf(point); - if(ItemIndex >= 0) - { - CLVListItem* ClickedItem = (CLVListItem*)BListView::ItemAt(ItemIndex); - if(ClickedItem->fSuperItem) - if(ClickedItem->fExpanderButtonRect.Contains(point)) - { - if(ClickedItem->IsExpanded()) - Collapse(ClickedItem); + + int32 itemIndex = IndexOf(point); + if (itemIndex >= 0) { + CLVListItem* clickedItem = (CLVListItem*)BListView::ItemAt(itemIndex); + if (clickedItem->fIsSuperItem) { + if (clickedItem->fExpanderButtonRect.Contains(point)) { + if (clickedItem->IsExpanded()) + Collapse(clickedItem); else - Expand(ClickedItem); + Expand(clickedItem); + return; } + } } - // If it's a right-click, hoist up the popup-menu - const char * selectedText = NULL; - CLVColumn * col = ColumnAt(_selectedColumn); - if (col) - { - BPopUpMenu * popup = col->GetPopup(); - if (popup) - { - BMessage * msg = Window()->CurrentMessage(); - int32 buttons; - if ((msg->FindInt32("buttons", &buttons) == B_NO_ERROR)&&(buttons == B_SECONDARY_MOUSE_BUTTON)) - { - BPoint where(point); - Select(IndexOf(where)); - ConvertToScreen(&where); - BMenuItem * result = popup->Go(where, false); - if (result) selectedText = result->Label(); - } - } + // if secondary mouse click, hoist up the popup-menu + const char* selectedText = NULL; + CLVColumn* column = ColumnAt(fSelectedColumn); + if (column != NULL) { + BPopUpMenu* popup = column->GetPopup(); + if (popup != NULL) { + BMessage* message = Window()->CurrentMessage(); + int32 buttons; + if ((message->FindInt32("buttons", &buttons) == B_NO_ERROR) + && (buttons == B_SECONDARY_MOUSE_BUTTON)) { + BPoint where(point); + Select(IndexOf(where)); + ConvertToScreen(&where); + BMenuItem* result = popup->Go(where, false); + if (result != NULL) + selectedText = result->Label(); + } + } } - int prevRow = CurrentSelection(); + int32 previousRow = CurrentSelection(); BListView::MouseDown(point); - int curRow = CurrentSelection(); - if ((_editMessage != NULL)&&((selectedText)||((_selectedColumn == prevColumn)&&(curRow == prevRow)))) - { - // Send mouse message... - BMessage temp(*_editMessage); - temp.AddInt32("column", _selectedColumn); - temp.AddInt32("row", CurrentSelection()); - if (selectedText) temp.AddString("text", selectedText); - else temp.AddInt32("mouseClick", 0); - _editTarget.SendMessage(&temp); + int32 currentRow = CurrentSelection(); + if ((fEditMessage != NULL) && (selectedText != NULL + || (fSelectedColumn == prevColumn && currentRow == previousRow))) { + // send mouse message... + BMessage temp(*fEditMessage); + temp.AddInt32("column", fSelectedColumn); + temp.AddInt32("row", CurrentSelection()); + if (selectedText) + temp.AddString("text", selectedText); + else + temp.AddInt32("mouseClick", 0); + + fEditTarget.SendMessage(&temp); } } -bool ColumnListView::AddUnder(CLVListItem* item, CLVListItem* superitem) + +bool +ColumnListView::AddUnder(CLVListItem* item, CLVListItem* superitem) { - if(!fHierarchical) + if (!fHierarchical) return false; - //Find the superitem in the full list and display list (if shown) - int32 SuperItemPos = fFullItemList.IndexOf(superitem); - if(SuperItemPos < 0) + // find the superitem in the full list and display list (if shown) + int32 superItemPosition = fFullItemList.IndexOf(superitem); + if (superItemPosition < 0) return false; - uint32 SuperItemLevel = superitem->fOutlineLevel; - //Add the item under the superitem in the full list - int32 ItemPos = SuperItemPos + 1; - item->fOutlineLevel = SuperItemLevel + 1; - while(true) - { - CLVListItem* Temp = (CLVListItem*)fFullItemList.ItemAt(ItemPos); - if(Temp) - { - if(Temp->fOutlineLevel > SuperItemLevel) - ItemPos++; + uint32 SuperitemLevel = superitem->fOutlineLevel; + + // add the item under the superitem in the full list + int32 itemPosition = superItemPosition + 1; + item->fOutlineLevel = SuperitemLevel + 1; + while (true) { + CLVListItem* temp = (CLVListItem*)fFullItemList.ItemAt(itemPosition); + if (temp) { + if (temp->fOutlineLevel > SuperitemLevel) + itemPosition++; else break; } else break; } - return AddItemPrivate(item,ItemPos); + + return AddItemPrivate(item, itemPosition); } -bool ColumnListView::AddItem(CLVListItem* item, int32 fullListIndex) +bool +ColumnListView::AddItem(CLVListItem* item, int32 fullListIndex) { - return AddItemPrivate(item,fullListIndex); + return AddItemPrivate(item, fullListIndex); } -bool ColumnListView::AddItem(CLVListItem* item) +bool +ColumnListView::AddItem(CLVListItem* item) { - if(fHierarchical) - return AddItemPrivate(item,fFullItemList.CountItems()); + if (fHierarchical) + return AddItemPrivate(item, fFullItemList.CountItems()); else - return AddItemPrivate(item,CountItems()); + return AddItemPrivate(item, CountItems()); } -bool ColumnListView::AddItem(BListItem* item, int32 fullListIndex) +bool +ColumnListView::AddItem(BListItem* item, int32 fullListIndex) { return BListView::AddItem(item, fullListIndex); } -bool ColumnListView::AddItem(BListItem* item) +bool +ColumnListView::AddItem(BListItem* item) { return BListView::AddItem(item); } -bool ColumnListView::AddItemPrivate(CLVListItem* item, int32 fullListIndex) +bool +ColumnListView::AddItemPrivate(CLVListItem* item, int32 fullListIndex) { - item->_selectedColumn = _selectedColumn; + item->fSelectedColumn = fSelectedColumn; - if(fHierarchical) - { - uint32 ItemLevel = item->OutlineLevel(); + if (fHierarchical) { + uint32 itemLevel = item->OutlineLevel(); - //Figure out whether it is visible (should it be added to visible list) - bool Visible = true; + // figure out whether it is visible (should it be added to visible list) + bool isVisible = true; - //Find the item that contains it in the full list - int32 SuperItemPos; - if(ItemLevel == 0) - SuperItemPos = -1; + // find the item that contains it in the full list + int32 superItemPosition; + if (itemLevel == 0) + superItemPosition = -1; else - SuperItemPos = fullListIndex - 1; - CLVListItem* SuperItem; - while(SuperItemPos >= 0) - { - SuperItem = (CLVListItem*)fFullItemList.ItemAt(SuperItemPos); - if(SuperItem) - { - if(SuperItem->fOutlineLevel >= ItemLevel) - SuperItemPos--; + superItemPosition = fullListIndex - 1; + + CLVListItem* superItem; + while (superItemPosition >= 0) { + superItem = (CLVListItem*)fFullItemList.ItemAt(superItemPosition); + if (superItem != NULL) { + if (superItem->fOutlineLevel >= itemLevel) + superItemPosition--; else break; - } - else + } else return false; } - if(SuperItemPos >= 0 && SuperItem) - { - if(!SuperItem->IsExpanded()) - //SuperItem's contents aren't visible - Visible = false; - if(!HasItem(SuperItem)) - //SuperItem itself isn't showing - Visible = false; + + if (superItemPosition >= 0 && superItem != NULL) { + if (!superItem->IsExpanded()) { + // superItem's contents aren't visible + isVisible = false; + } + if (!HasItem(superItem)) { + // superItem itself isn't showing + isVisible = false; + } } - //Add the item to the full list - if(!fFullItemList.AddItem(item,fullListIndex)) + // add the item to the full list + if (!fFullItemList.AddItem(item, fullListIndex)) return false; - else - { - //Add the item to the display list - if(Visible) - { - //Find the previous item, or -1 if the item I'm adding will be the first one - int32 PreviousItemPos = fullListIndex - 1; - CLVListItem* PreviousItem; - while(PreviousItemPos >= 0) - { - PreviousItem = (CLVListItem*)fFullItemList.ItemAt(PreviousItemPos); - if(PreviousItem && HasItem(PreviousItem)) + else { + // add the item to the display list + if (isVisible) { + // find the previous item, or -1 if the item I'm adding + // will be the first one + int32 PreviousitemPosition = fullListIndex - 1; + CLVListItem* previousItem; + while (PreviousitemPosition >= 0) { + previousItem + = (CLVListItem*)fFullItemList.ItemAt( + PreviousitemPosition); + if (previousItem != NULL && HasItem(previousItem)) break; else - PreviousItemPos--; + PreviousitemPosition--; } - //Add the item after the previous item, or first on the list - bool Result; - if(PreviousItemPos >= 0) - Result = BListView::AddItem((BListItem*)item,IndexOf(PreviousItem)+1); + // add the item after the previous item, or first on the list + bool itemAdded; + if (PreviousitemPosition >= 0) + itemAdded = BListView::AddItem((BListItem*)item, + IndexOf(previousItem) + 1); else - Result = BListView::AddItem((BListItem*)item,0); - if(Result == false) + itemAdded = BListView::AddItem((BListItem*)item, 0); + + if (itemAdded == false) fFullItemList.RemoveItem(item); - return Result; + + return itemAdded; } + return true; } - } + } else + return BListView::AddItem(item, fullListIndex); +} + + +bool +ColumnListView::AddList(BList* newItems) +{ + if (fHierarchical) + return AddListPrivate(newItems, fFullItemList.CountItems()); else - return BListView::AddItem(item,fullListIndex); + return AddListPrivate(newItems, CountItems()); } -bool ColumnListView::AddList(BList* newItems) +bool +ColumnListView::AddList(BList* newItems, int32 fullListIndex) { - if(fHierarchical) - return AddListPrivate(newItems,fFullItemList.CountItems()); - else - return AddListPrivate(newItems,CountItems()); + return AddListPrivate(newItems, fullListIndex); } -bool ColumnListView::AddList(BList* newItems, int32 fullListIndex) +bool +ColumnListView::AddListPrivate(BList* newItems, int32 fullListIndex) { - return AddListPrivate(newItems,fullListIndex); -} - - -bool ColumnListView::AddListPrivate(BList* newItems, int32 fullListIndex) -{ - int32 NumberOfItems = newItems->CountItems(); - for(int32 count = 0; count < NumberOfItems; count++) - if(!AddItemPrivate((CLVListItem*)newItems->ItemAt(count),fullListIndex+count)) + int32 itemCount = newItems->CountItems(); + for (int32 count = 0; count < itemCount; count++) { + if (!AddItemPrivate((CLVListItem*)newItems->ItemAt(count), + fullListIndex + count)) { return false; + } + } + return true; } -bool ColumnListView::RemoveItem(CLVListItem* item) +bool +ColumnListView::RemoveItem(CLVListItem* item) { - if(item == NULL || !fFullItemList.HasItem(item)) + if (item == NULL || !fFullItemList.HasItem(item)) return false; - if(fHierarchical) - { - int32 ItemsToRemove = 1 + FullListNumberOfSubitems(item); - return RemoveItems(fFullItemList.IndexOf(item),ItemsToRemove); - } - else + + if (fHierarchical) { + int32 itemsToRemove = 1 + FullListNumberOfSubitems(item); + return RemoveItems(fFullItemList.IndexOf(item), itemsToRemove); + } else return BListView::RemoveItem((BListItem*)item); } -BListItem* ColumnListView::RemoveItem(int32 fullListIndex) +BListItem* +ColumnListView::RemoveItem(int32 fullListIndex) { - if(fHierarchical) - { - CLVListItem* TheItem = (CLVListItem*)fFullItemList.ItemAt(fullListIndex); - if(TheItem) + if (fHierarchical) { + CLVListItem* item = (CLVListItem*)fFullItemList.ItemAt(fullListIndex); + if (item) { - int32 ItemsToRemove = 1 + FullListNumberOfSubitems(TheItem); - if(RemoveItems(fullListIndex,ItemsToRemove)) - return TheItem; + int32 itemsToRemove = 1 + FullListNumberOfSubitems(item); + if (RemoveItems(fullListIndex, itemsToRemove)) + return item; else return NULL; } else return NULL; - } - else + } else return BListView::RemoveItem(fullListIndex); } -bool ColumnListView::RemoveItems(int32 fullListIndex, int32 count) +bool +ColumnListView::RemoveItems(int32 fullListIndex, int32 count) { - CLVListItem* TheItem; - if(fHierarchical) - { - uint32 LastSuperItemLevel = UINT32_MAX; - int32 Counter; - int32 DisplayItemsToRemove = 0; - int32 FirstDisplayItemToRemove = -1; - for(Counter = fullListIndex; Counter < fullListIndex+count; Counter++) - { - TheItem = FullListItemAt(Counter); - if(TheItem->fOutlineLevel < LastSuperItemLevel) - LastSuperItemLevel = TheItem->fOutlineLevel; - if(BListView::HasItem((BListItem*)TheItem)) - { - DisplayItemsToRemove++; - if(FirstDisplayItemToRemove == -1) - FirstDisplayItemToRemove = BListView::IndexOf(TheItem); + CLVListItem* item; + if (fHierarchical) { + uint32 LastSuperitemLevel = UINT32_MAX; + int32 i; + int32 DisplayitemsToRemove = 0; + int32 firstDisplayItemToRemove = -1; + + for (i = fullListIndex; i < fullListIndex + count; i++) { + item = FullListItemAt(i); + if (item->fOutlineLevel < LastSuperitemLevel) + LastSuperitemLevel = item->fOutlineLevel; + + if (BListView::HasItem((BListItem*)item)) { + DisplayitemsToRemove++; + if (firstDisplayItemToRemove == -1) + firstDisplayItemToRemove = BListView::IndexOf(item); } } - while(true) - { - TheItem = FullListItemAt(Counter); - if(TheItem && TheItem->fOutlineLevel > LastSuperItemLevel) - { + + while (true) { + item = FullListItemAt(i); + if (item != NULL && item->fOutlineLevel > LastSuperitemLevel) { count++; - Counter++; - if(BListView::HasItem((BListItem*)TheItem)) - { - DisplayItemsToRemove++; - if(FirstDisplayItemToRemove == -1) - FirstDisplayItemToRemove = BListView::IndexOf((BListItem*)TheItem); + i++; + if (BListView::HasItem((BListItem*)item)) { + DisplayitemsToRemove++; + if (firstDisplayItemToRemove == -1) { + firstDisplayItemToRemove + = BListView::IndexOf((BListItem*)item); + } } - } - else + } else break; } - while(DisplayItemsToRemove > 0) - { - if(BListView::RemoveItem(FirstDisplayItemToRemove) == NULL) + + while (DisplayitemsToRemove > 0) { + if (BListView::RemoveItem(firstDisplayItemToRemove) == NULL) return false; - DisplayItemsToRemove--; + + DisplayitemsToRemove--; } - return fFullItemList.RemoveItems(fullListIndex,count); - } - else - return BListView::RemoveItems(fullListIndex,count); + + return fFullItemList.RemoveItems(fullListIndex, count); + } else + return BListView::RemoveItems(fullListIndex, count); } -bool ColumnListView::RemoveItem(BListItem* item) +bool +ColumnListView::RemoveItem(BListItem* item) { return BListView::RemoveItem(item); } -CLVListItem* ColumnListView::FullListItemAt(int32 fullListIndex) const +CLVListItem* +ColumnListView::FullListItemAt(int32 fullListIndex) const { return (CLVListItem*)fFullItemList.ItemAt(fullListIndex); } -int32 ColumnListView::FullListIndexOf(const CLVListItem* item) const +int32 +ColumnListView::FullListIndexOf(const CLVListItem* item) const { return fFullItemList.IndexOf((CLVListItem*)item); } -int32 ColumnListView::FullListIndexOf(BPoint point) const +int32 +ColumnListView::FullListIndexOf(BPoint point) const { int32 DisplayListIndex = IndexOf(point); - CLVListItem* TheItem = (CLVListItem*)ItemAt(DisplayListIndex); - if(TheItem) - return FullListIndexOf(TheItem); - else - return -1; + CLVListItem* item = (CLVListItem*)ItemAt(DisplayListIndex); + + return item != NULL ? FullListIndexOf(item) : -1; } -CLVListItem* ColumnListView::FullListFirstItem() const +CLVListItem* +ColumnListView::FullListFirstItem() const { return (CLVListItem*)fFullItemList.FirstItem(); } -CLVListItem* ColumnListView::FullListLastItem() const +CLVListItem* +ColumnListView::FullListLastItem() const { return (CLVListItem*)fFullItemList.LastItem(); } -bool ColumnListView::FullListHasItem(const CLVListItem* item) const +bool +ColumnListView::FullListHasItem(const CLVListItem* item) const { return fFullItemList.HasItem((CLVListItem*)item); } -int32 ColumnListView::FullListCountItems() const +int32 +ColumnListView::FullListCountItems() const { return fFullItemList.CountItems(); } -void ColumnListView::MakeEmpty() +void +ColumnListView::MakeEmpty() { fFullItemList.MakeEmpty(); BListView::MakeEmpty(); } -void ColumnListView::MakeEmptyPrivate() +void +ColumnListView::MakeEmptyPrivate() { fFullItemList.MakeEmpty(); BListView::MakeEmpty(); } -bool ColumnListView::FullListIsEmpty() const +bool +ColumnListView::FullListIsEmpty() const { return fFullItemList.IsEmpty(); } -int32 ColumnListView::FullListCurrentSelection(int32 index) const +int32 +ColumnListView::FullListCurrentSelection(int32 index) const { - int32 Selection = CurrentSelection(index); - CLVListItem* SelectedItem = (CLVListItem*)ItemAt(Selection); - return FullListIndexOf(SelectedItem); + return FullListIndexOf((CLVListItem*)ItemAt(CurrentSelection(index))); } -void ColumnListView::FullListDoForEach(bool (*func)(CLVListItem*)) +void +ColumnListView::FullListDoForEach(bool (*func)(CLVListItem*)) { - int32 NumberOfItems = fFullItemList.CountItems(); - for(int32 Counter = 0; Counter < NumberOfItems; Counter++) - if(func((CLVListItem*)fFullItemList.ItemAt(Counter)) == true) + int32 itemCount = fFullItemList.CountItems(); + for (int32 i = 0; i < itemCount; i++) { + if (func((CLVListItem*)fFullItemList.ItemAt(i)) == true) return; + } } -void ColumnListView::FullListDoForEach(bool (*func)(CLVListItem*, void*), void* arg2) +void +ColumnListView::FullListDoForEach(bool (*func)(CLVListItem*, void*), + void* arg2) { - int32 NumberOfItems = fFullItemList.CountItems(); - for(int32 Counter = 0; Counter < NumberOfItems; Counter++) - if(func((CLVListItem*)fFullItemList.ItemAt(Counter),arg2) == true) + int32 itemCount = fFullItemList.CountItems(); + for (int32 i = 0; i < itemCount; i++) { + if (func((CLVListItem*)fFullItemList.ItemAt(i), arg2) == true) return; + } } -CLVListItem* ColumnListView::Superitem(const CLVListItem* item) const +CLVListItem* +ColumnListView::Superitem(const CLVListItem* item) const { - int32 SuperItemPos; - uint32 ItemLevel = item->fOutlineLevel; - if(ItemLevel == 0) - SuperItemPos = -1; + int32 superItemPosition; + uint32 itemLevel = item->fOutlineLevel; + + if (itemLevel == 0) + superItemPosition = -1; else - SuperItemPos = fFullItemList.IndexOf((CLVListItem*)item) - 1; - CLVListItem* SuperItem; - while(SuperItemPos >= 0) - { - SuperItem = (CLVListItem*)fFullItemList.ItemAt(SuperItemPos); - if(SuperItem) - { - if(SuperItem->fOutlineLevel >= ItemLevel) - SuperItemPos--; + superItemPosition = fFullItemList.IndexOf((CLVListItem*)item) - 1; + + CLVListItem* superItem = NULL; + while (superItemPosition >= 0) { + superItem = (CLVListItem*)fFullItemList.ItemAt(superItemPosition); + if (superItem != NULL) { + if (superItem->fOutlineLevel >= itemLevel) + superItemPosition--; else break; - } - else + } else return NULL; } - if(SuperItemPos >= 0) - return SuperItem; - else - return NULL; + + return superItemPosition >= 0 ? superItem : NULL; } -int32 ColumnListView::FullListNumberOfSubitems(const CLVListItem* item) const +int32 +ColumnListView::FullListNumberOfSubitems(const CLVListItem* item) const { - if(!fHierarchical) + if (!fHierarchical) return 0; - int32 ItemPos = FullListIndexOf(item); - int32 SubItemPos; - uint32 SuperItemLevel = item->fOutlineLevel; - if(ItemPos >= 0) - { - for(SubItemPos = ItemPos + 1; SubItemPos >= 1; SubItemPos++) - { - CLVListItem* TheItem = FullListItemAt(SubItemPos); - if(TheItem == NULL || TheItem->fOutlineLevel <= SuperItemLevel) + + int32 itemPosition = FullListIndexOf(item); + int32 subitemPosition; + uint32 SuperitemLevel = item->fOutlineLevel; + if (itemPosition >= 0) { + for (subitemPosition = itemPosition + 1; subitemPosition >= 1; + subitemPosition++) { + CLVListItem* item = FullListItemAt(subitemPosition); + if (item == NULL || item->fOutlineLevel <= SuperitemLevel) break; } - } - else + } else return 0; - return SubItemPos-ItemPos-1; + + return subitemPosition - itemPosition - 1; } -void ColumnListView::Expand(CLVListItem* item) +void +ColumnListView::Expand(CLVListItem* item) { - BWindow* ParentWindow = Window(); - if(ParentWindow) - ParentWindow->Lock(); - if(!(item->fSuperItem)) - item->fSuperItem = true; - if(item->IsExpanded()) - { - if(ParentWindow) - ParentWindow->Unlock(); - return; - } - item->SetExpanded(true); - if(!fHierarchical) - { - if(ParentWindow) - ParentWindow->Unlock(); + BWindow* parentWindow = Window(); + if (parentWindow != NULL) + parentWindow->Lock(); + + if (!item->fIsSuperItem) + item->fIsSuperItem = true; + + if (item->IsExpanded()) { + if (parentWindow != NULL) + parentWindow->Unlock(); + return; } - int32 DisplayIndex = IndexOf(item); - if(DisplayIndex >= 0) - { - if(fExpanderColumn >= 0) - { - //Change the state of the arrow - item->DrawItemColumn(this,item->fExpanderColumnRect,fExpanderColumn, (fExpanderColumn == _selectedColumn), true); + item->SetExpanded(true); + if (!fHierarchical) { + if (parentWindow != NULL) + parentWindow->Unlock(); + + return; + } + + int32 displayIndex = IndexOf(item); + if (displayIndex >= 0) { + if (fExpanderColumn >= 0) { + // change the state of the arrow + item->DrawItemColumn(this, item->fExpanderColumnRect, + fExpanderColumn, (fExpanderColumn == fSelectedColumn), true); SetDrawingMode(B_OP_OVER); - DrawBitmap(&fDownArrow, BRect(0.0,0.0,item->fExpanderButtonRect.right- - item->fExpanderButtonRect.left,10.0),item->fExpanderButtonRect); + DrawBitmap(&fDownArrow, BRect(0.0, 0.0, + item->fExpanderButtonRect.right - + item->fExpanderButtonRect.left, 10.0), + item->fExpanderButtonRect); SetDrawingMode(B_OP_COPY); } - //Add the items under it - int32 FullListIndex = fFullItemList.IndexOf(item); - uint32 ItemLevel = item->fOutlineLevel; - int32 Counter = FullListIndex + 1; - int32 AddPos = DisplayIndex + 1; - while(true) - { - CLVListItem* NextItem = (CLVListItem*)fFullItemList.ItemAt(Counter); - if(NextItem == NULL) + // add the items under it + int32 fullListIndex = fFullItemList.IndexOf(item); + uint32 itemLevel = item->fOutlineLevel; + int32 i = fullListIndex + 1; + int32 addPosition = displayIndex + 1; + while (true) { + CLVListItem* nextItem = (CLVListItem*)fFullItemList.ItemAt(i); + if (nextItem == NULL) break; - if(NextItem->fOutlineLevel > ItemLevel) - { - BListView::AddItem((BListItem*)NextItem,AddPos++); - if(NextItem->fSuperItem && !NextItem->IsExpanded()) - { - //The item I just added is collapsed, so skip all its children - uint32 SkipLevel = NextItem->fOutlineLevel + 1; - while(true) - { - Counter++; - NextItem = (CLVListItem*)fFullItemList.ItemAt(Counter); - if(NextItem == NULL) + + if (nextItem->fOutlineLevel > itemLevel) { + BListView::AddItem((BListItem*)nextItem, addPosition++); + if (nextItem->fIsSuperItem && !nextItem->IsExpanded()) { + // the item I just added is collapsed, so skip over all + // its children + uint32 SkipLevel = nextItem->fOutlineLevel + 1; + while (true) { + i++; + nextItem = (CLVListItem*)fFullItemList.ItemAt(i); + if (nextItem == NULL) break; - if(NextItem->fOutlineLevel < SkipLevel) + + if (nextItem->fOutlineLevel < SkipLevel) break; } - } - else - Counter++; - } - else + } else + i++; + } else break; } } - if(ParentWindow) - ParentWindow->Unlock(); + + if (parentWindow != NULL) + parentWindow->Unlock(); } -void ColumnListView::Collapse(CLVListItem* item) +void +ColumnListView::Collapse(CLVListItem* item) { - BWindow* ParentWindow = Window(); - if(ParentWindow) - ParentWindow->Lock(); - if(!(item->fSuperItem)) - item->fSuperItem = true; - if(!(item->IsExpanded())) - { - if(ParentWindow) - ParentWindow->Unlock(); - return; - } - item->SetExpanded(false); - if(!fHierarchical) - { - if(ParentWindow) - ParentWindow->Unlock(); + BWindow* parentWindow = Window(); + if (parentWindow != NULL) + parentWindow->Lock(); + + if (!item->fIsSuperItem) + item->fIsSuperItem = true; + + if (!(item->IsExpanded())) { + if (parentWindow != NULL) + parentWindow->Unlock(); + return; } - int32 DisplayIndex = IndexOf((BListItem*)item); - if(DisplayIndex >= 0) - { - if(fExpanderColumn >= 0) - { - //Change the state of the arrow - item->DrawItemColumn(this,item->fExpanderColumnRect,fExpanderColumn,(fExpanderColumn == _selectedColumn), true); + item->SetExpanded(false); + if (!fHierarchical) { + if (parentWindow != NULL) + parentWindow->Unlock(); + return; + } + + int32 displayIndex = IndexOf((BListItem*)item); + if (displayIndex >= 0) { + if (fExpanderColumn >= 0) { + // change the state of the arrow + item->DrawItemColumn(this, item->fExpanderColumnRect, + fExpanderColumn, (fExpanderColumn == fSelectedColumn), true); SetDrawingMode(B_OP_OVER); - DrawBitmap(&fRightArrow, BRect(0.0,0.0,item->fExpanderButtonRect.right- - item->fExpanderButtonRect.left,10.0),item->fExpanderButtonRect); + DrawBitmap(&fRightArrow, BRect(0.0, 0.0, + item->fExpanderButtonRect.right - + item->fExpanderButtonRect.left, + 10.0), item->fExpanderButtonRect); SetDrawingMode(B_OP_COPY); } - //Remove the items under it - uint32 ItemLevel = item->fOutlineLevel; - int32 NextItemIndex = DisplayIndex+1; - while(true) - { - CLVListItem* NextItem = (CLVListItem*)ItemAt(NextItemIndex); - if(NextItem) - { - if(NextItem->fOutlineLevel > ItemLevel) - BListView::RemoveItem(NextItemIndex); + // remove the items under it + uint32 itemLevel = item->fOutlineLevel; + int32 nextItemIndex = displayIndex + 1; + while (true) { + CLVListItem* nextItem = (CLVListItem*)ItemAt(nextItemIndex); + if (nextItem != NULL) { + if (nextItem->fOutlineLevel > itemLevel) + BListView::RemoveItem(nextItemIndex); else break; - } - else + } else break; } } - if(ParentWindow) - ParentWindow->Unlock(); + + if (parentWindow != NULL) + parentWindow->Unlock(); } -bool ColumnListView::IsExpanded(int32 fullListIndex) const +bool +ColumnListView::IsExpanded(int32 fullListIndex) const { - BListItem* TheItem = (BListItem*)fFullItemList.ItemAt(fullListIndex); - if(TheItem) - return TheItem->IsExpanded(); + BListItem* item = (BListItem*)fFullItemList.ItemAt(fullListIndex); + return item != NULL ? item->IsExpanded() : false; +} + + +void +ColumnListView::SetSortFunction(CLVCompareFuncPtr compare) +{ + fCompareFunction = compare; +} + + +void +ColumnListView::SortItems() +{ + BWindow* parentWindow = Window(); + if (parentWindow != NULL) + parentWindow->Lock(); + + BList newList; + int32 itemCount; + if (!fHierarchical) + itemCount = CountItems(); else - return false; -} + itemCount = fFullItemList.CountItems(); + if (itemCount == 0) { + if (parentWindow != NULL) + parentWindow->Unlock(); -void ColumnListView::SetSortFunction(CLVCompareFuncPtr compare) -{ - fCompare = compare; -} - - -void ColumnListView::SortItems() -{ - BWindow* ParentWindow = Window(); - if(ParentWindow) - ParentWindow->Lock(); - - BList NewList; - int32 NumberOfItems; - if(!fHierarchical) - NumberOfItems = CountItems(); - else - NumberOfItems = fFullItemList.CountItems(); - if(NumberOfItems == 0) - { - if(ParentWindow) - ParentWindow->Unlock(); return; } - int32 Counter; - if(!fHierarchical) - { - //Plain sort - //Remember the list context for each item - for(Counter = 0; Counter < NumberOfItems; Counter++) - ((CLVListItem*)ItemAt(Counter))->fSortingContextCLV = this; - //Do the actual sort - BListView::SortItems((int (*)(const void*, const void*))ColumnListView::PlainBListSortFunc); - } - else - { - //Block-by-block sort - SortFullListSegment(0,0,&NewList); - fFullItemList = NewList; - //Remember the list context for each item - for(Counter = 0; Counter < NumberOfItems; Counter++) - ((CLVListItem*)fFullItemList.ItemAt(Counter))->fSortingContextBList = &NewList; - //Do the actual sort - BListView::SortItems((int (*)(const void*, const void*))ColumnListView::HierarchicalBListSortFunc); - } - if(ParentWindow) - ParentWindow->Unlock(); -} - - -int ColumnListView::PlainBListSortFunc(BListItem** a_item1, BListItem** a_item2) -{ - CLVListItem* item1 = (CLVListItem*)*a_item1; - CLVListItem* item2 = (CLVListItem*)*a_item2; - ColumnListView* SortingContext = item1->fSortingContextCLV; - int32 SortDepth = SortingContext->fSortKeyList.CountItems(); - int CompareResult = 0; - if(SortingContext->fCompare) - for(int32 SortIteration = 0; SortIteration < SortDepth && CompareResult == 0; SortIteration++) - { - CLVColumn* Column = (CLVColumn*)SortingContext->fSortKeyList.ItemAt(SortIteration); - CompareResult = SortingContext->fCompare(item1,item2,SortingContext->fColumnList.IndexOf(Column)); - if(Column->fSortMode == Descending) - CompareResult = 0-CompareResult; + int32 i; + if (!fHierarchical) { + // plain sort, remember the list context for each item + for (i = 0; i < itemCount; i++) + ((CLVListItem*)ItemAt(i))->fSortingContextCLV = this; + // do the actual sort + BListView::SortItems((int (*)(const void*, + const void*))ColumnListView::PlainBListSortFunc); + } else { + // block-by-block sort + SortFullListSegment(0, 0, &newList); + fFullItemList = newList; + // remember the list context for each item + for (i = 0; i < itemCount; i++) { + ((CLVListItem*)fFullItemList.ItemAt(i))->fSortingContextBList + = &newList; } - return CompareResult; + // do the actual sort + BListView::SortItems((int (*)(const void*, + const void*))ColumnListView::HierarchicalBListSortFunc); + } + + if (parentWindow != NULL) + parentWindow->Unlock(); } -int ColumnListView::HierarchicalBListSortFunc(BListItem** a_item1, BListItem** a_item2) +int +ColumnListView::PlainBListSortFunc(BListItem** firstItem, + BListItem** secondItem) { - CLVListItem* item1 = (CLVListItem*)*a_item1; - CLVListItem* item2 = (CLVListItem*)*a_item2; - if(item1->fSortingContextBList->IndexOf(item1) < item1->fSortingContextBList->IndexOf(item2)) + CLVListItem* item1 = (CLVListItem*)*firstItem; + CLVListItem* item2 = (CLVListItem*)*secondItem; + ColumnListView* sortingContext = item1->fSortingContextCLV; + int32 sortDepth = sortingContext->fSortKeyList.CountItems(); + int compareResult = 0; + + if (sortingContext->fCompareFunction) { + for (int32 SortIteration = 0; + SortIteration < sortDepth && compareResult == 0; + SortIteration++) { + CLVColumn* column = (CLVColumn*)sortingContext->fSortKeyList.ItemAt( + SortIteration); + compareResult = sortingContext->fCompareFunction(item1, item2, + sortingContext->fColumnList.IndexOf(column)); + if (column->fSortMode == SORT_MODE_DESCENDING) + compareResult = 0 - compareResult; + } + } + + return compareResult; +} + + +int +ColumnListView::HierarchicalBListSortFunc(BListItem** firstItem, + BListItem** secondItem) +{ + CLVListItem* item1 = (CLVListItem*)*firstItem; + CLVListItem* item2 = (CLVListItem*)*secondItem; + if (item1->fSortingContextBList->IndexOf(item1) + < item1->fSortingContextBList->IndexOf(item2)) { return -1; - else + } else return 1; } -void ColumnListView::SortFullListSegment(int32 OriginalListStartIndex, int32 InsertionPoint, - BList* NewList) +void +ColumnListView::SortFullListSegment(int32 originalListStartIndex, + int32 insertionPoint, BList* newList) { - //Identify and sort the items at this level - BList* ItemsInThisLevel = SortItemsInThisLevel(OriginalListStartIndex); - int32 NewItemsStopIndex = InsertionPoint + ItemsInThisLevel->CountItems(); - NewList->AddList(ItemsInThisLevel,InsertionPoint); - delete ItemsInThisLevel; + // identify and sort the items at this level + BList* itemCount = SortItemCount(originalListStartIndex); + int32 newItemsStopIndex = insertionPoint + itemCount->CountItems(); + newList->AddList(itemCount, insertionPoint); + delete itemCount; - //Identify and sort the subitems - for(int32 Counter = InsertionPoint; Counter < NewItemsStopIndex; Counter++) - { - CLVListItem* ThisItem = (CLVListItem*)NewList->ItemAt(Counter); - CLVListItem* NextItem = (CLVListItem*)fFullItemList.ItemAt(fFullItemList.IndexOf(ThisItem)+1); - if(ThisItem->IsSuperItem() && NextItem && ThisItem->fOutlineLevel < NextItem->fOutlineLevel) - { - int32 OldListSize = NewList->CountItems(); - SortFullListSegment(fFullItemList.IndexOf(ThisItem)+1,Counter+1,NewList); - int32 NewListSize = NewList->CountItems(); - NewItemsStopIndex += NewListSize - OldListSize; - Counter += NewListSize - OldListSize; + // identify and sort the subitems + for (int32 i = insertionPoint; i < newItemsStopIndex; i++) { + CLVListItem* item = (CLVListItem*)newList->ItemAt(i); + CLVListItem* nextItem = (CLVListItem*)fFullItemList.ItemAt( + fFullItemList.IndexOf(item) + 1); + if (item->fIsSuperItem && nextItem != NULL + && item->fOutlineLevel < nextItem->fOutlineLevel) { + int32 OldListSize = newList->CountItems(); + SortFullListSegment(fFullItemList.IndexOf(item) + 1, + i + 1, newList); + int32 newListSize = newList->CountItems(); + newItemsStopIndex += newListSize - OldListSize; + i += newListSize - OldListSize; } } } -BList* ColumnListView::SortItemsInThisLevel(int32 OriginalListStartIndex) +BList* +ColumnListView::SortItemCount(int32 originalListStartIndex) { - uint32 ThisLevel = ((CLVListItem*)fFullItemList.ItemAt(OriginalListStartIndex))->fOutlineLevel; + uint32 level = ((CLVListItem*)fFullItemList.ItemAt( + originalListStartIndex))->fOutlineLevel; - //Create a new BList of the items in this level - int32 Counter = OriginalListStartIndex; - int32 ItemsInThisLevel = 0; - BList* ThisLevelItems = new BList(16); - while(true) - { - CLVListItem* ThisItem = (CLVListItem*)fFullItemList.ItemAt(Counter); - if(ThisItem == NULL) + // create a new BList of the items in this level + int32 i = originalListStartIndex; + int32 itemCount = 0; + BList* itemsList = new BList(16); + while (true) { + CLVListItem* item = (CLVListItem*)fFullItemList.ItemAt(i); + if (item == NULL) break; - uint32 ThisItemLevel = ThisItem->fOutlineLevel; - if(ThisItemLevel == ThisLevel) - { - ThisLevelItems->AddItem(ThisItem); - ItemsInThisLevel++; - } - else if(ThisItemLevel < ThisLevel) + + uint32 itemLevel = item->fOutlineLevel; + if (itemLevel == level) { + itemsList->AddItem(item); + itemCount++; + } else if (itemLevel < level) break; - Counter++; + + i++; } - //Sort the BList of the items in this level - CLVListItem** SortArray = new CLVListItem*[ItemsInThisLevel]; - CLVListItem** ListItems = (CLVListItem**)ThisLevelItems->Items(); - for(Counter = 0; Counter < ItemsInThisLevel; Counter++) - SortArray[Counter] = ListItems[Counter]; - ThisLevelItems->MakeEmpty(); - SortListArray(SortArray,ItemsInThisLevel); - for(Counter = 0; Counter < ItemsInThisLevel; Counter++) - ThisLevelItems->AddItem(SortArray[Counter]); - delete [] SortArray; - return ThisLevelItems; + // sort the BList of the items in this level + CLVListItem** sortArray = new CLVListItem*[itemCount]; + CLVListItem** levelListItems = (CLVListItem**)itemsList->Items(); + for (i = 0; i < itemCount; i++) + sortArray[i] = levelListItems[i]; + + itemsList->MakeEmpty(); + SortListArray(sortArray, itemCount); + for (i = 0; i < itemCount; i++) + itemsList->AddItem(sortArray[i]); + + delete[] sortArray; + + return itemsList; } -void ColumnListView::SortListArray(CLVListItem** SortArray, int32 NumberOfItems) +void +ColumnListView::SortListArray(CLVListItem** sortArray, int32 itemCount) { - int32 SortDepth = fSortKeyList.CountItems(); - for(int32 Counter1 = 0; Counter1 < NumberOfItems-1; Counter1++) - for(int32 Counter2 = Counter1+1; Counter2 < NumberOfItems; Counter2++) - { - int CompareResult = 0; - if(fCompare) - for(int32 SortIteration = 0; SortIteration < SortDepth && CompareResult == 0; SortIteration++) - { - CLVColumn* Column = (CLVColumn*)fSortKeyList.ItemAt(SortIteration); - CompareResult = fCompare(SortArray[Counter1],SortArray[Counter2],fColumnList.IndexOf(Column)); - if(Column->fSortMode == Descending) - CompareResult = 0-CompareResult; + int32 sortDepth = fSortKeyList.CountItems(); + for (int32 i = 0; i < itemCount - 1; i++) { + for (int32 j = i + 1; j < itemCount; j++) { + int compareResult = 0; + if (fCompareFunction) { + for (int32 SortIteration = 0; + SortIteration < sortDepth && compareResult == 0; + SortIteration++) { + CLVColumn* Column = (CLVColumn*)fSortKeyList.ItemAt( + SortIteration); + compareResult = fCompareFunction(sortArray[i], + sortArray[j], fColumnList.IndexOf(Column)); + if (Column->fSortMode == SORT_MODE_DESCENDING) + compareResult = 0 - compareResult; } - if(CompareResult == 1) - { - CLVListItem* Temp = SortArray[Counter1]; - SortArray[Counter1] = SortArray[Counter2]; - SortArray[Counter2] = Temp; + } + + if (compareResult == 1) { + CLVListItem* Temp = sortArray[i]; + sortArray[i] = sortArray[j]; + sortArray[j] = Temp; } } + } } -void ColumnListView :: MessageReceived(BMessage * msg) +void +ColumnListView::MessageReceived(BMessage* message) { - switch(msg->what) - { - case B_UNMAPPED_KEY_DOWN: - if (_editMessage != NULL) - { - BMessage temp(*_editMessage); - temp.AddInt32("column", _selectedColumn); - temp.AddInt32("row", CurrentSelection()); + switch(message->what) { + case B_UNMAPPED_KEY_DOWN: + if (fEditMessage != NULL) { + BMessage temp(*fEditMessage); + temp.AddInt32("column", fSelectedColumn); + temp.AddInt32("row", CurrentSelection()); - int32 key; - if (msg->FindInt32("key", &key) == B_NO_ERROR) temp.AddInt32("unmappedkey", key); - _editTarget.SendMessage(&temp); - } - break; + int32 key; + if (message->FindInt32("key", &key) == B_NO_ERROR) + temp.AddInt32("unmappedkey", key); + fEditTarget.SendMessage(&temp); + } + break; - default: - BListView::MessageReceived(msg); - break; - } + default: + BListView::MessageReceived(message); + } } diff --git a/src/preferences/shortcuts/clv/ColumnListView.h b/src/preferences/shortcuts/clv/ColumnListView.h index 015a466a19..4392e794d3 100644 --- a/src/preferences/shortcuts/clv/ColumnListView.h +++ b/src/preferences/shortcuts/clv/ColumnListView.h @@ -1,155 +1,194 @@ -#ifndef ColumnListView_h -#define ColumnListView_h +/* + * Copyright 1999-2009 Jeremy Friesner + * Copyright 2009-2014 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jeremy Friesner + * John Scipione, jscipione@gmail.com + */ +#ifndef COLUMN_LIST_VIEW_H +#define COLUMN_LIST_VIEW_H -//Column list view header file -//****************************************************************************************************** -//**** PROJECT HEADER FILES AND CLASS NAME DECLARATIONS -//****************************************************************************************************** - -#include +#include #include "Colors.h" #include "CLVColumn.h" -class CLVListItem; -class CLVColumnLabelView; -class CLVFillerView; -class CLVContainerView; #include "PrefilledBitmap.h" #include "ScrollViewCorner.h" -//****************************************************************************************************** -//**** CONSTANTS AND TYPE DEFINITIONS -//****************************************************************************************************** -typedef int (*CLVCompareFuncPtr)(const CLVListItem* item1, const CLVListItem* item2, int32 sort_key); +class CLVListItem; +class CLVColumnLabelView; +class CLVFillerView; +class CLVContainerView; -//****************************************************************************************************** -//**** ColumnListView CLASS DECLARATION -//****************************************************************************************************** -class ColumnListView : public BListView -{ - public: - //Constructor and destructor - ColumnListView( BRect Frame, - BScrollView** ContainerView, //Used to get back a pointer to the container - //view that will hold the ColumnListView, the - //the CLVColumnLabelView, and the scrollbars. - //If no scroll bars or border are asked for, - //this will act like a plain BView container. - const char* Name = NULL, - uint32 ResizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, - uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE, - list_view_type Type = B_SINGLE_SELECTION_LIST, - bool hierarchical = false, - bool horizontal = true, //Which scroll bars should I add, if any - bool vertical = true, - border_style border = B_NO_BORDER, //What type of border to add, if any - const BFont* LabelFont = be_plain_font); - virtual ~ColumnListView(); - void AddScrollViewCorner(); - //Archival stuff - /*** Not implemented yet - ColumnListView(BMessage* archive); - static ColumnListView* Instantiate(BMessage* data); - virtual status_t Archive(BMessage* data, bool deep = true) const; - ***/ +typedef int (*CLVCompareFuncPtr)(const CLVListItem* item1, + const CLVListItem* item2, int32 sort_key); - virtual void MessageReceived(BMessage * msg); - //Column setup functions - virtual bool AddColumn(CLVColumn* Column); //Note that a column may only be added to - //one ColumnListView at a time, and may not - //be added more than once to the same - //ColumnListView without removing it - //inbetween - virtual bool AddColumnList(BList* NewColumns); - virtual bool RemoveColumn(CLVColumn* Column); - virtual bool RemoveColumns(CLVColumn* Column, int32 Count); //Finds Column in ColumnList - //and removes Count columns and - //their data from the view - //and its items - int32 CountColumns() const; - int32 IndexOfColumn(CLVColumn* column) const; - CLVColumn * ColumnAt(BPoint point) const; // Returns column located at point on screen --added by jaf - CLVColumn* ColumnAt(int32 column_index) const; - virtual bool SetDisplayOrder(const int32* Order); - //Sets the display order: each int32 in the Order list specifies the column index of the - //next column to display. Note that this DOES NOT get called if the user drags a - //column, so overriding it will not inform you of user changes. If you need that info, - //override DisplayOrderChanged instead. Also note that SetDisplayOrder does call - //DisplayOrderChanged(false). - virtual void ColumnWidthChanged(int32 ColumnIndex, float NewWidth); - virtual void DisplayOrderChanged(const int32* order); - //Override this if you want to find out when the display order changed. - int32* DisplayOrder() const; //Gets the display order in the same format as that used by - //SetDisplayOrder. The returned array belongs to the caller and - //must be delete[]'d when done with it. - virtual void SetSortKey(int32 ColumnIndex); - //Set it to -1 to remove the sort key. - virtual void AddSortKey(int32 ColumnIndex); - void ReverseSortMode(int32 ColumnIndex); - virtual void SetSortMode(int32 ColumnIndex,CLVSortMode Mode); - int32 Sorting(int32* SortKeys, CLVSortMode* SortModes) const; - //Returns the number of used sort keys, and fills the provided arrays with the sort keys - //by column index and sort modes, in priority order. The pointers should point to an array - //int32 SortKeys[n], and an array CLVSortMode SortModes[n] where n is the number of sortable - //columns in the ColumnListView. Note: sorting will only occur if the key column is shown. - void SetSorting(int32 NumberOfKeys, int32* SortKeys, CLVSortMode* SortModes); - //Sets the sorting parameters using the same format returned by Sorting +class ColumnListView : public BListView { +public: + ColumnListView(BRect frame, + BScrollView** containerView, + // Used to get back a pointer to the container + // view that will hold the ColumnListView, the + // the CLVColumnLabelView, and the scrollbars. + // If no scroll bars or border are asked for, + // this will act like a plain BView container. + const char* name = NULL, + uint32 resizingMode + = B_FOLLOW_LEFT | B_FOLLOW_TOP, + uint32 flags + = B_WILL_DRAW | B_FRAME_EVENTS + | B_NAVIGABLE, + list_view_type type + = B_SINGLE_SELECTION_LIST, + bool hierarchical = false, + bool horizontal = true, + // which scroll bars should I add, if any + bool vertical = true, + border_style border = B_NO_BORDER, + // what type of border to add, if any + const BFont* labelFont = be_plain_font); - //BView overrides - virtual void FrameResized(float Width, float Height); - virtual void AttachedToWindow(); - virtual void ScrollTo(BPoint point); - virtual void MouseDown(BPoint point); + virtual ~ColumnListView(); - //List functions - virtual bool AddUnder(CLVListItem*, CLVListItem* superitem); - virtual bool AddItem(CLVListItem*, int32 fullListIndex); - virtual bool AddItem(CLVListItem*); - virtual bool AddList(BList* newItems); //This must be a BList of - //CLVListItem*'s, NOT BListItem*'s - virtual bool AddList(BList* newItems, int32 fullListIndex); //This must be a BList of - //CLVListItem*'s, NOT BListItem*'s - virtual bool AddItem(BListItem*, int32 fullListIndex); // unhide - virtual bool AddItem(BListItem*); // unhide - virtual bool RemoveItem(CLVListItem* item); - virtual BListItem* RemoveItem(int32 fullListIndex); //Actually returns CLVListItem - virtual bool RemoveItems(int32 fullListIndex, int32 count); - virtual bool RemoveItem(BListItem* item); // unhide - virtual void MakeEmpty(); - CLVListItem* FullListItemAt(int32 fullListIndex) const; - int32 FullListIndexOf(const CLVListItem* item) const; - int32 FullListIndexOf(BPoint point) const; - CLVListItem* FullListFirstItem() const; - CLVListItem* FullListLastItem() const; - bool FullListHasItem(const CLVListItem* item) const; - int32 FullListCountItems() const; - bool FullListIsEmpty() const; - int32 FullListCurrentSelection(int32 index = 0) const; - void FullListDoForEach(bool (*func)(CLVListItem*)); - void FullListDoForEach(bool (*func)(CLVListItem*, void*), void* arg2); - CLVListItem* Superitem(const CLVListItem* item) const; - int32 FullListNumberOfSubitems(const CLVListItem* item) const; - virtual void Expand(CLVListItem* item); - virtual void Collapse(CLVListItem* item); - bool IsExpanded(int32 fullListIndex) const; - void SetSortFunction(CLVCompareFuncPtr compare); - void SortItems(); + void AddScrollViewCorner(); - virtual void KeyDown(const char * bytes, int32 numBytes); + //Archival stuff + /*** Not implemented yet + ColumnListView(BMessage* archive); + static ColumnListView* Instantiate(BMessage* data); + virtual status_t Archive(BMessage* data, bool deep = true) + const; + ***/ - void SetEditMessage(BMessage * newMsg, BMessenger target); - // Sets a BMessage that will be sent every time a key is pressed, or the mouse - // is clicked in the active cell. (newMsg) becomes property of this ColumnListView. - // Copies of (newMsg) will be sent to (target). + virtual void MessageReceived(BMessage* message); - virtual void Pulse(); + // column setup functions + virtual bool AddColumn(CLVColumn* column); + // Note that a column may only be added to + // one ColumnListView at a time, and may not + // be added more than once to the same + // ColumnListView without removing it + // inbetween + virtual bool AddColumnList(BList* newColumns); + virtual bool RemoveColumn(CLVColumn* column); + virtual bool RemoveColumns(CLVColumn* column, + int32 Count); + // Finds Column in ColumnList and removes Count columns and + // their data from the view and its items + int32 CountColumns() const; + int32 IndexOfColumn(CLVColumn* column) const; + CLVColumn* ColumnAt(BPoint point) const; + // Returns column located at point on screen --added by jaf + CLVColumn* ColumnAt(int32 columnIndex) const; + virtual bool SetDisplayOrder(const int32* order); + // Sets the display order: each int32 in the Order list specifies + // the column index of the next column to display. Note that this + // DOES NOT get called if the user drags a column, so overriding + // it will not inform you of user changes. If you need that info, + // override DisplayOrderChanged instead. Also note that + // SetDisplayOrder does call DisplayOrderChanged(false). + virtual void ColumnWidthChanged(int32 columnIndex, + float newWidth); + virtual void DisplayOrderChanged(const int32* order); + // Override this if you want to find out when the display order changed. + int32* DisplayOrder() const; + // Gets the display order in the same format as that used by + // SetDisplayOrder. The returned array belongs to the caller and + // must be delete[]'d when done with it. + virtual void SetSortKey(int32 columnIndex); + // Set it to -1 to remove the sort key. + virtual void AddSortKey(int32 columnIndex); + void ReverseSortMode(int32 columnIndex); + virtual void SetSortMode(int32 columnIndex, + CLVSortMode Mode); + int32 Sorting(int32* SortKeys, + CLVSortMode* SortModes) const; + // Returns the number of used sort keys, and fills the provided + // arrays with the sort keys by column index and sort modes, + // in priority order. The pointers should point to an array + // int32 SortKeys[n], and an array CLVSortMode SortModes[n] where + // n is the number of sortable columns in the ColumnListView. + // Note: sorting will only occur if the key column is shown. + void SetSorting(int32 NumberOfKeys, + int32* SortKeys, + CLVSortMode* SortModes); + // Sets the sorting parameters using the same format returned by sorting + + // BView overrides + virtual void FrameResized(float newWidth, + float newHeight); + virtual void AttachedToWindow(); + virtual void ScrollTo(BPoint point); + virtual void MouseDown(BPoint point); + + // List functions + virtual bool AddUnder(CLVListItem*, + CLVListItem* superitem); + virtual bool AddItem(CLVListItem*, + int32 fullListIndex); + virtual bool AddItem(CLVListItem*); + virtual bool AddList(BList* newItems); + // This must be a BList of CLVListItem*'s, NOT BListItem*'s + virtual bool AddList(BList* newItems, + int32 fullListIndex); + //This must be a BList of CLVListItem*'s, NOT BListItem*'s + virtual bool AddItem(BListItem*, int32 fullListIndex); + // unhide + virtual bool AddItem(BListItem*); + // unhide + virtual bool RemoveItem(CLVListItem* item); + virtual BListItem* RemoveItem(int32 fullListIndex); + // actually returns CLVListItem + virtual bool RemoveItems(int32 fullListIndex, + int32 count); + virtual bool RemoveItem(BListItem* item); + // unhide + virtual void MakeEmpty(); + CLVListItem* FullListItemAt(int32 fullListIndex) const; + int32 FullListIndexOf(const CLVListItem* item) + const; + int32 FullListIndexOf(BPoint point) const; + CLVListItem* FullListFirstItem() const; + CLVListItem* FullListLastItem() const; + bool FullListHasItem(const CLVListItem* item) + const; + int32 FullListCountItems() const; + bool FullListIsEmpty() const; + int32 FullListCurrentSelection(int32 index = 0) + const; + void FullListDoForEach( + bool (*func)(CLVListItem*)); + void FullListDoForEach(bool (*func)( + CLVListItem*, void*), void* arg2); + CLVListItem* Superitem(const CLVListItem* item) const; + int32 FullListNumberOfSubitems( + const CLVListItem* item) const; + virtual void Expand(CLVListItem* item); + virtual void Collapse(CLVListItem* item); + bool IsExpanded(int32 fullListIndex) const; + void SetSortFunction(CLVCompareFuncPtr compare); + void SortItems(); + + virtual void KeyDown(const char* bytes, int32 numBytes); + + void SetEditMessage(BMessage* message, + BMessenger target); + // Sets a BMessage that will be sent every time a key is pressed, + // or the mouse is clicked in the active cell. (message) becomes + // property of this ColumnListView. + // Copies of (message) will be sent to (target). + + virtual void Pulse(); // Used to make the cursor blink on the string column... - int32 GetSelectedColumn() const {return _selectedColumn;} + int32 GetSelectedColumn() const + { return fSelectedColumn; } private: friend class CLVMainView; @@ -157,48 +196,67 @@ class ColumnListView : public BListView friend class CLVColumnLabelView; friend class CLVListItem; - int32 GetActualIndexOf(int32 displayIndex) const; - // Returns the "real" index of the given display index, or -1 if there is none. + int32 GetActualIndexOf(int32 displayIndex) const; + // Returns the "real" index of the given display index, + // or -1 if there is none. - int32 GetDisplayIndexOf(int32 actualIndex) const; - // Returns the display index of the given "real" index, or -1 if there is none. + int32 GetDisplayIndexOf(int32 actualIndex) const; + // Returns the display index of the given "real" index, + // or -1 if there is none. - void SetSelectedColumnIndex(int32 selectedColumnIndex); - // Call this to change _selectedColumn to a new value properly. + void SetSelectedColumnIndex( + int32 selectedcolumnIndex); + // Call this to change fSelectedColumn to a new value properly. - void UpdateColumnSizesDataRectSizeScrollBars(); - void UpdateScrollBars(); - void ColumnsChanged(); - void CreateContainer(bool horizontal, bool vertical, border_style border, uint32 ResizingMode, - uint32 flags); - void SortListArray(CLVListItem** SortArray, int32 NumberOfItems); - void MakeEmptyPrivate(); - bool AddListPrivate(BList* newItems, int32 fullListIndex); - bool AddItemPrivate(CLVListItem* item, int32 fullListIndex); - void SortFullListSegment(int32 OriginalListStartIndex, int32 InsertionPoint, BList* NewList); - BList* SortItemsInThisLevel(int32 OriginalListStartIndex); - static int PlainBListSortFunc(BListItem** item1, BListItem** item2); - static int HierarchicalBListSortFunc(BListItem** item1, BListItem** item2); - - CLVColumnLabelView* fColumnLabelView; - CLVContainerView* fScrollView; - ScrollViewCorner* fFillerView; - bool fHierarchical; - BList fColumnList; - BList fColumnDisplayList; - float fDataWidth,fDataHeight,fPageWidth,fPageHeight; - BList fSortKeyList; //List contains CLVColumn pointers - PrefilledBitmap fRightArrow; - PrefilledBitmap fDownArrow; - BList fFullItemList; - int32 fExpanderColumn; - CLVCompareFuncPtr fCompare; + void ShiftDragGroup(); + void UpdateScrollBars(); + void ColumnsChanged(); + void CreateContainer(bool horizontal, + bool vertical, border_style border, + uint32 resizingMode, uint32 flags); + void SortListArray(CLVListItem** sortArray, + int32 itemCount); + void MakeEmptyPrivate(); + bool AddListPrivate(BList* newItems, + int32 fullListIndex); + bool AddItemPrivate(CLVListItem* item, + int32 fullListIndex); + void SortFullListSegment( + int32 originalListStartIndex, + int32 insertionPoint, BList* newList); + BList* SortItemCount( + int32 originalListStartIndex); + static int PlainBListSortFunc(BListItem** firstItem, + BListItem** secondItem); + static int HierarchicalBListSortFunc( + BListItem** firstItem, + BListItem** secondItem); + CLVColumnLabelView* fColumnLabelView; + CLVContainerView* fScrollView; + ScrollViewCorner* fFillerView; + bool fHierarchical; + BList fColumnList; + BList fColumnDisplayList; + float fDataWidth; + float fDataHeight; + float fPageWidth; + float fPageHeight; + BList fSortKeyList; + // list contains CLVColumn pointers + PrefilledBitmap fRightArrow; + PrefilledBitmap fDownArrow; + BList fFullItemList; + int32 fExpanderColumn; + CLVCompareFuncPtr fCompareFunction; // added by jaf - int32 _selectedColumn; // actual index of the column that contains the active cell. - BMessage * _editMessage; // if non-NULL, sent on keypress or when active cell is clicked. - BMessenger _editTarget; // target for _editMessage. + int32 fSelectedColumn; + // actual index of the column that contains the active cell. + BMessage* fEditMessage; + // if non-NULL, sent on keypress or when active cell is clicked. + BMessenger fEditTarget; + // target for fEditMessage. }; -#endif +#endif // COLUMN_LIST_VIEW_H diff --git a/src/preferences/shortcuts/clv/MouseWatcher.cpp b/src/preferences/shortcuts/clv/MouseWatcher.cpp index 1b59052af9..6259895061 100644 --- a/src/preferences/shortcuts/clv/MouseWatcher.cpp +++ b/src/preferences/shortcuts/clv/MouseWatcher.cpp @@ -1,72 +1,91 @@ +/* + * Copyright 1999-2009 Jeremy Friesner + * Copyright 2009-2014 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jeremy Friesner + * John Scipione, jscipione@gmail.com + */ + + #include "MouseWatcher.h" #include #include + int32 MouseWatcher(void* data); -thread_id StartMouseWatcher(BView* TargetView) +thread_id +StartMouseWatcher(BView* target) { - thread_id MouseWatcherThread = spawn_thread(MouseWatcher,"MouseWatcher",B_NORMAL_PRIORITY, - new BMessenger(TargetView)); - if(MouseWatcherThread != B_NO_MORE_THREADS && MouseWatcherThread != B_NO_MEMORY) + thread_id MouseWatcherThread = spawn_thread(MouseWatcher, + "MouseWatcher", B_NORMAL_PRIORITY, new BMessenger(target)); + if (MouseWatcherThread != B_NO_MORE_THREADS + && MouseWatcherThread != B_NO_MEMORY) { resume_thread(MouseWatcherThread); + } + return MouseWatcherThread; } -int32 MouseWatcher(void* data) +int32 +MouseWatcher(void* data) { - BMessenger* TheMessenger = (BMessenger*)data; - BPoint PreviousPos; - uint32 PreviousButtons = 0xFFFFFFFF; - bool FirstCheck = true; - BMessage MessageToSend; - MessageToSend.AddPoint("where",BPoint(0,0)); - MessageToSend.AddInt32("buttons",0); - MessageToSend.AddInt32("modifiers",0); - while(true) - { - if (!TheMessenger->LockTarget()) - { - delete TheMessenger; - return 0; // window is dead so exit - } - BLooper *TheLooper; - BView* TheView = (BView*)TheMessenger->Target(&TheLooper); - BPoint Where; - uint32 Buttons; - TheView->GetMouse(&Where,&Buttons,false); - if(FirstCheck) - { - PreviousPos = Where; - PreviousButtons = Buttons; - FirstCheck = false; - } - bool Send = false; - if(Buttons != PreviousButtons || Buttons == 0 || Where != PreviousPos) - { - if(Buttons == 0) - MessageToSend.what = MW_MOUSE_UP; - else if(Buttons != PreviousButtons) - MessageToSend.what = MW_MOUSE_DOWN; - else - MessageToSend.what = MW_MOUSE_MOVED; - MessageToSend.ReplacePoint("where",Where); - MessageToSend.ReplaceInt32("buttons",Buttons); - MessageToSend.ReplaceInt32("modifiers",modifiers()); - Send = true; - } - TheLooper->Unlock(); - if(Send) - TheMessenger->SendMessage(&MessageToSend); - if(Buttons == 0) - { - //Button was released - delete TheMessenger; + BMessenger* messenger = (BMessenger*)data; + BPoint previousPosition; + uint32 previousbuttons = 0xFFFFFFFF; + bool isFirstCheck = true; + BMessage messageToSend; + messageToSend.AddPoint("where", BPoint(0, 0)); + messageToSend.AddInt32("buttons", 0); + messageToSend.AddInt32("modifiers", 0); + + while(true) { + if (!messenger->LockTarget()) { + // window is dead so exit + delete messenger; return 0; } + BLooper* looper; + BView* view = (BView*)messenger->Target(&looper); + BPoint where; + uint32 buttons; + view->GetMouse(&where, &buttons, false); + if (isFirstCheck) { + previousPosition = where; + previousbuttons = buttons; + isFirstCheck = false; + } + bool shouldSend = false; + if (buttons != previousbuttons || buttons == 0 + || where != previousPosition) { + if (buttons == 0) + messageToSend.what = MW_MOUSE_UP; + else if (buttons != previousbuttons) + messageToSend.what = MW_MOUSE_DOWN; + else + messageToSend.what = MW_MOUSE_MOVED; + + messageToSend.ReplacePoint("where", where); + messageToSend.ReplaceInt32("buttons", buttons); + messageToSend.ReplaceInt32("modifiers", modifiers()); + shouldSend = true; + } + + looper->Unlock(); + if (shouldSend) + messenger->SendMessage(&messageToSend); + + if (buttons == 0) { + // mouse button was released + delete messenger; + return 0; + } + snooze(50000); } } diff --git a/src/preferences/shortcuts/clv/MouseWatcher.h b/src/preferences/shortcuts/clv/MouseWatcher.h index 8bfde210e5..2ad65f5c48 100644 --- a/src/preferences/shortcuts/clv/MouseWatcher.h +++ b/src/preferences/shortcuts/clv/MouseWatcher.h @@ -1,39 +1,60 @@ -/****DOCUMENTATION -Once started, MouseWatcher will watch the mouse until the mouse buttons are all released, sending -messages to the target BView (TargetView is specified as the target handler in the BMessenger used to -send the messages. The BLooper == window of the target view is determined automatically by the -BMessenger) +/* + * Copyright 1999-2009 Jeremy Friesner + * Copyright 2009-2014 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jeremy Friesner + * John Scipione, jscipione@gmail.com + */ +#ifndef MOUSE_WATCHER_H +#define MOUSE_WATCHER_H -If the mouse moves, a MW_MOUSE_MOVED message is sent. -If the mouse buttons are changed, but not released, a MW_MOUSE_DOWN message is sent. -If the mouse button(s) are released, a MW_MOUSE_UP message is sent. -These messages will have three data entries: +/**** DOCUMENTATION + * + * Once started, MouseWatcher will watch the mouse until the mouse buttons + * are all released, sendin messages to the target BView (TargetView is + * specified as the target handler in the BMessenger used to send the messages. + * The BLooper == window of the target view is determined automatically by the + * BMessenger) + * + * If the mouse moves, a MW_MOUSE_MOVED message is sent. + * If the mouse buttons are changed, but not released, a MW_MOUSE_DOWN + * message is sent. + * If the mouse button(s) are released, a MW_MOUSE_UP message is sent. + * + * These messages will have three data entries: + * + * "where" (B_POINT_TYPE) - The position of the mouse in TargetView's + * coordinate system. + * "buttons" (B_INT32_TYPE) - The mouse buttons. See BView::GetMouse(). + * "modifiers" (B_INT32_TYPE) - The modifier keys held down at the time. + * See modifiers(). + * + * Once it is started, you can't stop it, but that shouldn't matter - the user + * will most likely releas the buttons soon, and you can interpret the events + * however you want. + * + * StartMouseWatcher returns a valid thread ID, or it returns an error code: + * B_NO_MORE_THREADS All thread_id numbers are currently in use. + * B_NO_MEMORY Not enough memory to allocate the resources for another + * thread. + */ -"where" (B_POINT_TYPE) - The position of the mouse in TargetView's coordinate system. -"buttons" (B_INT32_TYPE) - The mouse buttons. See BView::GetMouse(). -"modifiers" (B_INT32_TYPE) - The modifier keys held down at the time. See modifiers(). - -Once it is started, you can't stop it, but that shouldn't matter - the user will most likely release -the buttons soon, and you can interpret the events however you want. - -StartMouseWatcher returns a valid thread ID, or it returns an error code: -B_NO_MORE_THREADS. all thread_id numbers are currently in use. -B_NO_MEMORY. Not enough memory to allocate the resources for another thread. -****/ -#ifndef MouseWatcher_h -#define MouseWatcher_h #include #include -class BView; const uint32 MW_MOUSE_DOWN = 'Mw-D'; const uint32 MW_MOUSE_UP = 'Mw-U'; const uint32 MW_MOUSE_MOVED = 'Mw-M'; -thread_id StartMouseWatcher(BView* TargetView); -#endif +class BView; +thread_id StartMouseWatcher(BView* target); + + +#endif // MOUSE_WATCHER_H diff --git a/src/preferences/shortcuts/clv/PrefilledBitmap.cpp b/src/preferences/shortcuts/clv/PrefilledBitmap.cpp index 00f377de69..14cc956f94 100644 --- a/src/preferences/shortcuts/clv/PrefilledBitmap.cpp +++ b/src/preferences/shortcuts/clv/PrefilledBitmap.cpp @@ -1,14 +1,28 @@ +/* + * Copyright 1999-2009 Jeremy Friesner + * Copyright 2009-2014 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jeremy Friesner + * John Scipione, jscipione@gmail.com + */ + + #include "PrefilledBitmap.h" -PrefilledBitmap::PrefilledBitmap(BRect bounds, color_space space, const void *data, bool acceptsViews, - bool needsContiguousMemory) -: BBitmap(bounds, space, acceptsViews, needsContiguousMemory) + +PrefilledBitmap::PrefilledBitmap(BRect bounds, color_space space, + const void* data, bool acceptsViews, bool needsContiguousMemory) + : + BBitmap(bounds, space, acceptsViews, needsContiguousMemory) { - int32 length = ((int32(bounds.right-bounds.left)+3) / 4) * 4; - length *= int32(bounds.bottom-bounds.top)+1; + int32 length = ((int32(bounds.right - bounds.left) + 3) / 4) * 4; + length *= int32(bounds.bottom - bounds.top) + 1; SetBits(data, length, 0, space); } PrefilledBitmap::~PrefilledBitmap() -{ } \ No newline at end of file +{ +} diff --git a/src/preferences/shortcuts/clv/PrefilledBitmap.h b/src/preferences/shortcuts/clv/PrefilledBitmap.h index eaf521ddd4..9284d5d470 100644 --- a/src/preferences/shortcuts/clv/PrefilledBitmap.h +++ b/src/preferences/shortcuts/clv/PrefilledBitmap.h @@ -1,18 +1,28 @@ -#ifndef PreFilledBitmap_h -#define PreFilledBitmap_h +/* + * Copyright 1999-2009 Jeremy Friesner + * Copyright 2009-2014 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jeremy Friesner + * John Scipione, jscipione@gmail.com + */ +#ifndef PREFILLED_BITMAP_H +#define PREFILLED_BITMAP_H + #include -//Useful until be implements BBitmap::BBitmap(BRect bounds, color_space space, const void *data, -// bool acceptsViews, bool needsContiguousMemory) -//or something like it... class PrefilledBitmap : public BBitmap { - public: - PrefilledBitmap(BRect bounds, color_space space, const void *data, bool acceptsViews, - bool needsContiguousMemory); - ~PrefilledBitmap(); +public: + PrefilledBitmap(BRect bounds, + color_space space, const void* data, + bool acceptsViews, + bool needsContiguousMemory); + virtual ~PrefilledBitmap(); }; -#endif \ No newline at end of file + +#endif // PREFILLED_BITMAP_H diff --git a/src/preferences/shortcuts/clv/ScrollViewCorner.cpp b/src/preferences/shortcuts/clv/ScrollViewCorner.cpp index 3ada5390c7..360ac869d6 100644 --- a/src/preferences/shortcuts/clv/ScrollViewCorner.cpp +++ b/src/preferences/shortcuts/clv/ScrollViewCorner.cpp @@ -1,11 +1,25 @@ +/* + * Copyright 1999-2009 Jeremy Friesner + * Copyright 2009-2014 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jeremy Friesner + * John Scipione, jscipione@gmail.com + */ + + #include "Colors.h" #include "ScrollViewCorner.h" #include -ScrollViewCorner::ScrollViewCorner(float Left,float Top) -: BView(BRect(Left,Top,Left+B_V_SCROLL_BAR_WIDTH,Top+B_H_SCROLL_BAR_HEIGHT),NULL,B_FOLLOW_RIGHT | - B_FOLLOW_BOTTOM,B_WILL_DRAW) + +ScrollViewCorner::ScrollViewCorner(float left, float top) + : + BView(BRect(left, top, left + B_V_SCROLL_BAR_WIDTH, + top + B_H_SCROLL_BAR_HEIGHT), NULL, + B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM, B_WILL_DRAW) { SetHighColor(BeShadow); SetViewColor(BeInactiveGrey); @@ -13,16 +27,19 @@ ScrollViewCorner::ScrollViewCorner(float Left,float Top) ScrollViewCorner::~ScrollViewCorner() -{ } - - -void ScrollViewCorner::Draw(BRect Update) { - if(Update.bottom >= B_H_SCROLL_BAR_HEIGHT) - StrokeLine(BPoint(0.0,B_H_SCROLL_BAR_HEIGHT),BPoint(B_V_SCROLL_BAR_WIDTH,B_H_SCROLL_BAR_HEIGHT)); - if(Update.right >= B_V_SCROLL_BAR_WIDTH) - StrokeLine(BPoint(B_V_SCROLL_BAR_WIDTH,0.0), - BPoint(B_V_SCROLL_BAR_WIDTH,B_H_SCROLL_BAR_HEIGHT-1.0)); } +void +ScrollViewCorner::Draw(BRect updateRect) +{ + if (updateRect.bottom >= B_H_SCROLL_BAR_HEIGHT) { + StrokeLine(BPoint(0.0, B_H_SCROLL_BAR_HEIGHT), + BPoint(B_V_SCROLL_BAR_WIDTH, B_H_SCROLL_BAR_HEIGHT)); + } + if (updateRect.right >= B_V_SCROLL_BAR_WIDTH) { + StrokeLine(BPoint(B_V_SCROLL_BAR_WIDTH, 0.0), + BPoint(B_V_SCROLL_BAR_WIDTH, B_H_SCROLL_BAR_HEIGHT - 1.0)); + } +} diff --git a/src/preferences/shortcuts/clv/ScrollViewCorner.h b/src/preferences/shortcuts/clv/ScrollViewCorner.h index 6507294792..39e819bf59 100644 --- a/src/preferences/shortcuts/clv/ScrollViewCorner.h +++ b/src/preferences/shortcuts/clv/ScrollViewCorner.h @@ -1,21 +1,35 @@ -#ifndef ScrollViewCorner_h -#define ScrollViewCorner_h +/* + * Copyright 1999-2009 Jeremy Friesner + * Copyright 2009-2014 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jeremy Friesner + * John Scipione, jscipione@gmail.com + */ +#ifndef SCROLL_VIEW_CORNER_H +#define SCROLL_VIEW_CORNER_H -//If you have a BScrollView with horizontal and vertical sliders that isn't -//seated to the lower-right corner of a B_DOCUMENT_WINDOW, there's a "hole" -//between the sliders that needs to be filled. You can use this to fill it. -//In general, it looks best to set the ScrollViewCorner color to -//BeInactiveControlGrey if the vertical BScrollBar is inactive, and the color -//to BeBackgroundGrey if the vertical BScrollBar is active. Have a look at -//Demo3 of ColumnListView to see what I mean if this is unclear. + +/* + * If you have a BScrollView with horizontal and vertical sliders that isn't + * seated to the lower-right corner of a B_DOCUMENT_WINDOW, there's a "hole" + * between the sliders that needs to be filled. You can use this to fill it. + * In general, it looks best to set the ScrollViewCorner color to + * BeInactiveControlGrey if the vertical BScrollBar is inactive, and the color + * to BeBackgroundGrey if the vertical BScrollBar is active. Have a look at + * Demo3 of ColumnListView to see what I mean if this is unclear. + */ class ScrollViewCorner : public BView { - public: - ScrollViewCorner(float Left,float Top); - ~ScrollViewCorner(); - void Draw(BRect Update); +public: + ScrollViewCorner(float left, float top); + virtual ~ScrollViewCorner(); + + virtual void Draw(BRect updateRect); }; -#endif + +#endif // SCROLL_VIEW_CORNER_H diff --git a/src/preferences/shortcuts/main.cpp b/src/preferences/shortcuts/main.cpp index 745450a18e..37e1e7003f 100644 --- a/src/preferences/shortcuts/main.cpp +++ b/src/preferences/shortcuts/main.cpp @@ -1,12 +1,12 @@ /* - * Copyright 1999-2010 Haiku Inc. All rights reserved. + * Copyright 1999-2009 Jeremy Friesner + * Copyright 2009-2010 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Jeremy Friesner */ - #include #include @@ -19,7 +19,6 @@ main(int argc, char** argv) { InitKeyIndices(); ShortcutsApp app; - + app.Run(); } -