static void Word_upper(Widget w, XEvent *event, char **str, Cardinal *num) { bool up, cap; XmTextPosition curpos, endpos; up = (str[0][0] == 'u'); cap = (str[0][0] == 'c'); curpos = XmTextGetCursorPosition(w); endpos = XmTextGetLastPosition(w); if (curpos < endpos) { int i, length, wstart, wend; char *buf = NULL; length = endpos - curpos; buf = (char *)CALLOC(length + 1, sizeof(char)); XmTextGetSubstring(w, curpos, length, length + 1, buf); wstart = 0; wend = length; for (i = 0; i < length; i++) if (!isspace((int)(buf[i]))) { wstart = i; break; } for (i = wstart + 1; i < length; i++) if (isspace((int)(buf[i]))) { wend = i; break; } if (cap) { buf[0] = toupper(buf[wstart]); buf[1] = '\0'; XmTextReplace(w, curpos + wstart, curpos + wstart + 1, buf); } else { int j; for (i = wstart, j = 0; i < wend; i++, j++) if (up) buf[j] = toupper(buf[i]); else buf[j] = tolower(buf[i]); buf[j] = '\0'; XmTextReplace(w, curpos + wstart, curpos + wend, buf); } XmTextSetCursorPosition(w, curpos + wend); if (buf) FREE(buf); } }
/****pkintextreplace()********************************************************/ void pkintextreplace(char texts[256]) {/*does this from the last position set by inserttexts*/ #ifdef UNIX_MOTIF /*060324 re compile with NOGUI, requires Lquiet=1*/ if(Lquiet==0) /*was Lcommanded before 990402*/ { if(!Limittext) { maxtextchar = maxtextchar - laststrlen + (long)strlen(texts); if(maxtextchar >= 32767L) { Limittext = 1; printf("Text about to exceed 32767 characters, \n" " no more text will be put into Text Window!\n"); } else { laststrlen = (long)strlen(texts);/*update*/ XmTextReplace(textwindow, position, XmTextGetLastPosition(textwindow), texts); /*position is end of last inserttext*/ } } } #endif /* UNIX_MOTIF 060324 re compile with NOGUI, requires Lquiet=1*/ }
static void templates_cb( Widget w, XtPointer cbd, XtPointer cbs) { TemplateCallbackData *cbdata = cbd; XmTextPosition start, end, after; if(!text_w) { char m[80]; sprintf(m, "unexpected argument %p", cbdata); msg("template handler", m); return; } if(get_map_state(text_w) != IsViewable) { beep(); return; } if( XmTextGetSelectionPosition(text_w, &start, &end) && start < end) { XmTextReplace(text_w, start, end, *cbdata); XmTextClearSelection(text_w, CurrentTime); } else { start = XmTextGetInsertionPosition(text_w); XmTextInsert(text_w, start, *cbdata); } after = start + strlen (*cbdata); XmTextSetInsertionPosition(text_w, after); XmTextShowPosition(text_w, after); set_input_focus(text_w); }
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); } } }
void Browser::clearMark() { unsigned long pos; if(!this->marker_char[0]) return; // // If the marker is on this page... // if( (this->marker_pos >= this->page_start) && (this->marker_pos < this->page_start + this->page_size) ) { pos = this->marker_pos - this->page_start; this->ignore_cb = True; XmTextReplace(this->text, pos, pos+1, this->marker_char); this->ignore_cb = False; } else { pos = XmTextGetInsertionPosition(this->text) - 1; } this->marker_pos = 0; this->marker_char[0] = '\0'; this->updateOffsets(pos+1); }
void clear_text (Widget textwid) { XmTextPosition last_pos; char *empty = ""; last_pos = XmTextGetLastPosition (textwid); XmTextReplace (textwid, 0, last_pos, empty); return; }
void RXmTextReplace(message_t message) { Widget w; XmTextPosition from,to; String value; toolkit_read_value(message,&w,XtRWidget); toolkit_read_value(message,&from,XtRInt); toolkit_read_value(message,&to,XtRInt); toolkit_read_value(message,&value,XtRString); XmTextReplace(w,from,to,value); }
void editCB( Widget w, XtPointer client_data, XtPointer call_data) { int i; char *s; long action; Time time; Widget widget; XButtonEvent *event; XmPushButtonCallbackStruct *acs; XmTextPosition left, right; action = (long) client_data; acs = (XmPushButtonCallbackStruct *) call_data; event = (XButtonEvent *) acs->event; time = event->time; widget = get_document_text(w, "editCB"); switch (action) { case EDIT_CUT: XmTextCut(widget, time); break; case EDIT_COPY: XmTextCopy(widget, time); break; case EDIT_PASTE: XmTextPaste(widget); break; case EDIT_DELETE: XmTextRemove(widget); break; case EDIT_CLEAR: if (False == XmTextGetSelectionPosition(widget, &left, &right)) break; s = calloc(1 + right - left, sizeof(char)); if (NULL == s) { perror("Dtpad (calloc)"); exit(1); } for (i = 0; i < right - left; i++) s[i] = ' '; s[right - left] = '\0'; XmTextReplace(widget, left, right, s); XtFree(s); break; default: break; } }
static void set_line_from_history() { private_gdb_history = true; const string& input = gdb_history[gdb_current_history]; XmTextReplace(gdb_w, promptPosition, XmTextGetLastPosition(gdb_w), XMST(input.chars())); XmTextSetInsertionPosition(gdb_w, XmTextGetLastPosition(gdb_w)); if (gdb_history_w) ListSetAndSelectPos(gdb_commands_w, gdb_current_history + 1); private_gdb_history = false; }
/****cleartexts()*************************************************************/ void cleartexts() { #ifdef UNIX_MOTIF /*060324 re compile with NOGUI, requires Lquiet=1*/ if(Lquiet==0) /*was Lcommanded before 990402*/ { XmTextReplace(textwindow, 0, XmTextGetLastPosition(textwindow), " "); /*reset text position*/ position = XmTextGetLastPosition(textwindow); maxtextchar = 0; } #endif /* UNIX_MOTIF 060324 re compile with NOGUI, requires Lquiet=1*/ }
// Remove any text up to the last GDB prompt void gdbClearWindowCB(Widget, XtPointer, XtPointer) { XmTextPosition start = start_of_line(); if (start == XmTextPosition(-1)) return; private_gdb_output = true; XmTextReplace(gdb_w, 0, start, XMST("")); promptPosition -= start; messagePosition -= start; XmTextSetInsertionPosition(gdb_w, XmTextGetLastPosition(gdb_w)); private_gdb_output = false; }
static void Text_transpose(Widget w, XEvent *event, char **str, Cardinal *num) { XmTextPosition curpos; curpos = XmTextGetCursorPosition(w); if (curpos > 1) { char buf[3]; /* needs room for null */ char tmp; XmTextGetSubstring(w, (XmTextPosition)(curpos - 1), 2, 3, buf); tmp = buf[0]; buf[0] = buf[1]; buf[1] = tmp; XmTextReplace(w, curpos - 1, curpos + 1, buf); XmTextSetCursorPosition(w, curpos + 1); } }
static int motTextSetSelectedTextAttrib(Ihandle* ih, const char* value) { XmTextPosition start, end; if (!value) return 0; if (XmTextGetSelectionPosition(ih->handle, &start, &end) && start!=end) { /* disable callbacks */ ih->data->disable_callbacks = 1; XmTextReplace(ih->handle, start, end, (char*)value); ih->data->disable_callbacks = 0; } return 0; }
static int motTextSetSelectedTextAttrib(Ihandle* ih, const char* value) { XmTextPosition start, end; if (!value) return 0; if (XmTextGetSelectionPosition(ih->handle, &start, &end) && start!=end) { /* disable callbacks */ iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", "1"); XmTextReplace(ih->handle, start, end, (char*)value); iupAttribSetStr(ih, "_IUPMOT_DISABLE_TEXT_CB", NULL); } return 0; }
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 Browser::placeMark() { int i; int line_no; char mark_str[2]; mark_str[0] = '\001'; mark_str[1] = '\0'; theIBMApplication->setBusyCursor(TRUE); char *str = XmTextGetString(this->text); this->clearMark(); // // Calc where it should go // unsigned long pos = XmTextGetInsertionPosition(this->text); this->marker_pos = this->page_start + pos; line_no = 0; for(i = 0; i < pos; i++) { if(str[i] == '\n') line_no++; } this->marker_line_no = this->page_start_line_no + line_no; this->updateOffsets(pos); // // Save the marker character // this->marker_char[0] = str[pos]; this->ignore_cb = True; XmTextReplace(this->text, pos, pos+1, mark_str); this->ignore_cb = False; XmTextSetInsertionPosition(this->text, pos); XtFree(str); theIBMApplication->setBusyCursor(FALSE); }
void all_messages(char from, char *call_sign, char *from_call, char *message) { char temp_my_course[10]; char *temp; char data1[97]; char data2[97]; int pos; int i; int my_size = 200; XmTextPosition drop_ptr; if (Read_messages_mine_only || (!Read_messages_mine_only && ((vm_range == 0) || ((int)distance_from_my_station(call_sign,temp_my_course) <= vm_range)) ) ) { // Check that it's coming from the correct type of interface // Compare Read_messages_packet_data_type against the port // type associated with data_port to determine whether or // not to display it. // // I = Internet // L = Local // T = TNC // F = File // switch (Read_messages_packet_data_type) { case 2: // Display NET data only // if not network_interface, return if (from != 'I') return; // Don't display it break; case 1: // Display TNC data only // if not local_tnc_interface, return if (from != 'T') return; // Don't display it break; case 0: // Display both TNC and NET data default: break; } // Check for my stations only if set if (Read_messages_mine_only) { char short_call[MAX_CALLSIGN]; char *p; xastir_snprintf(short_call, sizeof(short_call), "%s", my_callsign); if ( (p = index(short_call,'-')) ) { *p = '\0'; // Terminate it } if (!strstr(call_sign, short_call) && !strstr(from_call, short_call)) { return; } } if ((temp = malloc((size_t)my_size)) == NULL) return; if (strlen(message)>95) { xastir_snprintf(data1, sizeof(data1), "%s", message); data1[95]='\0'; xastir_snprintf(data2, sizeof(data2), "\n\t%s", message+95); } else { xastir_snprintf(data1, sizeof(data1), "%s", message); data2[0] = '\0'; } if (strncmp(call_sign, "java",4) == 0) { xastir_snprintf(call_sign, MAX_CALLSIGN+1, "%s", langcode("WPUPMSB015") ); // Broadcast xastir_snprintf(temp, my_size, "%s %s\t%s%s\n", from_call, call_sign, data1, data2); } else if (strncmp(call_sign, "USER", 4) == 0) { xastir_snprintf(call_sign, MAX_CALLSIGN+1, "%s", langcode("WPUPMSB015") ); // Broadcast xastir_snprintf(temp, my_size, "%s %s\t%s%s\n", from_call, call_sign, data1, data2); } else xastir_snprintf(temp, my_size, "%s to %s via:%c\t%s%s\n", from_call, call_sign, from, data1, data2); if ((All_messages_dialog != NULL)) { begin_critical_section(&All_messages_dialog_lock, "view_message_gui.c:all_messages" ); pos = (int)XmTextGetLastPosition(view_messages_text); XmTextInsert(view_messages_text, pos, temp); pos += strlen(temp); while (pos > view_message_limit) { for (drop_ptr = i = 0; i < 3; i++) { (void)XmTextFindString(view_messages_text, drop_ptr, "\n", XmTEXT_FORWARD, &drop_ptr); drop_ptr++; } XmTextReplace(view_messages_text, 0, drop_ptr, ""); pos = (int)XmTextGetLastPosition(view_messages_text); } XtVaSetValues(view_messages_text, XmNcursorPosition, pos, NULL); XmTextShowPosition(view_messages_text, pos); end_critical_section(&All_messages_dialog_lock, "view_message_gui.c:all_messages" ); } free(temp); } }
void view_message_print_record(Message *m_fill) { int pos; char *temp; int i; int my_size = 200; char temp_my_course[10]; XmTextPosition drop_ptr; int distance; // Make sure it's within our distance range we have set distance = (int)distance_from_my_station(m_fill->from_call_sign,temp_my_course); if (Read_messages_mine_only || (!Read_messages_mine_only && ( (vm_range == 0) || (distance <= vm_range) ) ) ) { // Check that it's coming from the correct type of interface // Compare Read_messages_packet_data_type against the port // type associated with data_port to determine whether or // not to display it. // // I = Internet // L = Local // T = TNC // F = File // switch (Read_messages_packet_data_type) { case 2: // Display NET data only // if not network_interface, return if (m_fill->data_via != 'I') return; // Don't display it break; case 1: // Display TNC data only // if not local_tnc_interface, return if (m_fill->data_via != 'T') return; // Don't display it break; case 0: // Display both TNC and NET data default: break; } // Check for my stations only if set if (Read_messages_mine_only) { char short_call[MAX_CALLSIGN]; char *p; xastir_snprintf(short_call, sizeof(short_call), "%s", my_callsign); if ( (p = index(short_call,'-')) ) { *p = '\0'; // Terminate it } if (!strstr(m_fill->call_sign, short_call) && !strstr(m_fill->from_call_sign, short_call)) { return; } } if ((temp = malloc((size_t)my_size)) == NULL) return; sprintf(temp,"%-9s>%-9s %s:%5s %s:%c :%s\n", m_fill->from_call_sign, m_fill->call_sign, langcode("WPUPMSB013"), m_fill->seq, langcode("WPUPMSB014"), m_fill->type, m_fill->message_line); pos = (int)XmTextGetLastPosition(view_messages_text); XmTextInsert(view_messages_text, pos, temp); pos += strlen(temp); while (pos > view_message_limit) { for (drop_ptr = i = 0; i < 3; i++) { (void)XmTextFindString(view_messages_text, drop_ptr, "\n", XmTEXT_FORWARD, &drop_ptr); drop_ptr++; } XmTextReplace(view_messages_text, 0, drop_ptr, ""); pos = (int)XmTextGetLastPosition(view_messages_text); } XtVaSetValues(view_messages_text, XmNcursorPosition, pos, NULL); free(temp); } }
void set_current_line(const string& input) { XmTextReplace(gdb_w, promptPosition, XmTextGetLastPosition(gdb_w), XMST(input.chars())); }
// Show prompt according to current mode static void show_isearch() { XmTextPosition start = start_of_line(); if (start == XmTextPosition(-1)) return; string prompt; switch (isearch_state) { case ISEARCH_NONE: prompt = gdb->prompt(); break; case ISEARCH_NEXT: prompt = isearch_prompt; break; case ISEARCH_PREV: prompt = reverse_isearch_prompt; break; } if (isearch_state != ISEARCH_NONE) prompt += "`" + cook(isearch_string) + "': "; string input = current_line(); string line = prompt + input; bool old_private_gdb_output = private_gdb_output; private_gdb_output = true; XmTextReplace(gdb_w, start, XmTextGetLastPosition(gdb_w), XMST(line.chars())); promptPosition = start + prompt.length(); XmTextPosition pos = promptPosition; int index = input.index(isearch_string); if (isearch_state == ISEARCH_NONE || index < 0) { XmTextSetHighlight(gdb_w, 0, XmTextGetLastPosition(gdb_w), XmHIGHLIGHT_NORMAL); } else { XmTextSetHighlight(gdb_w, 0, pos + index, XmHIGHLIGHT_NORMAL); XmTextSetHighlight(gdb_w, pos + index, pos + index + isearch_string.length(), XmHIGHLIGHT_SECONDARY_SELECTED); XmTextSetHighlight(gdb_w, pos + index + isearch_string.length(), XmTextGetLastPosition(gdb_w), XmHIGHLIGHT_NORMAL); } if (index >= 0) pos += index; XmTextSetInsertionPosition(gdb_w, pos); XmTextShowPosition(gdb_w, pos); have_isearch_line = false; private_gdb_output = old_private_gdb_output; }
void set_buttons_from_gdb(Widget buttons, string& text) { bool yn = gdb->ends_with_yn(text); if (yn) { if (!gdb_asks_yn) annotate("query"); gdb_asks_yn = true; } else if (gdb->isReadyWithPrompt()) { if (gdb_asks_yn) annotate("post-query"); gdb_asks_yn = false; unpost_gdb_yn(); } if (yn && !gdb_keyboard_command) { // Fetch previous output lines, in case this is a multi-line message. String s = XmTextGetString(gdb_w); string prompt(s); XtFree(s); // FIXME: Handle JDB char prompt_start = (gdb->type() == XDB ? '>' : '('); int pos = prompt.index(prompt_start, -1); if (pos >= 0) pos = prompt.index('\n', pos) + 1; if (pos == 0) pos = messagePosition; XmTextReplace(gdb_w, pos, XmTextGetLastPosition(gdb_w), XMST("")); promptPosition = pos; prompt = prompt.from(pos); if (text.contains('(')) prompt += text.before('(', -1); // Don't repeat `(y or n)' else prompt += text; post_gdb_yn(prompt); text = ""; return; } if (buttons == 0) return; static bool last_yn = false; if (yn == last_yn) return; last_yn = yn; if (XtIsComposite(buttons)) { set_sensitive(buttons, false); WidgetList children = 0; Cardinal num_children = 0; XtVaGetValues(buttons, XmNchildren, &children, XmNnumChildren, &num_children, XtPointer(0)); int i; for (i = 0; i < int(num_children); i++) XtManageChild(children[i]); for (i = 0; i < int(num_children); i++) { Widget w = children[i]; string name = XtName(w); if (yn == (name == "Yes" || name == "No")) XtManageChild(w); else XtUnmanageChild(w); } set_sensitive(buttons, true); } }
static void Listener_completion(Widget w, XEvent *event, char **str, Cardinal *num) { /* used only by the listener widget -- needs to be smart about text since overall string can be enormous * and we don't want to back up past the last prompt * also if at start of line (or all white-space to previous \n, indent */ int beg, end, len, matches = 0; char *old_text; ss->sgx->completion_requestor = listener_text; ss->sgx->completion_requestor_dialog = NULL; beg = printout_end + 1; end = XmTextGetLastPosition(w); if (end <= beg) return; len = end - beg + 1; old_text = (char *)CALLOC(len + 1, sizeof(char)); XmTextGetSubstring(w, beg, len, len + 1, old_text); /* now old_text is the stuff typed since the last prompt */ if (old_text) { char *new_text = NULL, *file_text = NULL; bool try_completion = true; new_text = complete_listener_text(old_text, end, &try_completion, &file_text); if (!try_completion) { FREE(old_text); return; } if (strcmp(old_text, new_text) == 0) matches = get_completion_matches(); XmTextReplace(w, beg, end, new_text); XmTextSetCursorPosition(w, XmTextGetLastPosition(w)); if (new_text) { FREE(new_text); new_text = NULL; } if (matches > 1) { bool need_position; clear_possible_completions(); set_save_completions(true); if (file_text) new_text = filename_completer(file_text, NULL); else new_text = command_completer(old_text, NULL); if (new_text) { FREE(new_text); new_text = NULL; } need_position = (completions_dialog == NULL); display_completions(); set_save_completions(false); if (need_position) { Position wx, wy; int xoff, yoff; Window wn; /* try to position the newly popped up help window below the text field */ XtVaGetValues(w, XmNx, &wx, XmNy, &wy, NULL); XTranslateCoordinates(XtDisplay(w), XtWindow(w), DefaultRootWindow(XtDisplay(w)), 0, 0, &xoff, &yoff, &wn); wx += xoff; wy += yoff; XtVaSetValues(completions_dialog, XmNx, wx, XmNy, wy + 140, NULL); } } if (file_text) FREE(file_text); if (old_text) FREE(old_text); } }
void wxTextEntry::Replace(long from, long to, const wxString& value) { XmTextReplace(GetText(), from, GetMotifPos(to), value.char_str()); }