Link to home
Start Free TrialLog in
Avatar of PinTail
PinTailFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Clipboard aware CListCtrl

I am looking for a nice implementation of a Clipboard Aware CListCtrl.

It should support:
Cut (copy contents of selected items into clipboard as delimited text, and delete items)
Copy (copy contents of selected items into clipboard as delimited text)
Paste (insert copy of delimited clipboard text as new row in List)

I have implemented a bodgy solution, which I am not very happy with,, and was hoping that someone more clever than me has a better solution.

ASKER CERTIFIED SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PinTail

ASKER

Zoppo,

Thanks for the reply.

This is very similar to what I have already.

A few things I don't like about my current implementation:

Doesn't pad blank subitems.
Doesn't maintain column width information.

I suppose in retrospect that my implementation is not so kludgy after all.

I'll wait for more suggestions, but will award points to you if nothing more suitable/elegant is suggested
Avatar of RONSLOW
RONSLOW

Why would you want to pad subitems?
What is the problem with column width?
BTW, what's the meaning of 'kludgy'? Do you mean mine is better or worse than yours? Never heard that before and cannot find a translation anywhere...
Avatar of PinTail

ASKER

Ronslow,

It is important to maintain some sort of column structure in the resultant clipboard data.  I suppose I could just use TAB as the delimiter, and let the client application figure out the columns, but this assumes that my data has no TABs in it, so I thought instead I should expand all column width information based upon font, and fill with the appropriate number of spaces.  better still, I would have though, would be to make a MetaFile of some form.

Zoppo,

Kludgy implies not neat, or elegant, sort of thrown together.  I would say your solution is so close to mine that the kludginess of mine is suspect. In retrospect, I can't think how this could be done any better than you (or I) have already arrived at.
If you want a nice solution, you should probably be using callbacks for your item and column text anyway.

That way you don't need toworry about column structure .. you only need to copy the lparam.

Because using callbacks separates the data more cleanly from the list control itself (ie. its not kludgy .. its nice an OO), the copy and paste logic no longer really needs to be in the list control class itself.  Instead, the data structure that represents the data can needs to know about copying and pasting .. the list view just shows whats there.

For example, what I do is have a list control with copy andpaste buttons.  The copy button asks the list control for the lparam data value (pointer or array index) and ask the data structure to make a copy of itself into the clipboard.  The paste button inserts from the clipboard into the data structure, and then repopulates the list control from there (this is quite quick when you use callbacks as you only need to setup the lparams, and not provided all the text).

I think you will find that a better solution.
Avatar of PinTail

ASKER

Ahh,

but this kind of 'forces' the use of callbacks.

While I'll admit that this solution is generally better ( I use callbacks almost all the time - especially when I know I will be dealing with large data sets, and sorting them ), it doesn't behave the way other controls deal with the clipboard.  

Clipboard aware controls place the data onto the clipboard themselves.
If you want to paste an arbitary row onto the clipboard, I'd use tab-seaparted text.  Or set up your own clipboard format (then you can copy/paste your own data format and use callbacks etc).  Usually one would copy both a text version AND native data.  That way you can copy/paste in your own app efficiently, and still get at the text form in other apps.
Avatar of PinTail

ASKER

Well, no more comments, or answers.

I am off on vacation at the end of the day, so I will assign the points as promised to Zoppo.

Too bad we can't split the points between answers, or I would gladly offer RONSLOW some as well for his comments.

Avatar of PinTail

ASKER

Comment accepted as answer
Now, tell me how many points you want to give to RONSLOW. If you agree I will offer this amount to him...

ZOPPO
Avatar of PinTail

ASKER

Fine,

I would say split it 50/50, so 250 points.
ok...
Thank you Zoppo .. most generous!