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:
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -89,4 +90,3 @@ MetaKeyStateMap::GetName() const
|
|||||||
{
|
{
|
||||||
return fKeyName;
|
return fKeyName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Jeremy Friesner
|
* Jeremy Friesner
|
||||||
*/
|
*/
|
||||||
#ifndef MetaKeyStateMap_h
|
#ifndef META_KEY_STATE_MAP_H
|
||||||
#define MetaKeyStateMap_h
|
#define META_KEY_STATE_MAP_H
|
||||||
|
|
||||||
|
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
@@ -21,7 +22,6 @@ class BitFieldTester;
|
|||||||
// description strings and qualifier bit-chords that go with them.
|
// description strings and qualifier bit-chords that go with them.
|
||||||
class MetaKeyStateMap {
|
class MetaKeyStateMap {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Note: You MUST call SetInfo() directly after using this ctor!
|
// Note: You MUST call SetInfo() directly after using this ctor!
|
||||||
MetaKeyStateMap();
|
MetaKeyStateMap();
|
||||||
|
|
||||||
@@ -65,5 +65,4 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif // META_KEY_STATE_MAP_H
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ resource app_version {
|
|||||||
internal = 0,
|
internal = 0,
|
||||||
|
|
||||||
short_info = "Shortcuts",
|
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 {
|
resource vector_icon {
|
||||||
|
|||||||
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
|
|||||||
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Jeremy Friesner
|
* Jeremy Friesner
|
||||||
* Fredrik Modéen
|
* Fredrik Modéen
|
||||||
*/
|
*/
|
||||||
#ifndef ShortcutsApp_h
|
#ifndef SHORTCUTS_APP_H
|
||||||
#define ShortcutsApp_h
|
#define SHORTCUTS_APP_H
|
||||||
|
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
@@ -21,5 +22,4 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif // SHORTCUTS_APP_H
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Jeremy Friesner
|
* Jeremy Friesner
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "ShortcutsSpec.h"
|
#include "ShortcutsSpec.h"
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@@ -227,7 +227,8 @@ ShortcutsSpec::ShortcutsSpec(BMessage* from)
|
|||||||
void
|
void
|
||||||
ShortcutsSpec::SetCommand(const char* command)
|
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;
|
fCommandLen = strlen(command) + 1;
|
||||||
fCommandNul = fCommandLen - 1;
|
fCommandNul = fCommandLen - 1;
|
||||||
fCommand = new char[fCommandLen];
|
fCommand = new char[fCommandLen];
|
||||||
@@ -342,7 +343,8 @@ void
|
|||||||
ShortcutsSpec::DrawItemColumn(BView* owner, BRect item_column_rect,
|
ShortcutsSpec::DrawItemColumn(BView* owner, BRect item_column_rect,
|
||||||
int32 column_index, bool columnSelected, bool complete)
|
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;
|
rgb_color color;
|
||||||
bool selected = IsSelected();
|
bool selected = IsSelected();
|
||||||
@@ -406,8 +408,8 @@ ShortcutsSpec::DrawItemColumn(BView* owner, BRect item_column_rect,
|
|||||||
_CacheViewFont(owner);
|
_CacheViewFont(owner);
|
||||||
|
|
||||||
// How about I draw a nice "key" background for this one?
|
// How about I draw a nice "key" background for this one?
|
||||||
BRect textRect(point.x - KEY_MARGIN, (point.y-sFontHeight) - KEY_MARGIN
|
BRect textRect(point.x - KEY_MARGIN, (point.y - sFontHeight) - KEY_MARGIN,
|
||||||
, point.x + textWidth + KEY_MARGIN - 2.0f, point.y + KEY_MARGIN);
|
point.x + textWidth + KEY_MARGIN - 2.0f, point.y + KEY_MARGIN);
|
||||||
|
|
||||||
if (column_index == KEY_COLUMN_INDEX)
|
if (column_index == KEY_COLUMN_INDEX)
|
||||||
lowColor = ReallyLightPurple;
|
lowColor = ReallyLightPurple;
|
||||||
@@ -547,7 +549,7 @@ ShortcutsSpec::ProcessColumnTextString(int whichColumn, const char* string)
|
|||||||
bool
|
bool
|
||||||
ShortcutsSpec::_AttemptTabCompletion()
|
ShortcutsSpec::_AttemptTabCompletion()
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool result = false;
|
||||||
|
|
||||||
int32 argc;
|
int32 argc;
|
||||||
char** argv = ParseArgvFromString(fCommand, argc);
|
char** argv = ParseArgvFromString(fCommand, argc);
|
||||||
@@ -555,11 +557,11 @@ ShortcutsSpec::_AttemptTabCompletion()
|
|||||||
// Try to complete the path partially expressed in the last argument!
|
// Try to complete the path partially expressed in the last argument!
|
||||||
char* arg = argv[argc - 1];
|
char* arg = argv[argc - 1];
|
||||||
char* fileFragment = strrchr(arg, '/');
|
char* fileFragment = strrchr(arg, '/');
|
||||||
if (fileFragment) {
|
if (fileFragment != NULL) {
|
||||||
const char* directoryName = (fileFragment == arg) ? "/" : arg;
|
const char* directoryName = (fileFragment == arg) ? "/" : arg;
|
||||||
*fileFragment = '\0';
|
*fileFragment = '\0';
|
||||||
fileFragment++;
|
fileFragment++;
|
||||||
int fragLen = strlen(fileFragment);
|
int fragmentLength = strlen(fileFragment);
|
||||||
|
|
||||||
BDirectory dir(directoryName);
|
BDirectory dir(directoryName);
|
||||||
if (dir.InitCheck() == B_NO_ERROR) {
|
if (dir.InitCheck() == B_NO_ERROR) {
|
||||||
@@ -573,7 +575,7 @@ ShortcutsSpec::_AttemptTabCompletion()
|
|||||||
while (dir.GetNextEntry(&nextEnt) == B_NO_ERROR) {
|
while (dir.GetNextEntry(&nextEnt) == B_NO_ERROR) {
|
||||||
if (nextEnt.GetPath(&nextPath) == B_NO_ERROR) {
|
if (nextEnt.GetPath(&nextPath) == B_NO_ERROR) {
|
||||||
char* filePath = strrchr(nextPath.Path(), '/') + 1;
|
char* filePath = strrchr(nextPath.Path(), '/') + 1;
|
||||||
if (strncmp(filePath, fileFragment, fragLen) == 0) {
|
if (strncmp(filePath, fileFragment, fragmentLength) == 0) {
|
||||||
int len = strlen(filePath);
|
int len = strlen(filePath);
|
||||||
if (len > maxEntryLen)
|
if (len > maxEntryLen)
|
||||||
maxEntryLen = len;
|
maxEntryLen = len;
|
||||||
@@ -586,13 +588,13 @@ ShortcutsSpec::_AttemptTabCompletion()
|
|||||||
|
|
||||||
// Now slowly extend our keyword to its full length, counting
|
// Now slowly extend our keyword to its full length, counting
|
||||||
// numbers of matches at each step. If the match list length
|
// 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
|
// is 1, we can use that whole entry. If it's greater than one,
|
||||||
// , we can use just the match length.
|
// we can use just the match length.
|
||||||
int matchLen = matchList.CountItems();
|
int matchLen = matchList.CountItems();
|
||||||
if (matchLen > 0) {
|
if (matchLen > 0) {
|
||||||
int i;
|
int i;
|
||||||
BString result(fileFragment);
|
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
|
// See if all the matching entries have the same letter
|
||||||
// in the next position... if so, we can go farther.
|
// in the next position... if so, we can go farther.
|
||||||
char commonLetter = '\0';
|
char commonLetter = '\0';
|
||||||
@@ -615,7 +617,7 @@ ShortcutsSpec::_AttemptTabCompletion()
|
|||||||
result.Append(commonLetter, 1);
|
result.Append(commonLetter, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free all the strings we allocated
|
// free all the strings we allocated
|
||||||
for (int k = 0; k < matchLen; k++)
|
for (int k = 0; k < matchLen; k++)
|
||||||
delete [] ((char*)matchList.ItemAt(k));
|
delete [] ((char*)matchList.ItemAt(k));
|
||||||
|
|
||||||
@@ -637,10 +639,10 @@ ShortcutsSpec::_AttemptTabCompletion()
|
|||||||
|
|
||||||
// Remove any trailing slash...
|
// Remove any trailing slash...
|
||||||
const char* fileStr = file.String();
|
const char* fileStr = file.String();
|
||||||
if (fileStr[strlen(fileStr)-1] == '/')
|
if (fileStr[strlen(fileStr) - 1] == '/')
|
||||||
file.RemoveLast("/");
|
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());
|
BDirectory testFileAsDir(file.String());
|
||||||
if ((strcmp(file.String(), "/") != 0)
|
if ((strcmp(file.String(), "/") != 0)
|
||||||
&& (testFileAsDir.InitCheck() == B_NO_ERROR))
|
&& (testFileAsDir.InitCheck() == B_NO_ERROR))
|
||||||
@@ -649,14 +651,15 @@ ShortcutsSpec::_AttemptTabCompletion()
|
|||||||
wholeLine += file;
|
wholeLine += file;
|
||||||
|
|
||||||
SetCommand(wholeLine.String());
|
SetCommand(wholeLine.String());
|
||||||
ret = true;
|
result = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*(fileFragment - 1) = '/';
|
*(fileFragment - 1) = '/';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FreeArgv(argv);
|
FreeArgv(argv);
|
||||||
return ret;
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -664,13 +667,14 @@ bool
|
|||||||
ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes,
|
ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes,
|
||||||
int32 key)
|
int32 key)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool result = false;
|
||||||
|
|
||||||
switch(whichColumn) {
|
switch(whichColumn) {
|
||||||
case KEY_COLUMN_INDEX:
|
case KEY_COLUMN_INDEX:
|
||||||
if (key > -1) {
|
if (key > -1) {
|
||||||
if ((int32)fKey != key) {
|
if ((int32)fKey != key) {
|
||||||
fKey = key;
|
fKey = key;
|
||||||
ret = true;
|
result = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -684,7 +688,7 @@ ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes,
|
|||||||
// trim a char off the string
|
// trim a char off the string
|
||||||
fCommand[fCommandNul - 1] = '\0';
|
fCommand[fCommandNul - 1] = '\0';
|
||||||
fCommandNul--; // note new nul position
|
fCommandNul--; // note new nul position
|
||||||
ret = true;
|
result = true;
|
||||||
_UpdateIconBitmap();
|
_UpdateIconBitmap();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -692,7 +696,7 @@ ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes,
|
|||||||
case B_TAB:
|
case B_TAB:
|
||||||
if (_AttemptTabCompletion()) {
|
if (_AttemptTabCompletion()) {
|
||||||
_UpdateIconBitmap();
|
_UpdateIconBitmap();
|
||||||
ret = true;
|
result = true;
|
||||||
} else
|
} else
|
||||||
beep();
|
beep();
|
||||||
break;
|
break;
|
||||||
@@ -722,7 +726,7 @@ ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes,
|
|||||||
// Here we should be guaranteed enough room.
|
// Here we should be guaranteed enough room.
|
||||||
strncat(fCommand, bytes, fCommandLen);
|
strncat(fCommand, bytes, fCommandLen);
|
||||||
fCommandNul += newCharLen;
|
fCommandNul += newCharLen;
|
||||||
ret = true;
|
result = true;
|
||||||
_UpdateIconBitmap();
|
_UpdateIconBitmap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -731,14 +735,15 @@ ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes,
|
|||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if ((whichColumn >= 0) && (whichColumn < NUM_META_COLUMNS)) {
|
if (whichColumn < 0 || whichColumn >= NUM_META_COLUMNS)
|
||||||
|
break;
|
||||||
|
|
||||||
MetaKeyStateMap * map = &sMetaMaps[whichColumn];
|
MetaKeyStateMap * map = &sMetaMaps[whichColumn];
|
||||||
int curState = fMetaCellStateIndex[whichColumn];
|
int curState = fMetaCellStateIndex[whichColumn];
|
||||||
int origState = curState;
|
int origState = curState;
|
||||||
int numStates = map->GetNumStates();
|
int numStates = map->GetNumStates();
|
||||||
|
|
||||||
switch(bytes[0])
|
switch(bytes[0]) {
|
||||||
{
|
|
||||||
case B_RETURN:
|
case B_RETURN:
|
||||||
// cycle to the previous state
|
// cycle to the previous state
|
||||||
curState = (curState + numStates - 1) % numStates;
|
curState = (curState + numStates - 1) % numStates;
|
||||||
@@ -769,34 +774,34 @@ ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes,
|
|||||||
curState = i;
|
curState = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
printf(B_TRANSLATE("Error, NULL state description?\n"));
|
puts(B_TRANSLATE(
|
||||||
|
"Error, NULL state description?"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fMetaCellStateIndex[whichColumn] = curState;
|
fMetaCellStateIndex[whichColumn] = curState;
|
||||||
|
|
||||||
if (curState != origState)
|
if (curState != origState)
|
||||||
ret = true;
|
result = true;
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
ShortcutsSpec::MyCompare(const CLVListItem* a_Item1, const CLVListItem* a_Item2,
|
ShortcutsSpec::CLVListItemCompare(const CLVListItem* firstItem,
|
||||||
int32 KeyColumn)
|
const CLVListItem* secondItem, int32 keyColumn)
|
||||||
{
|
{
|
||||||
ShortcutsSpec* left = (ShortcutsSpec*) a_Item1;
|
ShortcutsSpec* left = (ShortcutsSpec*) firstItem;
|
||||||
ShortcutsSpec* right = (ShortcutsSpec*) a_Item2;
|
ShortcutsSpec* right = (ShortcutsSpec*) secondItem;
|
||||||
|
|
||||||
int ret = strcmp(left->GetCellText(KeyColumn),
|
int result = strcmp(left->GetCellText(keyColumn),
|
||||||
right->GetCellText(KeyColumn));
|
right->GetCellText(keyColumn));
|
||||||
return (ret > 0) ? 1 : ((ret == 0) ? 0 : -1);
|
|
||||||
|
return result > 0 ? 1 : (result == 0 ? 0 : -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -821,13 +826,14 @@ ShortcutsSpec::_UpdateIconBitmap()
|
|||||||
{
|
{
|
||||||
BString firstWord = ParseArgvZeroFromString(fCommand);
|
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
|
if (fLastBitmapName == NULL || firstWord.Length() == 0
|
||||||
|| firstWord.Compare(fLastBitmapName)) {
|
|| firstWord.Compare(fLastBitmapName)) {
|
||||||
if (firstWord.ByteAt(0) == '*')
|
if (firstWord.ByteAt(0) == '*')
|
||||||
fBitmapValid = IsValidActuatorName(&firstWord.String()[1]);
|
fBitmapValid = IsValidActuatorName(&firstWord.String()[1]);
|
||||||
else {
|
else {
|
||||||
fBitmapValid = false; // default till we prove otherwise!
|
fBitmapValid = false;
|
||||||
|
// default until we prove otherwise
|
||||||
|
|
||||||
if (firstWord.Length() > 0) {
|
if (firstWord.Length() > 0) {
|
||||||
delete [] fLastBitmapName;
|
delete [] fLastBitmapName;
|
||||||
@@ -873,4 +879,3 @@ ShortcutsSpec::_InitModifierNames()
|
|||||||
"Name for modifier on keyboard");
|
"Name for modifier on keyboard");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Jeremy Friesner
|
* Jeremy Friesner
|
||||||
*/
|
*/
|
||||||
#ifndef ShortcutsSpec_h
|
#ifndef SHORTCUTS_SPEC_H
|
||||||
#define ShortcutsSpec_h
|
#define SHORTCUTS_SPEC_H
|
||||||
|
|
||||||
|
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
@@ -19,9 +20,10 @@ class CommandActuator;
|
|||||||
class MetaKeyStateMap;
|
class MetaKeyStateMap;
|
||||||
|
|
||||||
|
|
||||||
MetaKeyStateMap & GetNthKeyMap(int which);
|
MetaKeyStateMap& GetNthKeyMap(int which);
|
||||||
|
|
||||||
/* Objects of this class represent one hotkey "entry" in the preferences
|
/*
|
||||||
|
* Objects of this class represent one hotkey "entry" in the preferences
|
||||||
* ListView. Each ShortcutsSpec contains the info necessary to generate both
|
* ListView. Each ShortcutsSpec contains the info necessary to generate both
|
||||||
* the proper GUI display, and the proper BitFieldTester and CommandActuator
|
* the proper GUI display, and the proper BitFieldTester and CommandActuator
|
||||||
* object for the ShortcutsCatcher add-on to use.
|
* object for the ShortcutsCatcher add-on to use.
|
||||||
@@ -46,8 +48,8 @@ public:
|
|||||||
int32 column_index, bool columnSelected,
|
int32 column_index, bool columnSelected,
|
||||||
bool complete);
|
bool complete);
|
||||||
|
|
||||||
static int MyCompare(const CLVListItem* a_Item1,
|
static int CLVListItemCompare(const CLVListItem* firstItem,
|
||||||
const CLVListItem* a_Item2, int32 KeyColumn);
|
const CLVListItem* secondItem, int32 keyColumn);
|
||||||
|
|
||||||
// Returns the name of the Nth Column.
|
// Returns the name of the Nth Column.
|
||||||
static const char* GetColumnName(int index);
|
static const char* GetColumnName(int index);
|
||||||
@@ -64,8 +66,8 @@ public:
|
|||||||
bool ProcessColumnTextString(int whichColumn,
|
bool ProcessColumnTextString(int whichColumn,
|
||||||
const char* string);
|
const char* string);
|
||||||
|
|
||||||
int32 GetSelectedColumn() const {return fSelectedColumn;}
|
int32 GetSelectedColumn() const { return fSelectedColumn; }
|
||||||
void SetSelectedColumn(int32 i) {fSelectedColumn = i;}
|
void SetSelectedColumn(int32 i) { fSelectedColumn = i; }
|
||||||
|
|
||||||
// default layout of columns is set in here.
|
// default layout of columns is set in here.
|
||||||
enum {
|
enum {
|
||||||
@@ -112,5 +114,5 @@ private:
|
|||||||
static const char* sCommandName;
|
static const char* sCommandName;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
#endif // SHORTCUTS_SPEC_H
|
||||||
|
|||||||
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -57,7 +58,7 @@
|
|||||||
// Because the "shortcuts_settings" file (SHORTCUTS_SETTING_FILE_NAME) is
|
// Because the "shortcuts_settings" file (SHORTCUTS_SETTING_FILE_NAME) is
|
||||||
// already used as a communications method between this configurator and
|
// already used as a communications method between this configurator and
|
||||||
// the "shortcut_catcher" input_server filter, it should not be overloaded
|
// 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
|
#undef B_TRANSLATION_CONTEXT
|
||||||
#define B_TRANSLATION_CONTEXT "ShortcutsWindow"
|
#define B_TRANSLATION_CONTEXT "ShortcutsWindow"
|
||||||
@@ -69,13 +70,13 @@
|
|||||||
// 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.
|
// meta-key.
|
||||||
static BPopUpMenu*
|
static BPopUpMenu*
|
||||||
CreateMetaPopUp(int col)
|
CreateMetaPopUp(int column)
|
||||||
{
|
{
|
||||||
MetaKeyStateMap& map = GetNthKeyMap(col);
|
MetaKeyStateMap& map = GetNthKeyMap(column);
|
||||||
BPopUpMenu * popup = new BPopUpMenu(NULL, false);
|
BPopUpMenu* popup = new BPopUpMenu(NULL, false);
|
||||||
int numStates = map.GetNumStates();
|
int stateCount = map.GetNumStates();
|
||||||
|
|
||||||
for (int i = 0; i < numStates; i++)
|
for (int i = 0; i < stateCount; i++)
|
||||||
popup->AddItem(new BMenuItem(map.GetNthStateDesc(i), NULL));
|
popup->AddItem(new BMenuItem(map.GetNthStateDesc(i), NULL));
|
||||||
|
|
||||||
return popup;
|
return popup;
|
||||||
@@ -90,10 +91,10 @@ CreateKeysPopUp()
|
|||||||
int numKeys = GetNumKeyIndices();
|
int numKeys = GetNumKeyIndices();
|
||||||
for (int i = 0; i < numKeys; i++) {
|
for (int i = 0; i < numKeys; i++) {
|
||||||
const char* next = GetKeyName(i);
|
const char* next = GetKeyName(i);
|
||||||
|
if (next != NULL)
|
||||||
if (next)
|
|
||||||
popup->AddItem(new BMenuItem(next, NULL));
|
popup->AddItem(new BMenuItem(next, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
return popup;
|
return popup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +195,7 @@ ShortcutsWindow::ShortcutsWindow()
|
|||||||
minListWidth += 323.0 + 1;
|
minListWidth += 323.0 + 1;
|
||||||
minListWidth += B_V_SCROLL_BAR_WIDTH;
|
minListWidth += B_V_SCROLL_BAR_WIDTH;
|
||||||
|
|
||||||
fColumnListView->SetSortFunction(ShortcutsSpec::MyCompare);
|
fColumnListView->SetSortFunction(ShortcutsSpec::CLVListItemCompare);
|
||||||
top->AddChild(containerView);
|
top->AddChild(containerView);
|
||||||
|
|
||||||
fColumnListView->SetSelectionMessage(new BMessage(HOTKEY_ITEM_SELECTED));
|
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
|
// is a behind-the-scenes file that the user will never see or
|
||||||
// interact with.
|
// interact with.
|
||||||
BFile windowSettingsFile(&windowSettingsRef, B_READ_ONLY);
|
BFile windowSettingsFile(&windowSettingsRef, B_READ_ONLY);
|
||||||
BMessage loadMsg;
|
BMessage loadMessage;
|
||||||
if (loadMsg.Unflatten(&windowSettingsFile) == B_OK)
|
if (loadMessage.Unflatten(&windowSettingsFile) == B_OK)
|
||||||
_LoadWindowSettings(loadMsg);
|
_LoadWindowSettings(loadMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
entry_ref keySetRef;
|
entry_ref keySetRef;
|
||||||
if (_GetSettingsFile(&keySetRef)) {
|
if (_GetSettingsFile(&keySetRef)) {
|
||||||
BMessage msg(B_REFS_RECEIVED);
|
BMessage message(B_REFS_RECEIVED);
|
||||||
msg.AddRef("refs", &keySetRef);
|
message.AddRef("refs", &keySetRef);
|
||||||
msg.AddString("startupRef", "please");
|
message.AddString("startupRef", "please");
|
||||||
PostMessage(&msg);
|
PostMessage(&message);
|
||||||
// Tell ourselves to load this file if it exists.
|
// tell ourselves to load this file if it exists
|
||||||
}
|
}
|
||||||
|
|
||||||
Show();
|
Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,7 +281,7 @@ ShortcutsWindow::~ShortcutsWindow()
|
|||||||
bool
|
bool
|
||||||
ShortcutsWindow::QuitRequested()
|
ShortcutsWindow::QuitRequested()
|
||||||
{
|
{
|
||||||
bool ret = true;
|
bool result = true;
|
||||||
|
|
||||||
if (fKeySetModified) {
|
if (fKeySetModified) {
|
||||||
BAlert* alert = new BAlert(WARNING,
|
BAlert* alert = new BAlert(WARNING,
|
||||||
@@ -291,11 +293,11 @@ ShortcutsWindow::QuitRequested()
|
|||||||
alert->SetShortcut(2, 's');
|
alert->SetShortcut(2, 's');
|
||||||
switch(alert->Go()) {
|
switch(alert->Go()) {
|
||||||
case 0:
|
case 0:
|
||||||
ret = false;
|
result = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
ret = true;
|
result = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
@@ -309,17 +311,17 @@ ShortcutsWindow::QuitRequested()
|
|||||||
B_TRANSLATE("Oh no"));
|
B_TRANSLATE("Oh no"));
|
||||||
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
|
||||||
alert->Go();
|
alert->Go();
|
||||||
ret = true; //quit anyway
|
result = true; //quit anyway
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PostMessage(SAVE_KEYSET);
|
PostMessage(SAVE_KEYSET);
|
||||||
ret = false;
|
result = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret) {
|
if (result) {
|
||||||
fColumnListView->DeselectAll();
|
fColumnListView->DeselectAll();
|
||||||
|
|
||||||
// Save the window position.
|
// Save the window position.
|
||||||
@@ -330,7 +332,7 @@ ShortcutsWindow::QuitRequested()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -358,41 +360,43 @@ ShortcutsWindow::_SaveKeySet(BEntry& saveEntry)
|
|||||||
if (saveTo.InitCheck() != B_OK)
|
if (saveTo.InitCheck() != B_OK)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
BMessage saveMsg;
|
BMessage saveMessage;
|
||||||
for (int i = 0; i < fColumnListView->CountItems(); i++) {
|
for (int i = 0; i < fColumnListView->CountItems(); i++) {
|
||||||
BMessage next;
|
BMessage next;
|
||||||
if (((ShortcutsSpec*)fColumnListView->ItemAt(i))->Archive(&next)
|
if (((ShortcutsSpec*)fColumnListView->ItemAt(i))->Archive(&next)
|
||||||
== B_OK)
|
== B_OK) {
|
||||||
saveMsg.AddMessage("spec", &next);
|
saveMessage.AddMessage("spec", &next);
|
||||||
else
|
} else
|
||||||
printf("Error archiving ShortcutsSpec #%i!\n", i);
|
printf("Error archiving ShortcutsSpec #%i!\n", i);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ret = (saveMsg.Flatten(&saveTo) == B_OK);
|
bool result = (saveMessage.Flatten(&saveTo) == B_OK);
|
||||||
|
|
||||||
if (ret) {
|
if (result) {
|
||||||
fKeySetModified = false;
|
fKeySetModified = false;
|
||||||
fSaveButton->SetEnabled(false);
|
fSaveButton->SetEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Appends new entries from the file specified in the "spec" entry of
|
// Appends new entries from the file specified in the "spec" entry of
|
||||||
// (loadMsg). Returns true iff successful.
|
// (loadMessage). Returns true iff successful.
|
||||||
bool
|
bool
|
||||||
ShortcutsWindow::_LoadKeySet(const BMessage& loadMsg)
|
ShortcutsWindow::_LoadKeySet(const BMessage& loadMessage)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
BMessage msg;
|
BMessage message;
|
||||||
while (loadMsg.FindMessage("spec", i++, &msg) == B_OK) {
|
while (loadMessage.FindMessage("spec", i++, &message) == B_OK) {
|
||||||
ShortcutsSpec* spec = (ShortcutsSpec*)ShortcutsSpec::Instantiate(&msg);
|
ShortcutsSpec* spec
|
||||||
|
= (ShortcutsSpec*)ShortcutsSpec::Instantiate(&message);
|
||||||
if (spec != NULL)
|
if (spec != NULL)
|
||||||
fColumnListView->AddItem(spec);
|
fColumnListView->AddItem(spec);
|
||||||
else
|
else
|
||||||
printf("_LoadKeySet: Error parsing spec!\n");
|
printf("_LoadKeySet: Error parsing spec!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -432,20 +436,20 @@ ShortcutsWindow::_SaveWindowSettings(BEntry& saveEntry)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Loads the application settings file from (loadMsg) and resizes the interface
|
// Loads the application settings file from (loadMessage) and resizes
|
||||||
// to match the previously saved settings. Because this is a non-essential
|
// the interface to match the previously saved settings. Because this
|
||||||
// file, errors are ignored when loading the settings.
|
// is a non-essential file, errors are ignored when loading the settings.
|
||||||
void
|
void
|
||||||
ShortcutsWindow::_LoadWindowSettings(const BMessage& loadMsg)
|
ShortcutsWindow::_LoadWindowSettings(const BMessage& loadMessage)
|
||||||
{
|
{
|
||||||
BRect frame;
|
BRect frame;
|
||||||
if (loadMsg.FindRect("window frame", &frame) == B_OK) {
|
if (loadMessage.FindRect("window frame", &frame) == B_OK) {
|
||||||
// Ensure the frame does not resize below the computed minimum.
|
// ensure the frame does not resize below the computed minimum.
|
||||||
float width = max_c(Bounds().right, frame.right - frame.left);
|
float width = max_c(Bounds().right, frame.right - frame.left);
|
||||||
float height = max_c(Bounds().bottom, frame.bottom - frame.top);
|
float height = max_c(Bounds().bottom, frame.bottom - frame.top);
|
||||||
ResizeTo(width, height);
|
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);
|
BScreen screen(this);
|
||||||
float left = min_c(screen.Frame().right - width, frame.left);
|
float left = min_c(screen.Frame().right - width, frame.left);
|
||||||
float top = min_c(screen.Frame().bottom - height, frame.top);
|
float top = min_c(screen.Frame().bottom - height, frame.top);
|
||||||
@@ -455,7 +459,7 @@ ShortcutsWindow::_LoadWindowSettings(const BMessage& loadMsg)
|
|||||||
for (int i = 0; i < fColumnListView->CountColumns(); i++) {
|
for (int i = 0; i < fColumnListView->CountColumns(); i++) {
|
||||||
CLVColumn* column = fColumnListView->ColumnAt(i);
|
CLVColumn* column = fColumnListView->ColumnAt(i);
|
||||||
float columnWidth;
|
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));
|
column->SetWidth(max_c(column->Width(), columnWidth));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -486,26 +490,27 @@ ShortcutsWindow::_AddNewSpec(const char* defaultCommand)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ShortcutsWindow::MessageReceived(BMessage* msg)
|
ShortcutsWindow::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch(msg->what) {
|
switch(message->what) {
|
||||||
case OPEN_KEYSET:
|
case OPEN_KEYSET:
|
||||||
case APPEND_KEYSET:
|
case APPEND_KEYSET:
|
||||||
fLastOpenWasAppend = (msg->what == APPEND_KEYSET);
|
fLastOpenWasAppend = (message->what == APPEND_KEYSET);
|
||||||
if (fOpenPanel)
|
if (fOpenPanel)
|
||||||
fOpenPanel->Show();
|
fOpenPanel->Show();
|
||||||
else {
|
else {
|
||||||
BMessenger m(this);
|
BMessenger messenger(this);
|
||||||
fOpenPanel = new BFilePanel(B_OPEN_PANEL, &m, NULL, 0, false);
|
fOpenPanel = new BFilePanel(B_OPEN_PANEL, &messenger, NULL,
|
||||||
|
0, false);
|
||||||
fOpenPanel->Show();
|
fOpenPanel->Show();
|
||||||
}
|
}
|
||||||
fOpenPanel->SetButtonLabel(B_DEFAULT_BUTTON, fLastOpenWasAppend ?
|
fOpenPanel->SetButtonLabel(B_DEFAULT_BUTTON, fLastOpenWasAppend ?
|
||||||
B_TRANSLATE("Append") : B_TRANSLATE("Open"));
|
B_TRANSLATE("Append") : B_TRANSLATE("Open"));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// send a message to myself, to get me to reload the settings file
|
||||||
case REVERT_KEYSET:
|
case REVERT_KEYSET:
|
||||||
{
|
{
|
||||||
// Send a message to myself, to get me to reload the settings file
|
|
||||||
fLastOpenWasAppend = false;
|
fLastOpenWasAppend = false;
|
||||||
BMessage reload(B_REFS_RECEIVED);
|
BMessage reload(B_REFS_RECEIVED);
|
||||||
entry_ref eref;
|
entry_ref eref;
|
||||||
@@ -516,13 +521,13 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Respond to drag-and-drop messages here
|
// respond to drag-and-drop messages here
|
||||||
case B_SIMPLE_DATA:
|
case B_SIMPLE_DATA:
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
while (msg->FindRef("refs", i++, &ref) == B_OK) {
|
while (message->FindRef("refs", i++, &ref) == B_OK) {
|
||||||
BEntry entry(&ref);
|
BEntry entry(&ref);
|
||||||
if (entry.InitCheck() == B_OK) {
|
if (entry.InitCheck() == B_OK) {
|
||||||
BPath path(&entry);
|
BPath path(&entry);
|
||||||
@@ -538,13 +543,13 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Respond to FileRequester's messages here
|
// respond to FileRequester's messages here
|
||||||
case B_REFS_RECEIVED:
|
case B_REFS_RECEIVED:
|
||||||
{
|
{
|
||||||
// Find file ref
|
// Find file ref
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
bool isStartMsg = msg->HasString("startupRef");
|
bool isStartMsg = message->HasString("startupRef");
|
||||||
if (msg->FindRef("refs", &ref) == B_OK) {
|
if (message->FindRef("refs", &ref) == B_OK) {
|
||||||
// load the file into (fileMsg)
|
// load the file into (fileMsg)
|
||||||
BMessage fileMsg;
|
BMessage fileMsg;
|
||||||
{
|
{
|
||||||
@@ -596,22 +601,20 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
|
|||||||
break;
|
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:
|
case SELECT_APPLICATION:
|
||||||
{
|
{
|
||||||
int csel = fColumnListView->CurrentSelection();
|
int csel = fColumnListView->CurrentSelection();
|
||||||
if (csel >= 0) {
|
if (csel >= 0) {
|
||||||
entry_ref aref;
|
entry_ref aref;
|
||||||
if (msg->FindRef("refs", &aref) == B_OK) {
|
if (message->FindRef("refs", &aref) == B_OK) {
|
||||||
BEntry ent(&aref);
|
BEntry ent(&aref);
|
||||||
if (ent.InitCheck() == B_OK) {
|
if (ent.InitCheck() == B_OK) {
|
||||||
BPath path;
|
BPath path;
|
||||||
if ((ent.GetPath(&path) == B_OK)
|
if ((ent.GetPath(&path) == B_OK)
|
||||||
&& (((ShortcutsSpec *)
|
&& (((ShortcutsSpec*)fColumnListView->ItemAt(csel))->
|
||||||
fColumnListView->ItemAt(csel))->
|
ProcessColumnTextString(ShortcutsSpec::STRING_COLUMN_INDEX,
|
||||||
ProcessColumnTextString(ShortcutsSpec::
|
path.Path()))) {
|
||||||
STRING_COLUMN_INDEX, path.Path()))) {
|
|
||||||
|
|
||||||
fColumnListView->InvalidateItem(csel);
|
fColumnListView->InvalidateItem(csel);
|
||||||
_MarkKeySetModified();
|
_MarkKeySetModified();
|
||||||
}
|
}
|
||||||
@@ -625,10 +628,10 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
|
|||||||
{
|
{
|
||||||
bool showSaveError = false;
|
bool showSaveError = false;
|
||||||
|
|
||||||
const char * name;
|
const char* name;
|
||||||
entry_ref entry;
|
entry_ref entry;
|
||||||
if ((msg->FindString("name", &name) == B_OK)
|
if ((message->FindString("name", &name) == B_OK)
|
||||||
&& (msg->FindRef("directory", &entry) == B_OK)) {
|
&& (message->FindRef("directory", &entry) == B_OK)) {
|
||||||
BDirectory dir(&entry);
|
BDirectory dir(&entry);
|
||||||
BEntry saveTo(&dir, name, true);
|
BEntry saveTo(&dir, name, true);
|
||||||
showSaveError = ((saveTo.InitCheck() != B_OK)
|
showSaveError = ((saveTo.InitCheck() != B_OK)
|
||||||
@@ -636,7 +639,9 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
|
|||||||
} else if (fLastSaved.InitCheck() == B_OK) {
|
} else if (fLastSaved.InitCheck() == B_OK) {
|
||||||
// We've saved this before, save over previous file.
|
// We've saved this before, save over previous file.
|
||||||
showSaveError = (_SaveKeySet(fLastSaved) == false);
|
showSaveError = (_SaveKeySet(fLastSaved) == false);
|
||||||
} else PostMessage(SAVE_KEYSET_AS); // open the save requester...
|
} else
|
||||||
|
PostMessage(SAVE_KEYSET_AS);
|
||||||
|
// open the save requester...
|
||||||
|
|
||||||
if (showSaveError) {
|
if (showSaveError) {
|
||||||
BAlert* alert = new BAlert(ERROR,
|
BAlert* alert = new BAlert(ERROR,
|
||||||
@@ -653,10 +658,10 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
|
|||||||
if (fSavePanel)
|
if (fSavePanel)
|
||||||
fSavePanel->Show();
|
fSavePanel->Show();
|
||||||
else {
|
else {
|
||||||
BMessage msg(SAVE_KEYSET);
|
BMessage message(SAVE_KEYSET);
|
||||||
BMessenger messenger(this);
|
BMessenger messenger(this);
|
||||||
fSavePanel = new BFilePanel(B_SAVE_PANEL, &messenger, NULL, 0,
|
fSavePanel = new BFilePanel(B_SAVE_PANEL, &messenger, NULL, 0,
|
||||||
false, &msg);
|
false, &message);
|
||||||
fSavePanel->Show();
|
fSavePanel->Show();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -698,7 +703,7 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
|
|||||||
case HOTKEY_ITEM_SELECTED:
|
case HOTKEY_ITEM_SELECTED:
|
||||||
{
|
{
|
||||||
int32 index = -1;
|
int32 index = -1;
|
||||||
msg->FindInt32("index", &index);
|
message->FindInt32("index", &index);
|
||||||
bool validItem = (index >= 0);
|
bool validItem = (index >= 0);
|
||||||
fRemoveButton->SetEnabled(validItem);
|
fRemoveButton->SetEnabled(validItem);
|
||||||
break;
|
break;
|
||||||
@@ -709,8 +714,8 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
|
|||||||
{
|
{
|
||||||
int32 row, column;
|
int32 row, column;
|
||||||
|
|
||||||
if ((msg->FindInt32("row", &row) == B_OK)
|
if ((message->FindInt32("row", &row) == B_OK)
|
||||||
&& (msg->FindInt32("column", &column) == B_OK)) {
|
&& (message->FindInt32("column", &column) == B_OK)) {
|
||||||
int32 key;
|
int32 key;
|
||||||
const char* bytes;
|
const char* bytes;
|
||||||
|
|
||||||
@@ -719,27 +724,27 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
|
|||||||
fColumnListView->ItemAt(row);
|
fColumnListView->ItemAt(row);
|
||||||
bool repaintNeeded = false; // default
|
bool repaintNeeded = false; // default
|
||||||
|
|
||||||
if (msg->HasInt32("mouseClick")) {
|
if (message->HasInt32("mouseClick")) {
|
||||||
repaintNeeded = item->ProcessColumnMouseClick(column);
|
repaintNeeded = item->ProcessColumnMouseClick(column);
|
||||||
} else if ((msg->FindString("bytes", &bytes) == B_OK)
|
} else if ((message->FindString("bytes", &bytes) == B_OK)
|
||||||
&& (msg->FindInt32("key", &key) == B_OK)) {
|
&& (message->FindInt32("key", &key) == B_OK)) {
|
||||||
repaintNeeded = item->ProcessColumnKeyStroke(column,
|
repaintNeeded = item->ProcessColumnKeyStroke(column,
|
||||||
bytes, key);
|
bytes, key);
|
||||||
} else if (msg->FindInt32("unmappedkey", &key) ==
|
} else if (message->FindInt32("unmappedkey", &key) ==
|
||||||
B_OK) {
|
B_OK) {
|
||||||
repaintNeeded = ((column == item->KEY_COLUMN_INDEX)
|
repaintNeeded = ((column == item->KEY_COLUMN_INDEX)
|
||||||
&& ((key > 0xFF) || (GetKeyName(key) != NULL))
|
&& ((key > 0xFF) || (GetKeyName(key) != NULL))
|
||||||
&& (item->ProcessColumnKeyStroke(column, NULL,
|
&& (item->ProcessColumnKeyStroke(column, NULL,
|
||||||
key)));
|
key)));
|
||||||
} else if (msg->FindString("text", &bytes) == B_OK) {
|
} else if (message->FindString("text", &bytes) == B_OK) {
|
||||||
if ((bytes[0] == '(')&&(bytes[1] == 'C')) {
|
if ((bytes[0] == '(')&&(bytes[1] == 'C')) {
|
||||||
if (fSelectPanel)
|
if (fSelectPanel)
|
||||||
fSelectPanel->Show();
|
fSelectPanel->Show();
|
||||||
else {
|
else {
|
||||||
BMessage msg(SELECT_APPLICATION);
|
BMessage message(SELECT_APPLICATION);
|
||||||
BMessenger m(this);
|
BMessenger m(this);
|
||||||
fSelectPanel = new BFilePanel(B_OPEN_PANEL, &m,
|
fSelectPanel = new BFilePanel(B_OPEN_PANEL, &m,
|
||||||
NULL, 0, false, &msg);
|
NULL, 0, false, &message);
|
||||||
fSelectPanel->Show();
|
fSelectPanel->Show();
|
||||||
}
|
}
|
||||||
fSelectPanel->SetButtonLabel(B_DEFAULT_BUTTON,
|
fSelectPanel->SetButtonLabel(B_DEFAULT_BUTTON,
|
||||||
@@ -760,7 +765,7 @@ ShortcutsWindow::MessageReceived(BMessage* msg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BWindow::MessageReceived(msg);
|
BWindow::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -788,9 +793,9 @@ ShortcutsWindow::Quit()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ShortcutsWindow::DispatchMessage(BMessage* msg, BHandler* handler)
|
ShortcutsWindow::DispatchMessage(BMessage* message, BHandler* handler)
|
||||||
{
|
{
|
||||||
switch(msg->what) {
|
switch(message->what) {
|
||||||
case B_COPY:
|
case B_COPY:
|
||||||
case B_CUT:
|
case B_CUT:
|
||||||
if (be_clipboard->Lock()) {
|
if (be_clipboard->Lock()) {
|
||||||
@@ -808,7 +813,7 @@ ShortcutsWindow::DispatchMessage(BMessage* msg, BHandler* handler)
|
|||||||
strlen(spec->GetCellText(column)));
|
strlen(spec->GetCellText(column)));
|
||||||
be_clipboard->Commit();
|
be_clipboard->Commit();
|
||||||
|
|
||||||
if (msg->what == B_CUT) {
|
if (message->what == B_CUT) {
|
||||||
spec->ProcessColumnTextString(column, "");
|
spec->ProcessColumnTextString(column, "");
|
||||||
_MarkKeySetModified();
|
_MarkKeySetModified();
|
||||||
fColumnListView->InvalidateItem(row);
|
fColumnListView->InvalidateItem(row);
|
||||||
@@ -847,8 +852,7 @@ ShortcutsWindow::DispatchMessage(BMessage* msg, BHandler* handler)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BWindow::DispatchMessage(msg, handler);
|
BWindow::DispatchMessage(message, handler);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Jeremy Friesner
|
* Jeremy Friesner
|
||||||
*/
|
*/
|
||||||
#ifndef ShortcutsWindow_h
|
#ifndef SHORTCUTS_WINDOW_H
|
||||||
#define ShortcutsWindow_h
|
#define SHORTCUTS_WINDOW_H
|
||||||
|
|
||||||
|
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
@@ -14,6 +15,7 @@
|
|||||||
|
|
||||||
#include "ColumnListView.h"
|
#include "ColumnListView.h"
|
||||||
|
|
||||||
|
|
||||||
class BButton;
|
class BButton;
|
||||||
class BFilePanel;
|
class BFilePanel;
|
||||||
class BMessage;
|
class BMessage;
|
||||||
@@ -24,9 +26,10 @@ public:
|
|||||||
ShortcutsWindow();
|
ShortcutsWindow();
|
||||||
~ShortcutsWindow();
|
~ShortcutsWindow();
|
||||||
|
|
||||||
virtual void DispatchMessage(BMessage* msg, BHandler* handler);
|
virtual void DispatchMessage(BMessage* message,
|
||||||
|
BHandler* handler);
|
||||||
virtual void Quit();
|
virtual void Quit();
|
||||||
virtual void MessageReceived(BMessage* msg);
|
virtual void MessageReceived(BMessage* message);
|
||||||
virtual bool QuitRequested();
|
virtual bool QuitRequested();
|
||||||
|
|
||||||
// BMessage 'what' codes, representing commands understood by this Window.
|
// BMessage 'what' codes, representing commands understood by this Window.
|
||||||
@@ -49,15 +52,17 @@ public:
|
|||||||
SELECT_APPLICATION, // Set the current entry to point to the
|
SELECT_APPLICATION, // Set the current entry to point to the
|
||||||
// given file.
|
// given file.
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BMenuItem* _CreateActuatorPresetMenuItem(const char* label)
|
BMenuItem* _CreateActuatorPresetMenuItem(const char* label)
|
||||||
const;
|
const;
|
||||||
void _AddNewSpec(const char* defaultCommand);
|
void _AddNewSpec(const char* defaultCommand);
|
||||||
void _MarkKeySetModified();
|
void _MarkKeySetModified();
|
||||||
bool _LoadKeySet(const BMessage& loadMsg);
|
bool _LoadKeySet(const BMessage& loadMessage);
|
||||||
bool _SaveKeySet(BEntry& saveEntry);
|
bool _SaveKeySet(BEntry& saveEntry);
|
||||||
bool _GetSettingsFile(entry_ref* ref);
|
bool _GetSettingsFile(entry_ref* ref);
|
||||||
void _LoadWindowSettings(const BMessage& loadMsg);
|
void _LoadWindowSettings(
|
||||||
|
const BMessage& loadMessage);
|
||||||
void _SaveWindowSettings(BEntry& saveEntry);
|
void _SaveWindowSettings(BEntry& saveEntry);
|
||||||
bool _GetWindowSettingsFile(entry_ref* ref);
|
bool _GetWindowSettingsFile(entry_ref* ref);
|
||||||
|
|
||||||
@@ -65,9 +70,12 @@ private:
|
|||||||
BButton* fRemoveButton;
|
BButton* fRemoveButton;
|
||||||
BButton* fSaveButton;
|
BButton* fSaveButton;
|
||||||
ColumnListView* fColumnListView;
|
ColumnListView* fColumnListView;
|
||||||
BFilePanel* fSavePanel; // for saving settings
|
BFilePanel* fSavePanel;
|
||||||
BFilePanel* fOpenPanel; // for loading settings
|
// for saving settings
|
||||||
BFilePanel* fSelectPanel; // for selecting apps to launch
|
BFilePanel* fOpenPanel;
|
||||||
|
// for loading settings
|
||||||
|
BFilePanel* fSelectPanel;
|
||||||
|
// for selecting apps to launch
|
||||||
|
|
||||||
// Points to the settings file to save to
|
// Points to the settings file to save to
|
||||||
BEntry fLastSaved;
|
BEntry fLastSaved;
|
||||||
@@ -80,5 +88,4 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif // SHORTCUTS_WINDOW_H
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
#define CLVColumn_CPP
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "CLVColumn.h"
|
#include "CLVColumn.h"
|
||||||
#include "ColumnListView.h"
|
#include "ColumnListView.h"
|
||||||
#include "CLVColumnLabelView.h"
|
#include "CLVColumnLabelView.h"
|
||||||
|
|
||||||
|
|
||||||
//******************************************************************************************************
|
CLVColumn::CLVColumn(const char* label, BPopUpMenu* popup, float width,
|
||||||
//**** CLVColumn CLASS DEFINITION
|
uint32 flags, float minWidth)
|
||||||
//******************************************************************************************************
|
|
||||||
CLVColumn::CLVColumn(const char* label,BPopUpMenu * popup,float width,uint32 flags,float min_width)
|
|
||||||
{
|
{
|
||||||
fPopup = popup;
|
fPopup = popup;
|
||||||
|
|
||||||
if(flags & CLV_EXPANDER)
|
if (flags & CLV_EXPANDER) {
|
||||||
{
|
|
||||||
label = NULL;
|
label = NULL;
|
||||||
width = 20.0;
|
width = 20.0;
|
||||||
min_width = 20.0;
|
minWidth = 20.0;
|
||||||
flags &= CLV_NOT_MOVABLE | CLV_LOCK_AT_BEGINNING | CLV_HIDDEN | CLV_LOCK_WITH_RIGHT;
|
flags &= CLV_NOT_MOVABLE | CLV_LOCK_AT_BEGINNING | CLV_HIDDEN
|
||||||
|
| CLV_LOCK_WITH_RIGHT;
|
||||||
flags |= CLV_EXPANDER | CLV_NOT_RESIZABLE | CLV_MERGE_WITH_RIGHT;
|
flags |= CLV_EXPANDER | CLV_NOT_RESIZABLE | CLV_MERGE_WITH_RIGHT;
|
||||||
}
|
}
|
||||||
if(min_width < 4.0)
|
|
||||||
min_width = 4.0;
|
if (minWidth < 4.0)
|
||||||
if(width < min_width)
|
minWidth = 4.0;
|
||||||
width = min_width;
|
|
||||||
if(label)
|
if (width < minWidth)
|
||||||
{
|
width = minWidth;
|
||||||
fLabel = new char[strlen(label)+1];
|
|
||||||
strcpy((char*)fLabel,label);
|
if (label != NULL) {
|
||||||
}
|
fLabel = new char[strlen(label) + 1];
|
||||||
else
|
strcpy((char*)fLabel, label);
|
||||||
|
} else
|
||||||
fLabel = NULL;
|
fLabel = NULL;
|
||||||
|
|
||||||
fWidth = width;
|
fWidth = width;
|
||||||
fMinWidth = min_width;
|
fMinWidth = minWidth;
|
||||||
fFlags = flags;
|
fFlags = flags;
|
||||||
fPushedByExpander = false;
|
fPushedByExpander = false;
|
||||||
fParent = NULL;
|
fParent = NULL;
|
||||||
fSortMode = NoSort;
|
fSortMode = SORT_MODE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CLVColumn::~CLVColumn()
|
CLVColumn::~CLVColumn()
|
||||||
{
|
{
|
||||||
delete [] fLabel;
|
delete[] fLabel;
|
||||||
if(fParent) fParent->RemoveColumn(this);
|
if (fParent != NULL)
|
||||||
|
fParent->RemoveColumn(this);
|
||||||
|
|
||||||
delete fPopup;
|
delete fPopup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float CLVColumn::Width() const
|
float
|
||||||
|
CLVColumn::Width() const
|
||||||
{
|
{
|
||||||
return fWidth;
|
return fWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CLVColumn::SetWidth(float width)
|
void
|
||||||
|
CLVColumn::SetWidth(float width)
|
||||||
{
|
{
|
||||||
if(width < fMinWidth)
|
if(width < fMinWidth)
|
||||||
width = fMinWidth;
|
width = fMinWidth;
|
||||||
if(width != fWidth)
|
|
||||||
{
|
if(width != fWidth) {
|
||||||
float OldWidth = fWidth;
|
float oldWidth = fWidth;
|
||||||
fWidth = width;
|
fWidth = width;
|
||||||
if(IsShown() && fParent)
|
if (IsShown() && fParent != NULL) {
|
||||||
{
|
BWindow* parentWindow = fParent->Window();
|
||||||
BWindow* ParentWindow = fParent->Window();
|
if (parentWindow != NULL)
|
||||||
if(ParentWindow)
|
parentWindow->Lock();
|
||||||
ParentWindow->Lock();
|
|
||||||
//Figure out the area after this column to scroll
|
// figure out the area after this column to scroll
|
||||||
BRect ColumnViewBounds = fParent->fColumnLabelView->Bounds();
|
BRect ColumnViewBounds = fParent->fColumnLabelView->Bounds();
|
||||||
BRect MainViewBounds = fParent->Bounds();
|
BRect MainViewBounds = fParent->Bounds();
|
||||||
BRect SourceArea = ColumnViewBounds;
|
BRect sourceArea = ColumnViewBounds;
|
||||||
SourceArea.left = fColumnEnd+1.0;
|
sourceArea.left = fColumnEnd + 1.0;
|
||||||
BRect DestArea = SourceArea;
|
BRect destArea = sourceArea;
|
||||||
float Delta = width-OldWidth;
|
float delta = width-oldWidth;
|
||||||
DestArea.left += Delta;
|
destArea.left += delta;
|
||||||
DestArea.right += Delta;
|
destArea.right += delta;
|
||||||
float LimitShift;
|
float LimitShift;
|
||||||
if(DestArea.right > ColumnViewBounds.right)
|
if (destArea.right > ColumnViewBounds.right) {
|
||||||
{
|
LimitShift = destArea.right-ColumnViewBounds.right;
|
||||||
LimitShift = DestArea.right-ColumnViewBounds.right;
|
destArea.right -= LimitShift;
|
||||||
DestArea.right -= LimitShift;
|
sourceArea.right -= LimitShift;
|
||||||
SourceArea.right -= LimitShift;
|
|
||||||
}
|
}
|
||||||
if(DestArea.left < ColumnViewBounds.left)
|
if (destArea.left < ColumnViewBounds.left) {
|
||||||
{
|
LimitShift = ColumnViewBounds.left - destArea.left;
|
||||||
LimitShift = ColumnViewBounds.left - DestArea.left;
|
destArea.left += LimitShift;
|
||||||
DestArea.left += LimitShift;
|
sourceArea.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
|
// scroll the area that is being shifted
|
||||||
DestArea = ColumnViewBounds;
|
if(parentWindow)
|
||||||
if(width > OldWidth)
|
parentWindow->UpdateIfNeeded();
|
||||||
{
|
|
||||||
DestArea.left = fColumnEnd+1.0;
|
fParent->fColumnLabelView->CopyBits(sourceArea, destArea);
|
||||||
DestArea.right = fColumnEnd+Delta;
|
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
|
else
|
||||||
{
|
destArea.left = fColumnEnd + delta;
|
||||||
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.right = destArea.left;
|
||||||
DestArea = ColumnViewBounds;
|
fParent->fColumnLabelView->Invalidate(destArea);
|
||||||
if(width > OldWidth)
|
|
||||||
DestArea.left = fColumnEnd;
|
|
||||||
else
|
|
||||||
DestArea.left = fColumnEnd + Delta;
|
|
||||||
DestArea.right = DestArea.left;
|
|
||||||
fParent->fColumnLabelView->Invalidate(DestArea);
|
|
||||||
|
|
||||||
//Update the column sizes, positions and group positions
|
// update the column sizes, positions and group positions
|
||||||
fParent->UpdateColumnSizesDataRectSizeScrollBars();
|
fParent->ShiftDragGroup();
|
||||||
fParent->fColumnLabelView->UpdateDragGroups();
|
fParent->fColumnLabelView->UpdateDragGroups();
|
||||||
if(ParentWindow)
|
if(parentWindow)
|
||||||
ParentWindow->Unlock();
|
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;
|
return fFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CLVColumn::IsShown() const
|
bool
|
||||||
|
CLVColumn::IsShown() const
|
||||||
{
|
{
|
||||||
if(fFlags & CLV_HIDDEN)
|
if ((fFlags & CLV_HIDDEN) != 0)
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CLVColumn::SetShown(bool Shown)
|
void
|
||||||
|
CLVColumn::SetShown(bool show)
|
||||||
{
|
{
|
||||||
bool shown = IsShown();
|
bool shown = IsShown();
|
||||||
if(shown != Shown)
|
if (shown != show) {
|
||||||
{
|
if (show)
|
||||||
if(Shown)
|
|
||||||
fFlags &= 0xFFFFFFFF^CLV_HIDDEN;
|
fFlags &= 0xFFFFFFFF^CLV_HIDDEN;
|
||||||
else
|
else
|
||||||
fFlags |= CLV_HIDDEN;
|
fFlags |= CLV_HIDDEN;
|
||||||
if(fParent)
|
|
||||||
{
|
if (fParent != NULL) {
|
||||||
float UpdateLeft = fColumnBegin;
|
float updateLeft = fColumnBegin;
|
||||||
BWindow* ParentWindow = fParent->Window();
|
BWindow* parentWindow = fParent->Window();
|
||||||
if(ParentWindow)
|
if (parentWindow != NULL)
|
||||||
ParentWindow->Lock();
|
parentWindow->Lock();
|
||||||
fParent->UpdateColumnSizesDataRectSizeScrollBars();
|
|
||||||
|
fParent->ShiftDragGroup();
|
||||||
fParent->fColumnLabelView->UpdateDragGroups();
|
fParent->fColumnLabelView->UpdateDragGroups();
|
||||||
if(Shown)
|
if (show)
|
||||||
UpdateLeft = fColumnBegin;
|
updateLeft = fColumnBegin;
|
||||||
BRect Area = fParent->fColumnLabelView->Bounds();
|
|
||||||
Area.left = UpdateLeft;
|
BRect area = fParent->fColumnLabelView->Bounds();
|
||||||
fParent->fColumnLabelView->Invalidate(Area);
|
area.left = updateLeft;
|
||||||
Area = fParent->Bounds();
|
fParent->fColumnLabelView->Invalidate(area);
|
||||||
Area.left = UpdateLeft;
|
area = fParent->Bounds();
|
||||||
fParent->Invalidate(Area);
|
area.left = updateLeft;
|
||||||
if(fFlags & CLV_EXPANDER)
|
fParent->Invalidate(area);
|
||||||
{
|
if ((fFlags & CLV_EXPANDER) != 0) {
|
||||||
if(!Shown)
|
if (!show)
|
||||||
fParent->fExpanderColumn = -1;
|
fParent->fExpanderColumn = -1;
|
||||||
else
|
else
|
||||||
fParent->fExpanderColumn = fParent->IndexOfColumn(this);
|
fParent->fExpanderColumn = fParent->IndexOfColumn(this);
|
||||||
}
|
}
|
||||||
if(ParentWindow)
|
if (parentWindow != NULL)
|
||||||
ParentWindow->Unlock();
|
parentWindow->Unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CLVSortMode CLVColumn::SortMode() const
|
CLVSortMode
|
||||||
|
CLVColumn::SortMode() const
|
||||||
{
|
{
|
||||||
return fSortMode;
|
return fSortMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLVColumn::SetSortMode(CLVSortMode mode)
|
|
||||||
|
void
|
||||||
|
CLVColumn::SetSortMode(CLVSortMode mode)
|
||||||
{
|
{
|
||||||
if(fParent)
|
if (fParent != NULL)
|
||||||
fParent->SetSortMode(fParent->IndexOfColumn(this),mode);
|
fParent->SetSortMode(fParent->IndexOfColumn(this), mode);
|
||||||
else
|
else
|
||||||
fSortMode = mode;
|
fSortMode = mode;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,98 +1,107 @@
|
|||||||
#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 <support/SupportDefs.h>
|
||||||
#include <interface/PopUpMenu.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 ColumnListView;
|
||||||
class CLVColumn;
|
class CLVColumn;
|
||||||
class CLVListItem;
|
class CLVListItem;
|
||||||
|
|
||||||
|
|
||||||
//******************************************************************************************************
|
class CLVColumn {
|
||||||
//**** CONSTANTS
|
public:
|
||||||
//******************************************************************************************************
|
CLVColumn(const char* label,
|
||||||
//Flags
|
BPopUpMenu* popup = NULL,
|
||||||
enum
|
float width = 20.0, uint32 flags = 0L,
|
||||||
{
|
|
||||||
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
|
|
||||||
{
|
|
||||||
Ascending,
|
|
||||||
Descending,
|
|
||||||
NoSort
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
//******************************************************************************************************
|
|
||||||
//**** 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);
|
float min_width = 20.0);
|
||||||
virtual ~CLVColumn();
|
virtual ~CLVColumn();
|
||||||
|
|
||||||
//Archival stuff
|
// Archival stuff
|
||||||
/* Not implemented yet
|
/* Not implemented yet
|
||||||
CLVColumn(BMessage* archive);
|
CLVColumn(BMessage* archive);
|
||||||
static CLVColumn* Instantiate(BMessage* data);
|
static CLVColumn* Instantiate(BMessage* data);
|
||||||
virtual status_t Archive(BMessage* data, bool deep = true) const;
|
virtual status_t Archive(BMessage* data, bool deep = true) const;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//Functions
|
// Functions
|
||||||
float Width() const;
|
float Width() const;
|
||||||
virtual void SetWidth(float width); //Can be overridden to detect changes to the column width
|
virtual void SetWidth(float width);
|
||||||
//however since you are probably overriding
|
// Can be overridden to detect changes to the column width
|
||||||
//ColumnListView and dealing with an array of columns
|
// however since you are probably overriding ColumnListView
|
||||||
//anyway, it is probably more useful to override
|
// and dealing with an array of columns anyway, it is
|
||||||
//ColumnListView::ColumnWidthChanged to detect changes to
|
// probably more useful to override
|
||||||
//column widths
|
// ColumnListView::ColumnWidthChanged to detect changes to
|
||||||
|
// column widths
|
||||||
uint32 Flags() const;
|
uint32 Flags() const;
|
||||||
bool IsShown() const;
|
bool IsShown() const;
|
||||||
void SetShown(bool shown);
|
void SetShown(bool show);
|
||||||
CLVSortMode SortMode() const;
|
CLVSortMode SortMode() const;
|
||||||
void SetSortMode(CLVSortMode mode);
|
void SetSortMode(CLVSortMode mode);
|
||||||
const char * GetLabel() const {return fLabel;}
|
const char* GetLabel() const { return fLabel; }
|
||||||
BPopUpMenu * GetPopup() {return fPopup;}
|
BPopUpMenu* GetPopup() { return fPopup; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class ColumnListView;
|
friend class ColumnListView;
|
||||||
friend class CLVColumnLabelView;
|
friend class CLVColumnLabelView;
|
||||||
friend class CLVListItem;
|
friend class CLVListItem;
|
||||||
|
|
||||||
const char *fLabel;
|
const char* fLabel;
|
||||||
float fWidth;
|
float fWidth;
|
||||||
float fMinWidth;
|
float fMinWidth;
|
||||||
float fColumnBegin;
|
float fColumnBegin;
|
||||||
@@ -101,7 +110,9 @@ class CLVColumn
|
|||||||
bool fPushedByExpander;
|
bool fPushedByExpander;
|
||||||
CLVSortMode fSortMode;
|
CLVSortMode fSortMode;
|
||||||
ColumnListView* fParent;
|
ColumnListView* fParent;
|
||||||
BPopUpMenu * fPopup; // added by jaf
|
BPopUpMenu* fPopup;
|
||||||
|
// added by jaf
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
#endif // CLV_COLUMN_H
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -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 <support/SupportDefs.h>
|
||||||
#include <InterfaceKit.h>
|
#include <InterfaceKit.h>
|
||||||
|
|
||||||
//******************************************************************************************************
|
|
||||||
//**** PROJECT HEADER FILES AND CLASS NAME DECLARATIONS
|
|
||||||
//******************************************************************************************************
|
|
||||||
class ColumnListView;
|
class ColumnListView;
|
||||||
class CLVColumn;
|
class CLVColumn;
|
||||||
|
|
||||||
|
|
||||||
//******************************************************************************************************
|
|
||||||
//**** CLASS AND STRUCTURE DECLARATIONS, ASSOCIATED CONSTANTS AND STATIC FUNCTIONS
|
|
||||||
//******************************************************************************************************
|
|
||||||
struct CLVDragGroup
|
struct CLVDragGroup
|
||||||
{
|
{
|
||||||
int32 GroupStartDispListIndex; //Indices in the column display list where this group starts
|
int32 groupStartDisplayListIndex;
|
||||||
int32 GroupStopDispListIndex; //and finishes
|
// indices in the column display list where this group starts
|
||||||
float GroupBegin,GroupEnd; //-1.0 if whole group is hidden
|
int32 groupStopDisplayListIndex;
|
||||||
CLVColumn* LastColumnShown;
|
// and finishes
|
||||||
bool AllLockBeginning;
|
float groupBeginIndex;
|
||||||
bool AllLockEnd;
|
// -1.0 if whole group is hidden
|
||||||
bool Shown; //False if none of the columns in this group are shown
|
float groupEndIndex;
|
||||||
uint32 Flags; //Uses CLV_NOT_MOVABLE, CLV_LOCK_AT_BEGINNING, CLV_LOCK_AT_END
|
// -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
|
class CLVColumnLabelView : public BView
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//Constructor and destructor
|
CLVColumnLabelView(BRect frame,
|
||||||
CLVColumnLabelView(BRect Bounds,ColumnListView* Parent,const BFont* Font);
|
ColumnListView* parent,
|
||||||
|
const BFont* font);
|
||||||
~CLVColumnLabelView();
|
~CLVColumnLabelView();
|
||||||
|
|
||||||
//BView overrides
|
// BView overrides
|
||||||
void Draw(BRect UpdateRect);
|
void Draw(BRect UpdateRect);
|
||||||
void MouseDown(BPoint Point);
|
void MouseDown(BPoint Point);
|
||||||
void MessageReceived(BMessage *message);
|
void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class ColumnListView;
|
friend class ColumnListView;
|
||||||
friend class CLVColumn;
|
friend class CLVColumn;
|
||||||
|
|
||||||
|
void ShiftDragGroup(int32 newPosition);
|
||||||
|
void UpdateDragGroups();
|
||||||
|
void SetSnapMinMax();
|
||||||
|
|
||||||
float fFontAscent;
|
float fFontAscent;
|
||||||
BList* fDisplayList;
|
BList* fDisplayList;
|
||||||
|
|
||||||
//Column select and drag stuff
|
// column select and drag stuff
|
||||||
CLVColumn* fColumnClicked;
|
CLVColumn* fColumnClicked;
|
||||||
BPoint fPreviousMousePos;
|
BPoint fPreviousMousePosition;
|
||||||
BPoint fMouseClickedPos;
|
BPoint fMouseClickedPosition;
|
||||||
bool fColumnDragging;
|
bool fColumnDragging;
|
||||||
bool fColumnResizing;
|
bool fColumnResizing;
|
||||||
BList fDragGroups; //Groups of CLVColumns that must drag together
|
BList fDragGroupsList;
|
||||||
int32 fDragGroup; //Index into DragGroups of the group being dragged by user
|
// groups of CLVColumns that must drag together
|
||||||
CLVDragGroup* fTheDragGroup;
|
int32 fDragGroupIndex;
|
||||||
CLVDragGroup* fTheShownGroupBefore;
|
// index into DragGroups of the group being dragged by user
|
||||||
CLVDragGroup* fTheShownGroupAfter;
|
CLVDragGroup* fDragGroup;
|
||||||
int32 fSnapGroupBefore, //Index into DragGroups of TheShownGroupBefore and
|
CLVDragGroup* fShownGroupBefore;
|
||||||
fSnapGroupAfter; //TheShownGroupAfter, if the group the user is dragging is
|
CLVDragGroup* fShownGroupAfter;
|
||||||
//allowed to snap there, otherwise -1
|
int32 fSnapGroupBeforeIndex;
|
||||||
float fDragBoxMouseHoldOffset,fResizeMouseHoldOffset;
|
int32 fSnapGroupAfterIndex;
|
||||||
float fDragBoxWidth; //Can include multiple columns; depends on CLV_LOCK_WITH_RIGHT
|
// index into DragGroups of fShownGroupBefore and
|
||||||
float fPrevDragOutlineLeft,fPrevDragOutlineRight;
|
// fShownGroupAfter, if the group the user is dragging is
|
||||||
float fSnapMin,fSnapMax; //-1.0 indicates the column can't snap in the given direction
|
// 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;
|
ColumnListView* fParent;
|
||||||
|
|
||||||
//Private functions
|
|
||||||
void ShiftDragGroup(int32 NewPos);
|
|
||||||
void UpdateDragGroups();
|
|
||||||
void SetSnapMinMax();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
#endif // CLV_COLUMN_LABEL_VIEW_H
|
||||||
|
|||||||
@@ -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
|
#define CLVListItem_CPP
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "CLVListItem.h"
|
#include "CLVListItem.h"
|
||||||
#include "ColumnListView.h"
|
#include "ColumnListView.h"
|
||||||
#include "CLVColumn.h"
|
#include "CLVColumn.h"
|
||||||
@@ -13,162 +20,185 @@
|
|||||||
|
|
||||||
#include "InterfaceKit.h"
|
#include "InterfaceKit.h"
|
||||||
|
|
||||||
//******************************************************************************************************
|
|
||||||
//**** CLVItem CLASS DEFINITION
|
CLVListItem::CLVListItem(uint32 level, bool superitem, bool expanded,
|
||||||
//******************************************************************************************************
|
float minheight)
|
||||||
CLVListItem::CLVListItem(uint32 level, bool superitem, bool expanded, float minheight)
|
:
|
||||||
: BListItem(level, expanded),
|
BListItem(level, expanded),
|
||||||
fExpanderButtonRect(-1.0,-1.0,-1.0,-1.0),
|
fExpanderButtonRect(-1.0, -1.0, -1.0, -1.0),
|
||||||
fExpanderColumnRect(-1.0,-1.0,-1.0,-1.0),
|
fExpanderColumnRect(-1.0, -1.0, -1.0, -1.0),
|
||||||
_selectedColumn(-1)
|
fSelectedColumn(-1)
|
||||||
{
|
{
|
||||||
fSuperItem = superitem;
|
fIsSuperItem = superitem;
|
||||||
fOutlineLevel = level;
|
fOutlineLevel = level;
|
||||||
fMinHeight = minheight;
|
fMinHeight = minheight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CLVListItem::~CLVListItem()
|
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;
|
return fOutlineLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLVListItem::SetOutlineLevel(uint32 level)
|
|
||||||
|
void
|
||||||
|
CLVListItem::SetOutlineLevel(uint32 level)
|
||||||
{
|
{
|
||||||
fOutlineLevel = 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;
|
BList* displayList = &((ColumnListView*)owner)->fColumnDisplayList;
|
||||||
int32 NumberOfColumns = DisplayList->CountItems();
|
int32 columnCount = displayList->CountItems();
|
||||||
float PushMax = itemRect.right;
|
float PushMax = itemRect.right;
|
||||||
CLVColumn* ThisColumn;
|
CLVColumn* column;
|
||||||
BRect ThisColumnRect = itemRect;
|
BRect columnRect = itemRect;
|
||||||
float ExpanderDelta = OutlineLevel() * 20.0;
|
float expanderDelta = OutlineLevel() * 20.0;
|
||||||
//Figure out what the limit is for expanders pushing other columns
|
// figure out what the limit is for expanders pushing other columns
|
||||||
for(int32 Counter = 0; Counter < NumberOfColumns; Counter++)
|
for (int32 i = 0; i < columnCount; i++) {
|
||||||
{
|
column = (CLVColumn*)displayList->ItemAt(i);
|
||||||
ThisColumn = (CLVColumn*)DisplayList->ItemAt(Counter);
|
if((column->fFlags & CLV_EXPANDER) || column->fPushedByExpander)
|
||||||
if((ThisColumn->fFlags & CLV_EXPANDER) || ThisColumn->fPushedByExpander)
|
PushMax = column->fColumnEnd;
|
||||||
PushMax = ThisColumn->fColumnEnd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BRegion ClippingRegion;
|
BRegion ClippingRegion;
|
||||||
if(!complete)
|
if (!complete)
|
||||||
owner->GetClippingRegion(&ClippingRegion);
|
owner->GetClippingRegion(&ClippingRegion);
|
||||||
else
|
else
|
||||||
ClippingRegion.Set(itemRect);
|
ClippingRegion.Set(itemRect);
|
||||||
|
|
||||||
float LastColumnEnd = -1.0;
|
float LastColumnEnd = -1.0;
|
||||||
|
|
||||||
//Draw the columns
|
// draw the columns
|
||||||
for(int32 Counter = 0; Counter < NumberOfColumns; Counter++)
|
for (int32 Counter = 0; Counter < columnCount; Counter++) {
|
||||||
{
|
column = (CLVColumn*)displayList->ItemAt(Counter);
|
||||||
ThisColumn = (CLVColumn*)DisplayList->ItemAt(Counter);
|
if(!column->IsShown())
|
||||||
if(!ThisColumn->IsShown())
|
|
||||||
continue;
|
continue;
|
||||||
ThisColumnRect.left = ThisColumn->fColumnBegin;
|
|
||||||
ThisColumnRect.right = LastColumnEnd = ThisColumn->fColumnEnd;
|
columnRect.left = column->fColumnBegin;
|
||||||
float Shift = 0.0;
|
columnRect.right = LastColumnEnd = column->fColumnEnd;
|
||||||
if((ThisColumn->fFlags & CLV_EXPANDER) || ThisColumn->fPushedByExpander)
|
float shift = 0.0;
|
||||||
Shift = ExpanderDelta;
|
if ((column->fFlags & CLV_EXPANDER) || column->fPushedByExpander)
|
||||||
if(ThisColumn->fFlags & CLV_EXPANDER)
|
shift = expanderDelta;
|
||||||
{
|
|
||||||
ThisColumnRect.right += Shift;
|
if (column->fFlags & CLV_EXPANDER) {
|
||||||
if(ThisColumnRect.right > PushMax)
|
columnRect.right += shift;
|
||||||
ThisColumnRect.right = PushMax;
|
if(columnRect.right > PushMax)
|
||||||
fExpanderColumnRect = ThisColumnRect;
|
columnRect.right = PushMax;
|
||||||
if(ClippingRegion.Intersects(ThisColumnRect))
|
|
||||||
{
|
fExpanderColumnRect = columnRect;
|
||||||
//Give the programmer a chance to do his kind of highlighting if the item is selected
|
if (ClippingRegion.Intersects(columnRect)) {
|
||||||
int32 actualIndex = ((ColumnListView*)owner)->fColumnList.IndexOf(ThisColumn);
|
// give the programmer a chance to do his kind of
|
||||||
DrawItemColumn(owner, ThisColumnRect, actualIndex, (_selectedColumn == actualIndex), complete);
|
// highlighting if the item is selected
|
||||||
if(fSuperItem)
|
int32 actualIndex
|
||||||
{
|
= ((ColumnListView*)owner)->fColumnList.IndexOf(column);
|
||||||
//Draw the expander, clip manually
|
DrawItemColumn(owner, columnRect, actualIndex,
|
||||||
float TopOffset = ceil((ThisColumnRect.bottom-ThisColumnRect.top-10.0)/2.0);
|
(fSelectedColumn == actualIndex), complete);
|
||||||
float LeftOffset = ThisColumn->fColumnEnd + Shift - 3.0 - 10.0;
|
if (fIsSuperItem) {
|
||||||
float RightClip = LeftOffset + 10.0 - ThisColumnRect.right;
|
// draw the expander, clip manually
|
||||||
if(RightClip < 0.0)
|
float top
|
||||||
RightClip = 0.0;
|
= ceilf((columnRect.bottom-columnRect.top - 10.0)
|
||||||
BBitmap* Arrow;
|
/ 2.0);
|
||||||
if(IsExpanded())
|
float left = column->fColumnEnd + shift - 3.0 - 10.0;
|
||||||
Arrow = &((ColumnListView*)owner)->fDownArrow;
|
float rightClip = left + 10.0 - columnRect.right;
|
||||||
|
if (rightClip < 0.0)
|
||||||
|
rightClip = 0.0;
|
||||||
|
|
||||||
|
BBitmap* arrow;
|
||||||
|
if (IsExpanded())
|
||||||
|
arrow = &((ColumnListView*)owner)->fDownArrow;
|
||||||
else
|
else
|
||||||
Arrow = &((ColumnListView*)owner)->fRightArrow;
|
arrow = &((ColumnListView*)owner)->fRightArrow;
|
||||||
if(LeftOffset <= ThisColumnRect.right)
|
|
||||||
{
|
if (left <= columnRect.right) {
|
||||||
fExpanderButtonRect.Set(LeftOffset,ThisColumnRect.top+TopOffset,
|
fExpanderButtonRect.Set(left, columnRect.top + top,
|
||||||
LeftOffset+10.0-RightClip,ThisColumnRect.top+TopOffset+10.0);
|
left + 10.0 - rightClip, columnRect.top + top + 10.0);
|
||||||
owner->SetDrawingMode(B_OP_OVER);
|
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);
|
owner->SetDrawingMode(B_OP_COPY);
|
||||||
}
|
} else
|
||||||
else
|
fExpanderButtonRect.Set(-1.0, -1.0, -1.0, -1.0);
|
||||||
fExpanderButtonRect.Set(-1.0,-1.0,-1.0,-1.0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
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))
|
||||||
{
|
{
|
||||||
ThisColumnRect.left += Shift;
|
int32 actualIndex
|
||||||
ThisColumnRect.right += Shift;
|
= ((ColumnListView*)owner)->fColumnList.IndexOf(column);
|
||||||
if(Shift > 0.0 && ThisColumnRect.right > PushMax)
|
DrawItemColumn(owner, columnRect, actualIndex,
|
||||||
ThisColumnRect.right = PushMax;
|
(fSelectedColumn == actualIndex), complete);
|
||||||
if(ThisColumnRect.right >= ThisColumnRect.left && ClippingRegion.Intersects(ThisColumnRect))
|
|
||||||
{
|
|
||||||
int32 actualIndex = ((ColumnListView*)owner)->fColumnList.IndexOf(ThisColumn);
|
|
||||||
DrawItemColumn(owner, ThisColumnRect, actualIndex, (_selectedColumn == actualIndex), complete);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Fill the area after all the columns (so the select highlight goes all the way across)
|
|
||||||
ThisColumnRect.left = LastColumnEnd + 1.0;
|
// fill the area after all the columns (so the select highlight goes
|
||||||
ThisColumnRect.right = owner->Bounds().right;
|
// all the way across)
|
||||||
if(ThisColumnRect.left <= ThisColumnRect.right && ClippingRegion.Intersects(ThisColumnRect))
|
columnRect.left = LastColumnEnd + 1.0;
|
||||||
{
|
columnRect.right = owner->Bounds().right;
|
||||||
DrawItemColumn(owner, ThisColumnRect,-1, false, complete);
|
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;
|
BList* displayList = &((ColumnListView*)owner)->fColumnDisplayList;
|
||||||
CLVColumn* ThisColumn = (CLVColumn*)DisplayList->ItemAt(column_index);
|
CLVColumn* column = (CLVColumn*)displayList->ItemAt(columnIndex);
|
||||||
float ExpanderDelta = OutlineLevel() * 20.0;
|
float expanderDelta = OutlineLevel() * 20.0f;
|
||||||
if(!ThisColumn->fPushedByExpander)
|
if (!column->fPushedByExpander)
|
||||||
ExpanderDelta = 0.0;
|
expanderDelta = 0.0;
|
||||||
return ExpanderDelta;
|
|
||||||
|
return expanderDelta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CLVListItem::Update(BView* owner, const BFont* font)
|
void
|
||||||
|
CLVListItem::Update(BView* owner, const BFont* font)
|
||||||
{
|
{
|
||||||
BListItem::Update(owner,font);
|
BListItem::Update(owner, font);
|
||||||
float ItemHeight = Height();
|
float itemHeight = Height();
|
||||||
if(ItemHeight < fMinHeight)
|
if (itemHeight < fMinHeight)
|
||||||
ItemHeight = fMinHeight;
|
itemHeight = fMinHeight;
|
||||||
|
|
||||||
SetWidth(((ColumnListView*)owner)->fPageWidth);
|
SetWidth(((ColumnListView*)owner)->fPageWidth);
|
||||||
SetHeight(ItemHeight);
|
SetHeight(itemHeight);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
#include <interface/ListItem.h>
|
||||||
|
|
||||||
//******************************************************************************************************
|
|
||||||
//**** PROJECT HEADER FILES AND CLASS NAME DECLARATIONS
|
|
||||||
//******************************************************************************************************
|
|
||||||
class ColumnListView;
|
class ColumnListView;
|
||||||
|
|
||||||
|
|
||||||
//******************************************************************************************************
|
|
||||||
//**** CLVItem CLASS DECLARATION
|
|
||||||
//******************************************************************************************************
|
|
||||||
class CLVListItem : public BListItem
|
class CLVListItem : public BListItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//Constructor and destructor
|
CLVListItem(uint32 level = 0,
|
||||||
CLVListItem(uint32 level = 0, bool superitem = false, bool expanded = false, float minheight = 0.0);
|
bool superitem = false,
|
||||||
|
bool expanded = false,
|
||||||
|
float minheight = 0.0);
|
||||||
virtual ~CLVListItem();
|
virtual ~CLVListItem();
|
||||||
|
|
||||||
//Archival stuff
|
//Archival stuff
|
||||||
/* Not implemented yet
|
/* Not implemented yet
|
||||||
CLVItem(BMessage* archive);
|
CLVItem(BMessage* archive);
|
||||||
static CLVItem* Instantiate(BMessage* data);
|
static CLVItem* Instantiate(BMessage* data);
|
||||||
virtual status_t Archive(BMessage* data, bool deep = true) const;
|
virtual status_t Archive(BMessage* data, bool deep = true)
|
||||||
|
const;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
virtual void DrawItemColumn(BView* owner, BRect item_column_rect, int32 column_index, bool columnSelected,
|
virtual void DrawItemColumn(BView* owner,
|
||||||
bool complete) = 0; //column_index (0-N) is based on the order in which the columns were added
|
BRect columnRect,
|
||||||
//to the ColumnListView, not the display order. An index of -1 indicates
|
int32 columnIndex,
|
||||||
//that the program needs to draw a blank area beyond the last column. The
|
bool columnSelected,
|
||||||
//main purpose is to allow the highlighting bar to continue all the way to
|
bool complete) = 0;
|
||||||
//the end of the ColumnListView, even after the end of the last column.
|
// 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);
|
virtual void DrawItem(BView* owner, BRect itemRect,
|
||||||
//In general, you don't need or want to override DrawItem().
|
bool complete);
|
||||||
float ExpanderShift(int32 column_index, BView* owner);
|
// 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);
|
virtual void Update(BView* owner, const BFont* font);
|
||||||
bool IsSuperItem() const;
|
bool IsSuperItem() const;
|
||||||
void SetSuperItem(bool superitem);
|
void SetSuperItem(bool superitem);
|
||||||
uint32 OutlineLevel() const;
|
uint32 OutlineLevel() const;
|
||||||
void SetOutlineLevel(uint32 level);
|
void SetOutlineLevel(uint32 level);
|
||||||
|
|
||||||
virtual void Pulse(BView * owner); // Called periodically when this item is selected.
|
virtual void Pulse(BView* owner);
|
||||||
|
// Called periodically when this item is selected.
|
||||||
|
|
||||||
int32 GetSelectedColumn() const {return _selectedColumn;}
|
int32 GetSelectedColumn() const
|
||||||
void SetSelectedColumn(int32 i) {_selectedColumn = i;}
|
{ return fSelectedColumn; }
|
||||||
|
void SetSelectedColumn(int32 i)
|
||||||
|
{ fSelectedColumn = i; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class ColumnListView;
|
friend class ColumnListView;
|
||||||
|
|
||||||
bool fSuperItem;
|
bool fIsSuperItem;
|
||||||
uint32 fOutlineLevel;
|
uint32 fOutlineLevel;
|
||||||
float fMinHeight;
|
float fMinHeight;
|
||||||
BRect fExpanderButtonRect;
|
BRect fExpanderButtonRect;
|
||||||
BRect fExpanderColumnRect;
|
BRect fExpanderColumnRect;
|
||||||
BList* fSortingContextBList;
|
BList* fSortingContextBList;
|
||||||
ColumnListView* fSortingContextCLV;
|
ColumnListView* fSortingContextCLV;
|
||||||
int32 _selectedColumn;
|
int32 fSelectedColumn;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
#endif // CLV_LIST_ITEM_H
|
||||||
|
|||||||
@@ -1,45 +1,54 @@
|
|||||||
#ifndef JColors_h
|
/*
|
||||||
#define JColors_h
|
* Copyright 1999-2009 Jeremy Friesner
|
||||||
|
* Copyright 2009-2014 Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Jeremy Friesner
|
||||||
|
* John Scipione, jscipione@gmail.com
|
||||||
|
*/
|
||||||
|
#ifndef J_COLORS_H
|
||||||
|
#define J_COLORS_H
|
||||||
|
|
||||||
//Useful until be gets around to making these sorts of things
|
// useful until be gets around to making these sorts of things
|
||||||
//globals akin to be_plain_font, etc.
|
// globals akin to be_plain_font, etc.
|
||||||
#include <interface/ColorControl.h>
|
#include <ColorControl.h>
|
||||||
|
|
||||||
//Be standard UI colors
|
// Be standard UI colors
|
||||||
const rgb_color BeBackgroundGrey = {216,216,216, 255};
|
const rgb_color BeBackgroundGrey = { 216, 216, 216, 255 };
|
||||||
const rgb_color BeInactiveControlGrey = {240,240,240, 255};
|
const rgb_color BeInactiveControlGrey = { 240, 240, 240, 255 };
|
||||||
const rgb_color BeFocusBlue = {0, 0, 229, 255};
|
const rgb_color BeFocusBlue = { 0, 0, 229, 255 };
|
||||||
const rgb_color BeHighlight = {255,255,255, 255};
|
const rgb_color BeHighlight = { 255, 255, 255, 255 };
|
||||||
const rgb_color BeShadow = {152,152,152, 255};
|
const rgb_color BeShadow = { 152, 152, 152, 255 };
|
||||||
const rgb_color BeDarkShadow = {108,108,108, 255};
|
const rgb_color BeDarkShadow = { 108, 108, 108, 255 };
|
||||||
const rgb_color BeLightShadow = {194,194,194, 255};
|
const rgb_color BeLightShadow = { 194, 194, 194, 255 };
|
||||||
const rgb_color BeButtonGrey = {232,232,232, 255};
|
const rgb_color BeButtonGrey = { 232, 232, 232, 255 };
|
||||||
const rgb_color BeInactiveGrey = {127,127,127, 255};
|
const rgb_color BeInactiveGrey = { 127, 127, 127, 255 };
|
||||||
const rgb_color BeListSelectGrey = {178,178,178, 255};
|
const rgb_color BeListSelectGrey = { 178, 178, 178, 255 };
|
||||||
const rgb_color BeTitleBarYellow = {255,203,0, 255};
|
const rgb_color BeTitleBarYellow = { 255, 203, 0, 255 };
|
||||||
|
|
||||||
//Other colors
|
// Other colors
|
||||||
const rgb_color Black = {0, 0, 0, 255};
|
const rgb_color Black = { 0, 0, 0, 255 };
|
||||||
const rgb_color White = {255,255,255, 255};
|
const rgb_color White = { 255, 255, 255, 255 };
|
||||||
const rgb_color Red = {255,0, 0, 255};
|
const rgb_color Red = { 255, 0, 0, 255 };
|
||||||
const rgb_color Green = {0, 167,0, 255};
|
const rgb_color Green = { 0, 167, 0, 255 };
|
||||||
const rgb_color LightGreen = {90, 240,90, 255};
|
const rgb_color LightGreen = { 90, 240, 90, 255 };
|
||||||
const rgb_color Blue = {49, 61, 225, 255};
|
const rgb_color Blue = { 49, 61, 225, 255 };
|
||||||
const rgb_color LightBlue = {64, 162,255, 255};
|
const rgb_color LightBlue = { 64, 162, 255, 255 };
|
||||||
const rgb_color Purple = {144,64, 221, 255};
|
const rgb_color Purple = { 144, 64, 221, 255 };
|
||||||
const rgb_color LightPurple = {166,74, 255, 255};
|
const rgb_color LightPurple = { 166, 74, 255, 255 };
|
||||||
const rgb_color Lavender = {193,122,255, 255};
|
const rgb_color Lavender = { 193, 122, 255, 255 };
|
||||||
const rgb_color Yellow = {255,203,0, 255};
|
const rgb_color Yellow = { 255, 203, 0, 255 };
|
||||||
const rgb_color Orange = {255,163,0, 255};
|
const rgb_color Orange = { 255, 163, 0, 255 };
|
||||||
const rgb_color Flesh = {255,231,186, 255};
|
const rgb_color Flesh = { 255, 231, 186, 255 };
|
||||||
const rgb_color Tan = {208,182,121, 255};
|
const rgb_color Tan = { 208, 182, 121, 255 };
|
||||||
const rgb_color Brown = {154,110,45, 255};
|
const rgb_color Brown = { 154, 110, 45, 255 };
|
||||||
const rgb_color LightMetallicBlue = {143,166,240, 255};
|
const rgb_color LightMetallicBlue = { 143, 166, 240, 255 };
|
||||||
const rgb_color MedMetallicBlue = {75, 96, 154, 255};
|
const rgb_color MedMetallicBlue = { 75, 96, 154, 255 };
|
||||||
const rgb_color DarkMetallicBlue = {78, 89, 126, 255};
|
const rgb_color DarkMetallicBlue = { 78, 89, 126, 255 };
|
||||||
|
|
||||||
const rgb_color ReallyLightPurple = {255,210,255, 255};
|
const rgb_color ReallyLightPurple = { 255, 210, 255, 255 };
|
||||||
const rgb_color LightYellow = {255,255,210, 255};
|
const rgb_color LightYellow = { 255, 255, 210, 255 };
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
#endif // J_COLORS_H
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -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
|
|
||||||
|
|
||||||
//******************************************************************************************************
|
#include <ListView.h>
|
||||||
//**** PROJECT HEADER FILES AND CLASS NAME DECLARATIONS
|
|
||||||
//******************************************************************************************************
|
|
||||||
|
|
||||||
#include <interface/ListView.h>
|
|
||||||
|
|
||||||
#include "Colors.h"
|
#include "Colors.h"
|
||||||
#include "CLVColumn.h"
|
#include "CLVColumn.h"
|
||||||
class CLVListItem;
|
|
||||||
class CLVColumnLabelView;
|
|
||||||
class CLVFillerView;
|
|
||||||
class CLVContainerView;
|
|
||||||
#include "PrefilledBitmap.h"
|
#include "PrefilledBitmap.h"
|
||||||
#include "ScrollViewCorner.h"
|
#include "ScrollViewCorner.h"
|
||||||
|
|
||||||
|
|
||||||
//******************************************************************************************************
|
class CLVListItem;
|
||||||
//**** CONSTANTS AND TYPE DEFINITIONS
|
class CLVColumnLabelView;
|
||||||
//******************************************************************************************************
|
class CLVFillerView;
|
||||||
typedef int (*CLVCompareFuncPtr)(const CLVListItem* item1, const CLVListItem* item2, int32 sort_key);
|
class CLVContainerView;
|
||||||
|
|
||||||
//******************************************************************************************************
|
|
||||||
//**** ColumnListView CLASS DECLARATION
|
typedef int (*CLVCompareFuncPtr)(const CLVListItem* item1,
|
||||||
//******************************************************************************************************
|
const CLVListItem* item2, int32 sort_key);
|
||||||
class ColumnListView : public BListView
|
|
||||||
{
|
|
||||||
public:
|
class ColumnListView : public BListView {
|
||||||
//Constructor and destructor
|
public:
|
||||||
ColumnListView( BRect Frame,
|
ColumnListView(BRect frame,
|
||||||
BScrollView** ContainerView, //Used to get back a pointer to the container
|
BScrollView** containerView,
|
||||||
//view that will hold the ColumnListView, the
|
// Used to get back a pointer to the container
|
||||||
//the CLVColumnLabelView, and the scrollbars.
|
// view that will hold the ColumnListView, the
|
||||||
//If no scroll bars or border are asked for,
|
// the CLVColumnLabelView, and the scrollbars.
|
||||||
//this will act like a plain BView container.
|
// If no scroll bars or border are asked for,
|
||||||
const char* Name = NULL,
|
// this will act like a plain BView container.
|
||||||
uint32 ResizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
const char* name = NULL,
|
||||||
uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE,
|
uint32 resizingMode
|
||||||
list_view_type Type = B_SINGLE_SELECTION_LIST,
|
= 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 hierarchical = false,
|
||||||
bool horizontal = true, //Which scroll bars should I add, if any
|
bool horizontal = true,
|
||||||
|
// which scroll bars should I add, if any
|
||||||
bool vertical = true,
|
bool vertical = true,
|
||||||
border_style border = B_NO_BORDER, //What type of border to add, if any
|
border_style border = B_NO_BORDER,
|
||||||
const BFont* LabelFont = be_plain_font);
|
// what type of border to add, if any
|
||||||
|
const BFont* labelFont = be_plain_font);
|
||||||
|
|
||||||
virtual ~ColumnListView();
|
virtual ~ColumnListView();
|
||||||
|
|
||||||
void AddScrollViewCorner();
|
void AddScrollViewCorner();
|
||||||
|
|
||||||
//Archival stuff
|
//Archival stuff
|
||||||
/*** Not implemented yet
|
/*** Not implemented yet
|
||||||
ColumnListView(BMessage* archive);
|
ColumnListView(BMessage* archive);
|
||||||
static ColumnListView* Instantiate(BMessage* data);
|
static ColumnListView* Instantiate(BMessage* data);
|
||||||
virtual status_t Archive(BMessage* data, bool deep = true) const;
|
virtual status_t Archive(BMessage* data, bool deep = true)
|
||||||
|
const;
|
||||||
***/
|
***/
|
||||||
|
|
||||||
virtual void MessageReceived(BMessage * msg);
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
//Column setup functions
|
// column setup functions
|
||||||
virtual bool AddColumn(CLVColumn* Column); //Note that a column may only be added to
|
virtual bool AddColumn(CLVColumn* column);
|
||||||
//one ColumnListView at a time, and may not
|
// Note that a column may only be added to
|
||||||
//be added more than once to the same
|
// one ColumnListView at a time, and may not
|
||||||
//ColumnListView without removing it
|
// be added more than once to the same
|
||||||
//inbetween
|
// ColumnListView without removing it
|
||||||
virtual bool AddColumnList(BList* NewColumns);
|
// inbetween
|
||||||
virtual bool RemoveColumn(CLVColumn* Column);
|
virtual bool AddColumnList(BList* newColumns);
|
||||||
virtual bool RemoveColumns(CLVColumn* Column, int32 Count); //Finds Column in ColumnList
|
virtual bool RemoveColumn(CLVColumn* column);
|
||||||
//and removes Count columns and
|
virtual bool RemoveColumns(CLVColumn* column,
|
||||||
//their data from the view
|
int32 Count);
|
||||||
//and its items
|
// Finds Column in ColumnList and removes Count columns and
|
||||||
|
// their data from the view and its items
|
||||||
int32 CountColumns() const;
|
int32 CountColumns() const;
|
||||||
int32 IndexOfColumn(CLVColumn* column) const;
|
int32 IndexOfColumn(CLVColumn* column) const;
|
||||||
CLVColumn * ColumnAt(BPoint point) const; // Returns column located at point on screen --added by jaf
|
CLVColumn* ColumnAt(BPoint point) const;
|
||||||
CLVColumn* ColumnAt(int32 column_index) const;
|
// Returns column located at point on screen --added by jaf
|
||||||
virtual bool SetDisplayOrder(const int32* Order);
|
CLVColumn* ColumnAt(int32 columnIndex) const;
|
||||||
//Sets the display order: each int32 in the Order list specifies the column index of the
|
virtual bool SetDisplayOrder(const int32* order);
|
||||||
//next column to display. Note that this DOES NOT get called if the user drags a
|
// Sets the display order: each int32 in the Order list specifies
|
||||||
//column, so overriding it will not inform you of user changes. If you need that info,
|
// the column index of the next column to display. Note that this
|
||||||
//override DisplayOrderChanged instead. Also note that SetDisplayOrder does call
|
// DOES NOT get called if the user drags a column, so overriding
|
||||||
//DisplayOrderChanged(false).
|
// it will not inform you of user changes. If you need that info,
|
||||||
virtual void ColumnWidthChanged(int32 ColumnIndex, float NewWidth);
|
// override DisplayOrderChanged instead. Also note that
|
||||||
|
// SetDisplayOrder does call DisplayOrderChanged(false).
|
||||||
|
virtual void ColumnWidthChanged(int32 columnIndex,
|
||||||
|
float newWidth);
|
||||||
virtual void DisplayOrderChanged(const int32* order);
|
virtual void DisplayOrderChanged(const int32* order);
|
||||||
//Override this if you want to find out when the display order changed.
|
// 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
|
int32* DisplayOrder() const;
|
||||||
//SetDisplayOrder. The returned array belongs to the caller and
|
// Gets the display order in the same format as that used by
|
||||||
//must be delete[]'d when done with it.
|
// SetDisplayOrder. The returned array belongs to the caller and
|
||||||
virtual void SetSortKey(int32 ColumnIndex);
|
// must be delete[]'d when done with it.
|
||||||
//Set it to -1 to remove the sort key.
|
virtual void SetSortKey(int32 columnIndex);
|
||||||
virtual void AddSortKey(int32 ColumnIndex);
|
// Set it to -1 to remove the sort key.
|
||||||
void ReverseSortMode(int32 ColumnIndex);
|
virtual void AddSortKey(int32 columnIndex);
|
||||||
virtual void SetSortMode(int32 ColumnIndex,CLVSortMode Mode);
|
void ReverseSortMode(int32 columnIndex);
|
||||||
int32 Sorting(int32* SortKeys, CLVSortMode* SortModes) const;
|
virtual void SetSortMode(int32 columnIndex,
|
||||||
//Returns the number of used sort keys, and fills the provided arrays with the sort keys
|
CLVSortMode Mode);
|
||||||
//by column index and sort modes, in priority order. The pointers should point to an array
|
int32 Sorting(int32* SortKeys,
|
||||||
//int32 SortKeys[n], and an array CLVSortMode SortModes[n] where n is the number of sortable
|
CLVSortMode* SortModes) const;
|
||||||
//columns in the ColumnListView. Note: sorting will only occur if the key column is shown.
|
// Returns the number of used sort keys, and fills the provided
|
||||||
void SetSorting(int32 NumberOfKeys, int32* SortKeys, CLVSortMode* SortModes);
|
// arrays with the sort keys by column index and sort modes,
|
||||||
//Sets the sorting parameters using the same format returned by Sorting
|
// 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
|
// BView overrides
|
||||||
virtual void FrameResized(float Width, float Height);
|
virtual void FrameResized(float newWidth,
|
||||||
|
float newHeight);
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
virtual void ScrollTo(BPoint point);
|
virtual void ScrollTo(BPoint point);
|
||||||
virtual void MouseDown(BPoint point);
|
virtual void MouseDown(BPoint point);
|
||||||
|
|
||||||
//List functions
|
// List functions
|
||||||
virtual bool AddUnder(CLVListItem*, CLVListItem* superitem);
|
virtual bool AddUnder(CLVListItem*,
|
||||||
virtual bool AddItem(CLVListItem*, int32 fullListIndex);
|
CLVListItem* superitem);
|
||||||
|
virtual bool AddItem(CLVListItem*,
|
||||||
|
int32 fullListIndex);
|
||||||
virtual bool AddItem(CLVListItem*);
|
virtual bool AddItem(CLVListItem*);
|
||||||
virtual bool AddList(BList* newItems); //This must be a BList of
|
virtual bool AddList(BList* newItems);
|
||||||
//CLVListItem*'s, NOT BListItem*'s
|
// This must be a BList of CLVListItem*'s, NOT BListItem*'s
|
||||||
virtual bool AddList(BList* newItems, int32 fullListIndex); //This must be a BList of
|
virtual bool AddList(BList* newItems,
|
||||||
//CLVListItem*'s, NOT BListItem*'s
|
int32 fullListIndex);
|
||||||
virtual bool AddItem(BListItem*, int32 fullListIndex); // unhide
|
//This must be a BList of CLVListItem*'s, NOT BListItem*'s
|
||||||
virtual bool AddItem(BListItem*); // unhide
|
virtual bool AddItem(BListItem*, int32 fullListIndex);
|
||||||
|
// unhide
|
||||||
|
virtual bool AddItem(BListItem*);
|
||||||
|
// unhide
|
||||||
virtual bool RemoveItem(CLVListItem* item);
|
virtual bool RemoveItem(CLVListItem* item);
|
||||||
virtual BListItem* RemoveItem(int32 fullListIndex); //Actually returns CLVListItem
|
virtual BListItem* RemoveItem(int32 fullListIndex);
|
||||||
virtual bool RemoveItems(int32 fullListIndex, int32 count);
|
// actually returns CLVListItem
|
||||||
virtual bool RemoveItem(BListItem* item); // unhide
|
virtual bool RemoveItems(int32 fullListIndex,
|
||||||
|
int32 count);
|
||||||
|
virtual bool RemoveItem(BListItem* item);
|
||||||
|
// unhide
|
||||||
virtual void MakeEmpty();
|
virtual void MakeEmpty();
|
||||||
CLVListItem* FullListItemAt(int32 fullListIndex) const;
|
CLVListItem* FullListItemAt(int32 fullListIndex) const;
|
||||||
int32 FullListIndexOf(const CLVListItem* item) const;
|
int32 FullListIndexOf(const CLVListItem* item)
|
||||||
|
const;
|
||||||
int32 FullListIndexOf(BPoint point) const;
|
int32 FullListIndexOf(BPoint point) const;
|
||||||
CLVListItem* FullListFirstItem() const;
|
CLVListItem* FullListFirstItem() const;
|
||||||
CLVListItem* FullListLastItem() const;
|
CLVListItem* FullListLastItem() const;
|
||||||
bool FullListHasItem(const CLVListItem* item) const;
|
bool FullListHasItem(const CLVListItem* item)
|
||||||
|
const;
|
||||||
int32 FullListCountItems() const;
|
int32 FullListCountItems() const;
|
||||||
bool FullListIsEmpty() const;
|
bool FullListIsEmpty() const;
|
||||||
int32 FullListCurrentSelection(int32 index = 0) const;
|
int32 FullListCurrentSelection(int32 index = 0)
|
||||||
void FullListDoForEach(bool (*func)(CLVListItem*));
|
const;
|
||||||
void FullListDoForEach(bool (*func)(CLVListItem*, void*), void* arg2);
|
void FullListDoForEach(
|
||||||
|
bool (*func)(CLVListItem*));
|
||||||
|
void FullListDoForEach(bool (*func)(
|
||||||
|
CLVListItem*, void*), void* arg2);
|
||||||
CLVListItem* Superitem(const CLVListItem* item) const;
|
CLVListItem* Superitem(const CLVListItem* item) const;
|
||||||
int32 FullListNumberOfSubitems(const CLVListItem* item) const;
|
int32 FullListNumberOfSubitems(
|
||||||
|
const CLVListItem* item) const;
|
||||||
virtual void Expand(CLVListItem* item);
|
virtual void Expand(CLVListItem* item);
|
||||||
virtual void Collapse(CLVListItem* item);
|
virtual void Collapse(CLVListItem* item);
|
||||||
bool IsExpanded(int32 fullListIndex) const;
|
bool IsExpanded(int32 fullListIndex) const;
|
||||||
void SetSortFunction(CLVCompareFuncPtr compare);
|
void SetSortFunction(CLVCompareFuncPtr compare);
|
||||||
void SortItems();
|
void SortItems();
|
||||||
|
|
||||||
virtual void KeyDown(const char * bytes, int32 numBytes);
|
virtual void KeyDown(const char* bytes, int32 numBytes);
|
||||||
|
|
||||||
void SetEditMessage(BMessage * newMsg, BMessenger target);
|
void SetEditMessage(BMessage* message,
|
||||||
// Sets a BMessage that will be sent every time a key is pressed, or the mouse
|
BMessenger target);
|
||||||
// is clicked in the active cell. (newMsg) becomes property of this ColumnListView.
|
// Sets a BMessage that will be sent every time a key is pressed,
|
||||||
// Copies of (newMsg) will be sent to (target).
|
// 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();
|
virtual void Pulse();
|
||||||
// Used to make the cursor blink on the string column...
|
// Used to make the cursor blink on the string column...
|
||||||
|
|
||||||
int32 GetSelectedColumn() const {return _selectedColumn;}
|
int32 GetSelectedColumn() const
|
||||||
|
{ return fSelectedColumn; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class CLVMainView;
|
friend class CLVMainView;
|
||||||
@@ -158,27 +197,40 @@ class ColumnListView : public BListView
|
|||||||
friend class CLVListItem;
|
friend class CLVListItem;
|
||||||
|
|
||||||
int32 GetActualIndexOf(int32 displayIndex) const;
|
int32 GetActualIndexOf(int32 displayIndex) const;
|
||||||
// Returns the "real" index of the given display index, or -1 if there is none.
|
// Returns the "real" index of the given display index,
|
||||||
|
// or -1 if there is none.
|
||||||
|
|
||||||
int32 GetDisplayIndexOf(int32 actualIndex) const;
|
int32 GetDisplayIndexOf(int32 actualIndex) const;
|
||||||
// Returns the display index of the given "real" index, or -1 if there is none.
|
// Returns the display index of the given "real" index,
|
||||||
|
// or -1 if there is none.
|
||||||
|
|
||||||
void SetSelectedColumnIndex(int32 selectedColumnIndex);
|
void SetSelectedColumnIndex(
|
||||||
// Call this to change _selectedColumn to a new value properly.
|
int32 selectedcolumnIndex);
|
||||||
|
// Call this to change fSelectedColumn to a new value properly.
|
||||||
|
|
||||||
void UpdateColumnSizesDataRectSizeScrollBars();
|
void ShiftDragGroup();
|
||||||
void UpdateScrollBars();
|
void UpdateScrollBars();
|
||||||
void ColumnsChanged();
|
void ColumnsChanged();
|
||||||
void CreateContainer(bool horizontal, bool vertical, border_style border, uint32 ResizingMode,
|
void CreateContainer(bool horizontal,
|
||||||
uint32 flags);
|
bool vertical, border_style border,
|
||||||
void SortListArray(CLVListItem** SortArray, int32 NumberOfItems);
|
uint32 resizingMode, uint32 flags);
|
||||||
|
void SortListArray(CLVListItem** sortArray,
|
||||||
|
int32 itemCount);
|
||||||
void MakeEmptyPrivate();
|
void MakeEmptyPrivate();
|
||||||
bool AddListPrivate(BList* newItems, int32 fullListIndex);
|
bool AddListPrivate(BList* newItems,
|
||||||
bool AddItemPrivate(CLVListItem* item, int32 fullListIndex);
|
int32 fullListIndex);
|
||||||
void SortFullListSegment(int32 OriginalListStartIndex, int32 InsertionPoint, BList* NewList);
|
bool AddItemPrivate(CLVListItem* item,
|
||||||
BList* SortItemsInThisLevel(int32 OriginalListStartIndex);
|
int32 fullListIndex);
|
||||||
static int PlainBListSortFunc(BListItem** item1, BListItem** item2);
|
void SortFullListSegment(
|
||||||
static int HierarchicalBListSortFunc(BListItem** item1, BListItem** item2);
|
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;
|
CLVColumnLabelView* fColumnLabelView;
|
||||||
CLVContainerView* fScrollView;
|
CLVContainerView* fScrollView;
|
||||||
@@ -186,19 +238,25 @@ class ColumnListView : public BListView
|
|||||||
bool fHierarchical;
|
bool fHierarchical;
|
||||||
BList fColumnList;
|
BList fColumnList;
|
||||||
BList fColumnDisplayList;
|
BList fColumnDisplayList;
|
||||||
float fDataWidth,fDataHeight,fPageWidth,fPageHeight;
|
float fDataWidth;
|
||||||
BList fSortKeyList; //List contains CLVColumn pointers
|
float fDataHeight;
|
||||||
|
float fPageWidth;
|
||||||
|
float fPageHeight;
|
||||||
|
BList fSortKeyList;
|
||||||
|
// list contains CLVColumn pointers
|
||||||
PrefilledBitmap fRightArrow;
|
PrefilledBitmap fRightArrow;
|
||||||
PrefilledBitmap fDownArrow;
|
PrefilledBitmap fDownArrow;
|
||||||
BList fFullItemList;
|
BList fFullItemList;
|
||||||
int32 fExpanderColumn;
|
int32 fExpanderColumn;
|
||||||
CLVCompareFuncPtr fCompare;
|
CLVCompareFuncPtr fCompareFunction;
|
||||||
|
|
||||||
// added by jaf
|
// added by jaf
|
||||||
int32 _selectedColumn; // actual index of the column that contains the active cell.
|
int32 fSelectedColumn;
|
||||||
BMessage * _editMessage; // if non-NULL, sent on keypress or when active cell is clicked.
|
// actual index of the column that contains the active cell.
|
||||||
BMessenger _editTarget; // target for _editMessage.
|
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
|
||||||
|
|||||||
@@ -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 "MouseWatcher.h"
|
||||||
|
|
||||||
#include <Messenger.h>
|
#include <Messenger.h>
|
||||||
#include <InterfaceKit.h>
|
#include <InterfaceKit.h>
|
||||||
|
|
||||||
|
|
||||||
int32 MouseWatcher(void* data);
|
int32 MouseWatcher(void* data);
|
||||||
|
|
||||||
|
|
||||||
thread_id StartMouseWatcher(BView* TargetView)
|
thread_id
|
||||||
|
StartMouseWatcher(BView* target)
|
||||||
{
|
{
|
||||||
thread_id MouseWatcherThread = spawn_thread(MouseWatcher,"MouseWatcher",B_NORMAL_PRIORITY,
|
thread_id MouseWatcherThread = spawn_thread(MouseWatcher,
|
||||||
new BMessenger(TargetView));
|
"MouseWatcher", B_NORMAL_PRIORITY, new BMessenger(target));
|
||||||
if(MouseWatcherThread != B_NO_MORE_THREADS && MouseWatcherThread != B_NO_MEMORY)
|
if (MouseWatcherThread != B_NO_MORE_THREADS
|
||||||
|
&& MouseWatcherThread != B_NO_MEMORY) {
|
||||||
resume_thread(MouseWatcherThread);
|
resume_thread(MouseWatcherThread);
|
||||||
|
}
|
||||||
|
|
||||||
return MouseWatcherThread;
|
return MouseWatcherThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32 MouseWatcher(void* data)
|
int32
|
||||||
|
MouseWatcher(void* data)
|
||||||
{
|
{
|
||||||
BMessenger* TheMessenger = (BMessenger*)data;
|
BMessenger* messenger = (BMessenger*)data;
|
||||||
BPoint PreviousPos;
|
BPoint previousPosition;
|
||||||
uint32 PreviousButtons = 0xFFFFFFFF;
|
uint32 previousbuttons = 0xFFFFFFFF;
|
||||||
bool FirstCheck = true;
|
bool isFirstCheck = true;
|
||||||
BMessage MessageToSend;
|
BMessage messageToSend;
|
||||||
MessageToSend.AddPoint("where",BPoint(0,0));
|
messageToSend.AddPoint("where", BPoint(0, 0));
|
||||||
MessageToSend.AddInt32("buttons",0);
|
messageToSend.AddInt32("buttons", 0);
|
||||||
MessageToSend.AddInt32("modifiers",0);
|
messageToSend.AddInt32("modifiers", 0);
|
||||||
while(true)
|
|
||||||
{
|
while(true) {
|
||||||
if (!TheMessenger->LockTarget())
|
if (!messenger->LockTarget()) {
|
||||||
{
|
// window is dead so exit
|
||||||
delete TheMessenger;
|
delete messenger;
|
||||||
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;
|
|
||||||
return 0;
|
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);
|
snooze(50000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +1,60 @@
|
|||||||
/****DOCUMENTATION
|
/*
|
||||||
Once started, MouseWatcher will watch the mouse until the mouse buttons are all released, sending
|
* Copyright 1999-2009 Jeremy Friesner
|
||||||
messages to the target BView (TargetView is specified as the target handler in the BMessenger used to
|
* Copyright 2009-2014 Haiku, Inc. All rights reserved.
|
||||||
send the messages. The BLooper == window of the target view is determined automatically by the
|
* Distributed under the terms of the MIT License.
|
||||||
BMessenger)
|
*
|
||||||
|
* 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 <SupportDefs.h>
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
|
|
||||||
class BView;
|
|
||||||
|
|
||||||
const uint32 MW_MOUSE_DOWN = 'Mw-D';
|
const uint32 MW_MOUSE_DOWN = 'Mw-D';
|
||||||
const uint32 MW_MOUSE_UP = 'Mw-U';
|
const uint32 MW_MOUSE_UP = 'Mw-U';
|
||||||
const uint32 MW_MOUSE_MOVED = 'Mw-M';
|
const uint32 MW_MOUSE_MOVED = 'Mw-M';
|
||||||
|
|
||||||
thread_id StartMouseWatcher(BView* TargetView);
|
|
||||||
|
|
||||||
#endif
|
class BView;
|
||||||
|
|
||||||
|
thread_id StartMouseWatcher(BView* target);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // MOUSE_WATCHER_H
|
||||||
|
|||||||
@@ -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"
|
#include "PrefilledBitmap.h"
|
||||||
|
|
||||||
PrefilledBitmap::PrefilledBitmap(BRect bounds, color_space space, const void *data, bool acceptsViews,
|
|
||||||
bool needsContiguousMemory)
|
PrefilledBitmap::PrefilledBitmap(BRect bounds, color_space space,
|
||||||
: BBitmap(bounds, space, acceptsViews, needsContiguousMemory)
|
const void* data, bool acceptsViews, bool needsContiguousMemory)
|
||||||
|
:
|
||||||
|
BBitmap(bounds, space, acceptsViews, needsContiguousMemory)
|
||||||
{
|
{
|
||||||
int32 length = ((int32(bounds.right-bounds.left)+3) / 4) * 4;
|
int32 length = ((int32(bounds.right - bounds.left) + 3) / 4) * 4;
|
||||||
length *= int32(bounds.bottom-bounds.top)+1;
|
length *= int32(bounds.bottom - bounds.top) + 1;
|
||||||
SetBits(data, length, 0, space);
|
SetBits(data, length, 0, space);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PrefilledBitmap::~PrefilledBitmap()
|
PrefilledBitmap::~PrefilledBitmap()
|
||||||
{ }
|
{
|
||||||
|
}
|
||||||
|
|||||||
@@ -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>
|
#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
|
class PrefilledBitmap : public BBitmap
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PrefilledBitmap(BRect bounds, color_space space, const void *data, bool acceptsViews,
|
PrefilledBitmap(BRect bounds,
|
||||||
|
color_space space, const void* data,
|
||||||
|
bool acceptsViews,
|
||||||
bool needsContiguousMemory);
|
bool needsContiguousMemory);
|
||||||
~PrefilledBitmap();
|
virtual ~PrefilledBitmap();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
#endif // PREFILLED_BITMAP_H
|
||||||
|
|||||||
@@ -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 "Colors.h"
|
||||||
#include "ScrollViewCorner.h"
|
#include "ScrollViewCorner.h"
|
||||||
|
|
||||||
#include <InterfaceKit.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 |
|
ScrollViewCorner::ScrollViewCorner(float left, float top)
|
||||||
B_FOLLOW_BOTTOM,B_WILL_DRAW)
|
:
|
||||||
|
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);
|
SetHighColor(BeShadow);
|
||||||
SetViewColor(BeInactiveGrey);
|
SetViewColor(BeInactiveGrey);
|
||||||
@@ -13,16 +27,19 @@ ScrollViewCorner::ScrollViewCorner(float Left,float Top)
|
|||||||
|
|
||||||
|
|
||||||
ScrollViewCorner::~ScrollViewCorner()
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -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.
|
* If you have a BScrollView with horizontal and vertical sliders that isn't
|
||||||
//In general, it looks best to set the ScrollViewCorner color to
|
* seated to the lower-right corner of a B_DOCUMENT_WINDOW, there's a "hole"
|
||||||
//BeInactiveControlGrey if the vertical BScrollBar is inactive, and the color
|
* between the sliders that needs to be filled. You can use this to fill it.
|
||||||
//to BeBackgroundGrey if the vertical BScrollBar is active. Have a look at
|
* In general, it looks best to set the ScrollViewCorner color to
|
||||||
//Demo3 of ColumnListView to see what I mean if this is unclear.
|
* 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
|
class ScrollViewCorner : public BView
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ScrollViewCorner(float Left,float Top);
|
ScrollViewCorner(float left, float top);
|
||||||
~ScrollViewCorner();
|
virtual ~ScrollViewCorner();
|
||||||
void Draw(BRect Update);
|
|
||||||
|
virtual void Draw(BRect updateRect);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
#endif // SCROLL_VIEW_CORNER_H
|
||||||
|
|||||||
@@ -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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Jeremy Friesner
|
* Jeremy Friesner
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <Locale.h>
|
#include <Locale.h>
|
||||||
|
|
||||||
@@ -22,4 +22,3 @@ main(int argc, char** argv)
|
|||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user