Exemplo n.º 1
0
/// Replace/append/insert the selection with/at/after the specified string.
///
/// \param begin beginning of selection
/// \param end end of selection
/// \param insert the string to insert
/// \param append_mode can be one of REPLACE_MODE, INSERT_MODE or APPEND_MODE, affects the way the
/// test update is performed
static void replace_part(const wchar_t *begin, const wchar_t *end, const wchar_t *insert,
                         int append_mode) {
    const wchar_t *buff = get_buffer();
    size_t out_pos = get_cursor_pos();

    wcstring out;

    out.append(buff, begin - buff);

    switch (append_mode) {
        case REPLACE_MODE: {
            out.append(insert);
            out_pos = wcslen(insert) + (begin - buff);
            break;
        }
        case APPEND_MODE: {
            out.append(begin, end - begin);
            out.append(insert);
            break;
        }
        case INSERT_MODE: {
            long cursor = get_cursor_pos() - (begin - buff);
            out.append(begin, cursor);
            out.append(insert);
            out.append(begin + cursor, end - begin - cursor);
            out_pos += wcslen(insert);
            break;
        }
    }
    out.append(end);
    reader_set_buffer(out, out_pos);
}
Exemplo n.º 2
0
	LRESULT CALLBACK tagMAINWINDOW::WM_COMMAND_reaction(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
	{
		int wmId    = LOWORD(wParam);
		int wmEvent = HIWORD(wParam);
		switch (wmId)
		{
		case IDM_ABOUT:
			DialogBox(NULL, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
			break;
		case IDM_EXIT:
			DestroyWindow(hWnd);
			break;
		case STN_CLICKED:
			SetWindowPos(SetTimeWindow,NULL,get_cursor_pos(hWnd).x,get_cursor_pos(hWnd).y,0,0,SWP_NOSIZE);
			UpdateWindow(SetTimeWindow);
			ShowWindow	(SetTimeWindow,1);
			SetFocus	(STWY);
			break;
		case BPause_ID:
			GoParam = !GoParam;
			if(GoParam)
				SetWindowText(BPause,L"Пауза");
			else
				SetWindowText(BPause,L"Продолжить");
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		return 0;
	}
Exemplo n.º 3
0
/// Output the specified selection.
///
/// \param begin start of selection
/// \param end  end of selection
/// \param cut_at_cursor whether printing should stop at the surrent cursor position
/// \param tokenize whether the string should be tokenized, printing one string token on every line
/// and skipping non-string tokens
static void write_part(const wchar_t *begin, const wchar_t *end, int cut_at_cursor, int tokenize,
                       io_streams_t &streams) {
    size_t pos = get_cursor_pos() - (begin - get_buffer());

    if (tokenize) {
        wchar_t *buff = wcsndup(begin, end - begin);
        // fwprintf( stderr, L"Subshell: %ls, end char %lc\n", buff, *end );
        wcstring out;
        tokenizer_t tok(buff, TOK_ACCEPT_UNFINISHED);
        tok_t token;
        while (tok.next(&token)) {
            if ((cut_at_cursor) && (token.offset + token.text.size() >= pos)) break;

            if (token.type == TOK_STRING) {
                wcstring tmp = token.text;
                unescape_string_in_place(&tmp, UNESCAPE_INCOMPLETE);
                out.append(tmp);
                out.push_back(L'\n');
            }
        }

        streams.out.append(out);
        free(buff);
    } else {
        if (cut_at_cursor) {
            streams.out.append(begin, pos);
        } else {
            streams.out.append(begin, end - begin);
        }
        streams.out.push_back(L'\n');
    }
}
Exemplo n.º 4
0
/**
   Output the specified selection.

   \param begin start of selection
   \param end  end of selection
   \param cut_at_cursor whether printing should stop at the surrent cursor position
   \param tokenize whether the string should be tokenized, printing one string token on every line and skipping non-string tokens
*/
static void write_part(const wchar_t *begin,
                       const wchar_t *end,
                       int cut_at_cursor,
                       int tokenize)
{
    wcstring out;
    wchar_t *buff;
    size_t pos;

    pos = get_cursor_pos()-(begin-get_buffer());

    if (tokenize)
    {
        buff = wcsndup(begin, end-begin);
//    fwprintf( stderr, L"Subshell: %ls, end char %lc\n", buff, *end );
        out.clear();
        tokenizer_t tok(buff, TOK_ACCEPT_UNFINISHED);
        for (; tok_has_next(&tok); tok_next(&tok))
        {
            if ((cut_at_cursor) &&
                    (tok_get_pos(&tok)+wcslen(tok_last(&tok)) >= pos))
                break;

            switch (tok_last_type(&tok))
            {
                case TOK_STRING:
                {
                    out.append(escape_string(tok_last(&tok), UNESCAPE_INCOMPLETE));
                    out.push_back(L'\n');
                    break;
                }
                
                default:
                {
                    break;
                }
            }
        }

        stdout_buffer.append(out);

        free(buff);
    }
    else
    {
        if (cut_at_cursor)
        {
            end = begin+pos;
        }

//    debug( 0, L"woot2 %ls -> %ls", buff, esc );

        stdout_buffer.append(begin, end - begin);
        stdout_buffer.append(L"\n");

    }
}
Exemplo n.º 5
0
Arquivo: vga.c Projeto: jo-va/toutatis
device_t *vga_init()
{
        get_cursor_pos(&xpos, &ypos);
        vga_clear();

        vga_device.read = 0;
        vga_device.write = vga_write;

        return &vga_device;
}
Exemplo n.º 6
0
/**
   Replace/append/insert the selection with/at/after the specified string.

   \param begin beginning of selection
   \param end end of selection
   \param insert the string to insert
   \param append_mode can be one of REPLACE_MODE, INSERT_MODE or APPEND_MODE, affects the way the test update is performed
*/
static void replace_part( const wchar_t *begin,
						  const wchar_t *end,
						  wchar_t *insert,
						  int append_mode )
{
	const wchar_t *buff = get_buffer();
	string_buffer_t out;
	int out_pos=get_cursor_pos();

	sb_init( &out );

	sb_append_substring( &out, buff, begin-buff );

	switch( append_mode)
	{
		case REPLACE_MODE:
		{

			sb_append( &out, insert );
			out_pos = wcslen( insert ) + (begin-buff);
			break;

		}
		case APPEND_MODE:
		{
			sb_append_substring( &out, begin, end-begin );
			sb_append( &out, insert );
			break;
		}
		case INSERT_MODE:
		{
			int cursor = get_cursor_pos() -(begin-buff);
			sb_append_substring( &out, begin, cursor );
			sb_append( &out, insert );
			sb_append_substring( &out, begin+cursor, end-begin-cursor );
			out_pos +=  wcslen( insert );
			break;
		}
	}
	sb_append( &out, end );
	reader_set_buffer( (wchar_t *)out.buff, out_pos );
	sb_destroy( &out );
}
Exemplo n.º 7
0
Arquivo: menus.c Projeto: aspacsa/vlp
void display_msg(size_t row, size_t col, 
                 FORM * my_form, 
                 FIELD * curr_field,
                 char * message) {

  mvprintw( row, col, message );
  size_t cur_row, cur_col;
  get_cursor_pos( curr_field, &cur_row, &cur_col );
  move( cur_row, cur_col );
  set_current_field( my_form, curr_field );
  return;
}
Exemplo n.º 8
0
void CCamera::Mouse()
{
  HWND          hWnd = GetActiveWindow();
  POINT		  mousePos = get_cursor_pos(hWnd);
  RECT		  rt;	GetWindowRect(hWnd, &rt);
  int           mX = (rt.left + rt.right) >> 1;
  int           mY = (rt.top + rt.bottom) >> 1;

  float         angleY = 0.0f;
  float         angleZ = 0.0f;
  static float  currentRotX = 0.0f;

  if ((mousePos.x == mX) && (mousePos.y == mY))
    return;

  SetCursorPos(mX, mY);

  angleY = (float)((mX - mousePos.x)) / 1000.0f;
  angleZ = (float)((mY - mousePos.y)) / 1000.0f;

  static float lastRotX = 0.0f;
  lastRotX = currentRotX;

  if (currentRotX > 1.0f)
  {
    currentRotX = 1.0f;
    if (lastRotX < 1.0f)
    {
      fl3 vAxis = norm_ort(m_vView - m_vPosition, m_vUpVector);
      RotateView(1.0f - lastRotX, vAxis.m[0], vAxis.m[1], vAxis.m[2]);
    }
  }
  else {
    if (currentRotX < -1.0f) {
      currentRotX = -1.0f;
      if (lastRotX < -1.0f)
      {
        fl3 vAxis = norm_ort(m_vView - m_vPosition, m_vUpVector);
        RotateView(-1.0f - lastRotX, vAxis.m[0], vAxis.m[1], vAxis.m[2]);
      }
    }
    else {
      fl3 vAxis = norm_ort(m_vView - m_vPosition, m_vUpVector);
      RotateView(angleZ, vAxis.m[0], vAxis.m[1], vAxis.m[2]);
    }
  }
  RotateView(angleY, 0, 1, 0);
}
Exemplo n.º 9
0
static int console_height() {
  static int console_height = -1;

  if (console_height == -1) {
    /* determine the height of the console */
    int curstartrow, curstartcol;
    get_cursor_pos(&curstartrow, &curstartcol);
    console_height = 0;
    while ( set_cursor_pos(console_height, 0) == 0 ) {
      console_height++;
    }
    set_cursor_pos( curstartrow, curstartcol );

  }

  return console_height;
}
Exemplo n.º 10
0
void debug_view_memory::view_notify(debug_view_notification type)
{
	if (type == VIEW_NOTIFY_CURSOR_CHANGED)
	{
		// normalize the cursor
		set_cursor_pos(get_cursor_pos(m_cursor));
	}
	else if (type == VIEW_NOTIFY_SOURCE_CHANGED)
	{
		// update for the new source
		const debug_view_memory_source &source = downcast<const debug_view_memory_source &>(*m_source);
		m_chunks_per_row = m_bytes_per_chunk * m_chunks_per_row / source.m_prefsize;
		m_bytes_per_chunk = source.m_prefsize;
		if (source.m_space != NULL)
			m_expression.set_context(&source.m_space->device().debug()->symtable());
		else
			m_expression.set_context(NULL);
	}
}
Exemplo n.º 11
0
void LineEdit::delete_char() {

if ((text.length()<=0) || (cursor_pos==0)) return;

Ref<Font> font = get_font("font");
if (font != NULL) {
    cached_width -= font->get_char_size(text[cursor_pos - 1]).width;
}

text.erase( cursor_pos-1, 1 );

set_cursor_pos(get_cursor_pos()-1);

if (cursor_pos==window_pos) {

    //	set_window_pos(cursor_pos-get_window_length());
}

_text_changed();
}
Exemplo n.º 12
0
Arquivo: joyme.c Projeto: cjxgm/clabs
int main(int argc,char * argv[])
{
	int fd;
	int getnum;
	int success;
	struct js_event e;

	fd = open(argv[1], O_RDONLY);
	if (fd == -1) {
		fprintf(stderr, "error: joystick open failed!\n");
		return 1;
	}

    if (!(display = XOpenDisplay(NULL))) {
        fprintf(stderr, "Cannot open local X-display.\n");
        return;
    }
    root = DefaultRootWindow(display);

	set_cursor_pos(0, 0);

	while (1) {
		read(fd, &e, sizeof(struct js_event));
		printf("value:%d type:%d number:%d\n", e.value, e.type, e.number);
		if (e.type == 2) {
			if (e.number == 0) {	// Left-Right
				if (e.value > 0) {
					int x, y;
					get_cursor_pos(&x, &y);
					x += 10;
					set_cursor_pos(x, y);
				}
				else if (e.value < 0){
				}
			}
		}
	}

	return 0;
}
Exemplo n.º 13
0
Arquivo: menus.c Projeto: aspacsa/vlp
void summons_dataentry_scr(const char *curr_path, const char *case_num) {
  const size_t n_fields = 6;
  const size_t starty = 6;
  const size_t startx = 25;
  FIELD *field[n_fields];
  FORM *my_form;
  Summon_t record;
  int width[] = {  MAX_SUMM_NAME, MAX_SUMM_STATUS, MAX_SUMM_REASON,  
                   MAX_SUMM_CITY, MAX_SUMM_DATE
                };
 
  for ( size_t i = 0; i < n_fields - 1; ++i )
    field[i] = new_field(1, width[i], starty + i * 2, startx, 0, 0);
  field[n_fields - 1] = NULL;
  
  set_field_back( field[0], A_UNDERLINE );
  field_opts_off( field[0], O_AUTOSKIP  );
  set_field_back( field[1], A_UNDERLINE );
  field_opts_on(  field[1], O_BLANK     );
  field_opts_off( field[1], O_AUTOSKIP  );
  set_field_back( field[2], A_UNDERLINE );
  field_opts_off( field[2], O_AUTOSKIP  );
  field_opts_on(  field[2], O_BLANK     );
  set_field_back( field[3], A_UNDERLINE );
  field_opts_off( field[3], O_AUTOSKIP  );
  field_opts_on(  field[3], O_BLANK     );
  set_field_back( field[4], A_UNDERLINE );
  field_opts_off( field[4], O_AUTOSKIP  );

  my_form = new_form(field);
  post_form(my_form);
  refresh();
 
  mvprintw( 0, 0,   curr_path );
  mvprintw( 4, 10,  "Case Number:   %s", case_num );
  mvprintw( 6, 10,  "Person:        " );
  mvprintw( 8, 10,  "Status:        " );
  mvprintw( 10, 10, "Reason:        " );
  mvprintw( 12, 10, "City:          " );
  mvprintw( 14, 10, "Date Summoned: " );
  mvprintw( 16, 10, "(F1) = Options | (F2) = Update | (F3) = Delete | (F5) = List | (ESC) = Main Menu" );
  set_visible_fields( field, 1, 5 );
  move( 6, 25 );
  set_current_field( my_form, field[0] );
 
  record.id = 0;
  int ch;
  do {
    ch = getch();
   
    switch ( ch ) {
      case KEY_UP:
        form_driver(my_form, REQ_PREV_FIELD);
        form_driver(my_form, REQ_END_LINE);
        break;
      case KEY_LEFT:
        form_driver(my_form, REQ_LEFT_CHAR);
        break;
      case KEY_RIGHT:
        form_driver(my_form, REQ_RIGHT_CHAR);
        break;
      case KEY_BACKSPACE:
        form_driver(my_form, REQ_PREV_CHAR);
        form_driver(my_form, REQ_DEL_CHAR);
        break;
      case ENTER:
        form_driver( my_form, REQ_NEXT_FIELD );
        if ( current_field( my_form ) == field[0] )
          form_driver( my_form, REQ_END_LINE );
        break;
      case KEY_F(1):
        clear_lines( 20, 40 );
        {
          FIELD * curr_fld = current_field( my_form );
          size_t error = 0;
          size_t in_target_fld = 0;
          char fld_name[7];     

          if ( curr_fld == field[1] ) {
            error = query_select_all_codes_from_summon_status();
            in_target_fld = 1;
            strncpy( fld_name, "Status", 7 );
          } else if ( curr_fld == field[2] ) {
            error = query_select_all_codes_from_summon_reasons();
            in_target_fld = 1;
            strncpy( fld_name, "Reason", 7 );
          } else if ( curr_fld == field[3] ) {
            if ( query_select_all_codes_from_city_rates() ) {
              clear_line(20, 10);
              mvprintw( 20, 10, db_get_error_msg() );
              move( 12, 25 );
              set_current_field( my_form, curr_fld );
            } else {
              const SCode_t const * scode_ptr;
              size_t count = 0;
              size_t column = 10;

              mvprintw( 20, 5, "Cities:" );
              while ( ( scode_ptr = get_scode_from_result() ) != NULL ) {
                mvprintw( 21 + count++, column, "[%s] %s", scode_ptr->code, scode_ptr->name );
                if ( count == 30 ) {
                  column += 20;
                  count = 0;
                }
              }
              free_scode_result();
            }
          }
          if ( !error && in_target_fld ) {
            const Code_t const * code_ptr;
            size_t count = 0;

            mvprintw( 20, 5, "%s Options:", fld_name );
            while ( ( code_ptr = get_code_from_result() ) != NULL )          
              mvprintw( 21 + count++, 10, "[%d] %s", code_ptr->code, code_ptr->desc );
            free_code_result();
          }
          int row, col;
          get_cursor_pos( curr_fld, &row, &col );
          move( row, col );
          set_current_field( my_form, curr_fld );
        }
        break;
      case KEY_F(2):
        clear_lines( 20, 40 );

        char person_name[MAX_SUMM_NAME];
        strncpy( person_name, field_buffer(field[0], 0), MAX_SUMM_NAME );
         
        if ( is_empty_str( person_name, MAX_SUMM_NAME ) ) {
          mvprintw( 20, 10, "[!] Summon must at least have the person's name." ); 
          move( 6, 25 );
          set_current_field( my_form, field[0] );
          break;
        }
        strncpy( record.case_num, case_num, MAX_CANUM );
        strncpy( record.name, field_buffer(field[0], 0), MAX_SUMM_NAME );
        record.status = atoi( compress_str( field_buffer(field[1], 0) ) );
        record.reason = atoi( compress_str( field_buffer(field[2], 0) ) );
        strncpy( record.city_code, compress_str( field_buffer(field[3], 0) ), MAX_SUMM_CITY );
        strncpy( record.summon_date, compress_str( field_buffer(field[4], 0) ), MAX_SUMM_DATE );
        if ( query_update_summon( &record ) ) {
          mvprintw( 20, 10, db_get_error_msg() );
          move( 6, 25 );
          set_current_field( my_form, field[0] );
        } else {
          clear_fields( field, 0, 4 );
          mvprintw( 20, 10, "[!] Summon has been updated." );
          move( 6, 25 );
          set_current_field( my_form, field[0] );
          record.id = 0;
        }
        break;
      case KEY_F(3):
        clear_lines( 20, 40 );
        if ( record.id > 0 ) {
          mvprintw( 20, 10, "[?] Delete summon '%u' ? [Y/n]", record.id );
          int ch = toupper( getch() );
          if ( ch == 'Y' ) {
            if ( query_delete_summon( record.id ) ) {
              mvprintw( 20, 10, db_get_error_msg() );
            } else {
              clear_fields( field, 0, 4 );    
              mvprintw( 20, 10, "[!] Summon '%u' has been deleted.", record.id );
              move( 6, 25 );
              set_current_field( my_form, field[0] );
              record.id = 0;
            }
          }
        }
        break;
      case KEY_F(5):
        clear_lines( 20, 40 );
        if ( query_select_all_from_summons_for( case_num ) ) {
          mvprintw( 20, 10, db_get_error_msg() );
        } else {
          Summon_t *summ_ptr;
          Summon_t *summons[MAX_SUMM_SET];
          size_t count = 0;

          while ( ( summ_ptr = get_summon_from_result() ) != NULL ) {           
            summons[count] = summ_ptr;
            count++;
          }
          if ( count ) {
            size_t selection;
            char code_buff[4];

            summons_list_scr( summons, count, &selection );
            if ( selection > 0 ) {
              summ_ptr = summons[selection - 1];
              record.id = summ_ptr->id;
              set_field_buffer( field[0], 0, summ_ptr->name );
              snprintf( code_buff, 4, "%d", summ_ptr->status );
              set_field_buffer( field[1], 0, code_buff );
              snprintf( code_buff, 4, "%d", summ_ptr->reason );
              set_field_buffer( field[2], 0, code_buff );
              set_field_buffer( field[3], 0, summ_ptr->city_code );
               set_field_buffer( field[4], 0, summ_ptr->summon_date );
            }
            free_summon_result();
          } else {
            mvprintw( 20, 10, "[!] Case %s has no summons.", case_num );
          }
        }
        set_current_field( my_form, field[0] );
        move( 6, 25 );
        break;
      default:
        {
          FIELD * curr_fld = current_field( my_form );
          if ( ch == '\'' )
            break;

          if ( curr_fld == field[1] || curr_fld == field[2] ) {
            if ( !isdigit( ch ) )
              break;
          } else if ( curr_fld == field[3] ) {
            if ( !isalpha( ch ) )
              break;
            else
              ch = toupper( ch );
          }
          form_driver( my_form, ch );
          break;
        } 
    }
  } while ( ch != ESC );

  unpost_form( my_form );
  free_form( my_form );
  for ( size_t i = 0; i < n_fields - 1; ++i )
    free_field( field[i] );
  return;
}
Exemplo n.º 14
0
Arquivo: menus.c Projeto: aspacsa/vlp
void cases_menu(const char *curr_path) {
  const char *screen_title = "Cases";
  const size_t n_fields = 7;
  const size_t starty = 4;
  const size_t startx = 25;
  FIELD *field[n_fields];
  FORM *my_form;
  int width[] = { MAX_CANUM, MAX_CINUM, 
                  MAX_PHYADD, MAX_POSADD, 
                  MAX_STATUS, MAX_DELDATE 
                };
  
  initscr();
  curs_set(1);
  cbreak();
  clear();
  noecho();
  keypad(stdscr, TRUE);

  for (size_t i = 0; i < n_fields - 1; ++i) {
    field[i] = new_field(1, width[i], starty + i * 2, startx, 0, 0);
  }
  field[n_fields - 1] = NULL;

  set_field_back(field[0], A_UNDERLINE);
  field_opts_off(field[0], O_AUTOSKIP);
  field_opts_on(field[0], O_BLANK);
  set_field_back(field[1], A_UNDERLINE);
  field_opts_off(field[1], O_AUTOSKIP);
  set_field_back(field[2], A_UNDERLINE);
  field_opts_off(field[2], O_AUTOSKIP);
  set_field_back(field[3], A_UNDERLINE);
  field_opts_off(field[3], O_AUTOSKIP);
  set_field_back(field[4], A_UNDERLINE);
  field_opts_off(field[4], O_AUTOSKIP);
  set_field_back(field[5], A_UNDERLINE);
  field_opts_off(field[5], O_AUTOSKIP);

  my_form = new_form(field);
  post_form(my_form);
  refresh();

  mvprintw(0, 0, menu_path(curr_path, screen_title));
  mvprintw(4, 10,   "Case Num:      ");
  mvprintw(6, 10,   "Civil Num:     ");
  mvprintw(8, 10,   "Physical Add:  ");
  mvprintw(10, 10,  "Postal Add:    ");
  mvprintw(12, 10,  "Status:        ");
  mvprintw(14, 10,  "Delivery Date: ");
  mvprintw(16, 10,  "(F1) = Options | (F2) = Update | (F3) = Delete | (F4) = Exit");
  move(4, 25);
  refresh();

  int ch;
  do {
    ch = getch();
    switch(ch) {
      case KEY_UP:
        form_driver(my_form, REQ_PREV_FIELD);
        form_driver(my_form, REQ_END_LINE);
        break;
      case KEY_LEFT:
        form_driver(my_form, REQ_LEFT_CHAR);
        break;
      case KEY_RIGHT:
        form_driver(my_form, REQ_RIGHT_CHAR);
        break;
      case ENTER:
        form_driver( my_form, REQ_NEXT_FIELD );
        form_driver( my_form, REQ_END_LINE );
        if (field_status(field[0])) {
          size_t count = 0;
          char case_num[MAX_CANUM];

          clear_line( 20, 10 );
          strcpy( case_num, compress_str(field_buffer(field[0], 0) ) );
          if ( query_select_count_from_case_for(case_num, &count) ) {
            mvprintw( 20, 10, db_get_error_msg() );
            move( 4, 25 );
          } else {
            if ( count ) {
              //call routine to fill in fields
              Case_t record;
              if ( query_select_all_from_case_for(case_num, &record) ) {
                mvprintw( 20, 10, db_get_error_msg() );
                move( 4, 25 );
              } else {
                char status_buff[4];

                set_field_buffer( field[1], 0, record.civil );
                set_field_buffer( field[2], 0, record.physical_add );
                set_field_buffer( field[3], 0, record.postal_add );
                snprintf( status_buff, 4, "%d", record.status );
                set_field_buffer( field[4], 0, status_buff );
                set_field_buffer( field[5], 0, record.delivery_date );
              }
            } else {            
              clear_fields( field, 1, 5 );    
              mvprintw( 20, 10, "[!] Case %s does not exist.", case_num );
              move( 6, 25 );
              set_current_field( my_form, field[0] );
            }
          }
          set_field_status( field[0], 0 );
        }
        break;
      case KEY_BACKSPACE:
        form_driver(my_form, REQ_PREV_CHAR);
        form_driver(my_form, REQ_DEL_CHAR);
        break;
      case ESC:
        {
          FIELD * curr_field = current_field( my_form );
          int row, col;
          get_cursor_pos( curr_field, &row, &col );
          clear_lines( 20, 40 );
          move( row, col );
          set_current_field( my_form, curr_field );
        }
        break;
      case KEY_F(1):
        if ( current_field( my_form ) == field[4] ) {
          clear_lines( 20, 30 );
          if ( query_select_all_codes_from_case_status() ) {
            mvprintw( 20, 10, db_get_error_msg() );
          } else {
            const Code_t const * code_ptr;
            size_t count = 0;

            mvprintw( 20, 5, "Status Options:" );
            while ( ( code_ptr = get_code_from_result() ) != NULL ) {           
              mvprintw( 21 + count, 10, "[%d] %s", code_ptr->code, code_ptr->desc );
              count++;
            }
            free_code_result();
            move( 12, 25 );
            set_current_field( my_form, field[4] );
          }  
        } 
        break;
      case KEY_F(2):
      {
        size_t count = 0;
        char case_num[MAX_CANUM];
        
        clear_lines( 20, 30 );
        strncpy( case_num, compress_str(field_buffer(field[0], 0) ), MAX_CANUM );
        if ( query_select_count_from_case_for( case_num, &count ) ) {
          mvprintw( 20, 10, db_get_error_msg() );
        } else {
          Case_t record;
          strncpy( record.number, compress_str(field_buffer(field[0], 0)), MAX_CANUM );
          strncpy( record.civil, compress_str(field_buffer(field[1], 0)), MAX_CINUM );
          strncpy( record.physical_add, field_buffer(field[2], 0), MAX_PHYADD );
          strncpy( record.postal_add, field_buffer(field[3], 0), MAX_POSADD );
          record.status = atoi( compress_str(field_buffer(field[4], 0)) );
          strncpy( record.delivery_date, compress_str(field_buffer(field[5], 0)), MAX_DELDATE );
          if ( count ) {
            // update existing record
            if ( query_update_case( &record ) == 0 ) {
              mvprintw( 20, 10, "[!] Case has been updated." );
            } else {
              mvprintw( 20, 10, db_get_error_msg() );
            }
          } else {
            // create new record
            if ( query_create_new_case( &record ) == 0 ) {
              mvprintw (20, 10, "[!] Case has been created successfully." );
            } else {
              mvprintw( 20, 10, db_get_error_msg() );
            }
          }
        }
        move(4, 25);
        set_current_field( my_form, field[0] );
       }
       break;
      case KEY_F(3):
        {
          size_t count = 0;
          char case_num[MAX_CANUM];

          clear_lines(20, 30);
          strncpy(case_num, compress_str(field_buffer(field[0], 0) ), MAX_CANUM);
          if ( strlen(case_num) ) {
            if ( query_select_count_from_case_for(case_num, &count) ) {
              mvprintw( 20, 10, db_get_error_msg() );
            } else {
              if (count) {
                mvprintw(20, 10, "[?] Delete case '%s' ? [Y/n]", case_num);
                int ch = toupper(getch());
                if (ch == 'Y') {
                  if ( query_delete_case(case_num) ) {
                    mvprintw( 20, 10, db_get_error_msg() );
                  } else {
                    clear_fields(field, 0, 5);    
                    mvprintw(20, 10, "[!] Case '%s' has been deleted.");
                  }
                }
              } else {
                mvprintw(20, 10, "[!] Case '%s' does not exist.", case_num);
              }
            }
          } else {
            mvprintw(20, 10, "[!] Must enter a valid Case Number to be deleted.");
          }
        }
        move(4, 25);
        set_current_field(my_form, field[0]);
        break;
      case DEL:
        form_driver(my_form, REQ_DEL_CHAR);
        break;
      default:
        {
          FIELD * curr_fld = current_field( my_form );

          if ( ch == '\'' )
            break;
          if ( curr_fld == field[4] ) {
            if ( !isdigit( ch ) )
              break;
          }
        }
        form_driver(my_form, ch);
        break;
    } 
  } while( ch != KEY_F(4) ); 

  unpost_form(my_form);
  free_form(my_form);
  for (size_t i = 0; i < n_fields -1; ++i) {
    free_field(field[i]);
  }
  endwin();
  return;
}
Exemplo n.º 15
0
void LineEdit::_input_event(InputEvent p_event) {


    switch(p_event.type) {

    case InputEvent::MOUSE_BUTTON: {

        const InputEventMouseButton &b = p_event.mouse_button;

        if (b.pressed && b.button_index==BUTTON_RIGHT) {
            menu->set_pos(get_global_transform().xform(get_local_mouse_pos()));
            menu->set_size(Vector2(1,1));
            menu->popup();
            grab_focus();
            return;
        }

        if (b.button_index!=BUTTON_LEFT)
            break;

        _reset_caret_blink_timer();
        if (b.pressed) {

            shift_selection_check_pre(b.mod.shift);

            set_cursor_at_pixel_pos(b.x);

            if (b.mod.shift) {

                selection_fill_at_cursor();
                selection.creating=true;

            } else {

                if (b.doubleclick) {

                    selection.enabled=true;
                    selection.begin=0;
                    selection.end=text.length();
                    selection.doubleclick=true;
                }

                selection.drag_attempt=false;

                if ((cursor_pos<selection.begin) || (cursor_pos>selection.end) || !selection.enabled)  {

                    selection_clear();
                    selection.cursor_start=cursor_pos;
                    selection.creating=true;
                } else if (selection.enabled) {

                    selection.drag_attempt=true;
                }
            }

            //			if (!editable)
            //	non_editable_clicked_signal.call();
            update();

        } else {

            if ( (!selection.creating) && (!selection.doubleclick)) {
                selection_clear();
            }
            selection.creating=false;
            selection.doubleclick=false;

            if (OS::get_singleton()->has_virtual_keyboard())
                OS::get_singleton()->show_virtual_keyboard(text,get_global_rect());
        }

        update();
    }
    break;
    case InputEvent::MOUSE_MOTION: {

        const InputEventMouseMotion& m=p_event.mouse_motion;

        if (m.button_mask&BUTTON_LEFT) {

            if (selection.creating) {
                set_cursor_at_pixel_pos(m.x);
                selection_fill_at_cursor();
            }
        }

    }
    break;
    case InputEvent::KEY: {

        const InputEventKey &k =p_event.key;

        if (!k.pressed)
            return;
        unsigned int code  = k.scancode;


        if (k.mod.command) {

            bool handled=true;

            switch (code) {

            case (KEY_X): { // CUT

                if(editable) {
                    cut_text();
                }

            }
            break;

            case (KEY_C): { // COPY

                copy_text();

            }
            break;

            case (KEY_V): { // PASTE

                if(editable) {

                    paste_text();
                }

            }
            break;

            case (KEY_Z): { // Simple One level undo

                if(editable) {

                    undo();

                }


            }
            break;

            case (KEY_U): { // Delete from start to cursor

                if(editable) {

                    selection_clear();
                    undo_text = text;
                    text = text.substr(cursor_pos,text.length()-cursor_pos);

                    Ref<Font> font = get_font("font");

                    cached_width = 0;
                    if (font != NULL) {
                        for (int i = 0; i < text.length(); i++)
                            cached_width += font->get_char_size(text[i]).width;
                    }

                    set_cursor_pos(0);
                    _text_changed();

                }


            }
            break;

            case (KEY_Y): { // PASTE (Yank for unix users)

                if(editable) {

                    paste_text();
                }

            }
            break;
            case (KEY_K): { // Delete from cursor_pos to end

                if(editable) {

                    selection_clear();
                    undo_text = text;
                    text = text.substr(0,cursor_pos);
                    _text_changed();
                }

            }
            break;
            case (KEY_A): { //Select All
                select();
            }
            break;
            default: {
                handled=false;
            }
            }

            if (handled) {
                accept_event();
                return;
            }
        }

        _reset_caret_blink_timer();
        if (!k.mod.meta) {

            bool handled=true;
            switch (code) {

            case KEY_ENTER:
            case KEY_RETURN: {

                emit_signal( "text_entered",text );
                if (OS::get_singleton()->has_virtual_keyboard())
                    OS::get_singleton()->hide_virtual_keyboard();

                return;
            }
            break;

            case KEY_BACKSPACE: {

                if (!editable)
                    break;

                if (selection.enabled) {
                    undo_text=text;
                    selection_delete();
                    break;
                }

#ifdef APPLE_STYLE_KEYS
                if (k.mod.alt) {
#else
                if (k.mod.alt) {
                    handled=false;
                    break;
                } else if (k.mod.command) {
#endif
                    int cc=cursor_pos;
                    bool prev_char=false;

                    while (cc>0) {
                        bool ischar=_is_text_char(text[cc-1]);

                        if (prev_char && !ischar)
                            break;

                        prev_char=ischar;
                        cc--;
                    }

                    delete_text(cc, cursor_pos);

                    set_cursor_pos(cc);

                } else {
                    undo_text=text;
                    delete_char();
                }

            }
            break;
            case KEY_KP_4: {
                if (k.unicode != 0) {
                    handled = false;
                    break;
                }
                // numlock disabled. fallthrough to key_left
            }
            case KEY_LEFT: {

#ifndef APPLE_STYLE_KEYS
                if (!k.mod.alt)
#endif
                    shift_selection_check_pre(k.mod.shift);

#ifdef APPLE_STYLE_KEYS
                if (k.mod.command) {
                    set_cursor_pos(0);
                } else if (k.mod.alt) {

#else
                if (k.mod.alt) {
                    handled=false;
                    break;
                } else if (k.mod.command) {
#endif
                    bool prev_char=false;
                    int cc=cursor_pos;

                    while (cc>0) {
                        bool ischar=_is_text_char(text[cc-1]);

                        if (prev_char && !ischar)
                            break;

                        prev_char=ischar;
                        cc--;
                    }

                    set_cursor_pos(cc);

                } else {
                    set_cursor_pos(get_cursor_pos()-1);
                }

                shift_selection_check_post(k.mod.shift);

            }
            break;
            case KEY_KP_6: {
                if (k.unicode != 0) {
                    handled = false;
                    break;
                }
                // numlock disabled. fallthrough to key_right
            }
            case KEY_RIGHT: {

                shift_selection_check_pre(k.mod.shift);

#ifdef APPLE_STYLE_KEYS
                if (k.mod.command) {
                    set_cursor_pos(text.length());
                } else if (k.mod.alt) {
#else
                if (k.mod.alt) {
                    handled=false;
                    break;
                } else if (k.mod.command) {
#endif
                    bool prev_char=false;
                    int cc=cursor_pos;

                    while (cc<text.length()) {
                        bool ischar=_is_text_char(text[cc]);

                        if (prev_char && !ischar)
                            break;

                        prev_char=ischar;
                        cc++;
                    }

                    set_cursor_pos(cc);

                } else {
                    set_cursor_pos(get_cursor_pos()+1);
                }

                shift_selection_check_post(k.mod.shift);

            }
            break;
            case KEY_DELETE: {

                if (!editable)
                    break;

                if (k.mod.shift && !k.mod.command && !k.mod.alt) {
                    cut_text();
                    break;
                }

                if (selection.enabled) {
                    undo_text=text;
                    selection_delete();
                    break;
                }

                int text_len = text.length();

                if (cursor_pos==text_len)
                    break; // nothing to do

#ifdef APPLE_STYLE_KEYS
                if (k.mod.alt) {
#else
                if (k.mod.alt) {
                    handled=false;
                    break;
                } else if (k.mod.command) {
#endif
                    int cc=cursor_pos;

                    bool prev_char=false;

                    while (cc<text.length()) {

                        bool ischar=_is_text_char(text[cc]);

                        if (prev_char && !ischar)
                            break;
                        prev_char=ischar;
                        cc++;
                    }

                    delete_text(cursor_pos,cc);

                } else {
                    undo_text=text;
                    set_cursor_pos(cursor_pos+1);
                    delete_char();
                }

            }
            break;
            case KEY_KP_7: {
                if (k.unicode != 0) {
                    handled = false;
                    break;
                }
                // numlock disabled. fallthrough to key_home
            }
            case KEY_HOME: {

                shift_selection_check_pre(k.mod.shift);
                set_cursor_pos(0);
                shift_selection_check_post(k.mod.shift);
            }
            break;
            case KEY_KP_1: {
                if (k.unicode != 0) {
                    handled = false;
                    break;
                }
                // numlock disabled. fallthrough to key_end
            }
            case KEY_END: {

                shift_selection_check_pre(k.mod.shift);
                set_cursor_pos(text.length());
                shift_selection_check_post(k.mod.shift);
            }
            break;


            default: {

                handled=false;
            }
            break;
        }

        if (handled) {
            accept_event();
        } else if (!k.mod.alt && !k.mod.command) {
            if (k.unicode>=32 && k.scancode!=KEY_DELETE) {

                if (editable) {
                    selection_delete();
                    CharType ucodestr[2]= {(CharType)k.unicode,0};
                    append_at_cursor(ucodestr);
                    _text_changed();
                    accept_event();
                }

            } else {
                return;
            }
        }

        update();

    }


    return;

}
break;

    }
}

void LineEdit::set_align(Align p_align) {

ERR_FAIL_INDEX(p_align, 4);
align = p_align;
update();
}

LineEdit::Align LineEdit::get_align() const {

return align;
}

Variant LineEdit::get_drag_data(const Point2& p_point) {

if (selection.drag_attempt && selection.enabled) {
    String t = text.substr(selection.begin, selection.end - selection.begin);
    Label *l = memnew( Label );
    l->set_text(t);
    set_drag_preview(l);
    return 	t;
}

return Variant();

}
bool LineEdit::can_drop_data(const Point2& p_point,const Variant& p_data) const {

return p_data.get_type()==Variant::STRING;
}
void LineEdit::drop_data(const Point2& p_point,const Variant& p_data) {

if (p_data.get_type()==Variant::STRING) {
    set_cursor_at_pixel_pos(p_point.x);
    int selected = selection.end - selection.begin;

    Ref<Font> font = get_font("font");
    if (font != NULL) {
        for (int i = selection.begin; i < selection.end; i++)
            cached_width -= font->get_char_size(text[i]).width;
    }

    text.erase(selection.begin, selected);

    append_at_cursor(p_data);
    selection.begin = cursor_pos-selected;
    selection.end = cursor_pos;
}
}


void LineEdit::_notification(int p_what) {

switch(p_what) {
#ifdef TOOLS_ENABLED
case NOTIFICATION_ENTER_TREE: {
    if (get_tree()->is_editor_hint()) {
        cursor_set_blink_enabled(EDITOR_DEF("text_editor/caret_blink", false));
        cursor_set_blink_speed(EDITOR_DEF("text_editor/caret_blink_speed", 0.65));

        if (!EditorSettings::get_singleton()->is_connected("settings_changed",this,"_editor_settings_changed")) {
            EditorSettings::get_singleton()->connect("settings_changed",this,"_editor_settings_changed");
        }
    }
}
break;
#endif
case NOTIFICATION_RESIZED: {

    set_cursor_pos( get_cursor_pos() );

}
break;
case MainLoop::NOTIFICATION_WM_FOCUS_IN: {
    window_has_focus = true;
    draw_caret = true;
    update();
}
break;
case MainLoop::NOTIFICATION_WM_FOCUS_OUT: {
    window_has_focus = false;
    draw_caret = false;
    update();
}
break;
case NOTIFICATION_DRAW: {

    if ((!has_focus() && !menu->has_focus()) || !window_has_focus) {
        draw_caret = false;
    }

    int width,height;

    Size2 size=get_size();
    width=size.width;
    height=size.height;

    RID ci = get_canvas_item();

    Ref<StyleBox> style = get_stylebox("normal");
    if (!is_editable())
        style=get_stylebox("read_only");

    Ref<Font> font=get_font("font");

    style->draw( ci, Rect2( Point2(), size ) );

    if (has_focus()) {

        get_stylebox("focus")->draw( ci, Rect2( Point2(), size ) );
    }

    int x_ofs=0;

    switch (align) {

    case ALIGN_FILL:
    case ALIGN_LEFT: {

        x_ofs=style->get_offset().x;
    }
    break;
    case ALIGN_CENTER: {

        x_ofs=int(size.width-(cached_width))/2;
    }
    break;
    case ALIGN_RIGHT: {

        x_ofs=int(size.width-style->get_offset().x-(cached_width));
    }
    break;
    }

    int ofs_max=width-style->get_minimum_size().width;
    int char_ofs=window_pos;

    int y_area=height-style->get_minimum_size().height;
    int y_ofs=style->get_offset().y;

    int font_ascent=font->get_ascent();

    Color selection_color=get_color("selection_color");
    Color font_color=get_color("font_color");
    Color font_color_selected=get_color("font_color_selected");
    Color cursor_color=get_color("cursor_color");

    const String& t = text.empty() ? placeholder : text;
    // draw placeholder color
    if(text.empty())
        font_color.a *= placeholder_alpha;

    int caret_height = font->get_height() > y_area ? y_area : font->get_height();
    while(true) {

        //end of string, break!
        if (char_ofs>=t.length())
            break;

        CharType cchar=pass?'*':t[char_ofs];
        CharType next=pass?'*':t[char_ofs+1];
        int char_width=font->get_char_size( cchar,next ).width;

        // end of widget, break!
        if ((x_ofs + char_width) > ofs_max)
            break;


        bool selected=selection.enabled && char_ofs>=selection.begin && char_ofs<selection.end;

        if (selected)
            VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(char_width, caret_height)), selection_color);


        font->draw_char(ci, Point2(x_ofs, y_ofs + font_ascent), cchar, next, selected ? font_color_selected : font_color);

        if (char_ofs==cursor_pos && draw_caret) {
            VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(
                        Point2( x_ofs , y_ofs ), Size2( 1, caret_height ) ), cursor_color );
        }

        x_ofs+=char_width;
        char_ofs++;
    }

    if (char_ofs==cursor_pos && draw_caret) {//may be at the end
        VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(
                    Point2( x_ofs , y_ofs ), Size2( 1, caret_height ) ), cursor_color );
    }
}
break;
case NOTIFICATION_FOCUS_ENTER: {

    if (!caret_blink_enabled) {
        draw_caret = true;
    }

    if (OS::get_singleton()->has_virtual_keyboard())
        OS::get_singleton()->show_virtual_keyboard(text,get_global_rect());

}
break;
case NOTIFICATION_FOCUS_EXIT: {

    if (OS::get_singleton()->has_virtual_keyboard())
        OS::get_singleton()->hide_virtual_keyboard();

}
break;

}
}

void LineEdit::copy_text() {

if(selection.enabled) {

    OS::get_singleton()->set_clipboard(text.substr(selection.begin, selection.end - selection.begin));
}
}

void LineEdit::cut_text() {

if(selection.enabled) {
    undo_text = text;
    OS::get_singleton()->set_clipboard(text.substr(selection.begin, selection.end - selection.begin));
    selection_delete();
}
}

void LineEdit::paste_text() {

String paste_buffer = OS::get_singleton()->get_clipboard();

if(paste_buffer != "") {

    if(selection.enabled) selection_delete();
    append_at_cursor(paste_buffer);

    _text_changed();
}



}

void LineEdit::undo() {

int old_cursor_pos = cursor_pos;
text = undo_text;

Ref<Font> font = get_font("font");

cached_width = 0;
for (int i = 0; i<text.length(); i++)
    cached_width += font->get_char_size(text[i]).width;

if(old_cursor_pos > text.length()) {
    set_cursor_pos(text.length());
} else {
    set_cursor_pos(old_cursor_pos);
}

_text_changed();
}
Exemplo n.º 16
0
Arquivo: menus.c Projeto: aspacsa/vlp
void actions_dataentry_scr(const char *curr_path, const char *case_num) {
  const size_t n_fields = 4;
  const size_t starty = 6;
  const size_t startx = 25;
  FIELD *field[n_fields];
  FORM *my_form;
  Action_t record;
  int width[] = {  MAX_ACT_DATE - 1, MAX_ACT_TYPE, MAX_ACT_NOTE - 200 };
  int height[] = { 1, 1, 4 };
 
  for ( size_t i = 0; i < n_fields - 1; ++i )
    field[i] = new_field(height[i], width[i], starty + i * 2, startx, 0, 0);
  field[n_fields - 1] = NULL;

  set_field_back( field[0], A_UNDERLINE  );
  field_opts_off( field[0], O_AUTOSKIP   );
  set_field_back( field[1], A_UNDERLINE  );
  field_opts_off( field[1], O_AUTOSKIP   );
  set_field_back( field[2], A_UNDERLINE  );
  field_opts_off( field[2], O_AUTOSKIP   );
  field_opts_off( field[2], O_STATIC     );
  set_max_field(  field[2], MAX_ACT_NOTE );

  my_form = new_form(field);
  post_form(my_form);
  refresh();

  int note_count = MAX_ACT_NOTE;
  char note_msg[4];
  char date_str[MAX_ACT_DATE];
  get_curr_date( date_str );
  mvprintw( 0, 0,   curr_path );
  mvprintw( 4, 10,  "Case Number:   %s", case_num );
  mvprintw( 6, 10,  "Entry Date:    " );
  mvprintw( 8, 10,  "Type:          " );
  mvprintw( 10, 10, "Note:          " );
  mvprintw( 15, 77, "%d", note_count );
  mvprintw( 16, 10, "(F2) = Add | (ESC) = Previous Screen" );
  set_visible_fields( field, 1, 3 );
  size_t actions_count = actions_list( case_num );
  move( 6, 25 );
  set_field_buffer( field[0], 0, date_str );
  set_current_field( my_form, field[0] );

  record.id = 0;
  int ch;

  do {
 
    ch = getch();

    switch ( ch ) {
      case KEY_UP:
        form_driver(my_form, REQ_PREV_FIELD);
        form_driver(my_form, REQ_END_LINE);
        break;
      case KEY_LEFT:
        form_driver(my_form, REQ_LEFT_CHAR);
        break;
      case KEY_RIGHT:
        form_driver(my_form, REQ_RIGHT_CHAR);
        break;
      case KEY_BACKSPACE:
        {
          FIELD * curr_fld = current_field( my_form );

          if ( curr_fld == field[2] ) {
            snprintf( note_msg, 4, "%d", ++note_count );
            display_msg( 15, 77, my_form, curr_fld, note_msg );
          }
        }
        form_driver(my_form, REQ_PREV_CHAR);
        form_driver(my_form, REQ_DEL_CHAR);
        break;
     case DEL:
        {
          FIELD * curr_fld = current_field( my_form );

          if ( curr_fld == field[2] ) {
            snprintf( note_msg, 4, "%d", ++note_count );
            display_msg( 15, 77, my_form, curr_fld, note_msg );
          }
        }
        form_driver( my_form, REQ_DEL_CHAR );
        break;
      case ENTER:
        form_driver( my_form, REQ_NEXT_FIELD );
        form_driver( my_form, REQ_END_LINE );
        break;
      case KEY_F(1):
        {
          FIELD * curr_fld = current_field( my_form );

          if ( curr_fld == field[1] ) {
            if ( query_select_all_codes_from_action_types()  ) {
              clear_line(18, 10);
              mvprintw( 18, 10, db_get_error_msg() );
            } else {
              const Code_t const * code_ptr;
              size_t count = 0;
              
              mvprintw( 8, 75, "Type Options:" );
              while ( ( code_ptr = get_code_from_result() ) != NULL )      
                mvprintw( 9 + count++, 81, "[%d] %s", code_ptr->code, code_ptr->desc );
              free_code_result();

              int row, col;
              get_cursor_pos( curr_fld, &row, &col );
              move( row, col );
              set_current_field( my_form, curr_fld );
            }
          }
        }
        break;
      case KEY_F(2):
        {
          clear_line( 18, 10 );
          strncpy( record.case_num, case_num, MAX_CANUM );
          strncpy( record.entry_date, compress_str( field_buffer(field[0], 0) ), MAX_ACT_DATE );
          record.type = atoi( compress_str( field_buffer(field[1], 0) ) );
          strncpy( record.note, field_buffer(field[2], 0), MAX_ACT_NOTE );
          
          if ( is_empty_str( record.note, MAX_ACT_NOTE ) ) {
            mvprintw( 18, 10, "[!] Action must at least have a note." ); 
            move( 10, 25 );
            set_current_field( my_form, field[2] );
            break;
          }

          if ( query_add_action( &record ) ) {
            mvprintw( 18, 10, db_get_error_msg() );
          } else {
            clear_fields( field, 0, 2 );
            actions_count++;
            print_action( &record, actions_count );
            note_count = MAX_ACT_NOTE;
            mvprintw( 15, 77, "%d", note_count );
          }
          move( 6, 25 );
          set_current_field( my_form, field[0] );
        }
        break;
      default:
        {
          FIELD * curr_fld = current_field( my_form );

          if ( ch == '\'' )
            break;
          if ( curr_fld == field[1] ) {
            if ( !isdigit( ch ) )
              break;
          } else if ( curr_fld == field[2] ) {
            snprintf( note_msg, 4, "%d", --note_count );
            display_msg( 15, 77, my_form, curr_fld, note_msg );
          }
        }
        form_driver( my_form, ch );
        break;
    }
  } while ( ch != ESC );

  unpost_form( my_form );
  free_form( my_form );
  for ( size_t i = 0; i < n_fields - 1; ++i )
    free_field( field[i] );
  return;
}
Exemplo n.º 17
0
/**
   The commandline builtin. It is used for specifying a new value for
   the commandline.
*/
static int builtin_commandline( wchar_t **argv )
{

	int buffer_part=0;
	int cut_at_cursor=0;

	int argc = builtin_count_args( argv );
	int append_mode=0;

	int function_mode = 0;

	int tokenize = 0;

	int cursor_mode = 0;
	int line_mode = 0;
	int search_mode = 0;
	wchar_t *begin, *end;

	current_buffer = (wchar_t *)builtin_complete_get_temporary_buffer();
	if( current_buffer )
	{
		current_cursor_pos = wcslen( current_buffer );
	}
	else
	{
		current_buffer = reader_get_buffer();
		current_cursor_pos = reader_get_cursor_pos();
	}

	if( !get_buffer() )
	{
		if (is_interactive_session)
		{
			/*
			  Prompt change requested while we don't have
			  a prompt, most probably while reading the
			  init files. Just ignore it.
			*/
			return 1;
		}

		sb_append( sb_err,
			    argv[0],
			    L": Can not set commandline in non-interactive mode\n",
			    (void *)0 );
		builtin_print_help( argv[0], sb_err );
		return 1;
	}

	woptind=0;

	while( 1 )
	{
		static const struct woption
			long_options[] =
			{
				{
					L"append", no_argument, 0, 'a'
				}
				,
				{
					L"insert", no_argument, 0, 'i'
				}
				,
				{
					L"replace", no_argument, 0, 'r'
				}
				,
				{
					L"current-job", no_argument, 0, 'j'
				}
				,
				{
					L"current-process", no_argument, 0, 'p'
				}
				,
				{
					L"current-token", no_argument, 0, 't'
				}
				,
				{
					L"current-buffer", no_argument, 0, 'b'
				}
				,
				{
					L"cut-at-cursor", no_argument, 0, 'c'
				}
				,
				{
					L"function", no_argument, 0, 'f'
				}
				,
				{
					L"tokenize", no_argument, 0, 'o'
				}
				,
				{
					L"help", no_argument, 0, 'h'
				}
				,
				{
					L"input", required_argument, 0, 'I'
				}
				,
				{
					L"cursor", no_argument, 0, 'C'
				}
				,
				{
					L"line", no_argument, 0, 'L'
				}
				,
				{
					L"search-mode", no_argument, 0, 'S'
				}
				,
				{
					0, 0, 0, 0
				}
			}
		;

		int opt_index = 0;

		int opt = wgetopt_long( argc,
								argv,
								L"abijpctwforhI:CLS",
								long_options,
								&opt_index );
		if( opt == -1 )
			break;

		switch( opt )
		{
			case 0:
				if(long_options[opt_index].flag != 0)
					break;
                sb_printf( sb_err,
                           BUILTIN_ERR_UNKNOWN,
                           argv[0],
                           long_options[opt_index].name );
				builtin_print_help( argv[0], sb_err );

				return 1;

			case L'a':
				append_mode = APPEND_MODE;
				break;

			case L'b':
				buffer_part = STRING_MODE;
				break;


			case L'i':
				append_mode = INSERT_MODE;
				break;

			case L'r':
				append_mode = REPLACE_MODE;
				break;

			case 'c':
				cut_at_cursor=1;
				break;

			case 't':
				buffer_part = TOKEN_MODE;
				break;

			case 'j':
				buffer_part = JOB_MODE;
				break;

			case 'p':
				buffer_part = PROCESS_MODE;
				break;

			case 'f':
				function_mode=1;
				break;

			case 'o':
				tokenize=1;
				break;

			case 'I':
				current_buffer = woptarg;
				current_cursor_pos = wcslen( woptarg );
				break;

			case 'C':
				cursor_mode = 1;
				break;

			case 'L':
				line_mode = 1;
				break;

			case 'S':
				search_mode = 1;
				break;

			case 'h':
				builtin_print_help( argv[0], sb_out );
				return 0;

			case L'?':
				builtin_unknown_option( argv[0], argv[woptind-1] );
				return 1;
		}
	}

	if( function_mode )
	{
		int i;

		/*
		  Check for invalid switch combinations
		*/
		if( buffer_part || cut_at_cursor || append_mode || tokenize || cursor_mode || line_mode || search_mode )
		{
			sb_printf(sb_err,
					  BUILTIN_ERR_COMBO,
					  argv[0] );

			builtin_print_help( argv[0], sb_err );
			return 1;
		}


		if( argc == woptind )
		{
			sb_printf( sb_err,
					   BUILTIN_ERR_MISSING,
					   argv[0] );

			builtin_print_help( argv[0], sb_err );
			return 1;
 		}
		for( i=woptind; i<argc; i++ )
		{
			wint_t c = input_function_get_code( argv[i] );
			if( c != -1 )
			{
				/*
				  input_unreadch inserts the specified keypress or
				  readline function at the top of the stack of unused
				  keypresses
				*/
				input_unreadch(c);
			}
			else
			{
				sb_printf( sb_err,
					   _(L"%ls: Unknown input function '%ls'\n"),
					   argv[0],
					   argv[i] );
				builtin_print_help( argv[0], sb_err );
				return 1;
			}
		}

		return 0;
	}

	/*
	  Check for invalid switch combinations
	*/
	if( (search_mode || line_mode || cursor_mode) && (argc-woptind > 1) )
	{

		sb_append( sb_err,
					argv[0],
					L": Too many arguments\n",
					(void *)0 );
		builtin_print_help( argv[0], sb_err );
		return 1;
	}

	if( (buffer_part || tokenize || cut_at_cursor) && (cursor_mode || line_mode || search_mode) )
	{
		sb_printf( sb_err,
				   BUILTIN_ERR_COMBO,
				   argv[0] );

		builtin_print_help( argv[0], sb_err );
		return 1;
	}


	if( (tokenize || cut_at_cursor) && (argc-woptind) )
	{
		sb_printf( sb_err,
				   BUILTIN_ERR_COMBO2,
				   argv[0],
				   L"--cut-at-cursor and --tokenize can not be used when setting the commandline" );


		builtin_print_help( argv[0], sb_err );
		return 1;
	}

	if( append_mode && !(argc-woptind) )
	{
		sb_printf( sb_err,
                    BUILTIN_ERR_COMBO2,
                    argv[0],
				   L"insertion mode switches can not be used when not in insertion mode" );

        builtin_print_help( argv[0], sb_err );
        return 1;
	}

	/*
	  Set default modes
	*/
	if( !append_mode )
	{
		append_mode = REPLACE_MODE;
	}

	if( !buffer_part )
	{
		buffer_part = STRING_MODE;
	}

	if( cursor_mode )
	{
		if( argc-woptind )
		{
			wchar_t *endptr;
			int new_pos;
			errno = 0;

			new_pos = wcstol( argv[woptind], &endptr, 10 );
			if( *endptr || errno )
			{
				sb_printf( sb_err,
					   BUILTIN_ERR_NOT_NUMBER,
					   argv[0],
					   argv[woptind] );
				builtin_print_help( argv[0], sb_err );
			}

			current_buffer = reader_get_buffer();
			new_pos = maxi( 0, mini( new_pos, wcslen( current_buffer ) ) );
			reader_set_buffer( current_buffer, new_pos );
			return 0;
		}
		else
		{
			sb_printf( sb_out, L"%d\n", reader_get_cursor_pos() );
			return 0;
		}

	}

	if( line_mode )
	{
		int pos = reader_get_cursor_pos();
		wchar_t *buff = reader_get_buffer();
		sb_printf( sb_out, L"%d\n", parse_util_lineno( buff, pos ) );
		return 0;

	}

	if( search_mode )
	{
		return !reader_search_mode();
	}


	switch( buffer_part )
	{
		case STRING_MODE:
		{
			begin = get_buffer();
			end = begin+wcslen(begin);
			break;
		}

		case PROCESS_MODE:
		{
			parse_util_process_extent( get_buffer(),
									   get_cursor_pos(),
									   &begin,
									   &end );
			break;
		}

		case JOB_MODE:
		{
			parse_util_job_extent( get_buffer(),
								   get_cursor_pos(),
								   &begin,
								   &end );
			break;
		}

		case TOKEN_MODE:
		{
			parse_util_token_extent( get_buffer(),
									 get_cursor_pos(),
									 &begin,
									 &end,
									 0, 0 );
			break;
		}

	}

	switch(argc-woptind)
	{
		case 0:
		{
			write_part( begin, end, cut_at_cursor, tokenize );
			break;
		}

		case 1:
		{
			replace_part( begin, end, argv[woptind], append_mode );
			break;
		}

		default:
		{
			string_buffer_t sb;
			int i;

			sb_init( &sb );

			sb_append( &sb, argv[woptind] );

			for( i=woptind+1; i<argc; i++ )
			{
				sb_append( &sb, L"\n" );
				sb_append( &sb, argv[i] );
			}

			replace_part( begin, end, (wchar_t *)sb.buff, append_mode );
			sb_destroy( &sb );

			break;
		}
	}

	return 0;
}
Exemplo n.º 18
0
/**
   Output the specified selection.

   \param begin start of selection
   \param end  end of selection
   \param cut_at_cursor whether printing should stop at the surrent cursor position
   \param tokenize whether the string should be tokenized, printing one string token on every line and skipping non-string tokens
*/
static void write_part( const wchar_t *begin,
						const wchar_t *end,
						int cut_at_cursor,
						int tokenize )
{
	tokenizer tok;
	string_buffer_t out;
	wchar_t *buff;
	int pos;

	pos = get_cursor_pos()-(begin-get_buffer());

	if( tokenize )
	{
		buff = wcsndup( begin, end-begin );
//		fwprintf( stderr, L"Subshell: %ls, end char %lc\n", buff, *end );
		sb_init( &out );

		for( tok_init( &tok, buff, TOK_ACCEPT_UNFINISHED );
			 tok_has_next( &tok );
			 tok_next( &tok ) )
		{
			if( (cut_at_cursor) &&
				(tok_get_pos( &tok)+wcslen(tok_last( &tok)) >= pos) )
				break;

			switch( tok_last_type( &tok ) )
			{
				case TOK_STRING:
				{
					wchar_t *tmp = unescape( tok_last( &tok ), UNESCAPE_INCOMPLETE );
					sb_append( &out, tmp, L"\n", (void *)0 );
					free( tmp );
					break;
				}

			}
		}

		sb_append( sb_out,
				   (wchar_t *)out.buff );

		free( buff );
		tok_destroy( &tok );
		sb_destroy( &out );
	}
	else
	{
		wchar_t *buff, *esc;

		if( cut_at_cursor )
		{
			end = begin+pos;
		}

		buff = wcsndup( begin, end-begin );
		esc = unescape( buff, UNESCAPE_INCOMPLETE );

//		debug( 0, L"woot2 %ls -> %ls", buff, esc );

		sb_append( sb_out, esc );
		sb_append( sb_out, L"\n" );

		free( esc );
		free( buff );

	}
}
Exemplo n.º 19
0
void putchar(char ch)
{
	static u16 attr = 7 << 8;

	u32 cursor_x;
	u32 cursor_y;
	get_cursor_pos(&cursor_x, &cursor_y);

	u32 w, h;
	vid_drv->get_text_resolution(&w, &h);

	// You can change attribute by using "\e\x??"
	if (out_mode == 1) {
		attr = ch << 8;
		out_mode = 0;
		return;
	}
	if (ch == '\033') {	// \033 = \e, change attribute
		out_mode = 1;
		return;
	}

	if (ch == '\032') {	// \032, clear whole screen
		clear_screen();
		cursor_x = cursor_y = 0;
	}

	else if (ch == '\031') {	// \031, clear current line
		int i;
		for (i=0; i<w; i++)
			vid_drv->putchar((7 << 8) | ' ', i, cursor_y);
		cursor_x = 0;
	}

	else if (ch == '\b' && cursor_x)
		cursor_x--;

	else if (ch == '\t')
		cursor_x = (cursor_x+4) & ~(4-1);

	else if (ch == '\r')
		cursor_x = 0;

	else if (ch == '\n') {
		cursor_x = 0;
		cursor_y++;
	}
	else if(ch >= ' ')	// other printable char.
		vid_drv->putchar(ch | attr, cursor_x++, cursor_y);

	if (cursor_x >= w) {	// reached end of screen
		cursor_x = 0;
		cursor_y++;
	}

	if (cursor_y >= h) {	// scroll the screen if needed.
		int x, y;

		// move up
		for (y=1; y<=h; y++)
			for (x=0; x<w; x++) {
				u16 t = vid_drv->getchar(x, y);
				vid_drv->putchar(t, x, y - 1);
			}

		// clear last line
		for (x=0; x<w; x++)
			vid_drv->putchar((7 << 8) | ' ', x, h - 1);

		cursor_y = h - 1;
	}

	set_cursor_pos(cursor_x, cursor_y);
}
Exemplo n.º 20
0
/**
   The commandline builtin. It is used for specifying a new value for
   the commandline.
*/
static int builtin_commandline(parser_t &parser, io_streams_t &streams, wchar_t **argv)
{
    wgetopter_t w;
    int buffer_part=0;
    int cut_at_cursor=0;

    int argc = builtin_count_args(argv);
    int append_mode=0;

    int function_mode = 0;
    int selection_mode = 0;

    int tokenize = 0;

    int cursor_mode = 0;
    int line_mode = 0;
    int search_mode = 0;
    int paging_mode = 0;
    const wchar_t *begin = NULL, *end = NULL;
    
    scoped_push<const wchar_t *> saved_current_buffer(&current_buffer);
    scoped_push<size_t> saved_current_cursor_pos(&current_cursor_pos);
    
    wcstring transient_commandline;
    if (get_top_transient(&transient_commandline))
    {
        current_buffer = transient_commandline.c_str();
        current_cursor_pos = transient_commandline.size();
    }
    else
    {
        current_buffer = reader_get_buffer();
        current_cursor_pos = reader_get_cursor_pos();
    }

    if (!get_buffer())
    {
        if (is_interactive_session)
        {
            /*
              Prompt change requested while we don't have
              a prompt, most probably while reading the
              init files. Just ignore it.
            */
            return 1;
        }

        streams.err.append(argv[0]);
        streams.err.append(L": Can not set commandline in non-interactive mode\n");
        builtin_print_help(parser, streams, argv[0], streams.err);
        return 1;
    }

    w.woptind=0;

    while (1)
    {
        static const struct woption
                long_options[] =
        {
            { L"append", no_argument, 0, 'a' },
            { L"insert", no_argument, 0, 'i' },
            { L"replace", no_argument, 0, 'r' },
            { L"current-job", no_argument, 0, 'j' },
            { L"current-process", no_argument, 0, 'p' },
            { L"current-token", no_argument, 0, 't' },
            { L"current-buffer", no_argument, 0, 'b' },
            { L"cut-at-cursor", no_argument, 0, 'c' },
            { L"function", no_argument, 0, 'f' },
            { L"tokenize", no_argument, 0, 'o' },
            { L"help", no_argument, 0, 'h' },
            { L"input", required_argument, 0, 'I' },
            { L"cursor", no_argument, 0, 'C' },
            { L"line", no_argument, 0, 'L' },
            { L"search-mode", no_argument, 0, 'S' },
            { L"selection", no_argument, 0, 's' },
            { L"paging-mode", no_argument, 0, 'P' },
            { 0, 0, 0, 0 }
        };

        int opt_index = 0;

        int opt = w.wgetopt_long(argc,
                                 argv,
                                 L"abijpctwforhI:CLSsP",
                                 long_options,
                                 &opt_index);
        if (opt == -1)
            break;

        switch (opt)
        {
            case 0:
                if (long_options[opt_index].flag != 0)
                    break;
                streams.err.append_format(BUILTIN_ERR_UNKNOWN,
                              argv[0],
                              long_options[opt_index].name);
                builtin_print_help(parser, streams, argv[0], streams.err);

                return 1;

            case L'a':
                append_mode = APPEND_MODE;
                break;

            case L'b':
                buffer_part = STRING_MODE;
                break;


            case L'i':
                append_mode = INSERT_MODE;
                break;

            case L'r':
                append_mode = REPLACE_MODE;
                break;

            case 'c':
                cut_at_cursor=1;
                break;

            case 't':
                buffer_part = TOKEN_MODE;
                break;

            case 'j':
                buffer_part = JOB_MODE;
                break;

            case 'p':
                buffer_part = PROCESS_MODE;
                break;

            case 'f':
                function_mode=1;
                break;

            case 'o':
                tokenize=1;
                break;

            case 'I':
                current_buffer = w.woptarg;
                current_cursor_pos = wcslen(w.woptarg);
                break;

            case 'C':
                cursor_mode = 1;
                break;

            case 'L':
                line_mode = 1;
                break;

            case 'S':
                search_mode = 1;
                break;

            case 's':
                selection_mode = 1;
                break;

            case 'P':
                paging_mode = 1;
                break;

            case 'h':
                builtin_print_help(parser, streams, argv[0], streams.out);
                return 0;

            case L'?':
                builtin_unknown_option(parser, streams, argv[0], argv[w.woptind-1]);
                return 1;
        }
    }

    if (function_mode)
    {
        int i;

        /*
          Check for invalid switch combinations
        */
        if (buffer_part || cut_at_cursor || append_mode || tokenize || cursor_mode || line_mode || search_mode || paging_mode)
        {
            streams.err.append_format(BUILTIN_ERR_COMBO,
                          argv[0]);

            builtin_print_help(parser, streams, argv[0], streams.err);
            return 1;
        }


        if (argc == w.woptind)
        {
            streams.err.append_format(BUILTIN_ERR_MISSING,
                          argv[0]);

            builtin_print_help(parser, streams, argv[0], streams.err);
            return 1;
        }
        for (i=w.woptind; i<argc; i++)
        {
            wchar_t c = input_function_get_code(argv[i]);
            if (c != INPUT_CODE_NONE)
            {
                /*
                  input_unreadch inserts the specified keypress or
                  readline function at the back of the queue of unused
                  keypresses
                */
                input_queue_ch(c);
            }
            else
            {
                streams.err.append_format(_(L"%ls: Unknown input function '%ls'\n"),
                              argv[0],
                              argv[i]);
                builtin_print_help(parser, streams, argv[0], streams.err);
                return 1;
            }
        }

        return 0;
    }

    if (selection_mode)
    {
        size_t start, len;
        const wchar_t *buffer = reader_get_buffer();
        if (reader_get_selection(&start, &len))
        {
            streams.out.append(buffer + start, len);
        }
        return 0;
    }

    /*
      Check for invalid switch combinations
    */
    if ((search_mode || line_mode || cursor_mode || paging_mode) && (argc-w.woptind > 1))
    {

        streams.err.append_format(argv[0],
                      L": Too many arguments\n",
                      NULL);
        builtin_print_help(parser, streams, argv[0], streams.err);
        return 1;
    }

    if ((buffer_part || tokenize || cut_at_cursor) && (cursor_mode || line_mode || search_mode || paging_mode))
    {
        streams.err.append_format(BUILTIN_ERR_COMBO,
                      argv[0]);

        builtin_print_help(parser, streams, argv[0], streams.err);
        return 1;
    }


    if ((tokenize || cut_at_cursor) && (argc-w.woptind))
    {
        streams.err.append_format(BUILTIN_ERR_COMBO2,
                      argv[0],
                      L"--cut-at-cursor and --tokenize can not be used when setting the commandline");


        builtin_print_help(parser, streams, argv[0], streams.err);
        return 1;
    }

    if (append_mode && !(argc-w.woptind))
    {
        streams.err.append_format(BUILTIN_ERR_COMBO2,
                      argv[0],
                      L"insertion mode switches can not be used when not in insertion mode");

        builtin_print_help(parser, streams, argv[0], streams.err);
        return 1;
    }

    /*
      Set default modes
    */
    if (!append_mode)
    {
        append_mode = REPLACE_MODE;
    }

    if (!buffer_part)
    {
        buffer_part = STRING_MODE;
    }

    if (cursor_mode)
    {
        if (argc-w.woptind)
        {
            wchar_t *endptr;
            long new_pos;
            errno = 0;

            new_pos = wcstol(argv[w.woptind], &endptr, 10);
            if (*endptr || errno)
            {
                streams.err.append_format(BUILTIN_ERR_NOT_NUMBER,
                              argv[0],
                              argv[w.woptind]);
                builtin_print_help(parser, streams, argv[0], streams.err);
            }

            current_buffer = reader_get_buffer();
            new_pos = maxi(0L, mini(new_pos, (long)wcslen(current_buffer)));
            reader_set_buffer(current_buffer, (size_t)new_pos);
            return 0;
        }
        else
        {
            streams.out.append_format( L"%lu\n", (unsigned long)reader_get_cursor_pos());
            return 0;
        }

    }

    if (line_mode)
    {
        size_t pos = reader_get_cursor_pos();
        const wchar_t *buff = reader_get_buffer();
        streams.out.append_format( L"%lu\n", (unsigned long)parse_util_lineno(buff, pos));
        return 0;

    }

    if (search_mode)
    {
        return ! reader_search_mode();
    }

    if (paging_mode)
    {
        return ! reader_has_pager_contents();
    }


    switch (buffer_part)
    {
        case STRING_MODE:
        {
            begin = get_buffer();
            end = begin+wcslen(begin);
            break;
        }

        case PROCESS_MODE:
        {
            parse_util_process_extent(get_buffer(),
                                      get_cursor_pos(),
                                      &begin,
                                      &end);
            break;
        }

        case JOB_MODE:
        {
            parse_util_job_extent(get_buffer(),
                                  get_cursor_pos(),
                                  &begin,
                                  &end);
            break;
        }

        case TOKEN_MODE:
        {
            parse_util_token_extent(get_buffer(),
                                    get_cursor_pos(),
                                    &begin,
                                    &end,
                                    0, 0);
            break;
        }

    }

    switch (argc-w.woptind)
    {
        case 0:
        {
            write_part(begin, end, cut_at_cursor, tokenize, streams);
            break;
        }

        case 1:
        {
            replace_part(begin, end, argv[w.woptind], append_mode);
            break;
        }

        default:
        {
            wcstring sb = argv[w.woptind];
            int i;

            for (i=w.woptind+1; i<argc; i++)
            {
                sb.push_back(L'\n');
                sb.append(argv[i]);
            }

            replace_part(begin, end, sb.c_str(), append_mode);

            break;
        }
    }

    return 0;
}
/*void insert_string(const J_UI_String&)*/
void J_Text_Box::insert_string(const J_UI_String& irk_string){
	insert_string(get_cursor_pos(), irk_string);
}