Shortcuts: Big style refactor

Update the style of this preference app to match Haiku’s coding guidelines.
Since this app used a completely different style this is a big commit, but,
there should be no behavioral changes.

Style changes include but are not limited to:
* private member variables use fMemberVariable style
* local variables and public member variables use camelCase style
* compare pointers to NULL explicitly
* compare integers against 0 explicitly
* always flank binary operators with spaces such as + - , / *
* pointer goes with type, not value or flanked by spaces
* lots of variable renaming especially for abbreviations
* comments start with a leading space, prefer lowercase unless full sentence
* space after keywords such as if and for and { and } on same line
* multi-line if statement style fixes
* remove trailing spaces
* 80 char fixes
* ... and many more, and I'm sure I missed some.

Add/update copyright headers giving credit where due, obviously this code
can’t be copyright Haiku, Inc. from 1999 since Haiku, Inc. didn’t exist
so this change attributes copyright to Jeremy Friesner from 1999-2009 and
Haiku, Inc. from 2009 onwards matching the long description of the rdef file.

Added myself to the authors section of the files in the clv directory.
This commit is contained in:
John Scipione 2014-01-20 18:30:59 -05:00
parent 87784cafb8
commit b42302c5d3
25 changed files with 3248 additions and 2755 deletions

View File

@ -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;
}

View File

@ -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 <List.h>
@ -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

View File

@ -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 {

View File

@ -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()
{
{
}

View File

@ -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 <Application.h>
@ -21,5 +22,4 @@ public:
};
#endif
#endif // SHORTCUTS_APP_H

View File

@ -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 <ctype.h>
@ -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
}

View File

@ -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 <Bitmap.h>
@ -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

View File

@ -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;
}
}

View File

@ -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 <Entry.h>
@ -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

View File

@ -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 <string.h>
#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;
}

View File

@ -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 <support/SupportDefs.h>
#include <interface/PopUpMenu.h>
//******************************************************************************************************
//**** 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

File diff suppressed because it is too large Load Diff

View File

@ -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 <support/SupportDefs.h>
#include <InterfaceKit.h>
//******************************************************************************************************
//**** 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

View File

@ -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 <stdio.h>
#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);
}

View File

@ -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 <interface/ListItem.h>
//******************************************************************************************************
//**** 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

View File

@ -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 <interface/ColorControl.h>
// useful until be gets around to making these sorts of things
// globals akin to be_plain_font, etc.
#include <ColorControl.h>
//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

File diff suppressed because it is too large Load Diff

View File

@ -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 <interface/ListView.h>
#include <ListView.h>
#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

View File

@ -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 <Messenger.h>
#include <InterfaceKit.h>
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);
}
}

View File

@ -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 <SupportDefs.h>
#include <OS.h>
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

View File

@ -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()
{ }
{
}

View File

@ -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 <interface/Bitmap.h>
//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
#endif // PREFILLED_BITMAP_H

View File

@ -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 <InterfaceKit.h>
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));
}
}

View File

@ -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

View File

@ -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 <Catalog.h>
#include <Locale.h>
@ -19,7 +19,6 @@ main(int argc, char** argv)
{
InitKeyIndices();
ShortcutsApp app;
app.Run();
}