void CEdit::xd_rootwidget(Widget xd_rootwidget) { CWnd::xd_rootwidget ( xd_rootwidget ); if (XmIsScrolledWindow(xd_rootwidget)) { WidgetList children = (WidgetList) 0 ; Cardinal numchildren = (Cardinal) 0 ; int i ; XtVaGetValues(xd_rootwidget, XmNchildren, &children, XmNnumChildren, &numchildren, NULL) ; for ( i = 0; i < numchildren; i++ ) if (XmIsText(children[i]) || XmIsTextField(children[i])) { _xd_textwidget = children[i]; break; } } else _xd_textwidget = _xd_rootwidget; }
int CEdit::xd_get_window_text_length(void) const { // Implements GetWindowTextLength() for XmText and XmTextField // Return value: // 0 if the widget has not been created (no call to create() yet). // The length of the text otherwise. if (_xd_textwidget != NULL) { char *s = (char *) 0 ; if (XmIsText(_xd_textwidget)) s = XmTextGetString(_xd_textwidget); else if (XmIsTextField(_xd_textwidget)) s = XmTextFieldGetString(_xd_textwidget); if (s) { int length = strlen(s) ; XtFree(s) ; return length; } } return 0; }
void CEdit::ReplaceSel(LPCSTR lpszNewText) { // Inserts the given text to replace the current selection // or at the insert cursor position if there is no selection. Boolean has_selection = False; XmTextPosition left = (XmTextPosition) 0 ; XmTextPosition right = (XmTextPosition) 0 ; if (_xd_textwidget!=NULL) { if (XmIsText(_xd_textwidget)) { has_selection = XmTextGetSelectionPosition(_xd_textwidget, &left, &right); if (!has_selection) left = right = XmTextGetInsertionPosition(_xd_textwidget); XmTextReplace(_xd_textwidget, left, right, (char *)lpszNewText); } else if (XmIsTextField(_xd_textwidget)) { has_selection = XmTextFieldGetSelectionPosition(_xd_textwidget, &left, &right); if (!has_selection) left = right = XmTextFieldGetInsertionPosition(_xd_textwidget); XmTextFieldReplace(_xd_textwidget, left, right, (char *)lpszNewText); } } }
int CEdit::xd_get_window_text(LPSTR lpszStringBuf, int nMaxCount) const { // Implements GetWindowText() for XmText and XmTextField. // Return value: // 0 if the widget has not been created (no call to create() yet). // The length of the text otherwise. if (_xd_textwidget!=NULL) { char *s = (char *) 0 ; if (XmIsText(_xd_textwidget)) s = XmTextGetString(_xd_textwidget); else if (XmIsTextField(_xd_textwidget)) s = XmTextFieldGetString(_xd_textwidget); if (s) { (void) strncpy(lpszStringBuf, s, nMaxCount - 1); XtFree(s); lpszStringBuf[nMaxCount-1]='\0'; return strlen(lpszStringBuf); } } return 0; }
Boolean XmTextFindStringWcs(Widget w, XmTextPosition start, wchar_t* wc_string, XmTextDirection direction, XmTextPosition *position) { wchar_t *tmp_wc; char *string; int num_chars = 0; Boolean return_val = False; XmTextWidget tw = (XmTextWidget) w; int wcs_ret_val = 0; _XmWidgetToAppContext(w); _XmAppLock(app); if (!XmIsTextField(w)) { for (num_chars = 0, tmp_wc = wc_string; *tmp_wc != (wchar_t)0L; num_chars++) tmp_wc++; string = XtMalloc ((unsigned) (num_chars + 1) * (int)tw->text.char_size); wcs_ret_val = wcstombs(string, wc_string, (num_chars + 1) * (int)tw->text.char_size); if (wcs_ret_val >= 0) return_val = XmTextFindString(w, start, string, direction, position); XtFree(string); _XmAppUnlock(app); return(return_val); } else { _XmAppUnlock(app); return False; } }
Boolean XmTextFindString(Widget w, XmTextPosition start, char* search_string, XmTextDirection direction, XmTextPosition *position) { XmSourceData data; Boolean ret_val; _XmWidgetToAppContext(w); if (XmIsTextField(w)) return False; _XmAppLock(app); data = ((XmTextWidget)w)->text.source->data; if (start > data->length) start = data->length; else if (start < 0) start = 0; if (direction == XmTEXT_BACKWARD) ret_val = _XmTextFindStringBackwards(w, start, search_string, position); else ret_val = _XmTextFindStringForwards(w, start, search_string, position); _XmAppUnlock(app); return (ret_val); }
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::Clear(void) { // Deletes the currently selected text if (_xd_textwidget != NULL) { if (XmIsText(_xd_textwidget)) XmTextRemove(_xd_textwidget); else if (XmIsTextField(_xd_textwidget)) XmTextFieldRemove(_xd_rootwidget); } }
void CEdit::xd_set_window_text(LPCSTR lpszString) { // Implements SetWindowText() for XmText and XmTextField. if (_xd_textwidget != NULL) { if (XmIsText(_xd_textwidget)) XmTextSetString(_xd_textwidget, (char *)lpszString); else if (XmIsTextField(_xd_textwidget)) XmTextFieldSetString(_xd_textwidget, (char *)lpszString); } }
void CEdit::Paste(void) { // Insert data from the clipboard into the text if (_xd_textwidget != NULL) { if (XmIsText(_xd_textwidget)) XmTextPaste(_xd_textwidget); else if (XmIsTextField(_xd_textwidget)) XmTextFieldPaste(_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; }
void insert_source_argAct(Widget w, XEvent*, String*, Cardinal*) { clear_isearch(); string arg = source_arg->get_string(); if (XmIsText(w)) { if (XmTextGetEditable(w)) { XmTextPosition pos = XmTextGetInsertionPosition(w); XmTextReplace(w, pos, pos, XMST(arg.chars())); } } else if (XmIsTextField(w)) { if (XmTextFieldGetEditable(w)) { XmTextPosition pos = XmTextFieldGetInsertionPosition(w); XmTextFieldReplace(w, pos, pos, XMST(arg.chars())); } } }
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))); } }
// Apply button static void ApplyPlotCommandCB(Widget, XtPointer client_data, XtPointer) { PlotWindowInfo *plot = (PlotWindowInfo *)client_data; Widget text = XmCommandGetChild(plot->command, XmDIALOG_COMMAND_TEXT); String cmd_s = 0; if (XmIsTextField(text)) cmd_s = XmTextFieldGetString(text); else if (XmIsText(text)) cmd_s = XmTextGetString(text); else { assert(0); ::abort(); } string cmd = cmd_s; XtFree(cmd_s); send_and_replot(plot, cmd); }
void CEdit::GetSel(int& nStartChar, int& nEndChar) const { // Get the start and end of the selected text // Returns start and end as zero if there is no selected text Boolean has_selection = False ; XmTextPosition left = (XmTextPosition) 0 ; XmTextPosition right = (XmTextPosition) 0 ; nStartChar = nEndChar = 0; if (_xd_textwidget != NULL) { if (XmIsText(_xd_textwidget)) has_selection = XmTextGetSelectionPosition(_xd_textwidget, &left, &right); else if (XmIsTextField(_xd_textwidget)) has_selection = XmTextFieldGetSelectionPosition(_xd_textwidget, &left, &right); if (has_selection) { nStartChar = (int)left; nEndChar = (int)right; } } }