@@ -36,6 +36,7 @@ extern function getfocusview;
3636extern function getmotionview;
3737extern function getbuttonview;
3838extern function getkeyview;
39+ extern function getselectionview;
3940extern function getclientview;
4041extern function getxcolorview;
4142extern function getxftcolorview;
@@ -1117,6 +1118,44 @@ class Window : Drawable
11171118 {
11181119 getfun("XUngrabPointer")(self.display.xdisplay, time);
11191120 }
1121+ function GetPropertyString(int property)
1122+ {
1123+ var display = self.display;
1124+ var viewint = new ["StructView"] ( [ DATATYPE_STRUCT, 1, DATATYPE_INT ] );
1125+ var viewlong = new ["StructView"] ( [ DATATYPE_STRUCT, 1, DATATYPE_LONG ] );
1126+ var viewptr = new ["StructView"] ( [ DATATYPE_STRUCT, 1, DATATYPE_PTR ] );
1127+ var actual_type_return = viewint.alloc();
1128+ var actual_format_return = viewint.alloc();
1129+ var nitems_return = viewlong.alloc();
1130+ var bytes_after_return = viewlong.alloc();
1131+ var prop_return = viewptr.alloc();
1132+ // Get 0 items, to check the size,
1133+ int r = getfun("XGetWindowProperty")(display.xdisplay, self.xdrawable,
1134+ property, 0, 0, false,
1135+ XA_STRING,
1136+ actual_type_return, actual_format_return,
1137+ nitems_return, bytes_after_return, prop_return);
1138+ if (r != Success)
1139+ return string(null);
1140+ var prop = viewptr[prop_return, 0];
1141+ Free(prop);
1142+ int n = viewint[bytes_after_return, 0];
1143+ if (n == 0)
1144+ return "";
1145+ n = (n + 3 ) / 4;
1146+ // Now get the size obtained
1147+ r = getfun("XGetWindowProperty")(display.xdisplay, self.xdrawable,
1148+ property, 0, n, true,
1149+ XA_STRING,
1150+ actual_type_return, actual_format_return, nitems_return,
1151+ bytes_after_return, prop_return);
1152+ if (r != Success)
1153+ return string(null);
1154+ prop = viewptr[prop_return, 0];
1155+ string result = prop.as_string("utf8");
1156+ Free(prop);
1157+ return result;
1158+ }
11201159}
11211160
11221161//**************************************************************
@@ -1229,6 +1268,7 @@ class ListenerWindow : Window
12291268 var OnLeave;
12301269 var OnFocusIn;
12311270 var OnFocusOut;
1271+ var OnSelectionNotify;
12321272 var OnClientMessage;
12331273 function ListenerWindow(controller)
12341274 {
@@ -1244,6 +1284,7 @@ class ListenerWindow : Window
12441284 self.OnLeave = new EventHandler(self, LeaveWindowMask);
12451285 self.OnFocusIn = new EventHandler(self, FocusChangeMask);
12461286 self.OnFocusOut = new EventHandler(self, FocusChangeMask);
1287+ self.OnSelectionNotify = new EventHandler(self, 0);
12471288 self.OnClientMessage = new EventHandler(self, 0);
12481289 self.controller = controller;
12491290 controller.register(self);
@@ -1294,6 +1335,9 @@ class ListenerWindow : Window
12941335 case LeaveNotify:
12951336 handler = self.OnLeave;
12961337 break;
1338+ case SelectionNotify:
1339+ handler = self.OnSelectionNotify;
1340+ break;
12971341 case ClientMessage:
12981342 handler = self.OnClientMessage;
12991343 break;
@@ -1431,6 +1475,7 @@ class EditBox : ChildWindow
14311475 self.OnKeyPress += function (event) { self.onkeypress(event); };
14321476 self.OnFocusIn += function (event) { self.onfocusin(event); };
14331477 self.OnFocusOut += function (event) { self.onfocusout(event); };
1478+ self.OnSelectionNotify += function (event) { self.onselectionnotify(event); };
14341479 }
14351480 function getValue()
14361481 {
@@ -1606,6 +1651,9 @@ class EditBox : ChildWindow
16061651 switch (key) {
16071652 case "\n": case "\r": case "\e":
16081653 return;
1654+ case "\x{16}":
1655+ self.paste(event.time());
1656+ return;
16091657 }
16101658 self.cursor();
16111659 text = substr(text, 0, pos) + key + substr(text, pos);
@@ -1622,6 +1670,40 @@ class EditBox : ChildWindow
16221670 self.drawall();
16231671 self.cursor();
16241672 }
1673+ function onselectionnotify(event)
1674+ {
1675+ var view = getselectionview();
1676+ var data = event.eventdata;
1677+ int selection = view[data, 5];
1678+ int property = view[data, 7];
1679+ if (property == None)
1680+ return;
1681+ string pasted = self.GetPropertyString(property);
1682+ if (pasted == null)
1683+ return;
1684+ int l = length(pasted);
1685+ self.cursor();
1686+ int pos = self.pos;
1687+ string text = self.text;
1688+ text = substr(text, 0, pos) + pasted + substr(text, pos);
1689+ pos += l;
1690+ self.text =: text;
1691+ self.pos =: pos;
1692+ int offset = self.offset;
1693+ int width = self.width;
1694+ int x = self.font.getTextxOff(self.display, substr(text, 0, pos));
1695+ if (x - offset >= width)
1696+ self.offset =: x - width / 4;
1697+ self.drawall();
1698+ self.cursor();
1699+ }
1700+ function paste(int time)
1701+ {
1702+ var display = self.display;
1703+ int clipboard = display.InternAtom("CLIPBOARD");
1704+ getfun("XConvertSelection")(display.xdisplay,
1705+ clipboard, XA_STRING, clipboard, self.xdrawable, time);
1706+ }
16251707}
16261708
16271709//**************************************************************
0 commit comments