static String SelectSwap(Widget w, String s) { GwinWidget gw; String ans; gw = (GwinWidget)w; if(gw->gwin.selection){ XtFree(gw->gwin.selection); gw->gwin.selection = NULL; } XtGetSelectionValue(w, XInternAtom(_dpy, clipatom, 0), XInternAtom(_dpy, "UTF8_STRING", 0), SelCallback, 0, XtLastTimestampProcessed(XtDisplay(w))); while(gw->gwin.selection == NULL) XtAppProcessEvent(XtWidgetToApplicationContext(w) , XtIMAll); ans = gw->gwin.selection; gw->gwin.selection = XtMalloc(strlen(s)+1); strcpy(gw->gwin.selection, s); XtOwnSelection(w, XInternAtom(_dpy, clipatom, 0), XtLastTimestampProcessed(XtDisplay(w)), SendSel, NULL, NULL); return ans; }
static String SelectSwap(Widget w, String s) { GwinWidget gw; String ans; gw = (GwinWidget)w; if(gw->gwin.selection){ XtFree(gw->gwin.selection); gw->gwin.selection = 0; } #ifdef R3 XtGetSelectionValue(w, XA_PRIMARY, XA_STRING, SelCallback, 0, CurrentTime); #else XtGetSelectionValue(w, XA_PRIMARY, XA_STRING, SelCallback, 0, XtLastTimestampProcessed(XtDisplay(w))); #endif while(gw->gwin.selection == 0) XtAppProcessEvent(XtWidgetToApplicationContext(w) , XtIMAll); ans = gw->gwin.selection; gw->gwin.selection = XtMalloc(strlen(s)+1); strcpy(gw->gwin.selection, s); #ifdef R3 XtOwnSelection(w, XA_PRIMARY, CurrentTime, SendSel, NULL, NULL); #else XtOwnSelection(w, XA_PRIMARY, XtLastTimestampProcessed(XtDisplay(w)), SendSel, NULL, NULL); #endif return ans; }
void CEdit::Copy(void) { // Copies the currently selected text to the clipboard if (_xd_textwidget != NULL) { if (XmIsText(_xd_textwidget)) XmTextCopy(_xd_textwidget, XtLastTimestampProcessed(XtDisplay(_xd_textwidget))); else if (XmIsTextField(_xd_textwidget)) XmTextFieldCopy(_xd_textwidget, XtLastTimestampProcessed(XtDisplay(_xd_textwidget))); } }
void CEdit::Cut(void) { // Deletes the currently selected text and copies it to // the clipboard if (_xd_textwidget != NULL) { if (XmIsText(_xd_textwidget)) XmTextCut(_xd_textwidget, XtLastTimestampProcessed(XtDisplay(_xd_textwidget))); else if (XmIsTextField(_xd_textwidget)) XmTextFieldCut(_xd_textwidget, XtLastTimestampProcessed(XtDisplay(_xd_textwidget))); } return; }
/* ** Getting the current selection by making the request, and then blocking ** (processing events) while waiting for a reply. On failure (timeout or ** bad format) returns NULL, otherwise returns the contents of the selection. */ char *GetAnySelection(WindowInfo *window) { static char waitingMarker[1] = ""; char *selText = waitingMarker; XEvent nextEvent; /* If the selection is in the window's own buffer get it from there, but substitute null characters as if it were an external selection */ if (window->buffer->primary.selected) { selText = BufGetSelectionText(window->buffer); BufUnsubstituteNullChars(selText, window->buffer); return selText; } /* Request the selection value to be delivered to getAnySelectionCB */ XtGetSelectionValue(window->textArea, XA_PRIMARY, XA_STRING, (XtSelectionCallbackProc)getAnySelectionCB, &selText, XtLastTimestampProcessed(XtDisplay(window->textArea))); /* Wait for the value to appear */ while (selText == waitingMarker) { XtAppNextEvent(XtWidgetToApplicationContext(window->textArea), &nextEvent); ServerDispatchEvent(&nextEvent); } return selText; }
/* * If the application doesn't receive events with timestamp for a long time * XtLastTimestampProcessed() will return out-of-date value. This may cause * selection handling routines to fail (see BugTraq ID 4085183). * This routine is to resolve this problem. It queries the current X server * time by appending a zero-length data to a property as prescribed by * X11 Reference Manual. * Note that this is a round-trip request, so it can be slow. If you know * that the Xt timestamp is up-to-date use XtLastTimestampProcessed(). */ Time awt_util_getCurrentServerTime() { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); static Atom _XA_JAVA_TIME_PROPERTY_ATOM = 0; Time server_time = 0; AWT_LOCK(); if (_XA_JAVA_TIME_PROPERTY_ATOM == 0) { XtAddEventHandler(awt_root_shell, PropertyChangeMask, False, propertyChangeEventHandler, NULL); _XA_JAVA_TIME_PROPERTY_ATOM = XInternAtom(awt_display, "_SUNW_JAVA_AWT_TIME", False); } timeStampUpdated = False; XChangeProperty(awt_display, XtWindow(awt_root_shell), _XA_JAVA_TIME_PROPERTY_ATOM, XA_ATOM, 32, PropModeAppend, (unsigned char *)"", 0); XFlush(awt_display); if (awt_currentThreadIsPrivileged(env)) { XEvent event; XMaskEvent(awt_display, PropertyChangeMask, &event); XtDispatchEvent(&event); } else { awt_MToolkit_modalWait(isTimeStampUpdated, NULL); } server_time = XtLastTimestampProcessed(awt_display); AWT_UNLOCK(); return server_time; }
/*********************************************************************** * Event Handler to forward WM_DELETE_WINDOW events to the client windows ***********************************************************************/ void RxpWmDelWinHandler ( Widget widget, XtPointer client_data, XEvent* event, Boolean* cont) { PluginInstance* This = (PluginInstance*) client_data; int i; if (event == NULL || (event->type == ClientMessage && event->xclient.message_type == RxGlobal.wm_protocols && event->xclient.data.l[0] == RxGlobal.wm_delete_window)) { for (i = 0; i < This->nclient_windows; i++) { if (This->client_windows[i].flags & RxpWmDelWin) { XClientMessageEvent ev; ev.type = ClientMessage; ev.window = This->client_windows[i].win; ev.message_type = RxGlobal.wm_protocols; ev.format = 32; ev.data.l[0] = RxGlobal.wm_delete_window; ev.data.l[1] = XtLastTimestampProcessed (XtDisplay (widget)); XSendEvent (RxGlobal.dpy, ev.window, FALSE, 0L, (XEvent*) &ev); } } } }
void gdbFindCB(Widget w, XtPointer client_data, XtPointer call_data) { SourceView::SearchDirection direction = (SourceView::SearchDirection) (long) client_data; assert(direction == SourceView::forward || direction == SourceView::backward); if (direction != last_find_direction) { last_find_direction = direction; update_options(); } XmPushButtonCallbackStruct *cbs = (XmPushButtonCallbackStruct *)call_data; // LessTif 0.79 sometimes returns NULL in cbs->event. Handle this. Time tm; if (cbs->event != 0) tm = time(cbs->event); else tm = XtLastTimestampProcessed(XtDisplay(w)); string key = source_arg->get_string(); source_view->find(key, direction, app_data.find_words_only, app_data.find_case_sensitive, tm); source_arg->set_string(key); }
/*ARGSUSED*/ static void Initialize(Widget req, /* unused */ Widget new_w, ArgList args, /* unused */ Cardinal *num_args) /* unused */ { XmGrabShellWidget grabsh = (XmGrabShellWidget)new_w; XtAddEventHandler(new_w, StructureNotifyMask, False, MapNotifyHandler, NULL); grabsh->grab_shell.unpost_time = (Time) -1; grabsh->grab_shell.cursor = None; grabsh->grab_shell.top_shadow_GC = _XmGetPixmapBasedGC (new_w, grabsh->grab_shell.top_shadow_color, grabsh->core.background_pixel, grabsh->grab_shell.top_shadow_pixmap); grabsh->grab_shell.bottom_shadow_GC = _XmGetPixmapBasedGC (new_w, grabsh->grab_shell.bottom_shadow_color, grabsh->core.background_pixel, grabsh->grab_shell.bottom_shadow_pixmap); /* CR 6723: The BtnUp event may arrive before MapNotify. */ grabsh->grab_shell.post_time = XtLastTimestampProcessed(XtDisplay(new_w)); /* CR 9920: Popdown may be requested before MapNotify. */ grabsh->grab_shell.mapped = False; }
/* ARGSUSED */ static void GetSelection(Widget w, XtPointer closure, XtPointer callData) { XtGetSelectionValue(w, options.selection, XA_STRING, StoreBuffer, NULL, XtLastTimestampProcessed(XtDisplay(w))); }
/* Function Name: LoseSelection * Description: Called when we have lost the selection, asks client * for the selection value. * Arguments: w - the widget that just lost the selection. * sel - the selection. * Returns: none. */ static void LoseSelection(Widget w, Atom *sel) { if (global_client.timeout != 0) { XtRemoveTimeOut(global_client.timeout); global_client.timeout = 0; /* reset the countdown */ global_countdown = 0; if (global_timeout) { XtRemoveTimeOut(global_timeout); global_timeout = 0; SetWaitLabel(0); } /* if (old timeout running) */ } XtGetSelectionValue(w, *sel, atom_client_value, GetClientValue, NULL, XtLastTimestampProcessed(XtDisplay(w))); } /* LoseSelection() */
void activateCB_filetype_icon (Widget wid, XtPointer client_data, DtIconCallbackStruct *cbs) { Time lts, mct = 0; static Time prev_lts = 0; if (cbs->reason == XmCR_ACTIVATE) { #ifdef DEBUG printf("In activate_filetype_icon callback.\n"); #endif if (last_filetype_pushed && (last_filetype_pushed != wid)) { XtVaSetValues(XtParent(last_filetype_pushed), XmNborderWidth, 0, NULL); } XtVaSetValues(XtParent(wid), XmNborderWidth, ICON_BORDER_WIDTH, NULL); last_filetype_pushed = wid; /********************************************************************/ /* This is the support needed to provide double-click functionality */ /* to the icon gadgets. When double-clicked, the icon editor will */ /* be launched. */ /********************************************************************/ XtVaSetValues(wid, XmNpushButtonClickTime, 0, NULL); lts = XtLastTimestampProcessed(XtDisplay(wid)); mct = XtGetMultiClickTime(XtDisplay(wid)); if ((prev_lts + mct) > lts) { prev_lts = XtLastTimestampProcessed(XtDisplay(wid)); } else { prev_lts = XtLastTimestampProcessed(XtDisplay(wid)); return; } #ifdef DEBUG printf("DblClick icon callback.\n"); #endif activateCB_edit_icon(wid, (XtPointer)CA_FILETYPE_ICONS, (XmPushButtonCallbackStruct *)cbs /* unused anyway */); } return; }
void RXmTextClearSelection(message_t message) { Widget w; Time t; toolkit_read_value(message,&w,XtRWidget); t = XtLastTimestampProcessed(display); XmTextClearSelection(w,t); }
void RXmTextCut(message_t message) { Widget w; Time t; toolkit_read_value(message,&w,XtRWidget); t = XtLastTimestampProcessed(display); reply_with_boolean(message,XmTextCut(w,t)); }
void ShowRateChangeDialog(struct rpar_object *rp,int focus) { Arg args[1]; char tempString[LINEMAX]; Widget focusTo; XmString XmTemp; char *insert; int insertlen; cur_rpar = rp; if(cur_rpar != NULL) { XmTemp=XmStringCreate("Change Rate Parameter",XmSTRING_DEFAULT_CHARSET); XtSetArg(args[0],XmNdialogTitle,XmTemp); XtSetValues(rate_dlg,args,1); if(cur_rpar->tag != NULL) XmTextFieldSetString(rate_tag,cur_rpar->tag); else XmTextFieldSetString(rate_tag,""); sprintf(tempString,"%f",cur_rpar->value); XmTextFieldSetString(rate_rate,tempString); switch(focus) { case 0: focusTo=rate_tag; break; default: focusTo=rate_rate; } } else { XmTemp=XmStringCreate("Create Rate Parameter",XmSTRING_DEFAULT_CHARSET); XtSetArg(args[0],XmNdialogTitle,XmTemp); XtSetValues(rate_dlg,args,1); XmTextFieldSetString(rate_tag,""); XmTextFieldSetString(rate_rate,""); focusTo = rate_tag; } XmStringFree(XmTemp); XtManageChild(rate_dlg); XmProcessTraversal(focusTo,XmTRAVERSE_CURRENT); insert=XmTextFieldGetString(focusTo); insertlen=strlen(insert); XmTextFieldSetSelection(focusTo,0,insertlen,XtLastTimestampProcessed(XtDisplay(focusTo))); XmTextFieldSetHighlight(focusTo,0,insertlen,XmHIGHLIGHT_SELECTED); XtFree(insert); }
void CEdit:: SetSel(int nStartChar, int nEndChar, BOOL bNoScroll) { // Set the current selection. if (_xd_textwidget != NULL) { XtVaSetValues(_xd_textwidget, XmNautoShowCursorPosition, !bNoScroll, NULL); XmTextPosition len = XmTextGetLastPosition(_xd_textwidget); if (nEndChar > len) nEndChar = (int)len ; if (XmIsText(_xd_textwidget)) XmTextSetSelection(_xd_textwidget, nStartChar, nEndChar, XtLastTimestampProcessed(XtDisplay(_xd_textwidget))); else if (XmIsTextField(_xd_textwidget)) XmTextFieldSetSelection(_xd_textwidget, nStartChar, nEndChar, XtLastTimestampProcessed(XtDisplay(_xd_textwidget))); } }
static void LoseSelection(Widget w, Atom *sel) { if (global_client.timeout != 0) { XtRemoveTimeOut(global_client.timeout); global_client.timeout = 0; } XtGetSelectionValue(w, *sel, atom_client_value, GetClientValue, NULL, XtLastTimestampProcessed(XtDisplay(w))); }
void RXmTextSetSelection(message_t message) { Widget w; XmTextPosition first,last; Time t; toolkit_read_value(message,&w,XtRWidget); toolkit_read_value(message,&first,XtRInt); toolkit_read_value(message,&last,XtRInt); t = XtLastTimestampProcessed(display); XmTextSetSelection(w,first,last,t); }
static void CutCB(Widget widget,XtPointer client_data, XtPointer call_data) { Boolean status; Widget container; container = (Widget) client_data; status = XmContainerCut(container, XtLastTimestampProcessed(XtDisplay(container))); printf("Return status of XmContainerCut function: %d\n\n", (int) status); }
void PalMotif::set_selection_owner() { int sts; sts = XtOwnSelection( brow_widget, XA_PRIMARY, XtLastTimestampProcessed(flow_Display(brow_widget)), pal_sel_convert_cb, pal_sel_lose_cb , NULL); if ( !sts) { brow_SelectClear( brow_ctx); return; } selection_owner = 1; }
/* ARGSUSED */ static void GetBuffer(Widget w, XtPointer closure, XtPointer callData) { if (options.value) XFree( options.value ); options.value = XFetchBuffer(XtDisplay(w), &options.length, options.buffer); if (options.value != NULL) { if (XtOwnSelection(w, options.selection, XtLastTimestampProcessed(XtDisplay(w)), ConvertSelection, LoseSelection, NULL)) SetButton((ButtonState*)closure, True); } }
/* ARGSUSED */ static void ClientTimedOut(XtPointer data, XtIntervalId *id) { char msg[BUFSIZ]; Widget w = (Widget) data; global_client.ident = NO_IDENT; XtDisownSelection(w, global_client.atom, XtLastTimestampProcessed(XtDisplay(w))); sprintf(msg, res_labels[4], "the Editres Protocol."); SetMessage(global_screen_data.info_label, msg); }
void WNavMotif::set_selection_owner() { int sts; sts = XtOwnSelection( brow_widget, XA_PRIMARY, XtLastTimestampProcessed(flow_Display(brow_widget)), WNavMotif::sel_convert_cb, WNavMotif::sel_lose_cb , NULL); if ( !sts) { message('E', "Failed attempting to become primary selection owner"); brow_SelectClear( brow->ctx); return; } selection_owner = 1; }
bool wxClipboard::AddData( wxDataObject *data ) { wxCHECK_MSG( data, false, "data is invalid" ); wxCHECK_MSG( m_open, false, "clipboard not open" ); m_data.Append( data ); Display* xdisplay = wxGlobalDisplay(); Widget xwidget = (Widget)wxTheApp->GetTopLevelRealizedWidget(); Window xwindow = XtWindow( xwidget ); wxXmString label( wxTheApp->GetAppDisplayName() ); Time timestamp = XtLastTimestampProcessed( xdisplay ); long itemId; int retval; while( ( retval = XmClipboardStartCopy( xdisplay, xwindow, label(), timestamp, xwidget, wxClipboardCallback, &itemId ) ) == XmClipboardLocked ); if( retval != XmClipboardSuccess ) return false; size_t count = data->GetFormatCount( wxDataObject::Get ); wxDataFormatScopedArray dfarr(count); data->GetAllFormats( dfarr.get(), wxDataObject::Get ); for( size_t i = 0; i < count; ++i ) { size_t size = data->GetDataSize( dfarr[i] ); long data_id; wxString id = dfarr[i].GetId(); while( ( retval = XmClipboardCopy( xdisplay, xwindow, itemId, id.char_str(), NULL, size, i, &data_id ) ) == XmClipboardLocked ); m_idToObject.Append( new wxDataIdToDataObject( data, data_id, size ) ); } while( XmClipboardEndCopy( xdisplay, xwindow, itemId ) == XmClipboardLocked ); return true; }
void NavMotif::set_selection_owner( int set) { int sts; if ( set) { sts = XtOwnSelection( brow_widget, XA_PRIMARY, XtLastTimestampProcessed(flow_Display(brow_widget)), nav_sel_convert_cb, nav_sel_lose_cb , NULL); if ( !sts) { brow_SelectClear( brow_ctx); return; } } else { // Todo... } }
/* ARGSUSED */ static void ClientTimedOut(XtPointer data, XtIntervalId *id) { Widget w = (Widget) data; global_client.ident = NO_IDENT; XtDisownSelection(w, global_client.atom, XtLastTimestampProcessed(XtDisplay(w))); /* "It appears that this client does not understand */ /* the Editres Protocol" */ SetMessage(global_screen_data.info_label, res_labels[4], "It appears that this client does not understand the Editres Protocol"); } /* ClientTimedOut() */
/*ARGSUSED*/ static void MapNotifyHandler(Widget shell, XtPointer client_data, XEvent *event, Boolean *cont) { XmGrabShellWidget grabshell = (XmGrabShellWidget)shell; Time time; XErrorHandler old_handler; /* Only handles map events */ if (event -> type != MapNotify) return; /* CR 9920: Popdown may be called before MapNotify. */ grabshell->grab_shell.mapped = True; if (!(time = XtLastTimestampProcessed(XtDisplay(shell)))) time = CurrentTime; if (grabshell->grab_shell.cursor == None) grabshell->grab_shell.cursor = XCreateFontCursor (XtDisplay(grabshell), XC_arrow); _XmFastExpose(shell); (void) XtGrabKeyboard(shell, grabshell -> grab_shell.owner_events, grabshell -> grab_shell.grab_style, GrabModeAsync, time); (void) XtGrabPointer(shell, grabshell -> grab_shell.owner_events, Events, grabshell -> grab_shell.grab_style, GrabModeAsync, None, grabshell->grab_shell.cursor, time); GSAllowEvents(shell, SyncPointer, time); /* Fix focus to shell */ XGetInputFocus(XtDisplay(shell), &grabshell->grab_shell.old_focus, &grabshell->grab_shell.old_revert_to); old_handler = XSetErrorHandler(IgnoreXErrors); XSetInputFocus(XtDisplay(shell), XtWindow(shell), RevertToParent, time); XSync(XtDisplay(shell), False); XSetErrorHandler(old_handler); }
/********************************************************************** DestinationCallback: **********************************************************************/ void DestinationCallback(Widget w, XtPointer ignore, XtPointer call_data) { XmDestinationCallbackStruct *dcs = (XmDestinationCallbackStruct *)call_data; Atom TARGETS = XInternAtom(XtDisplay(w), "TARGETS", False); Atom _MOTIF_EXPORT_TARGETS = XInternAtom(XtDisplay(w), "_MOTIF_EXPORT_TARGETS", False); printf("\n\nNow in Destination Callback.\n"); printf("\tSelection: "); OutputAnAtomName ((Widget)w, dcs->selection); /* Ask the source to return a list of all the export targets that it knows how to convert. */ XmTransferValue(dcs->transfer_id, _MOTIF_EXPORT_TARGETS, (XtCallbackProc)TransferProc, NULL, XtLastTimestampProcessed(XtDisplay(w))); }
/*ARGSUSED*/ static void Popdown(Widget shell, XEvent *event, /* unused */ String *params, Cardinal *num_params) { XmScreen screen = (XmScreen) XmGetXmScreen(XtScreen(shell)); XmGrabShellWidget grabshell = (XmGrabShellWidget)shell; Time time; /* Record for replay detection */ if (event && (event->type == ButtonPress || event->type == ButtonRelease)) { grabshell->grab_shell.unpost_time = event->xbutton.time; } if (!(time = XtLastTimestampProcessed(XtDisplay(shell)))) time = CurrentTime; /* CR 9920: Popdown may be called before MapNotify. */ if (grabshell->shell.popped_up && grabshell->grab_shell.mapped) { XErrorHandler old_handler; if (screen -> screen.unpostBehavior == XmUNPOST_AND_REPLAY) GSAllowEvents(shell, ReplayPointer, event ? event->xbutton.time : time); XtUngrabPointer(shell, time); XtUngrabKeyboard(shell, time); _XmPopdown(shell); /* Reset focus to old holder */ old_handler = XSetErrorHandler(IgnoreXErrors); if (time != CurrentTime) time = time - 1; /* Avoid race in wm */ XSetInputFocus(XtDisplay(shell), grabshell->grab_shell.old_focus, grabshell->grab_shell.old_revert_to, time); XSync(XtDisplay(shell), False); XSetErrorHandler(old_handler); } grabshell->grab_shell.mapped = False; }
void raise_shell(Widget w) { if (w == 0 || !XtIsRealized(w)) return; // Place current shell on top Widget shell = findShellParent(w); if (shell != 0 && XtIsRealized(shell)) { XRaiseWindow(XtDisplay(w), XtWindow(shell)); #if 0 wait_until_mapped(w); // Get focus XSetInputFocus(XtDisplay(w), XtWindow(w), RevertToParent, XtLastTimestampProcessed(XtDisplay(w))); #endif // Try this one XmProcessTraversal(w, XmTRAVERSE_CURRENT); } }