From 6148963f6a155ca1a3376fbe06e8a7e11d55433e Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Tue, 2 May 1995 20:54:09 +0000 Subject: [PATCH] Add primitives to read and write the OS/2 clipboard. Also implement Shift-Insert command on the console window to allow pasting from the clipboard. --- v7/src/microcode/os2msg.h | 6 +- v7/src/microcode/os2pm.c | 122 +++++++++++++++++++++++++++++++++++- v7/src/microcode/os2pm.h | 5 +- v7/src/microcode/os2pmcon.c | 41 ++++++++++-- v7/src/microcode/pros2pm.c | 26 +++++++- 5 files changed, 190 insertions(+), 10 deletions(-) diff --git a/v7/src/microcode/os2msg.h b/v7/src/microcode/os2msg.h index 2c65e3d3c..d48f8b09c 100644 --- a/v7/src/microcode/os2msg.h +++ b/v7/src/microcode/os2msg.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: os2msg.h,v 1.8 1995/04/22 21:17:54 cph Exp $ +$Id: os2msg.h,v 1.9 1995/05/02 20:53:30 cph Exp $ Copyright (c) 1994-95 Massachusetts Institute of Technology @@ -142,6 +142,10 @@ typedef enum mt_ps_set_bitmap_bits_request, /* set bitmap contents */ mt_ps_set_bitmap_bits_reply, + mt_clipboard_write_text, /* write text to clipboard */ + mt_clipboard_read_text_request, /* read text from clipboard */ + mt_clipboard_read_text_reply, + /* These are messages that are automatically generated by the PM thread when the corresponding events occur. */ mt_button_event, /* mouse button press */ diff --git a/v7/src/microcode/os2pm.c b/v7/src/microcode/os2pm.c index acced5637..8664b58c5 100644 --- a/v7/src/microcode/os2pm.c +++ b/v7/src/microcode/os2pm.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: os2pm.c,v 1.8 1995/04/28 07:05:01 cph Exp $ +$Id: os2pm.c,v 1.9 1995/05/02 20:53:53 cph Exp $ Copyright (c) 1994-95 Massachusetts Institute of Technology @@ -689,6 +689,24 @@ typedef struct } sm_ps_set_bitmap_bits_reply_t; #define SM_PS_SET_BITMAP_BITS_REPLY_LENGTH(m) \ (((sm_ps_set_bitmap_bits_reply_t *) (m)) -> length) + +typedef struct +{ + DECLARE_MSG_HEADER_FIELDS; + const char * text; +} sm_clipboard_write_text_t; +#define SM_CLIPBOARD_WRITE_TEXT_TEXT(m) \ + (((sm_clipboard_write_text_t *) (m)) -> text) + +typedef msg_t sm_clipboard_read_text_request_t; + +typedef struct +{ + DECLARE_MSG_HEADER_FIELDS; + const char * text; +} sm_clipboard_read_text_reply_t; +#define SM_CLIPBOARD_READ_TEXT_REPLY_TEXT(m) \ + (((sm_clipboard_read_text_reply_t *) (m)) -> text) static void sync_transaction (qid_t, msg_t *); static void sync_reply (qid_t); @@ -765,6 +783,9 @@ static unsigned long ps_set_bitmap_bits (ps_t *, unsigned long, unsigned long, PBYTE, PBITMAPINFO2); static font_metrics_t * ps_set_font (ps_t *, unsigned short, const char *); +static void clipboard_write_text (const char *); +static const char * clipboard_read_text (void); + static msg_t * make_button_event (wid_t, unsigned char, unsigned char, unsigned short, unsigned short, unsigned short); @@ -898,6 +919,12 @@ OS2_initialize_pm_thread (void) SET_MSG_TYPE_LENGTH (mt_ps_set_bitmap_bits_reply, sm_ps_set_bitmap_bits_reply_t); + SET_MSG_TYPE_LENGTH (mt_clipboard_write_text, sm_clipboard_write_text_t); + SET_MSG_TYPE_LENGTH (mt_clipboard_read_text_request, + sm_clipboard_read_text_request_t); + SET_MSG_TYPE_LENGTH (mt_clipboard_read_text_reply, + sm_clipboard_read_text_reply_t); + SET_MSG_TYPE_LENGTH (mt_button_event, sm_button_event_t); SET_MSG_TYPE_LENGTH (mt_close_event, sm_close_event_t); SET_MSG_TYPE_LENGTH (mt_focus_event, sm_focus_event_t); @@ -1198,6 +1225,9 @@ static void handle_get_bitmap_parameters_request (msg_t *); static void handle_ps_get_bitmap_bits_request (msg_t *); static void handle_ps_set_bitmap_bits_request (msg_t *); +static void handle_clipboard_write_text_request (msg_t *); +static void handle_clipboard_read_text_request (msg_t *); + static MRESULT EXPENTRY object_window_procedure (HWND window, ULONG msg, MPARAM mp1, MPARAM mp2) { @@ -1333,6 +1363,12 @@ object_window_procedure (HWND window, ULONG msg, MPARAM mp1, MPARAM mp2) case mt_ps_set_bitmap_bits_request: handle_ps_set_bitmap_bits_request (message); break; + case mt_clipboard_write_text: + handle_clipboard_write_text_request (message); + break; + case mt_clipboard_read_text_request: + handle_clipboard_read_text_request (message); + break; default: OS2_logic_error ("Unknown message type sent to PM thread."); @@ -2392,6 +2428,46 @@ handle_ps_set_bitmap_bits_request (msg_t * request) OS2_destroy_message (request); OS2_send_message (sender, reply); } + +void +OS2_clipboard_write_text (qid_t qid, const char * text) +{ + msg_t * message = (OS2_create_message (mt_clipboard_write_text)); + (SM_CLIPBOARD_WRITE_TEXT_TEXT (message)) = text; + sync_transaction (qid, message); +} + +static void +handle_clipboard_write_text_request (msg_t * message) +{ + qid_t sender = (MSG_SENDER (message)); + clipboard_write_text (SM_CLIPBOARD_WRITE_TEXT_TEXT (message)); + OS2_destroy_message (message); + sync_reply (sender); +} + +const char * +OS2_clipboard_read_text (qid_t qid) +{ + msg_t * message + = (OS2_message_transaction + (qid, + (OS2_create_message (mt_clipboard_read_text_request)), + mt_clipboard_read_text_reply)); + const char * text = (SM_CLIPBOARD_READ_TEXT_REPLY_TEXT (message)); + OS2_destroy_message (message); + return (text); +} + +static void +handle_clipboard_read_text_request (msg_t * request) +{ + qid_t sender = (MSG_SENDER (request)); + msg_t * reply = (OS2_create_message (mt_clipboard_read_text_reply)); + (SM_CLIPBOARD_READ_TEXT_REPLY_TEXT (reply)) = (clipboard_read_text ()); + OS2_destroy_message (request); + OS2_send_message (sender, reply); +} static window_t * make_window (qid_t, qid_t); @@ -3024,6 +3100,50 @@ ps_set_bitmap_bits (ps_t * ps, unsigned long start, unsigned long length, window_error (GpiSetBitmapBits); return (r); } + +static void +clipboard_write_text (const char * text) +{ + unsigned int len = ((strlen (text)) + 1); + PVOID shared_copy; + int copy_used = 0; + + STD_API_CALL + (dos_alloc_shared_mem, + ((&shared_copy), 0, len, + (PAG_COMMIT | PAG_READ | PAG_WRITE | OBJ_GIVEABLE))); + FASTCOPY (text, ((char *) shared_copy), len); + + if (WinOpenClipbrd (pm_hab)) + { + if (WinEmptyClipbrd (pm_hab)) + copy_used + = (WinSetClipbrdData + (pm_hab, ((ULONG) shared_copy), CF_TEXT, CFI_POINTER)); + (void) WinCloseClipbrd (pm_hab); + } + if (!copy_used) + STD_API_CALL (dos_free_mem, (shared_copy)); +} + +static const char * +clipboard_read_text (void) +{ + char * result = 0; + if (WinOpenClipbrd (pm_hab)) + { + const char * shared_copy + = ((const char *) (WinQueryClipbrdData (pm_hab, CF_TEXT))); + if (shared_copy != 0) + { + unsigned int len = ((strlen (shared_copy)) + 1); + result = (OS_malloc (len)); + FASTCOPY (shared_copy, result, len); + } + (void) WinCloseClipbrd (pm_hab); + } + return (result); +} static int parse_font_spec (const char *, PSZ *, LONG *, USHORT *); static int ps_set_font_1 (HPS, PSZ, LONG, USHORT, LONG); diff --git a/v7/src/microcode/os2pm.h b/v7/src/microcode/os2pm.h index b679f007f..217f2be34 100644 --- a/v7/src/microcode/os2pm.h +++ b/v7/src/microcode/os2pm.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: os2pm.h,v 1.6 1995/02/21 22:54:23 cph Exp $ +$Id: os2pm.h,v 1.7 1995/05/02 20:53:43 cph Exp $ Copyright (c) 1994-95 Massachusetts Institute of Technology @@ -216,4 +216,7 @@ extern unsigned long OS2_ps_get_bitmap_bits extern unsigned long OS2_ps_set_bitmap_bits (psid_t, unsigned long, unsigned long, void *, void *); +extern void OS2_clipboard_write_text (qid_t, const char *); +extern const char * OS2_clipboard_read_text (qid_t); + #endif /* SCM_OS2PM_H */ diff --git a/v7/src/microcode/os2pmcon.c b/v7/src/microcode/os2pmcon.c index c5a6ce21b..e030c2c6f 100644 --- a/v7/src/microcode/os2pmcon.c +++ b/v7/src/microcode/os2pmcon.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: os2pmcon.c,v 1.5 1995/02/21 22:55:42 cph Exp $ +$Id: os2pmcon.c,v 1.6 1995/05/02 20:54:02 cph Exp $ Copyright (c) 1994-95 Massachusetts Institute of Technology @@ -68,6 +68,8 @@ static int console_visiblep; static int console_closedp; static unsigned short readahead_repeat; static char readahead_char; +static const char * readahead_insert; +static const char * readahead_insert_scan; static msg_list_t * pending_events_head; static msg_list_t * pending_events_tail; static tqueue_t * console_tqueue; @@ -103,6 +105,7 @@ OS2_initialize_pm_console (void) console_visiblep = 0; console_closedp = 0; readahead_repeat = 0; + readahead_insert = 0; pending_events_head = 0; console_tqueue = (OS2_make_std_tqueue ()); { @@ -342,7 +345,7 @@ console_clear_all (void) int OS2_pm_console_getch (void) { - if (readahead_repeat == 0) + if ((readahead_repeat == 0) && (readahead_insert == 0)) while (1) { process_events (pending_events_head == 0); @@ -364,6 +367,18 @@ OS2_pm_console_getch (void) readahead_repeat = repeat; goto do_read; } + else if (translation == (-2)) + { + readahead_insert + = (OS2_clipboard_read_text (console_pm_qid)); + if ((*readahead_insert) != '\0') + { + readahead_insert_scan = readahead_insert; + goto do_read; + } + else + OS_free ((void *) readahead_insert); + } break; } case mt_close_event: @@ -383,10 +398,22 @@ OS2_pm_console_getch (void) } } do_read: - if ((readahead_repeat == 0) && console_closedp) - return (-1); - readahead_repeat -= 1; - return (readahead_char); + if (readahead_insert != 0) + { + char c = (*readahead_insert_scan++); + if ((*readahead_insert_scan) == '\0') + { + OS_free ((void *) readahead_insert); + readahead_insert = 0; + } + return (c); + } + if (readahead_repeat != 0) + { + readahead_repeat -= 1; + return (readahead_char); + } + return (-1); } static int @@ -413,6 +440,8 @@ translate_key_event (msg_t * message) case VK_ENTER: code = '\r'; break; + case VK_INSERT: + return (((flags & KC_SHIFT) != 0) ? (-2) : (-1)); default: return (-1); } diff --git a/v7/src/microcode/pros2pm.c b/v7/src/microcode/pros2pm.c index 36fbe59b1..713f96965 100644 --- a/v7/src/microcode/pros2pm.c +++ b/v7/src/microcode/pros2pm.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: pros2pm.c,v 1.6 1995/04/28 07:01:32 cph Exp $ +$Id: pros2pm.c,v 1.7 1995/05/02 20:54:09 cph Exp $ Copyright (c) 1994-95 Massachusetts Institute of Technology @@ -655,6 +655,30 @@ DEFINE_PRIMITIVE ("OS2PS-SET-BITMAP-BITS", Prim_OS2_ps_set_bitmap_bits, 5, 5, 0) (STRING_ARG (4)), (STRING_ARG (5))))); } + +DEFINE_PRIMITIVE ("OS2-CLIPBOARD-WRITE-TEXT", Prim_OS2_clipboard_write_text, 1, 1, 0) +{ + PRIMITIVE_HEADER (1); + OS2_clipboard_write_text (pm_qid, (STRING_ARG (1))); + PRIMITIVE_RETURN (UNSPECIFIC); +} + +DEFINE_PRIMITIVE ("OS2-CLIPBOARD-READ-TEXT", Prim_OS2_clipboard_read_text, 0, 0, 0) +{ + PRIMITIVE_HEADER (0); + { + const char * text = (OS2_clipboard_read_text (pm_qid)); + SCHEME_OBJECT result; + if (text == 0) + result = SHARP_F; + else + { + result = (char_pointer_to_string ((unsigned char *) text)); + OS_free ((void *) text); + } + PRIMITIVE_RETURN (result); + } +} DEFINE_PRIMITIVE ("OS2WIN-OPEN-EVENT-QID", Prim_OS2_window_open_event_qid, 0, 0, 0) { -- 2.25.1