clipboard content not up to date [message #463317] |
Thu, 03 November 2005 11:57 |
Florian Huber Messages: 15 Registered: July 2009 |
Junior Member |
|
|
Hi everybody!
I want to get selected text from an ole-integrated acrobat reader.
At present, to get the string, I select the text with the mouse, press
ctrl+c and press a button that reads the content clipboard.
To shorten the workflow, I post an "ctrl+c" keyevent to the display just
before I read the content of the clipboard.
The unsatisfying result of this operation: I get the old clipboard content.
The content is actual, only when I part the actions!
Can anybody help me with this problem?
I've written some code to illustrate this problem.
Just enter some text, press the "ctrlc" button (watch debug output) and at
the end "show clipboard".
Thank you,
Florian
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
public class clipboardTest{
static Clipboard cb = null;
static Display display = null;
public static void ctrlc(Text text){
System.out.println("ctrlc");
text.setFocus();
Event event = new Event();
event.type = SWT.KeyDown;
event.keyCode = SWT.CTRL;
display.post(event);
event = new Event();
event.type = SWT.KeyDown;
event.character = 'c';
display.post(event);
event = new Event();
event.type = SWT.KeyUp;
event.character = 'c';
display.post(event);
event = new Event();
event.type = SWT.KeyUp;
event.keyCode = SWT.CTRL;
display.post(event);
}//ctrlc
public static void showClipboard(){
TextTransfer transfer = TextTransfer.getInstance();
String data = (String) cb.getContents(transfer);
System.out.println("clipboard: " + data);
}//clipboardZeigen
public static void main(String[] args){
display = new Display();
cb = new Clipboard(display);
final Shell shell = new Shell(display);
shell.setLayout(new GridLayout(1, false));
final Text text = new Text(shell, SWT.BORDER);
text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Button ctc = new Button(shell, SWT.PUSH);
ctc.setText("ctrlc");
Button showClipboard = new Button(shell, SWT.PUSH);
showClipboard.setText("show clipboard");
shell.pack();
shell.open();
ctc.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent event){
ctrlc(text);
showClipboard();
}
});
showClipboard.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent event){
showClipboard();
}
});
while(!shell.isDisposed()){
if(!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
}
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03154 seconds