copying to clipboard
"corvid" <[email protected]>
| Newsgroups | gmane.comp.web.dillo.devel |
|---|---|
| Message-ID | <20121006042454.GA2521@local> |
I was thinking how I sometimes see where newbies suppose that dillo can't copy and paste because they think ctrl-c must be how everything does copying...and I thought I'd find out what it would take to make that work. Some not-scrutinized code attached. There is this circuitous part where control goes from Layout to SelectionState to Layout again to Platform, which isn't too pleasing... _______________________________________________ Dillo-dev mailing list [email protected] http://lists.auriga.wearlab.de/cgi-bin/mailman/listinfo/dillo-dev
clipboard_selection.diff
(text/plain, 6 KB)
diff -r f99afbd38ae7 dw/fltkplatform.cc
--- a/dw/fltkplatform.cc Fri Oct 05 19:12:25 2012 +0000
+++ b/dw/fltkplatform.cc Sat Oct 06 03:55:20 2012 +0000
@@ -698,9 +698,17 @@
return FltkTooltip::create (text);
}
-void FltkPlatform::copySelection(const char *text)
+void FltkPlatform::copySelection(core::SelectionType st, const char *text)
{
- Fl::copy(text, strlen(text), 0);
+ int dest;
+
+ if (st == core::SELECTION_CLIPBOARD) {
+ dest = 1;
+ } else {
+ // core::SELECTION_PRIMARY
+ dest = 0;
+ }
+ Fl::copy(text, strlen(text), dest);
}
core::Imgbuf *FltkPlatform::createImgbuf (core::Imgbuf::Type type,
diff -r f99afbd38ae7 dw/fltkplatform.hh
--- a/dw/fltkplatform.hh Fri Oct 05 19:12:25 2012 +0000
+++ b/dw/fltkplatform.hh Sat Oct 06 03:55:20 2012 +0000
@@ -172,7 +172,7 @@
core::Imgbuf *createImgbuf (core::Imgbuf::Type type, int width, int height);
- void copySelection(const char *text);
+ void copySelection(core::SelectionType st, const char *text);
core::ui::ResourceFactory *getResourceFactory ();
diff -r f99afbd38ae7 dw/layout.hh
--- a/dw/layout.hh Fri Oct 05 19:12:25 2012 +0000
+++ b/dw/layout.hh Sat Oct 06 03:55:20 2012 +0000
@@ -362,9 +362,14 @@
return platform->createImgbuf (type, width, height);
}
- inline void copySelection(const char *text)
+ inline void copySelection(SelectionType st, const char *text)
{
- platform->copySelection(text);
+ platform->copySelection(st, text);
+ }
+
+ inline void clipboardCopy()
+ {
+ selectionState.copy(SELECTION_CLIPBOARD);
}
inline ui::ResourceFactory *getResourceFactory ()
diff -r f99afbd38ae7 dw/platform.hh
--- a/dw/platform.hh Fri Oct 05 19:12:25 2012 +0000
+++ b/dw/platform.hh Sat Oct 06 03:55:20 2012 +0000
@@ -156,7 +156,7 @@
/**
* \brief Copy selected text (0-terminated).
*/
- virtual void copySelection(const char *text) = 0;
+ virtual void copySelection(SelectionType st, const char *text) = 0;
/**
* ...
diff -r f99afbd38ae7 dw/selection.cc
--- a/dw/selection.cc Fri Oct 05 19:12:25 2012 +0000
+++ b/dw/selection.cc Sat Oct 06 03:55:20 2012 +0000
@@ -177,7 +177,7 @@
// nothing selected
resetSelection ();
else {
- copy ();
+ copy (SELECTION_PRIMARY);
selectionState = SELECTED;
}
}
@@ -400,7 +400,7 @@
}
}
-void SelectionState::copy()
+void SelectionState::copy(SelectionType st)
{
if (from && to) {
Iterator *si;
@@ -472,7 +472,7 @@
delete i;
}
- layout->copySelection(strbuf.getChars());
+ layout->copySelection(st, strbuf.getChars());
}
}
diff -r f99afbd38ae7 dw/selection.hh
--- a/dw/selection.hh Fri Oct 05 19:12:25 2012 +0000
+++ b/dw/selection.hh Sat Oct 06 03:55:20 2012 +0000
@@ -214,7 +214,6 @@
void highlight0 (bool fl, DeepIterator *from, int fromChar,
DeepIterator *to, int toChar, int dir);
- void copy ();
public:
enum EventType { BUTTON_PRESS, BUTTON_RELEASE, BUTTON_MOTION };
@@ -233,6 +232,7 @@
bool handleEvent (EventType eventType, Iterator *it, int charPos,
int linkNo, MousePositionEvent *event);
+ void copy (SelectionType t);
};
} // namespace dw
diff -r f99afbd38ae7 dw/types.hh
--- a/dw/types.hh Fri Oct 05 19:12:25 2012 +0000
+++ b/dw/types.hh Sat Oct 06 03:55:20 2012 +0000
@@ -46,6 +46,12 @@
HIGHLIGHT_NUM_LAYERS
};
+enum SelectionType
+{
+ SELECTION_PRIMARY,
+ SELECTION_CLIPBOARD,
+};
+
struct Point
{
int x;
diff -r f99afbd38ae7 src/keys.cc
--- a/src/keys.cc Fri Oct 05 19:12:25 2012 +0000
+++ b/src/keys.cc Sat Oct 06 03:55:20 2012 +0000
@@ -108,6 +108,7 @@
{ "right-tab" , KEYS_RIGHT_TAB , FL_CTRL , FL_Page_Down },
{ "close-tab" , KEYS_CLOSE_TAB , FL_CTRL , 'w' },
{ "find" , KEYS_FIND , FL_CTRL , 'f' },
+ { "copy" , KEYS_COPY , FL_CTRL , 'c' },
{ "websearch" , KEYS_WEBSEARCH , FL_CTRL , 's' },
{ "bookmarks" , KEYS_BOOKMARKS , FL_CTRL , 'b' },
{ "reload" , KEYS_RELOAD , FL_CTRL , 'r' },
diff -r f99afbd38ae7 src/keys.hh
--- a/src/keys.hh Fri Oct 05 19:12:25 2012 +0000
+++ b/src/keys.hh Sat Oct 06 03:55:20 2012 +0000
@@ -25,6 +25,7 @@
KEYS_FIRST_TAB,
KEYS_LAST_TAB,
KEYS_FIND,
+ KEYS_COPY,
KEYS_WEBSEARCH,
KEYS_BOOKMARKS,
KEYS_RELOAD,
diff -r f99afbd38ae7 src/ui.cc
--- a/src/ui.cc Fri Oct 05 19:12:25 2012 +0000
+++ b/src/ui.cc Sat Oct 06 03:55:20 2012 +0000
@@ -737,6 +737,9 @@
} else if (cmd == KEYS_FIND) {
findbar_toggle(1);
ret = 1;
+ } else if (cmd == KEYS_COPY) {
+ a_UIcmd_clipboard_copy(a_UIcmd_get_bw_by_widget(this));
+ ret = 1;
} else if (cmd == KEYS_WEBSEARCH) {
a_UIcmd_search_dialog(a_UIcmd_get_bw_by_widget(this));
ret = 1;
diff -r f99afbd38ae7 src/uicmd.cc
--- a/src/uicmd.cc Fri Oct 05 19:12:25 2012 +0000
+++ b/src/uicmd.cc Sat Oct 06 03:55:20 2012 +0000
@@ -1011,7 +1011,7 @@
void a_UIcmd_copy_urlstr(BrowserWindow *bw, const char *urlstr)
{
Layout *layout = (Layout*)bw->render_layout;
- layout->copySelection(urlstr);
+ layout->copySelection(SELECTION_PRIMARY, urlstr);
}
/*
@@ -1339,6 +1339,14 @@
BW2UI(bw)->findbar_toggle(on);
}
+void a_UIcmd_clipboard_copy(BrowserWindow *bw)
+{
+ Layout *layout = (Layout*)bw->render_layout;
+
+ if (layout)
+ layout->clipboardCopy();
+}
+
/*
* Focus the rendered area.
*/
diff -r f99afbd38ae7 src/uicmd.hh
--- a/src/uicmd.hh Fri Oct 05 19:12:25 2012 +0000
+++ b/src/uicmd.hh Sat Oct 06 03:55:20 2012 +0000
@@ -40,6 +40,7 @@
int backwards);
void a_UIcmd_findtext_reset(BrowserWindow *bw);
void a_UIcmd_findbar_toggle(BrowserWindow *bw, int on);
+void a_UIcmd_clipboard_copy(BrowserWindow *bw);
void a_UIcmd_focus_main_area(BrowserWindow *bw);
void a_UIcmd_focus_location(void *vbw);
void a_UIcmd_page_popup(void *vbw, bool_t has_bugs, void *v_cssUrls);