Пример #1
0
void OpPersonalbar::OnTreeChanged(OpTreeModel* tree_model)
{
    if( tree_model == g_hotlist_manager->GetBookmarksModel() )
    {
        for( INT32 i=GetWidgetCount()-1; i>=0; i-- )
        {
            OpWidget* widget = GetWidget(i);
            if( widget && widget->GetType() != WIDGET_TYPE_SEARCH_EDIT )
            {
                RemoveWidget(i);
            }
        }
    }
#ifdef DESKTOP_UTIL_SEARCH_ENGINES
    else if( tree_model == g_searchEngineManager )
    {
        for( INT32 i=GetWidgetCount()-1; i>=0; i-- )
        {
            OpWidget* widget = GetWidget(i);
            if( widget && widget->GetType() == WIDGET_TYPE_SEARCH_EDIT )
            {
                RemoveWidget(i);
            }
        }
    }
#endif // DESKTOP_UTIL_SEARCH_ENGINES

    for (INT32 i = 0; i < tree_model->GetItemCount(); i++)
    {
        AddItem(tree_model, i, TRUE);
    }
}
Пример #2
0
void OpPersonalbar::Write()
{
    for (INT32 i = 0; i < GetWidgetCount(); i++)
    {
        OpTreeModel* model = (OpTreeModel*) GetUserData(i);
        INT32 id = GetWidget(i)->GetID();

#ifdef DESKTOP_UTIL_SEARCH_ENGINES
        if (model != g_searchEngineManager)
        {
#endif // DESKTOP_UTIL_SEARCH_ENGINES
            g_hotlist_manager->SetPersonalBarPosition(id, i, FALSE);
#ifdef DESKTOP_UTIL_SEARCH_ENGINES
        }
        else
        {
            OpTreeModelItem* search;
            g_searchEngineManager->GetItemByID(id, search);
            if(search)
            {
                ((SearchTemplate*)search)->SetPersonalbarPos(i);
            }
        }
#endif // DESKTOP_UTIL_SEARCH_ENGINES
    }
#ifdef DESKTOP_UTIL_SEARCH_ENGINES
    g_searchEngineManager->Write();
#endif // DESKTOP_UTIL_SEARCH_ENGINES
}
Пример #3
0
// We can have the same identifier in search and bookmarks/contacts model. That will
// lead to confusion so we test for model as well.
INT32 OpPersonalbar::FindItem(INT32 id, OpTreeModel* model_that_id_belongs_to)
{
    for (INT32 i = 0; i < GetWidgetCount(); i++)
    {
        OpWidget* widget = GetWidget(i);

        if (id == widget->GetID())
        {
            if( model_that_id_belongs_to )
            {
                BOOL is_search_template = widget->GetType() == WIDGET_TYPE_SEARCH_EDIT;
#ifdef DESKTOP_UTIL_SEARCH_ENGINES
                BOOL is_search_model    = g_searchEngineManager == model_that_id_belongs_to;
                if( is_search_template != is_search_model )
                {
                    continue;
                }
#endif // DESKTOP_UTIL_SEARCH_ENGINES
            }

            return i;
        }
    }

    return -1;
}
Пример #4
0
INT32 OpPersonalbar::GetPosition(OpWidget* wdg)
{
    INT32 count = GetWidgetCount();

    for (INT32 i = 0; i < count; ++i)
    {
        OpWidget *widget = GetWidget(i);
        if (widget == wdg)
            return i;
    }
    return -1;
}
Пример #5
0
INT32 OpPersonalbar::FindItem(INT32 id)
{
    for (INT32 i = 0; i < GetWidgetCount(); i++)
    {
        if (id == GetWidget(i)->GetID())
        {
            return i;
        }
    }

    return -1;
}
Пример #6
0
PG_Widget* PG_WidgetList::FindWidget(int index) {

	if((index < 0) || (index >= GetWidgetCount())) {
		return NULL;
	}

	int i = 0;
	PG_Widget* list = my_scrollarea->GetChildList()->first();
	for( ; list != NULL; list = list->next()) {
		if(i == index) {
			return list;
		}
		i++;
	}

	return NULL;
}
Пример #7
0
/***********************************************************************************
 **
 **	GetItemCount
 **
 ***********************************************************************************/
INT32 HotlistSelector::GetItemCount()
{
	return GetWidgetCount();
}
Пример #8
0
void HotlistSelector::OnLayout()
{
	OpBar::OnLayout(); // needs to be done before the floating bar is positioned

	// if the floating bar is shown
	if ((m_floating_bar->IsOn() && m_floating_bar->GetWidgetCount() > 0) ||
		g_application->IsCustomizingHiddenToolbars())
	{
		INT32 used_width = 0, used_height = 0;

		OpRect floating_rect;
		INT32 left, top, right, bottom;

		OpToolbar::GetPadding(&left, &top, &right, &bottom);

		// layout the floating toolbar to be within the padding of this toolbar
		OpRect rect = GetBounds();
		OpToolbar::OnLayout(TRUE, rect.width, rect.height, used_width, used_height);

		rect.x += left;
		rect.y += top;
		rect.width -= left + right;
		rect.height -= top + bottom;

		m_floating_bar->GetRequiredSize(floating_rect.width, floating_rect.height);

		INT32 pos = GetWidgetCount();

		OpWidget *last_button = pos ? GetWidget(pos - 1) : NULL;

		if(IsHorizontal())
		{
			INT32 w, row_height;
			GetBorderSkin()->GetSize(&w, &row_height);
			if (row_height > floating_rect.height)
				floating_rect.height = row_height;

			// align after the last button, if any
			if(last_button)
			{
				OpRect b_rect = last_button->GetRect();

				floating_rect.x = rect.width - floating_rect.width; //b_rect.Right() + 1;
				floating_rect.y = b_rect.y + (b_rect.height - floating_rect.height) / 2;
			}
			else
			{
				floating_rect.x = 0;
				floating_rect.y = rect.y + (rect.height - floating_rect.height) / 2;
			}
		}
		else // isVertical
		{
			// right-align the floating bar and grow-to-fit the rest of the buttons (done automatically for vertical toolbars?)
			// TODO: Margins and paddings
			floating_rect.x = rect.x + (rect.width - floating_rect.width) / 2;
			if(last_button)
			{
				OpRect b_rect = last_button->GetRect();

				floating_rect.y = b_rect.Bottom() + 1;
			}
			else
			{
				floating_rect.y = 0;
			}
		}
		m_floating_bar->LayoutToAvailableRect(floating_rect);
	}
}
Пример #9
0
/***********************************************************************************
**
**	OnDragMove
**
***********************************************************************************/
void OpPersonalbar::DragMoveDrop(OpWidget* widget, OpDragObject* op_drag_object, INT32 pos, INT32 x, INT32 y, BOOL drop)
{
    DesktopDragObject* drag_object = static_cast<DesktopDragObject *>(op_drag_object);

    if (widget == this)
    {
        // Make it possible to drop into folder
        int target_pos = GetWidgetPosition(x,y);
        HotlistModelItem* target_folder = NULL;
        OpWidget* target_widget = NULL;
        BOOL drag_into_folder = FALSE;

        if (target_pos >= 0 && target_pos < GetWidgetCount())
        {
            target_widget = GetWidget(target_pos);
            HotlistModelItem* item = GetModelItemFromPos(target_pos);

            if (target_widget && target_widget->GetType() == OpTypedObject::WIDGET_TYPE_BUTTON
                    && item && item->IsFolder())
            {
                OpRect rect = target_widget->GetRect();
                if (x > rect.x + rect.width/4 && x < rect.x + rect.width*3/4 && rect.Contains(OpPoint(x,y)))
                {
                    target_folder = item;
                }
            }
        }

        if (drag_object->GetType() == DRAG_TYPE_SEARCH_EDIT)
        {
#ifdef DESKTOP_UTIL_SEARCH_ENGINES
            SearchTemplate* search = g_searchEngineManager->GetSearchEngine(drag_object->GetID());

            BOOL copy = search ? (search->GetPersonalbarPos() == -1) : FALSE;

            if (drop && search)
            {
                search->SetPersonalbarPos(pos);
                g_searchEngineManager->ChangeItem(search, drag_object->GetID(), SearchEngineManager::FLAG_PERSONALBAR);
            }
            if(!drop && search)
            {
                drag_object->SetDesktopDropType(copy ? DROP_COPY : DROP_MOVE);
            }
#endif // DESKTOP_UTIL_SEARCH_ENGINES
        }
        else if (drag_object->GetType() == DRAG_TYPE_BOOKMARK || drag_object->GetType() == DRAG_TYPE_CONTACT)
        {
            BOOL copy = FALSE;
            HotlistManager::ItemData item_data;
            if( g_hotlist_manager->GetItemValue(drag_object->GetID(0), item_data) )
            {
                copy = item_data.personalbar_position == -1;
            }

            if (drop)
            {
                for (INT32 i = 0; i < drag_object->GetIDCount(); i++)
                {
                    g_hotlist_manager->SetPersonalBarPosition( drag_object->GetID(i), pos, TRUE);
                }
            }
            else
                drag_object->SetDesktopDropType(copy ? DROP_COPY : DROP_MOVE);
        }
        else if (drag_object->GetType() == DRAG_TYPE_HISTORY)
        {
            DesktopHistoryModel* history_model = DesktopHistoryModel::GetInstance();

            if (drop)
            {
                for (INT32 i = 0; i < drag_object->GetIDCount(); i++)
                {
                    HistoryModelItem* history_item = history_model->FindItem(drag_object->GetID(i));

                    if (history_item)
                    {
                        BookmarkItemData item_data;

                        OpString title;
                        OpString address;

                        history_item->GetTitle(title);
                        history_item->GetAddress(address);

                        item_data.name.Set( title.CStr() );
                        item_data.url.Set( address.CStr() );
                        item_data.personalbar_position = target_folder ? -1 : pos;

                        g_desktop_bookmark_manager->DropItem( item_data, target_folder ? target_folder->GetID() : HotlistModel::BookmarkRoot,
                                                              DesktopDragObject::INSERT_INTO, TRUE, DRAG_TYPE_HISTORY );
                    }
                }
            }
            else if( drag_object->GetIDCount() > 0 )
            {
                HistoryModelItem* history_item = history_model->FindItem(drag_object->GetID(0));

                if (history_item)
                {
                    BookmarkItemData item_data;
                    item_data.personalbar_position = target_folder ? -1 : pos;

                    if( g_desktop_bookmark_manager->DropItem( item_data, target_folder ? target_folder->GetID() : HotlistModel::BookmarkRoot,
                            DesktopDragObject::INSERT_INTO, FALSE, DRAG_TYPE_HISTORY ) )
                    {
                        drag_object->SetDesktopDropType(DROP_COPY);
                        drag_into_folder = target_folder != NULL;
                    }
                }
            }
        }
        else if (drag_object->GetURL() && *drag_object->GetURL() )
        {
            if (drop)
            {
                if( drag_object->GetURLs().GetCount() > 0 )
                {
                    for( UINT32 i=0; i<drag_object->GetURLs().GetCount(); i++ )
                    {
                        BookmarkItemData item_data;
                        if( i == 0 )
                            item_data.name.Set( drag_object->GetTitle() );

                        item_data.url.Set( *drag_object->GetURLs().Get(i) );
                        item_data.personalbar_position = target_folder ? -1 : pos+i;
                        if (i == 0)
                            item_data.description.Set(DragDrop_Data_Utils::GetText(drag_object));

                        g_desktop_bookmark_manager->DropItem( item_data, target_folder ? target_folder->GetID() : HotlistModel::BookmarkRoot,
                                                              DesktopDragObject::INSERT_INTO, TRUE, drag_object->GetType() );
                    }
                }
                else
                {
                    BookmarkItemData item_data;
                    item_data.name.Set( drag_object->GetTitle() );
                    item_data.url.Set( drag_object->GetURL() );
                    item_data.personalbar_position = target_folder ? -1 : pos;

                    item_data.description.Set(DragDrop_Data_Utils::GetText(drag_object));

                    g_desktop_bookmark_manager->DropItem( item_data, target_folder ? target_folder->GetID() : HotlistModel::BookmarkRoot,
                                                          DesktopDragObject::INSERT_INTO, TRUE, drag_object->GetType() );
                }
            }
            else
            {
                BookmarkItemData item_data;
                item_data.personalbar_position = pos;

                if( g_desktop_bookmark_manager->DropItem( item_data, target_folder ? target_folder->GetID() : HotlistModel::BookmarkRoot,
                        DesktopDragObject::INSERT_INTO, FALSE, drag_object->GetType()) )
                {
                    drag_object->SetDesktopDropType(DROP_COPY);
                    drag_into_folder = target_folder != NULL;
                }
            }
        }

        if (drop)
        {
            Write();
        }

        // Highlight folder button
        if (target_widget)
            target_widget->SetValue(drag_into_folder);

        m_disable_indicator = drag_into_folder;

        return;
    }
    if(drop)
    {
        OpToolbar::OnDragDrop(widget, drag_object, pos, x, y);
    }
    else
    {
        OpToolbar::OnDragMove(widget, drag_object, pos, x, y);
    }
}
Пример #10
0
BOOL OpPersonalbar::AddItem(OpTreeModel* model, INT32 model_pos, BOOL init)
{
    OpTreeModelItem* model_item = model->GetItemByPosition(model_pos);

    BookmarkItemData item_data;
    INT32 personalbar_pos;

    if (model_item->GetType() == SEARCHTEMPLATE_TYPE)
    {
#ifdef DESKTOP_UTIL_SEARCH_ENGINES
        SearchTemplate* search = (SearchTemplate*) model_item;
        personalbar_pos = search->GetPersonalbarPos();

        if (personalbar_pos == -1)
        {
            return FALSE;
        }
#endif // DESKTOP_UTIL_SEARCH_ENGINES
    }
    else // Assumption: then its hotlist
    {
        // BOOKMARKS!

        if (!g_hotlist_manager->IsOnPersonalBar(model_item))
        {
            return FALSE;
        }
        if (!g_desktop_bookmark_manager->GetItemValue(model_item, item_data))
        {
            return FALSE;
        }
        personalbar_pos = item_data.personalbar_position;
    }

    if (init)
    {
        for (INT32 i = 0; i < GetWidgetCount(); i++)
        {
            INT32 compare_pos = -1;

            OpTreeModel* model = (OpTreeModel*) GetUserData(i);
            INT32 id = GetWidget(i)->GetID();

#ifdef DESKTOP_UTIL_SEARCH_ENGINES
            if (model != g_searchEngineManager)
            {
#endif // DESKTOP_UTIL_SEARCH_ENGINES

                compare_pos = g_hotlist_manager->GetPersonalBarPosition(id);

#ifdef DESKTOP_UTIL_SEARCH_ENGINES
            }
            else
            {
                OpTreeModelItem* search;
                g_searchEngineManager->GetItemByID(id, search);
                if(search)
                {
                    compare_pos = ((SearchTemplate*)search)->GetPersonalbarPos();
                }
            }
#endif // DESKTOP_UTIL_SEARCH_ENGINES

            if (compare_pos >= personalbar_pos)
            {
                if( compare_pos == -1 && personalbar_pos == -1 )
                {
                    personalbar_pos = GetWidgetCount();
                }
                else
                {
                    personalbar_pos = i;
                }
                break;
            }
        }
        if( GetWidgetCount() == 0  && personalbar_pos == -1 )
        {
            personalbar_pos = 0;
        }
    }

    if (model_item->GetType() == SEARCHTEMPLATE_TYPE)
    {

        OpSearchEdit* edit = OP_NEW(OpSearchEdit, (model_pos)); //model pos equals search number.. clean up later
        if (edit)
        {
            edit->SetID(model_item->GetID());
            edit->SetUserData(model);
            AddWidget(edit, personalbar_pos);
        }
    }
    else
    {
        OpInputAction* action = NULL;

        if (model_item->GetType() == OpTypedObject::BOOKMARK_TYPE)
        {
            action = OP_NEW(OpInputAction, (OpInputAction::ACTION_OPEN_LINK));
        }
#ifdef M2_SUPPORT
        else if (model_item->GetType() == OpTypedObject::CONTACT_TYPE)
        {
            action = OP_NEW(OpInputAction, (OpInputAction::ACTION_VIEW_MESSAGES_FROM_CONTACT));
        }
#endif // M2_SUPPORT
        else if (model_item->GetType() == OpTypedObject::FOLDER_TYPE )
        {
            action = OP_NEW(OpInputAction, (OpInputAction::ACTION_SHOW_POPUP_MENU));
            if (!action)
                return TRUE;
            if( model == g_hotlist_manager->GetBookmarksModel() )
            {
                action->SetActionDataString(UNI_L("Bookmark Folder Menu"));
            }
            else if( model == g_hotlist_manager->GetContactsModel() )
            {
                action->SetActionDataString(UNI_L("Contact Folder Menu"));
            }
        }

        if( action )
        {
            action->SetActionData(model_item->GetID());

            ((HotlistModelItem*)model_item)->GetInfoText(action->GetActionInfo());

            OpButton *button = AddButton(item_data.name.CStr(), item_data.direct_image_pointer, action, model, personalbar_pos);
            if( button )
            {
                Image icon = ((HotlistModelItem*)model_item)->GetIcon();
                button->GetForegroundSkin()->SetBitmapImage( icon, FALSE );
                button->GetForegroundSkin()->SetRestrictImageSize(TRUE);

                button->SetID(model_item->GetID());
                button->SetEllipsis(g_pcui->GetIntegerPref(PrefsCollectionUI::EllipsisInCenter) == 1 ? ELLIPSIS_CENTER : ELLIPSIS_END);
                button->SetTabStop(TRUE);
            }
        }
    }
    return TRUE;
}