第一印象
範例程式
截圖
與其它函式庫比較
相關應用
下載
教學文件
作品展示(Bazaar)
現狀及發展藍圖
常見問題(FAQ)
作者與授權
論壇
資助Ultimate++
搜尋本網站
語言
中文(繁體)











SourceForge.net Logo



ArrayCtrlDnD

 

Drag&Drop with ArrayCtrl as target

 

 

main.cpp

 

#include <CtrlLib/CtrlLib.h>

 

using namespace Upp;

 

struct App : TopWindow {

    ArrayCtrl a, b;

    Splitter  s;

 

    void DnD(PasteClip& d)

    {

        if(AcceptText(d)) {

            a.Add(GetString(d), GetString(d));

            a.SetFocus();

        }

    }

 

    void DnDInsert(int line, PasteClip& d)

    {

        if(AcceptInternal<ArrayCtrl>(d, "array")) {

            a.InsertDrop(line, d);

            a.SetFocus();

        }

        if(AcceptText(d)) {

            a.Insert(line);

            a.Set(line, 0, GetString(d));

            a.SetCursor(line);

            a.SetFocus();

        }

    }

 

    void DnDInsertB(int line, PasteClip& d)

    {

        if(AcceptInternal<ArrayCtrl>(d, "array")) {

            const ArrayCtrl& src = GetInternal<ArrayCtrl>(d);

            bool self = &src == &b;

            Vector< Vector<Value> > data;

            for(int i = 0; i < src.GetCount(); i++)

                if(src.IsSel(i)) {

                    Value v = src.Get(i, 0);

                    data.Add().Add(IsNumber(v) ? FormatIntRoman((int)src.Get(i, 0)) : String(v));

                }

            b.InsertDrop(line, data, d, self);

            b.SetFocus();

        }

    }

 

    void Drag()

    {

        if(a.DoDragAndDrop(InternalClip(a, "array")) == DND_MOVE)

            a.RemoveSelection();

    }

 

    void DragB()

    {

        if(b.DoDragAndDrop(InternalClip(b, "array"), b.GetDragSample()) == DND_MOVE)

            b.RemoveSelection();

    }

 

    typedef App CLASSNAME;

 

    App() {

        a.AddColumn("You can paste the text here too");

        a.MultiSelect();

        a.WhenDropInsert = THISBACK(DnDInsert);

        a.WhenDrop = THISBACK(DnD);

        a.WhenDrag = THISBACK(Drag);

 

        b.AddColumn("Roman numbers");

        b.MultiSelect();

        b.WhenDropInsert = THISBACK(DnDInsertB);

        b.WhenDrag = THISBACK(DragB);

 

        Add(s.Horz(a, b));

        for(int i = 0; i < 200; i++) {

            a.Add(i);

            b.Add(FormatIntRoman(i, true));

        }

        Sizeable();

    }

};

 

GUI_APP_MAIN

{

    App().Run();

}

 

 

 

 

本頁也正在english, català, čeština, deutsch, español, euskara, français, română, русский中文(简体)中. 你想幫忙嗎?