2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Copyright (c) 2001-2002, OpenBeOS
|
2002-07-09 16:24:59 +04:00
|
|
|
//
|
2003-06-16 11:43:42 +04:00
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the "Software"),
|
|
|
|
// to deal in the Software without restriction, including without limitation
|
|
|
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
// Software is furnished to do so, subject to the following conditions:
|
2002-07-09 16:24:59 +04:00
|
|
|
//
|
2003-06-16 11:43:42 +04:00
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
2002-07-09 16:24:59 +04:00
|
|
|
//
|
2003-06-16 11:43:42 +04:00
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
2002-07-09 16:24:59 +04:00
|
|
|
//
|
2003-06-16 11:43:42 +04:00
|
|
|
// File Name: ListView.cpp
|
|
|
|
// Author: Ulrich Wimboeck
|
|
|
|
// Marc Flerackers (mflerackers@androme.be)
|
|
|
|
// Description: BListView represents a one-dimensional list view.
|
|
|
|
//------------------------------------------------------------------------------
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
// Standard Includes -----------------------------------------------------------
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
// System Includes -------------------------------------------------------------
|
|
|
|
#include <ListView.h>
|
|
|
|
#include <ScrollBar.h>
|
|
|
|
#include <ScrollView.h>
|
|
|
|
#include <support/Errors.h>
|
|
|
|
#include <PropertyInfo.h>
|
|
|
|
#include <Window.h>
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
// Project Includes ------------------------------------------------------------
|
|
|
|
|
|
|
|
// Local Includes --------------------------------------------------------------
|
|
|
|
|
|
|
|
// Local Defines ---------------------------------------------------------------
|
|
|
|
|
|
|
|
// Globals ---------------------------------------------------------------------
|
|
|
|
static property_info prop_list[] =
|
|
|
|
{
|
|
|
|
{ "Item", { B_COUNT_PROPERTIES, 0 }, { B_DIRECT_SPECIFIER, 0 },
|
|
|
|
"Returns the number of BListItems currently in the list." },
|
|
|
|
{ "Item", { B_EXECUTE_PROPERTY, 0 }, { B_INDEX_SPECIFIER, B_REVERSE_INDEX_SPECIFIER,
|
|
|
|
B_RANGE_SPECIFIER, B_REVERSE_RANGE_SPECIFIER, 0 },
|
|
|
|
"Select and invoke the specified items, first removing any existing selection." },
|
|
|
|
{ "Selection", { B_COUNT_PROPERTIES, 0 }, { B_DIRECT_SPECIFIER, 0 },
|
|
|
|
"Returns int32 count of items in the selection." },
|
|
|
|
{ "Selection", { B_EXECUTE_PROPERTY, 0 }, { B_DIRECT_SPECIFIER, 0 },
|
|
|
|
"Invoke items in selection." },
|
|
|
|
{ "Selection", { B_GET_PROPERTY, 0 }, { B_DIRECT_SPECIFIER, 0 },
|
|
|
|
"Returns int32 indices of all items in the selection." },
|
|
|
|
{ "Selection", { B_SET_PROPERTY, 0 }, { B_INDEX_SPECIFIER, B_REVERSE_INDEX_SPECIFIER,
|
|
|
|
B_RANGE_SPECIFIER, B_REVERSE_RANGE_SPECIFIER, 0 },
|
|
|
|
"Extends current selection or deselects specified items. Boolean field \"data\" "
|
|
|
|
"chooses selection or deselection." },
|
|
|
|
{ "Selection", { B_SET_PROPERTY, 0 }, { B_DIRECT_SPECIFIER, 0 },
|
|
|
|
"Select or deselect all items in the selection. Boolean field \"data\" chooses "
|
|
|
|
"selection or deselection." },
|
|
|
|
};
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
BListView::BListView(BRect frame, const char *name, list_view_type type,
|
|
|
|
uint32 resizingMode, uint32 flags)
|
|
|
|
: BView(frame, name, resizingMode, flags)
|
|
|
|
{
|
|
|
|
InitObject(type);
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
BListView::BListView(BMessage *archive)
|
|
|
|
: BView(archive)
|
|
|
|
{
|
|
|
|
int32 listType;
|
|
|
|
|
|
|
|
archive->FindInt32("_lv_type", &listType);
|
|
|
|
fListType = (list_view_type)listType;
|
|
|
|
|
|
|
|
fFirstSelected = -1;
|
|
|
|
fLastSelected = -1;
|
|
|
|
fAnchorIndex = -1;
|
|
|
|
|
|
|
|
fSelectMessage = NULL;
|
|
|
|
fScrollView = NULL;
|
|
|
|
fTrack = NULL;
|
|
|
|
|
|
|
|
fWidth = Bounds().Width();
|
|
|
|
|
|
|
|
int32 i = 0;
|
|
|
|
BMessage subData;
|
|
|
|
|
|
|
|
while (archive->FindMessage("_l_items", i++, &subData))
|
|
|
|
{
|
|
|
|
BArchivable *object = instantiate_object(&subData);
|
|
|
|
|
|
|
|
if (!object)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
BListItem *item = dynamic_cast<BListItem*>(object);
|
|
|
|
|
|
|
|
if (!item)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
AddItem(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (archive->HasMessage("_msg"))
|
|
|
|
{
|
|
|
|
BMessage *invokationMessage = new BMessage;
|
|
|
|
|
|
|
|
archive->FindMessage("_msg", invokationMessage);
|
|
|
|
SetInvocationMessage(invokationMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (archive->HasMessage("_2nd_msg"))
|
|
|
|
{
|
|
|
|
BMessage *selectionMessage = new BMessage;
|
|
|
|
|
|
|
|
archive->FindMessage("_2nd_msg", selectionMessage);
|
|
|
|
SetSelectionMessage(selectionMessage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
BListView::~BListView()
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
SetSelectionMessage(NULL);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (fSelectMessage)
|
|
|
|
delete fSelectMessage;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
BArchivable *BListView::Instantiate(BMessage *archive)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
if (validate_instantiation(archive, "BListView"))
|
|
|
|
return new BListView(archive);
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
status_t BListView::Archive(BMessage *archive, bool deep) const
|
|
|
|
{
|
|
|
|
BView::Archive ( archive, deep );
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
archive->AddInt32("_lv_type", fListType);
|
|
|
|
|
|
|
|
if (deep)
|
|
|
|
{
|
|
|
|
int32 i = 0;
|
|
|
|
BListItem *item;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:55:04 +04:00
|
|
|
while ((item = ItemAt(i++)))
|
2003-06-16 11:43:42 +04:00
|
|
|
{
|
|
|
|
BMessage subData;
|
|
|
|
|
|
|
|
if (item->Archive(&subData, true) != B_OK)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
archive->AddMessage("_l_items", &subData);
|
|
|
|
}
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (InvocationMessage())
|
|
|
|
archive->AddMessage("_msg", InvocationMessage());
|
|
|
|
|
|
|
|
if (fSelectMessage)
|
|
|
|
archive->AddMessage("_2nd_msg", fSelectMessage);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::Draw(BRect updateRect)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < CountItems(); i++)
|
|
|
|
{
|
|
|
|
BRect item_frame = ItemFrame(i);
|
|
|
|
|
|
|
|
if (item_frame.Intersects(updateRect))
|
|
|
|
DrawItem(((BListItem*)ItemAt(i)), item_frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::MessageReceived ( BMessage *msg )
|
|
|
|
{
|
|
|
|
switch ( msg->what )
|
|
|
|
{
|
|
|
|
case B_COUNT_PROPERTIES:
|
|
|
|
case B_EXECUTE_PROPERTY:
|
|
|
|
case B_GET_PROPERTY:
|
|
|
|
case B_SET_PROPERTY:
|
|
|
|
{
|
|
|
|
BPropertyInfo propInfo ( prop_list );
|
|
|
|
BMessage specifier;
|
|
|
|
const char *property;
|
|
|
|
|
|
|
|
if ( msg->GetCurrentSpecifier ( NULL, &specifier ) != B_OK ||
|
|
|
|
specifier.FindString ( "property", &property ) != B_OK )
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch ( propInfo.FindMatch ( msg, 0, &specifier, msg->what, property ) )
|
|
|
|
{
|
|
|
|
case B_ERROR:
|
|
|
|
BView::MessageReceived ( msg );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
BMessage reply ( B_REPLY );
|
|
|
|
|
|
|
|
reply.AddInt32 ( "result", CountItems () );
|
|
|
|
reply.AddInt32 ( "error", B_OK );
|
|
|
|
|
|
|
|
msg->SendReply ( &reply );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
BMessage reply ( B_REPLY );
|
|
|
|
|
|
|
|
int32 count = 0;
|
|
|
|
|
|
|
|
for ( int32 i = 0; i < CountItems (); i++ )
|
|
|
|
if ( ItemAt ( i )->IsSelected () )
|
|
|
|
count++;
|
|
|
|
|
|
|
|
reply.AddInt32 ( "result", count );
|
|
|
|
reply.AddInt32 ( "error", B_OK );
|
|
|
|
|
|
|
|
msg->SendReply ( &reply );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
BMessage reply ( B_REPLY );
|
|
|
|
|
|
|
|
for ( int32 i = 0; i < CountItems (); i++ )
|
|
|
|
if ( ItemAt ( i )->IsSelected () )
|
|
|
|
reply.AddInt32 ( "result", i );
|
|
|
|
|
|
|
|
reply.AddInt32 ( "error", B_OK );
|
|
|
|
|
|
|
|
msg->SendReply ( &reply );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
BMessage reply ( B_REPLY );
|
|
|
|
|
|
|
|
bool select;
|
|
|
|
|
|
|
|
msg->FindBool ( "data", &select );
|
|
|
|
|
|
|
|
if ( select )
|
|
|
|
Select ( 0, CountItems () - 1, false );
|
|
|
|
else
|
|
|
|
DeselectAll ();
|
|
|
|
|
|
|
|
reply.AddInt32 ( "error", B_OK );
|
|
|
|
|
|
|
|
msg->SendReply ( &reply );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case B_SELECT_ALL:
|
|
|
|
{
|
|
|
|
Select(0, CountItems() - 1, false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
BView::MessageReceived(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::MouseDown(BPoint point)
|
|
|
|
{
|
|
|
|
if (!IsFocus())
|
|
|
|
{
|
|
|
|
MakeFocus();
|
|
|
|
Sync();
|
|
|
|
Window()->UpdateIfNeeded();
|
|
|
|
}
|
|
|
|
|
|
|
|
int index = IndexOf(point);
|
|
|
|
|
|
|
|
if (index > -1)
|
|
|
|
{
|
|
|
|
BMessage *message = Looper()->CurrentMessage();
|
|
|
|
int32 clicks;
|
|
|
|
int32 modifiers;
|
|
|
|
|
|
|
|
message->FindInt32("clicks", &clicks);
|
|
|
|
message->FindInt32("modifiers", &modifiers);
|
|
|
|
|
|
|
|
bool extend = false;
|
|
|
|
|
|
|
|
if (fListType == B_MULTIPLE_SELECTION_LIST && (modifiers & B_CONTROL_KEY))
|
|
|
|
extend = true;
|
|
|
|
|
|
|
|
if (clicks == 2)
|
|
|
|
{
|
|
|
|
if (!ItemAt(index)->IsSelected())
|
|
|
|
Select(index, extend);
|
|
|
|
Invoke();
|
|
|
|
}
|
|
|
|
if (!InitiateDrag(point, index, IsItemSelected(index)))
|
|
|
|
{
|
|
|
|
if (CurrentSelection() == -1 || (!ItemAt(index)->IsSelected() &&
|
|
|
|
!(modifiers & B_SHIFT_KEY)))
|
|
|
|
fAnchorIndex = index;
|
|
|
|
|
|
|
|
if (modifiers & B_SHIFT_KEY)
|
|
|
|
Select(fAnchorIndex, index, extend);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!ItemAt(index)->IsSelected())
|
|
|
|
Select(index, extend);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ItemAt(index)->Deselect();
|
|
|
|
InvalidateItem(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: InitiateDrag
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::KeyDown(const char *bytes, int32 numBytes)
|
|
|
|
{
|
|
|
|
switch ( bytes[0] )
|
|
|
|
{
|
|
|
|
case B_UP_ARROW:
|
|
|
|
{
|
|
|
|
if (fFirstSelected == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
bool extend = false;
|
|
|
|
|
|
|
|
if (fListType == B_MULTIPLE_SELECTION_LIST && (modifiers() & B_SHIFT_KEY))
|
|
|
|
extend = true;
|
|
|
|
|
|
|
|
Select (fFirstSelected - 1, extend);
|
|
|
|
|
|
|
|
ScrollToSelection ();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case B_DOWN_ARROW:
|
|
|
|
{
|
|
|
|
if (fFirstSelected == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
bool extend = false;
|
|
|
|
|
|
|
|
if (fListType == B_MULTIPLE_SELECTION_LIST && (modifiers() & B_SHIFT_KEY))
|
|
|
|
extend = true;
|
|
|
|
|
|
|
|
Select (fLastSelected + 1, extend);
|
|
|
|
|
|
|
|
ScrollToSelection ();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case B_HOME:
|
|
|
|
{
|
|
|
|
Select ( 0, fListType == B_MULTIPLE_SELECTION_LIST );
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
ScrollToSelection ();
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case B_END:
|
|
|
|
{
|
|
|
|
Select ( CountItems () - 1, fListType == B_MULTIPLE_SELECTION_LIST );
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
ScrollToSelection ();
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case B_RETURN:
|
|
|
|
case B_SPACE:
|
|
|
|
{
|
|
|
|
Invoke ();
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
BView::KeyDown ( bytes, numBytes );
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::MakeFocus(bool focused)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
if (IsFocus() == focused)
|
|
|
|
return;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
BView::MakeFocus(focused);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (fScrollView)
|
|
|
|
fScrollView->SetBorderHighlighted(focused);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::FrameResized(float width, float height)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
// TODO
|
|
|
|
FixupScrollBar();
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::TargetedByScrollView(BScrollView *view)
|
|
|
|
{
|
|
|
|
fScrollView = view;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::ScrollTo(BPoint point)
|
|
|
|
{
|
|
|
|
BView::ScrollTo(point);
|
|
|
|
fWidth = Bounds().right;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
bool BListView::AddItem(BListItem *item, int32 index)
|
|
|
|
{
|
|
|
|
if (!fList.AddItem(item, index))
|
|
|
|
return false;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (fFirstSelected != -1 && index < fFirstSelected)
|
|
|
|
fFirstSelected++;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (fLastSelected != -1 && index < fLastSelected)
|
|
|
|
fLastSelected++;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (Window())
|
|
|
|
{
|
|
|
|
BFont font;
|
|
|
|
GetFont(&font);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
item->Update(this, &font);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
FixupScrollBar();
|
|
|
|
InvalidateFrom(index);
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
bool BListView::AddItem(BListItem *item)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
if (!fList.AddItem(item))
|
|
|
|
return false;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (Window())
|
|
|
|
{
|
|
|
|
BFont font;
|
|
|
|
GetFont(&font);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
item->Update(this, &font);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
FixupScrollBar();
|
|
|
|
InvalidateItem(CountItems() - 1);
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
return true;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
bool BListView::AddList(BList *list, int32 index)
|
|
|
|
{
|
|
|
|
if (!fList.AddList(list, index))
|
|
|
|
return false;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
int32 count = fList.CountItems();
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (fFirstSelected != -1 && index < fFirstSelected)
|
|
|
|
fFirstSelected += count;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (fLastSelected != -1 && index < fLastSelected)
|
|
|
|
fLastSelected += count;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (Window())
|
|
|
|
{
|
|
|
|
BFont font;
|
|
|
|
GetFont(&font);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
int32 i = 0;
|
|
|
|
while(BListItem *item = (BListItem*)list->ItemAt(i))
|
|
|
|
{
|
|
|
|
item->Update(this, &font);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
FixupScrollBar();
|
|
|
|
Invalidate(); // TODO
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
return true;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
bool BListView::AddList(BList *list)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
return AddList(list, CountItems());
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
BListItem *BListView::RemoveItem(int32 index)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
BListItem *item = ItemAt(index);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (!item)
|
|
|
|
return NULL;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (item->IsSelected())
|
|
|
|
Deselect(index);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if(!fList.RemoveItem(item))
|
|
|
|
return item;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (fFirstSelected != -1 && index < fFirstSelected)
|
|
|
|
fFirstSelected--;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (fLastSelected != -1 && index < fLastSelected)
|
|
|
|
fLastSelected--;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
InvalidateFrom(index);
|
|
|
|
FixupScrollBar();
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
return item;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
bool BListView::RemoveItem(BListItem *item)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
return RemoveItem(IndexOf(item)) != NULL;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
bool BListView::RemoveItems(int32 index, int32 count)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
if (index >= CountItems())
|
|
|
|
index = -1;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (index < 0)
|
|
|
|
return false;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
while (count--)
|
|
|
|
RemoveItem(index);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
return true;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::SetSelectionMessage(BMessage *message)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
if (fSelectMessage)
|
|
|
|
delete fSelectMessage;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
fSelectMessage = message;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::SetInvocationMessage(BMessage *message)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
BInvoker::SetMessage(message);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
BMessage *BListView::InvocationMessage() const
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
return BInvoker::Message();
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
uint32 BListView::InvocationCommand() const
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
return BInvoker::Command();
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
BMessage *BListView::SelectionMessage() const
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
return fSelectMessage;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
uint32 BListView::SelectionCommand() const
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
if (fSelectMessage)
|
|
|
|
return fSelectMessage->what;
|
|
|
|
else
|
|
|
|
return 0;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::SetListType(list_view_type type)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
if (fListType == B_MULTIPLE_SELECTION_LIST &&
|
|
|
|
type == B_SINGLE_SELECTION_LIST)
|
|
|
|
DeselectAll();
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
fListType = type;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
list_view_type BListView::ListType() const
|
|
|
|
{
|
|
|
|
return fListType;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
BListItem *BListView::ItemAt(int32 index) const
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
return (BListItem*)fList.ItemAt(index);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
int32 BListView::IndexOf(BListItem *item) const
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
return fList.IndexOf(item);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
int32 BListView::IndexOf(BPoint point) const
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
float y = 0.0f;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
for (int i = 0; i < fList.CountItems(); i++)
|
|
|
|
{
|
|
|
|
y += ItemAt(i)->Height();
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if ( point.y < y )
|
|
|
|
return i;
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
return -1;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
BListItem *BListView::FirstItem() const
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
return (BListItem*)fList.FirstItem();
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
BListItem *BListView::LastItem() const
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
return (BListItem*)fList.LastItem();
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
bool BListView::HasItem(BListItem *item) const
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
return fList.HasItem(item);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
int32 BListView::CountItems() const
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
return fList.CountItems();
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::MakeEmpty()
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
_DeselectAll(-1, -1);
|
|
|
|
fList.MakeEmpty();
|
|
|
|
//virtual(&int32[2])
|
|
|
|
Invalidate();
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
bool BListView::IsEmpty() const
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
return fList.IsEmpty();
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::DoForEach(bool (*func)(BListItem *))
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
fList.DoForEach(reinterpret_cast<bool (*)(void*)>(func));
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::DoForEach(bool (*func)(BListItem *, void *), void *arg )
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
fList.DoForEach(reinterpret_cast<bool (*)(void*, void*)>(func), arg);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
const BListItem **BListView::Items() const
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
return (const BListItem**)fList.Items();
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::InvalidateItem(int32 index)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
Invalidate(Bounds() & ItemFrame(index));
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::ScrollToSelection ()
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
BRect item_frame = ItemFrame ( CurrentSelection ( 0 ) );
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if ( Bounds ().Intersects ( item_frame.InsetByCopy ( 0.0f, 2.0f ) ) )
|
|
|
|
return;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if ( item_frame.top < Bounds ().top )
|
|
|
|
ScrollTo ( 0, item_frame.top );
|
|
|
|
else
|
|
|
|
ScrollTo ( 0, item_frame.bottom - Bounds ().Height () );
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::Select(int32 index, bool extend)
|
|
|
|
{
|
|
|
|
_Select(index, extend);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
SelectionChanged();
|
|
|
|
InvokeNotify(fSelectMessage, B_CONTROL_MODIFIED);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::Select(int32 start, int32 finish, bool extend)
|
|
|
|
{
|
|
|
|
_Select(start, finish, extend);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
SelectionChanged();
|
|
|
|
InvokeNotify(fSelectMessage, B_CONTROL_MODIFIED);
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
bool BListView::IsItemSelected(int32 index) const
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
BListItem *item = ItemAt(index);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (item)
|
|
|
|
return item->IsSelected();
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
int32 BListView::CurrentSelection(int32 index) const
|
|
|
|
{
|
|
|
|
if (fFirstSelected == -1)
|
|
|
|
return -1;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:55:04 +04:00
|
|
|
if (index == 0)
|
2003-06-16 11:43:42 +04:00
|
|
|
return fFirstSelected;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
for (int32 i = fFirstSelected; i <= fLastSelected; i++)
|
|
|
|
{
|
|
|
|
if (ItemAt(i)->IsSelected())
|
|
|
|
{
|
|
|
|
if (index == 0)
|
|
|
|
return i;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
index--;
|
|
|
|
}
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
return -1;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
status_t BListView::Invoke(BMessage *message)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
bool notify = false;
|
|
|
|
uint32 kind = InvokeKind(¬ify);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
BMessage clone(kind);
|
|
|
|
status_t err = B_BAD_VALUE;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (!message && !notify)
|
|
|
|
message = Message();
|
|
|
|
|
|
|
|
if (!message)
|
|
|
|
{
|
|
|
|
if (!IsWatched())
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
clone = *message;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
clone.AddInt64("when", (int64)system_time());
|
|
|
|
clone.AddPointer("source", this);
|
|
|
|
clone.AddMessenger("be:sender", BMessenger(this));
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (fListType == B_SINGLE_SELECTION_LIST)
|
|
|
|
clone.AddInt32("index", fFirstSelected);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int32 i = fFirstSelected; i <= fLastSelected; i++)
|
|
|
|
{
|
|
|
|
if (ItemAt(i)->IsSelected())
|
|
|
|
clone.AddInt32("index", i);
|
|
|
|
}
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (message)
|
|
|
|
err = BInvoker::Invoke(&clone);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
// TODO: assynchronous messaging
|
|
|
|
// SendNotices(kind, &clone);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::DeselectAll()
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
if (fFirstSelected == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (int32 index = fFirstSelected; index <= fLastSelected; ++index)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
if (!ItemAt(index)->IsSelected())
|
|
|
|
{
|
|
|
|
ItemAt(index)->Deselect();
|
|
|
|
InvalidateItem(index);
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::DeselectExcept(int32 start, int32 finish)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
if (fFirstSelected == -1 || finish < start)
|
|
|
|
return;
|
2003-06-16 11:55:04 +04:00
|
|
|
|
|
|
|
int32 index;
|
2003-06-16 11:43:42 +04:00
|
|
|
|
2003-06-16 11:55:04 +04:00
|
|
|
for (index = fFirstSelected; index < start; ++index)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
if (!ItemAt(index)->IsSelected())
|
|
|
|
{
|
|
|
|
ItemAt(index)->Deselect();
|
|
|
|
InvalidateItem(index);
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
for (index = finish + 1; index <= fLastSelected; ++index)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
if (!ItemAt(index)->IsSelected())
|
|
|
|
{
|
|
|
|
ItemAt(index)->Deselect();
|
|
|
|
InvalidateItem(index);
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
SelectionChanged();
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::Deselect(int32 index)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
if (_Deselect(index))
|
|
|
|
{
|
|
|
|
SelectionChanged();
|
|
|
|
InvokeNotify(fSelectMessage, B_CONTROL_MODIFIED);
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::SelectionChanged()
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::SortItems(int (*cmp)(const void *, const void *))
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
if (_DeselectAll(-1, -1))
|
|
|
|
{
|
|
|
|
SelectionChanged();
|
|
|
|
InvokeNotify(fSelectMessage, B_CONTROL_MODIFIED);
|
|
|
|
}
|
|
|
|
|
|
|
|
fList.SortItems(cmp);
|
|
|
|
Invalidate();
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
bool BListView::SwapItems(int32 a, int32 b)
|
|
|
|
{
|
|
|
|
MiscData data;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
data.swap.a = a;
|
|
|
|
data.swap.b = b;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
return DoMiscellaneous(B_SWAP_OP, &data);
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
bool BListView::MoveItem(int32 from, int32 to)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
MiscData data;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
data.move.from = from;
|
|
|
|
data.move.to = to;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
return DoMiscellaneous(B_MOVE_OP, &data);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
bool BListView::ReplaceItem(int32 index, BListItem *item)
|
|
|
|
{
|
|
|
|
MiscData data;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
data.replace.index = index;
|
|
|
|
data.replace.item = item;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
return DoMiscellaneous(B_REPLACE_OP, &data);
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::AttachedToWindow()
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
BView::AttachedToWindow();
|
|
|
|
FontChanged();
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (!Messenger().IsValid())
|
|
|
|
SetTarget(Window(), NULL);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
FixupScrollBar();
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::FrameMoved(BPoint new_position)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
BView::FrameMoved(new_position);
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
BRect BListView::ItemFrame(int32 index)
|
|
|
|
{
|
|
|
|
BRect frame(0, 0, Bounds().Width(), -1);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (index < 0 || index >= CountItems())
|
|
|
|
return frame;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
for (int32 i = 0; i <= index; i++)
|
|
|
|
{
|
|
|
|
frame.top = frame.bottom + 1;
|
|
|
|
frame.bottom += (float)ceil(ItemAt(i)->Height());
|
|
|
|
}
|
|
|
|
|
|
|
|
return frame;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
BHandler *BListView::ResolveSpecifier(BMessage *msg, int32 index,
|
|
|
|
BMessage *specifier, int32 form,
|
|
|
|
const char *property)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
BPropertyInfo propInfo(prop_list);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (propInfo.FindMatch(msg, 0, specifier, form, property) < 0)
|
|
|
|
return BView::ResolveSpecifier(msg, index, specifier, form, property);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
// TODO: msg->AddInt32("_match_code_", );
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
return this;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
status_t BListView::GetSupportedSuites( BMessage *data )
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
data->AddString("suites", "suite/vnd.Be-list-view");
|
|
|
|
data->AddFlat("messages", &BPropertyInfo(prop_list));
|
|
|
|
|
|
|
|
return BView::GetSupportedSuites(data);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
status_t BListView::Perform(perform_code d, void *arg)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
return BView::Perform(d, arg);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::WindowActivated(bool state)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
BView::WindowActivated(state);
|
|
|
|
|
|
|
|
if (IsFocus())
|
|
|
|
Draw(Bounds());
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::MouseUp(BPoint pt)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
if (fWidth == 0)
|
|
|
|
return;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
DoMouseMoved(pt);
|
|
|
|
DoMouseUp(pt);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::MouseMoved(BPoint pt, uint32 code, const BMessage *msg)
|
|
|
|
{
|
|
|
|
if (fTrack == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (TryInitiateDrag(pt))
|
|
|
|
return;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
DoMouseMoved(pt);
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::DetachedFromWindow()
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
BView::DetachedFromWindow();
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
bool BListView::InitiateDrag(BPoint point, int32 index, bool wasSelected)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
return false;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::ResizeToPreferred()
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
BView::ResizeToPreferred();
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::GetPreferredSize(float *width, float *height)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
BView::GetPreferredSize(width, height);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::AllAttached()
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
BView::AllAttached();
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::AllDetached()
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
BView::AllDetached();
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
bool BListView::DoMiscellaneous(MiscCode code, MiscData *data)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
if (code > B_SWAP_OP)
|
|
|
|
return false;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
switch (code)
|
|
|
|
{
|
|
|
|
case B_NO_OP:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case B_REPLACE_OP:
|
|
|
|
{
|
|
|
|
return ReplaceItem(data->replace.index, data->replace.item);
|
|
|
|
}
|
|
|
|
case B_MOVE_OP:
|
|
|
|
{
|
|
|
|
return MoveItem(data->move.from, data->move.to);
|
|
|
|
}
|
|
|
|
case B_SWAP_OP:
|
|
|
|
{
|
|
|
|
return SwapItems(data->swap.a, data->swap.b);
|
|
|
|
}
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
return false;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::_ReservedListView2() {}
|
|
|
|
void BListView::_ReservedListView3() {}
|
|
|
|
void BListView::_ReservedListView4() {}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
BListView &BListView::operator=(const BListView &)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
return *this;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::InitObject(list_view_type type)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
fListType = type;
|
|
|
|
fFirstSelected = -1;
|
|
|
|
fLastSelected = -1;
|
|
|
|
fAnchorIndex = -1;
|
|
|
|
fWidth = Bounds().Width();
|
|
|
|
fSelectMessage = NULL;
|
|
|
|
fScrollView = NULL;
|
|
|
|
fTrack = NULL;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::FixupScrollBar()
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
BRect bounds, frame;
|
|
|
|
BScrollBar *vertScroller = ScrollBar(B_VERTICAL);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (!vertScroller)
|
|
|
|
return;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
bounds = Bounds();
|
|
|
|
int32 count = CountItems();
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
float y = 0;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
for (int32 i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
frame = ItemFrame(i);
|
|
|
|
y += frame.Height();
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (bounds.Height() > y)
|
|
|
|
{
|
|
|
|
vertScroller->SetRange(0.0f, 0.0f);
|
|
|
|
vertScroller->SetValue(0.0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vertScroller->SetRange(0.0f, y - bounds.Height());
|
|
|
|
vertScroller->SetProportion(bounds.Height () / y);
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (count != 0)
|
|
|
|
vertScroller->SetSteps((float)ceil(FirstItem()->Height()),
|
|
|
|
bounds.Height());
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::InvalidateFrom(int32 index)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
if (index <= fList.CountItems())
|
|
|
|
Invalidate(Bounds() & ItemFrame(index));
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::FontChanged()
|
|
|
|
{
|
|
|
|
BFont font;
|
|
|
|
GetFont(&font);
|
|
|
|
|
|
|
|
for (int i = 0; i < CountItems (); i ++)
|
|
|
|
ItemAt(i)->Update(this, &font);
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
bool BListView::_Select(int32 index, bool extend)
|
|
|
|
{
|
|
|
|
if (index < 0 || index >= CountItems())
|
|
|
|
return false;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if ((fFirstSelected != -1) && (!extend))
|
|
|
|
{
|
|
|
|
for (int32 item = fFirstSelected; item <= fLastSelected; ++item)
|
|
|
|
{
|
|
|
|
if ((ItemAt(item)->IsSelected()) && (item != index))
|
|
|
|
{
|
|
|
|
ItemAt(item)->Deselect();
|
|
|
|
InvalidateItem(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fFirstSelected = -1;
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (fFirstSelected == -1)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
fFirstSelected = index;
|
|
|
|
fLastSelected = index;
|
|
|
|
}
|
|
|
|
else if (index < fFirstSelected)
|
|
|
|
fFirstSelected = index;
|
|
|
|
else if (index > fLastSelected)
|
|
|
|
fLastSelected = index;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (!ItemAt(index)->IsSelected())
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
ItemAt(index)->Select();
|
|
|
|
InvalidateItem(index);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
bool BListView::_Select(int32 from, int32 to, bool extend)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
if (to < from)
|
|
|
|
return false;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if ((fFirstSelected != -1) && (!extend))
|
|
|
|
{
|
|
|
|
for (int32 item = fFirstSelected; item <= fLastSelected; ++item)
|
|
|
|
{
|
|
|
|
if ((ItemAt(item)->IsSelected()) && (item < from || item > to))
|
|
|
|
{
|
|
|
|
ItemAt(item)->Deselect();
|
|
|
|
InvalidateItem(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fFirstSelected = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fFirstSelected == -1)
|
|
|
|
{
|
|
|
|
fFirstSelected = from;
|
|
|
|
fLastSelected = to;
|
|
|
|
}
|
|
|
|
else if (from < fFirstSelected)
|
|
|
|
fFirstSelected = from;
|
|
|
|
else if (to > fLastSelected)
|
|
|
|
fLastSelected = to;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
for (int32 item = from; item <= to; ++item)
|
|
|
|
{
|
|
|
|
if (!ItemAt(item)->IsSelected())
|
|
|
|
{
|
|
|
|
ItemAt(item)->Select();
|
|
|
|
InvalidateItem(item);
|
|
|
|
}
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
return true;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
bool BListView::_Deselect(int32 index)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
if (index < 0 || index >= CountItems())
|
|
|
|
return false;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (!Window()->Lock())
|
|
|
|
return false;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
BListItem *item = ItemAt(index);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (item->IsSelected())
|
|
|
|
{
|
|
|
|
BRect frame(ItemFrame(index));
|
|
|
|
BRect bounds(Bounds());
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
item->Deselect();
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (fFirstSelected == index && fLastSelected == index)
|
|
|
|
{
|
|
|
|
fFirstSelected = -1;
|
|
|
|
fLastSelected = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (fFirstSelected == index)
|
|
|
|
fFirstSelected = CalcFirstSelected(index);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (fLastSelected == index)
|
|
|
|
fLastSelected = CalcLastSelected(index);
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (bounds.Intersects(frame))
|
|
|
|
DrawItem(ItemAt(index), frame, true);
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
Window()->Unlock();
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
return true;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::Deselect(int32 from, int32 to)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
if (from < 0 || from >= CountItems() || to < 0 || to >= CountItems())
|
|
|
|
return;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
bool changed = false;
|
|
|
|
|
|
|
|
for (int32 i = from; i <= to; i++)
|
|
|
|
{
|
|
|
|
if (_Deselect(i))
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed)
|
|
|
|
{
|
|
|
|
SelectionChanged();
|
|
|
|
InvokeNotify(fSelectMessage, B_CONTROL_MODIFIED);
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
bool BListView::_DeselectAll(int32 except_from, int32 except_to)
|
|
|
|
{
|
|
|
|
if (fFirstSelected == -1)
|
|
|
|
return true;
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
bool BListView::TryInitiateDrag(BPoint where)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
return false;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
int32 BListView::CalcFirstSelected(int32 after)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
if (after >= CountItems())
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (int32 i = after; i < CountItems(); i++)
|
|
|
|
{
|
|
|
|
if (ItemAt(i)->IsSelected())
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
int32 BListView::CalcLastSelected(int32 before)
|
|
|
|
{
|
|
|
|
if (before < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (int32 i = before; i >= 0; i--)
|
|
|
|
{
|
|
|
|
if (ItemAt(i)->IsSelected())
|
|
|
|
return i;
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::DrawItem(BListItem *item, BRect itemRect, bool complete)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
item->DrawItem(this, itemRect, complete);
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
bool BListView::DoSwapItems(int32 a, int32 b)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
if (!fList.SwapItems(a, b))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Invalidate(ItemFrame(a));
|
|
|
|
Invalidate(ItemFrame(b));
|
|
|
|
|
2003-06-16 11:55:04 +04:00
|
|
|
if (fAnchorIndex == a)
|
2003-06-16 11:43:42 +04:00
|
|
|
fAnchorIndex = b;
|
2003-06-16 11:55:04 +04:00
|
|
|
else if (fAnchorIndex == b)
|
2003-06-16 11:43:42 +04:00
|
|
|
fAnchorIndex = a;
|
|
|
|
|
|
|
|
RescanSelection(a, b);
|
|
|
|
|
|
|
|
return true;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
bool BListView::DoMoveItem(int32 from, int32 to)
|
|
|
|
{
|
|
|
|
BRect frameFrom = ItemFrame(from);
|
|
|
|
BRect frameTo = ItemFrame(to);
|
|
|
|
|
|
|
|
if (!fList.MoveItem(from, to))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
RescanSelection(from, to);
|
|
|
|
|
|
|
|
BRect frame = frameFrom | frameTo;
|
|
|
|
|
|
|
|
if (Bounds().Intersects(frame))
|
|
|
|
Invalidate(Bounds() & frame);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
bool BListView::DoReplaceItem(int32 index, BListItem *item)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
2003-06-16 11:43:42 +04:00
|
|
|
BRect frame = ItemFrame(index);
|
|
|
|
|
|
|
|
if (!fList.ReplaceItem(index, item))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (frame != ItemFrame(index))
|
|
|
|
InvalidateFrom(index);
|
|
|
|
else
|
|
|
|
Invalidate(frame);
|
|
|
|
|
|
|
|
return true;
|
2002-07-09 16:24:59 +04:00
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::RescanSelection(int32 from, int32 to)
|
|
|
|
{
|
|
|
|
if (from > to)
|
|
|
|
{
|
|
|
|
int32 tmp = from;
|
|
|
|
from = to;
|
|
|
|
to = tmp;
|
|
|
|
}
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-06-16 11:43:42 +04:00
|
|
|
if (fAnchorIndex != -1)
|
|
|
|
{
|
|
|
|
if (fAnchorIndex == from)
|
|
|
|
fAnchorIndex = to;
|
|
|
|
else if (fAnchorIndex == to)
|
|
|
|
fAnchorIndex = from;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if (from < fFirstSelected && from < fLastSelected)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (to > fFirstSelected && to > fLastSelected)
|
|
|
|
return;*/
|
2003-06-16 11:55:04 +04:00
|
|
|
|
|
|
|
int32 i;
|
2003-06-16 11:43:42 +04:00
|
|
|
|
2003-06-16 11:55:04 +04:00
|
|
|
for (i = from; i <= to; i++)
|
2003-06-16 11:43:42 +04:00
|
|
|
{
|
|
|
|
if (ItemAt(i)->IsSelected())
|
|
|
|
{
|
|
|
|
fFirstSelected = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = from; i <= to; i++)
|
|
|
|
if (ItemAt(i)->IsSelected())
|
|
|
|
fLastSelected = i;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::DoMouseUp(BPoint where)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void BListView::DoMouseMoved(BPoint where)
|
2002-07-09 16:24:59 +04:00
|
|
|
{
|
|
|
|
}
|
2003-06-16 11:43:42 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/*
|
|
|
|
* $Log $
|
|
|
|
*
|
|
|
|
* $Id $
|
|
|
|
*
|
|
|
|
*/
|