Exemplo n.º 1
0
int32
BListView::_CalcFirstSelected(int32 after)
{
    if (after >= CountItems())
        return -1;

    int32 count = CountItems();
    for (int32 i = after; i < count; i++) {
        if (ItemAt(i)->IsSelected())
            return i;
    }

    return -1;
}
Exemplo n.º 2
0
	inline bool operator ==(const Selection& other)
		{
			if (other.CountItems() == CountItems()) {
				int32* items = Items();
				int32* otherItems = other.Items();
				for (int32 i = 0; i < CountItems(); i++) {
					if (items[i] != otherItems[i])
						return false;
					items++;
					otherItems++;
				}
				return true;
			} else
				return false;
		}
Exemplo n.º 3
0
//------------------------------------------------------------------------------
void BMessageField::PrintToStream(const char* name) const
{
	int32 type = B_BENDIAN_TO_HOST_INT32(Type());
	printf("    entry %14s, type='%.4s', c=%2ld, ",
		   name, (char*)&type, CountItems());

	for (int32 i = 0; i < CountItems(); ++i)
	{
		if (i)
		{
			printf("                                            ");
		}
		PrintDataItem(i);
	}
}
Exemplo n.º 4
0
	virtual void Entered()
	{
		_DeleteItems();

		if (fDirectory != NULL) {
			void* cookie;
			if (fDirectory->Open(&cookie, O_RDONLY) == B_OK) {
				Node* node;
				while (fDirectory->GetNextNode(cookie, &node) == B_OK) {
					BlacklistMenuItem* item = _CreateItem(node);
					node->Release();
					if (item == NULL)
						break;

					AddItem(item);

					item->UpdateBlacklisted();
				}
				fDirectory->Close(cookie);
			}

			SortItems(&BlacklistMenuItem::Less);
		}

		if (CountItems() > 0)
			AddSeparatorItem();
		AddItem(new(nothrow) MenuItem("Return to parent directory"));
	}
Exemplo n.º 5
0
void NetListView::FrameResized(float width, float height)
{
	BListView::FrameResized(width, height);
	//Ensure the bevel on the right is drawn properly
	if(width < oldWidth)
		oldWidth = width;
	PushState();
	BRect invalRect(oldWidth, 0, oldWidth, height);
	ConvertFromParent(&invalRect);
	BRegion lineRegion(invalRect);
	ConstrainClippingRegion(&lineRegion);
	Draw(invalRect);
	oldWidth = width;
	PopState();
	
	//Do word wrapping
	BFont curFont;
	GetFont(&curFont);
	float itemWidth = Bounds().Width();
	float wrapWidth = (itemWidth - 6)/curFont.Size();
	for(int itemNum = 0; itemNum < CountItems(); itemNum++)
	{
		NetListItem* item = (NetListItem*)(Items()[itemNum]);
		item->SetWidth(itemWidth);
		item->CalcWordWrap(wrapWidth);
	}
	//DoForEach(UpdateItem, (void*)this);
	Invalidate();
	
	BListView::FrameResized(width, height);
}
void DraggableListView::MessageReceived(BMessage *message) {
	if (message->what != B_PULSE) {
		printf("DraggableListView:\n");
		message->PrintToStream();
		printf("\n");
	}
	switch(message->what) {
		case SM_DRAG_FILTER: {
			if (accepts_drags) {
				int32 item_count;
				type_code type_found;
				message->GetInfo("filter_name", &type_found, &item_count);
				int32 current_item = 0;
				char* text = NULL;
				int32 filter_id = 0;
				message->FindString("filter_name", current_item, &text);
				// Do add-filter stuff
				BMessage app_msg(SM_ADD_FILTER);
				app_msg.AddString("addon_name", text);
				app_msg.AddInt32("position", CountItems());
				BMessage reply;
				be_app_messenger.SendMessage(&app_msg, &reply);
				reply.FindInt32("filter_id", &filter_id);
				BStringItem *newItem = new FilterItem(text, filter_id);
				AddItem(newItem);
			}
			break;
		}
		default: {
			BListView::MessageReceived(message);
			break;
		}
	}
}
Exemplo n.º 7
0
void
NetworkMenu::AttachedToWindow (void)
{
	if (CountItems())
	{
		BMenuItem *item (NULL);
		while ((item = RemoveItem((int32)0)) != NULL)
			delete item;
	}

	BMessage msg;
	BMessage *invoke (NULL);
	for (int32 i = 0; (msg = vision_app->GetNetwork (i)), !msg.HasBool ("error"); i++)
	{
		const char *name = msg.FindString ("name");
		invoke = new BMessage (fMsgConst);
		invoke->AddString ("network", name);
		BMenuItem *item (new BMenuItem(name, invoke));
		AddItem (item);
		if (!vision_app->CheckNetworkValid (name))
			item->SetEnabled (false);
	}
	SetTargetForItems (fTarget.Target(NULL));
	BMenu::AttachedToWindow();
}
Exemplo n.º 8
0
IFWL_ListItem* CFWL_ListBox::CFWL_ListBoxDP::GetItem(IFWL_Widget* pWidget,
                                                     int32_t nIndex) {
  if (nIndex < 0 || nIndex >= CountItems(pWidget))
    return nullptr;

  return m_ItemArray[nIndex].get();
}
Exemplo n.º 9
0
/***********************************************************
 * DeleteItem
 ***********************************************************/
void
HListView::DeleteItem(int32 index) {
	HListItem* item = cast_as(RemoveItem(index), HListItem);
	fPointerList.RemoveItem(item);
	delete item;

	HApp* app = cast_as(be_app, HApp);
	bool queue;

	int32 max_transfer;
	app->Prefs()->GetData("queue", &queue);
	app->Prefs()->GetData("max_transfer", &max_transfer);

	if (queue) {
		int32 num_task = max_transfer - CountDownloadingItems();
		if (num_task > 0) {
			int32 count = CountItems();
			HListItem** items = (HListItem**)Items();
			for (int32 i = 0; i < count; i++) {
				item = items[i];
				if (!item->IsStarted() && item->State() != T_FINISHED && item->State() != T_NOTFOUND) {
					item->Start();
					num_task--;
				}
				if (num_task <= 0)
					break;
			}
		}
	}
}
Exemplo n.º 10
0
void ArpOutlineListView::ComputeDimens(ArpDimens& cur_dimens)
{
	float min_w=0, min_h=0;
	float pref_w=0, pref_h=0;
	
	int32 num = CountItems();
	int32 max_num = 4;
	for( int32 i=0; i<num; i++ ) {
		BListItem* item = ItemAt(i);
		if( item ) {
			item->Update(this,BasicFont());
			float w = item->Width();
			float h = item->Height();
			min_h = max(min_h,h);
			pref_w = max(pref_w,w);
			if( max_num > 0 ) pref_h += h;
			max_num--;
		}
	}
	pref_h+=2;
	float fw = BasicFont()->StringWidth("WWWW");
	font_height fhs;
	BasicFont()->GetHeight(&fhs);
	float fh = fhs.ascent+fhs.descent+fhs.leading;
	min_w = max(min_w,fw);
	min_h = max(min_h,fh);
	pref_w = max(pref_w,min_w);
	pref_h = max(pref_h,min_h);
	
	cur_dimens.X().SetTo(0, min_w, pref_w, ArpAnySize, 0);
	cur_dimens.Y().SetTo(0, min_h, pref_h, ArpAnySize, 0);
}
Exemplo n.º 11
0
bool
BrowsingHistory::_AddItem(const BrowsingHistoryItem& item, bool internal)
{
	int32 count = CountItems();
	int32 insertionIndex = count;
	for (int32 i = 0; i < count; i++) {
		BrowsingHistoryItem* existingItem
			= reinterpret_cast<BrowsingHistoryItem*>(
			fHistoryItems.ItemAtFast(i));
		if (item.URL() == existingItem->URL()) {
			if (!internal) {
				existingItem->Invoked();
				_SaveSettings();
			}
			return true;
		}
		if (item < *existingItem)
			insertionIndex = i;
	}
	BrowsingHistoryItem* newItem = new(std::nothrow) BrowsingHistoryItem(item);
	if (!newItem || !fHistoryItems.AddItem(newItem, insertionIndex)) {
		delete newItem;
		return false;
	}

	if (!internal) {
		newItem->Invoked();
		_SaveSettings();
	}

	return true;
}
Exemplo n.º 12
0
void
BListView::_RescanSelection(int32 from, int32 to)
{
	if (from > to) {
		int32 tmp = from;
		from = to;
		to = tmp;
	}

	from = max_c(0, from);
	to = min_c(to, CountItems() - 1);

	if (fAnchorIndex != -1) {
		if (fAnchorIndex == from)
			fAnchorIndex = to;
		else if (fAnchorIndex == to)
			fAnchorIndex = from;
	}

	for (int32 i = from; i <= to; i++) {
		if (ItemAt(i)->IsSelected()) {
			fFirstSelected = i;
			break;
		}
	}

	if (fFirstSelected > from)
		from = fFirstSelected;

	fLastSelected = fFirstSelected;
	for (int32 i = from; i <= to; i++) {
		if (ItemAt(i)->IsSelected())
			fLastSelected = i;
	}
}
Exemplo n.º 13
0
bool ColumnListView::AddList(BList* newItems)
{
	if(fHierarchical)
		return AddListPrivate(newItems,fFullItemList.CountItems());
	else
		return AddListPrivate(newItems,CountItems());
}
Exemplo n.º 14
0
bool ColumnListView::AddItem(CLVListItem* item)
{
	if(fHierarchical)
		return AddItemPrivate(item,fFullItemList.CountItems());
	else
		return AddItemPrivate(item,CountItems());
}
Exemplo n.º 15
0
void
BSlowContextMenu::ClearMenu()
{
	RemoveItems(0, CountItems(), true);

	fMenuBuilt = false;
}
Exemplo n.º 16
0
void
TExpandoMenuBar::DrawBackground(BRect updateRect)
{
	if (fVertical)
		return;

	BRect bounds(Bounds());
	rgb_color menuColor = ui_color(B_MENU_BACKGROUND_COLOR);
	rgb_color hilite = tint_color(menuColor, B_DARKEN_1_TINT);
	rgb_color vlight = tint_color(menuColor, B_LIGHTEN_2_TINT);

	int32 count = CountItems() - 1;
	if (count >= 0)
		bounds.left = ItemAt(count)->Frame().right + 1;
	else
		bounds.left = 0;

	if (be_control_look != NULL) {
		SetHighColor(tint_color(menuColor, 1.22));
		StrokeLine(bounds.LeftTop(), bounds.LeftBottom());
		bounds.left++;
		uint32 borders = BControlLook::B_TOP_BORDER
			| BControlLook::B_BOTTOM_BORDER | BControlLook::B_RIGHT_BORDER;

		be_control_look->DrawButtonBackground(this, bounds, bounds, menuColor,
			0, borders);
	} else {
		SetHighColor(vlight);
		StrokeLine(bounds.LeftTop(), bounds.RightTop());
		StrokeLine(BPoint(bounds.left, bounds.top + 1), bounds.LeftBottom());
		SetHighColor(hilite);
		StrokeLine(BPoint(bounds.left + 1, bounds.bottom),
			bounds.RightBottom());
	}
}
Exemplo n.º 17
0
int32 QueryMenu::QueryThread()
{
	BAutolock lock(fQueryLock);

	if (!lock.IsLocked())
		return B_ERROR;

	// Begin resolving query
	fCancelQuery = false;
	fQuery->Fetch();

	// Build Menu
	entry_ref ref;
	node_ref node;
	while (fQuery->GetNextRef(&ref) == B_OK && !fCancelQuery)
	{
		BEntry entry(&ref);
		entry.GetNodeRef(&node);
		EntryCreated(ref, node.node);
	}

	// Remove the group separator if there are no groups or no items without groups
	BMenuItem *item;
	if (dynamic_cast<BSeparatorItem *>(item = ItemAt(0)) != NULL)
		RemoveItem(item);
	else if (dynamic_cast<BSeparatorItem *>(item = ItemAt(CountItems() - 1)) != NULL)
		RemoveItem(item);

	return B_OK;
}
Exemplo n.º 18
0
BPose*
PoseList::DeepFindPose(const node_ref* node, int32* resultingIndex) const
{
	int32 count = CountItems();
	for (int32 index = 0; index < count; index++) {
		BPose* pose = ItemAt(index);
		Model* model = pose->TargetModel();
		if (*model->NodeRef() == *node) {
			if (resultingIndex != NULL)
				*resultingIndex = index;

			return pose;
		}
		// if model is a symlink, try matching node with the target
		// of the link
		if (model->IsSymLink()) {
			model = model->LinkTo();
			if (model != NULL && *model->NodeRef() == *node) {
				if (resultingIndex != NULL)
					*resultingIndex = index;

				return pose;
			}
		}
	}

	return NULL;
}
Exemplo n.º 19
0
void DesktopOpDropDown::OnUpdateActionState()
{
	if (GetAction())
		return OpDropDown::OnUpdateActionState();

	if (m_item_actions.GetCount() == 0)
		return;

	BOOL enabled = FALSE;	
	for (int i = 0; i < CountItems(); i++)
	{
		OpInputAction* action = NULL;
		OpStatus::Ignore(m_item_actions.GetData(i, &action));
		
		if (!action)
			continue;

		INT32 state = g_input_manager->GetActionState(action, GetParentInputContext());

		//Update the selection to match the action state, but not when the user is
		//selecting a new item in the dropdown window
		if (m_dropdown_window == NULL && state & OpInputAction::STATE_SELECTED)
		{
			SelectItem(i, TRUE);
		}

		if (!(state & OpInputAction::STATE_DISABLED) || state & OpInputAction::STATE_ENABLED || IsCustomizing())
			enabled = TRUE;
	}

	SetEnabled(enabled);
}
Exemplo n.º 20
0
void
ClipView::AdjustColors()
{
	bool fade;
	int32 delay;
	int32 step;
	float maxlevel;
	bool pause;
	ClipdingerSettings* settings = my_app->Settings();
	if (settings->Lock()) {
		fade = settings->GetFade();
		step = settings->GetFadeStep();
		delay = settings->GetFadeDelay() * kMinuteUnits;
		maxlevel = 1.0 + 0.025 * settings->GetFadeMaxLevel();
		pause = settings->GetFadePause();
		settings->Unlock();
	}

	if (pause)
		return;

	bigtime_t now(real_time_clock());
	for (int32 i = 0; i < CountItems(); i++) {
		ClipItem* sItem = dynamic_cast<ClipItem *> (ItemAt(i));
		if (fade) {
			bigtime_t minutes = (now - sItem->GetTimeSince()) / 60;
			float level = B_NO_TINT
				+ (maxlevel / step * ((float)minutes / delay) / kMinuteUnits);
			sItem->SetColor(tint_color(ui_color(B_LIST_BACKGROUND_COLOR),
			(level < maxlevel) ? level : maxlevel));  // limit to maxlevel
		} else
			sItem->SetColor(ui_color(B_LIST_BACKGROUND_COLOR));
	}
}
Exemplo n.º 21
0
PoseList*
PoseList::FindAllPoses(const node_ref* node) const
{
	int32 count = CountItems();
	PoseList *result = new PoseList(5, false);
	for (int32 index = 0; index < count; index++) {
		BPose *pose = ItemAt(index);
		Model *model = pose->TargetModel();
		if (*model->NodeRef() == *node) {
			result->AddItem(pose, 0);
			continue;
		}

		if (!model->IsSymLink())
			continue;

		model = model->LinkTo();
		if (model != NULL && *model->NodeRef() == *node) {
			result->AddItem(pose);
			continue;
		}

		if (model == NULL) {
			Model model(pose->TargetModel()->EntryRef(), true);
			if (*model.NodeRef() == *node)
				result->AddItem(pose);
		}
	}

	return result;
}
Exemplo n.º 22
0
// _SetDropIndex
void
DragSortableListView::_SetDropIndex(int32 index)
{
	if (fDropIndex != index) {
		fDropIndex = index;
		if (fDropIndex >= 0) {
			int32 count = CountItems();
			if (fDropIndex == count) {
				BRect r;
				if (ItemAt(count - 1)) {
					r = ItemFrame(count - 1);
					r.top = r.bottom;
					r.bottom = r.top + 1.0;
				} else {
					r = Bounds();
					r.bottom--;	// compensate for scrollbars moved slightly out of window
				}
				_SetDropAnticipationRect(r);
			} else {
				BRect r = ItemFrame(fDropIndex);
				r.top--;
				r.bottom = r.top + 1.0;
				_SetDropAnticipationRect(r);
			}
		}
	}
}
Exemplo n.º 23
0
void
TExpandoMenuBar::DrawBackground(BRect)
{
	BRect bounds(Bounds());
	rgb_color menuColor = ui_color(B_MENU_BACKGROUND_COLOR);
	rgb_color hilite = tint_color(menuColor, B_DARKEN_1_TINT);
	rgb_color dark = tint_color(menuColor, B_DARKEN_2_TINT);
	rgb_color vlight = tint_color(menuColor, B_LIGHTEN_2_TINT);
	int32 last = CountItems() - 1;
	float start;

	if (last >= 0) 
		start = ItemAt(last)->Frame().right + 1;
	else 
		start = 0;

	
	if (!fVertical) {
		SetHighColor(vlight);
		StrokeLine(BPoint(start, bounds.top+1), bounds.RightTop() + BPoint(0,1));
		StrokeLine(BPoint(start, bounds.top+1), BPoint(start, bounds.bottom));
		SetHighColor(hilite);
		StrokeLine(BPoint(start+1, bounds.bottom), bounds.RightBottom());
	}
}
Exemplo n.º 24
0
// MessageReceived
void
DragSortableListView::MessageReceived(BMessage* message)
{
	if (message->what == fDragCommand) {
		int32 count = CountItems();
		if (fDropIndex < 0 || fDropIndex > count)
			fDropIndex = count;
		HandleDropMessage(message, fDropIndex);
		fDropIndex = -1;
	} else {
		switch (message->what) {
			case MSG_TICK: {
				float scrollV = 0.0;
				BRect rect(Bounds());
				BPoint point;
				uint32 buttons;
				GetMouse(&point, &buttons, false);
				if (rect.Contains(point)) {
					// calculate the vertical scrolling offset
					float hotDist = rect.Height() * SCROLL_AREA;
					if (point.y > rect.bottom - hotDist)
						scrollV = hotDist - (rect.bottom - point.y);
					else if (point.y < rect.top + hotDist)
						scrollV = (point.y - rect.top) - hotDist;
				}
				// scroll
				if (scrollV != 0.0 && fScrollView) {
					if (BScrollBar* scrollBar = fScrollView->ScrollBar(B_VERTICAL)) {
						float value = scrollBar->Value();
						scrollBar->SetValue(scrollBar->Value() + scrollV);
						if (scrollBar->Value() != value) {
							// update mouse position
							uint32 buttons;
							BPoint point;
							GetMouse(&point, &buttons, false);
							uint32 transit = Bounds().Contains(point) ? B_INSIDE_VIEW : B_OUTSIDE_VIEW;
							MouseMoved(point, transit, &fDragMessageCopy);
						}
					}
				}
				break;
			}
//			case B_MODIFIERS_CHANGED:
//				ModifiersChanged();
//				break;
			case B_MOUSE_WHEEL_CHANGED: {
				BListView::MessageReceived(message);
				BPoint point;
				uint32 buttons;
				GetMouse(&point, &buttons, false);
				uint32 transit = Bounds().Contains(point) ? B_INSIDE_VIEW : B_OUTSIDE_VIEW;
				MouseMoved(point, transit, &fDragMessageCopy);
				break;
			}
			default:
				BListView::MessageReceived(message);
				break;
		}
	}
}
Exemplo n.º 25
0
// SetDropTargetRect
void
DragSortableListView::SetDropTargetRect(const BMessage* message, BPoint where)

{
	if (AcceptDragMessage(message)) {
		bool copy = modifiers() & B_SHIFT_KEY;
		bool replaceAll = !message->HasPointer("list") && !copy;
		BRect r = Bounds();
		if (replaceAll) {
			r.bottom--;	// compensate for scrollbar offset
			_SetDropAnticipationRect(r);
			fDropIndex = -1;
		} else {
			// offset where by half of item height
			r = ItemFrame(0);
			where.y += r.Height() / 2.0;
	
			int32 index = IndexOf(where);
			if (index < 0)
				index = CountItems();
			_SetDropIndex(index);

			const uchar* cursorData = copy ? kCopyCursor : B_HAND_CURSOR;
			BCursor cursor(cursorData);
			SetViewCursor(&cursor, true);
		}
	}
}
Exemplo n.º 26
0
// Draw
void
DragSortableListView::Draw(BRect updateRect)
{
	int32 firstIndex = IndexOf(updateRect.LeftTop());
	int32 lastIndex = IndexOf(updateRect.RightBottom());
	if (firstIndex >= 0) {
		if (lastIndex < firstIndex)
			lastIndex = CountItems() - 1;
		// update rect contains items
		BRect r = updateRect;
		for (int32 i = firstIndex; i <= lastIndex; i++) {
			r = ItemFrame(i);
			DrawListItem(this, i, r);
		}
		updateRect.top = r.bottom + 1.0;
		if (updateRect.IsValid()) {
			SetLowColor(255, 255, 255, 255);
			FillRect(updateRect, B_SOLID_LOW);
		}
	} else {
		SetLowColor(255, 255, 255, 255);
		FillRect(updateRect, B_SOLID_LOW);
	}
	// drop anticipation indication
	if (fDropRect.IsValid()) {
		SetHighColor(255, 0, 0, 255);
		StrokeRect(fDropRect);
	}
/*	// focus indication
	if (IsFocus()) {
		SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
		StrokeRect(Bounds());
	}*/
}
Exemplo n.º 27
0
bool
ShowImageWindow::RecentDocumentsMenu::AddDynamicItem(add_state addState)
{
	if (addState != B_INITIAL_ADD)
		return false;

	while (CountItems() > 0)
		delete RemoveItem(0L);

	BMenuItem *item;
	BMessage list, *msg;
	entry_ref ref;
	char name[B_FILE_NAME_LENGTH];

	be_roster->GetRecentDocuments(&list, 20, NULL, kApplicationSignature);
	for (int i = 0; list.FindRef("refs", i, &ref) == B_OK; i++) {
		BEntry entry(&ref);
		if (entry.Exists() && entry.GetName(name) == B_OK) {
			msg = new BMessage(B_REFS_RECEIVED);
			msg->AddRef("refs", &ref);
			item = new EntryMenuItem(&ref, name, msg, 0, 0);
			AddItem(item);
			item->SetTarget(be_app, NULL);
		}
	}

	return false;
}
Exemplo n.º 28
0
/*!	Returns the team menu item that belongs to the item under the
	specified \a point.
	If \a _item is given, it will return the exact menu item under
	that point (which might be a window item when the expander is on).
*/
TTeamMenuItem*
TExpandoMenuBar::TeamItemAtPoint(BPoint point, BMenuItem** _item)
{
	TTeamMenuItem* lastApp = NULL;
	int32 count = CountItems();

	for (int32 i = fFirstApp; i < count; i++) {
		BMenuItem* item = ItemAt(i);

		if (dynamic_cast<TTeamMenuItem*>(item) != NULL)
			lastApp = (TTeamMenuItem*)item;

		if (item && item->Frame().Contains(point)) {
			if (_item != NULL)
				*_item = item;

			return lastApp;
		}
	}

	// no item found

	if (_item != NULL)
		*_item = NULL;

	return NULL;
}
Exemplo n.º 29
0
/*****************************************************************************
 * PlaylistView::SetPlaying
 *****************************************************************************/
void
PlaylistView::RebuildList()
{
    playlist_t * p_playlist;
    p_playlist = (playlist_t *) vlc_object_find( p_intf,
        VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );

    if( !p_playlist )
    {
        return;
    }

    // remove all items
    BListItem * item;
    int32 count = CountItems();
    while( ( item = RemoveItem( --count ) ) )
        delete item;
    
    // rebuild listview from VLC's playlist
    vlc_mutex_lock( &p_playlist->object_lock );
    for( int i = 0; i < p_playlist->i_size; i++ )
        AddItem( new PlaylistItem( p_playlist->pp_items[i]->input.psz_name ) );
    vlc_mutex_unlock( &p_playlist->object_lock );

    vlc_object_release( p_playlist );
}
Exemplo n.º 30
0
void
AudioListView::RenumberTracks()
{
	for (int32 i = 0; i < CountItems(); i++) {
		AudioListItem* item = dynamic_cast<AudioListItem *>(ItemAt(i));
		item->SetTrack(i);
	}
}