⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dialogs.c

📁 SEAL是DOS 下的32位保护模式的GUI程序
💻 C
📖 第 1 页 / 共 4 页
字号:

       TEXTLINE(o)->sel_all(TEXTLINE(o), 0, 0);

       if ( set ) TEXTLINE(o)->sel_all(TEXTLINE(o), 0, -1);

    };

    VIEW(o)->draw_view(VIEW(o));

    TEXTLINE(o)->show_cursor(TEXTLINE(o), set);

  };

};


void  textline_set_options ( p_object o, l_dword op, l_bool set )
{

  obj_set_options(o, op, set);

  if ( op & OB_OF_ENABLE ) {

    TEXTLINE(o)->sel_all(TEXTLINE(o), 0, 0);

    VIEW(o)->draw_view(VIEW(o));

  };

};


void  textline_draw ( p_view o )
{

  t_rect  r = o->get_local_extent(o);
  t_point p = o->get_global_point(o, r.a);

  BITMAP *out = o->begin_paint(o, &p, r);

  if ( out ) {

    rectfill(out, p.x+r.a.x, p.y+r.a.y, p.x+r.b.x, p.y+r.b.y, color_3d_face);
    button3d(o,out, p.x+r.a.x, p.y+r.a.y, p.x+r.b.x, p.y+r.b.y, 1);

    TEXTLINE(o)->draw_text(TEXTLINE(o));
    TEXTLINE(o)->draw_cursor(TEXTLINE(o), -1, -1);

  };

  o->end_of_paint(o, r);

};


/*

  Get data from textline, if textline is selected from some pos1 to pos2
  it return this selected text if rec->style comes as DS_SELECTED. If pos1
  and pos2 are same = there is no selected area, it store all text to
  rec->data.

  This function return DAT_TEXT id if some of styles are support.

  Styles supported by textline :

         DS_SELECTED - rec->data is set to selected text, if some is,
                       else set all text
         DS_ALL      - set rec->data to all text
         DS_WHATEVER - set rec->data to text, which textline want to send
                       [ if some selected it return this, else return all,
                         same as DS_SELECTED in this case ]

*/

l_bool textline_get_data ( p_object o, t_data *rec )
{
  if ( rec ) {

     rec->info_obj = o;

     l_tag_cpy(rec->id, DAT_TEXT);

     switch ( rec->style ) {

       case DS_SELECTED : {

          p_textline tl = TEXTLINE(o);

          if ( is_sel(tl) )

            rec->data = (void *)stridup(&(tl->text[tl->sel_from]), tl->sel_to-tl->sel_from);

          else

            rec->data = (void *)_strdup(tl->text);

          return true;

       }; break;

       case DS_ALL : {

          rec->data = (void *)_strdup(TEXTLINE(o)->text);

          return true;

       }; break;

       case DS_WHATEVER : {

          rec->style = DS_SELECTED;

          return o->get_data(o, rec);

       }; break;

     };

     l_tag_cpy(rec->id, DAT_NONE);

  };

  return false;

};


/*
   drag_where control draging process, that's defined in t_view structure.

   - First is called drag_data, when CTRL+mouse button is pressed. This set
     new cursor and wait for unpressed button. While this operation run,
     view_drag_data function call drag_where function for redrawing objects,
     that placed right under mouse cursor.
*/

l_bool textline_drag_where ( p_view o, t_data *rec, t_point where )
{
   /*
      if mouse is under this object in drag_data function &&
      rec->id == OBJECT(o)->data_type then redraw cursor
   */
   if ( view_drag_where(o, rec, where) ) {

       l_int mpos = TEXTLINE(o)->get_pos_from_xy(TEXTLINE(o), where);

       if ( is_sel(TEXTLINE(o)) )

            TEXTLINE(o)->sel_all(TEXTLINE(o), 0, 0);

       if ( !TEXTLINE(o)->cursor_visible )

            TEXTLINE(o)->show_cursor(TEXTLINE(o), true);

       if ( mpos != TEXTLINE(o)->pos )

            TEXTLINE(o)->redraw_text(TEXTLINE(o), mpos, 0);

       return true;

   } else /* Out of place || old */

   if ( OBJECT(o)->is_state(OBJECT(o), OB_SF_FOCUSED) ) {

       if ( rec ) TEXTLINE(o)->show_cursor(TEXTLINE(o), false);

       else  /* give things to right place, I'm focused so my cursor must be showed */

          TEXTLINE(o)->show_cursor(TEXTLINE(o), true);

   } else

     TEXTLINE(o)->show_cursor(TEXTLINE(o), false);

   return false;

};


/*
   set_data

   - set data to textline in these cases :

     o   textline is writeable [ is_wable(o) ],
     o   rec->id is one of textline->data_type-s ( standard is DAT_TEXT )
     o   rec->info_obj != this object, it means data are not from this object
*/

l_bool textline_set_data ( p_object o, t_data *rec )
{
  if ( rec && is_wable(TEXTLINE(o)) &&
       l_tag_cmp(o->data_type, rec->id) /*&& rec->info_obj != o*/ ) {

     p_textline tl  = TEXTLINE(o);
     l_bool was_sel = false;
     l_bool ok = true;

     if ( rec->style & DS_DELETE ) { /* if data is deleted */

       if ( rec->style & DS_ALL ) {

         return tl->set_text(tl, NULL);  /* delete all text */

       } else {

         if ( is_sel(tl) ) { /* delete only selected text */

            tl->redraw_text(tl, tl->pos, TO_KEY(KB_DEL));

            ok = true;

         };

         ok = false;
       };


     } else { /* if data is inserted to */

       if ( is_sel(tl) ) {

          tl->redraw_text(tl, tl->pos, TO_KEY(KB_DEL));

       };

       tl->ins_text(tl, tl->pos, (l_text)rec->data);

     };

     sel_clear(tl);

     set_format_text(&(VIEW(tl)->info_text), "%s: %i\n%s: '%s'", TXT_SIZE, strlen(tl->text), TXT_TEXT, tl->text);

     if ( !was_sel ) {

       tl->draw_text(tl);

       tl->draw_cursor(tl, -1, -1);

     };

     return ok;
  };

  return false;
};



l_bool textline_set_text ( p_textline o, l_text text )
{

  free(o->text);

  o->text = text ? _strdup(text) : NULL;

  sel_clear(o);

  set_format_text(&(VIEW(o)->info_text), "%s: %i\n%s: '%s'", TXT_SIZE, strlen(o->text), TXT_TEXT, o->text);

  o->draw_text(o);
  o->draw_cursor(o, -1, -1);
  o->redraw_text(o, 0, 0);

  return (l_bool)o->text;

};


/*
  textline execute
  repeat until mouse is pressed out of textline or key ESC | ENTER is pressed
*/
l_dword  textline_execute ( p_object o )
{

  l_int end = 0;

  while ( !end ) { /* not end command */

      if ( event_main.type & EV_KEYBOARD && KEYPRESSED(TO_KEY(KB_ESC)) )

         end = 1;

      if ( event_main.type & EV_KEYBOARD && KEYPRESSED(TO_KEY(KB_ENTER)) )

         end = 2;


      if ( event_main.type & EV_MOUSE ) {

         if ( !VIEW(o)->is_mouse_in_view(VIEW(o)) )

            if ( OBJECT(mouse)->state & MO_SF_MOUSEDOWN ||
                 OBJECT(mouse)->state & MO_SF_MOUSEUP ) end = 3;

      };

      o->translate_event(o, &event_main);

      INTMAIN(&event_main);

      if ( end ) {

        if ( end <= 2 ) /* not mouse events */

            clear_event(&event_main);

        if ( end == 1 )

            return MSG_CANCEL; /* ESC */

        else

            return MSG_OK;

      };

      o->get_event(o, &event_main);

  };

  return MSG_CANCEL;

};


void  textline_translate_event ( p_object o, t_event *event )
{
  RETVIEW(o, event);


  view_translate_event(o, event); /* old translate_event function */


  if ( event->type & EV_MOUSE ) { /* mouse event */

    if ( OBJECT(mouse)->state & MO_SF_MOUSERDOWN ) {

      show_edit_menu(o,is_sel(TEXTLINE(o)));

      clear_event(event);

    } else if ( OBJECT(mouse)->state & MO_SF_MOUSELDOWN ) { /* select */

      if ( !o->is_state(o, OB_SF_SELECTED) ) {

         clear_event(event);

         o->select(o);

         return;
      };

    };

    if ( o->is_state(o, OB_SF_SELECTED) &&

         OBJECT(mouse)->state & MO_SF_MOUSELAUTO ) { /* select text */

        sel_clear(TEXTLINE(o));

        TEXTLINE(o)->sel_ok = 3;

        while ( OBJECT(mouse)->state & MO_SF_MOUSELAUTO ) {

          l_int mpos = TEXTLINE(o)->get_pos_from_xy(TEXTLINE(o), VIEW(o)->get_local_point(VIEW(o), mouse->where));

          TEXTLINE(o)->redraw_text(TEXTLINE(o), mpos, 0);

          o->get_event(o, event);

        };

    };

  };


  if ( o->is_state(o, OB_SF_FOCUSED) )

                                  /* keyboard events */
  if ( event->type & EV_KEYBOARD ) {

    if ( keyb->shifts & KB_SHIFT_FLAG ) {

      if ( TEXTLINE(o)->sel_ok == 0 )

         TEXTLINE(o)->sel_ok = 1;

      else

      if ( TEXTLINE(o)->sel_ok == 4 )

         TEXTLINE(o)->sel_ok = 2;

    } else TEXTLINE(o)->sel_ok = 0;


    if ( OBJECT(keyb)->state & KB_SF_KEYDOWN )

    switch ( KEY_TO(keyb->code) ) {

      case KB_RIGHT : {  /* arrow RIGHT was pressed */

        TEXTLINE(o)->redraw_text(TEXTLINE(o), TEXTLINE(o)->pos+1, 0);

        clear_event(event);

      }; break;

      case KB_LEFT : {  /* arrow LEFT was pressed */

        TEXTLINE(o)->redraw_text(TEXTLINE(o), TEXTLINE(o)->pos-1, 0);

        clear_event(event);

      }; break;

      case KB_HOME : {  /* key HOME was pressed */

        TEXTLINE(o)->redraw_text(TEXTLINE(o), 0, 0);

        clear_event(event);

      }; break;

      case KB_END : {  /* key END was pressed */

        TEXTLINE(o)->redraw_text(TEXTLINE(o), strlen(TEXTLINE(o)->text), 0);

        clear_event(event);

      }; break;

      case KB_DEL : {  /* key DEL was pressed */

        TEXTLINE(o)->redraw_text(TEXTLINE(o), TEXTLINE(o)->pos, TO_KEY(KB_DEL));

        clear_event(event);

      }; break;

      case KB_BACKSPACE : {  /* key BACKSPACE was pressed */

        TEXTLINE(o)->redraw_text(TEXTLINE(o), TEXTLINE(o)->pos-1, TO_KEY(KB_DEL));

        clear_event(event);

      }; break;

      default :

        if ( (l_byte)TO_CHAR(keyb->code) >= 32 &&
             (l_byte)TO_CHAR(keyb->code) <= 255 ) {

             TEXTLINE(o)->redraw_text(TEXTLINE(o), TEXTLINE(o)->pos+1, keyb->code);

             clear_event(event);

        }; break;
    };

  };

};


l_bool  textline_select_data ( p_object o, l_int data_style, l_bool set )
{

   if ( !data_style || data_style & DS_ALL ) {

      if ( set )

          TEXTLINE(o)->sel_all(TEXTLINE(o), 0, -1); /* select */

      else

          TEXTLINE(o)->sel_all(TEXTLINE(o), 0, 0); /* unselect */

      return true;

   };

   return false;
};


t_rect textline_size_limits ( p_view o )
{

  return rect_assign(2, 2, rect_sizex(o->bounds)-2, rect_sizey(o->bounds)-2);

};


l_int  textline_get_pos_from_xy ( p_textline o, t_point p )
{

  t_rect r = VIEW(o)->size_limits(VIEW(o));
  l_int  pos = 0;

  if ( p.x > r.a.x ) {

    pos = o->charsin_size ( o, p.x-r.a.x, o->line, 1);

    return max(0, pos+o->line);

  };

  pos = o->charsin_size ( o, -(p.x), o->line, -1);

  return max(0, o->line-pos);

};


l_int textline_charsin ( p_textline o, l_int from, l_int plus )
{

   return o->charsin_size(o, rect_sizex(VIEW(o)->bounds)-(4+FONT_GETWIDTH(VIEW(o)->font, ' ')), from, plus);

};


l_int textline_charsin_size ( p_textline o, l_int size, l_int from, l_int plus )
{

  l_int sizex = size;
  l_int tsize = strlen(o->text);
  l_int chars = 0;

  if ( o->text ) {

    from += plus;

    while ( sizex > 0 && from >= 0 && from <= tsize ) {

      sizex -= FONT_GETWIDTH(VIEW(o)->font, o->text[from]);

      from += plus;

      chars++;

    };

    if ( sizex < 0 ) chars--;

    return max(0, chars);

  };

  return 0;

};

void textline_timer ( p_object o ) {


  if ( !is_wable(TEXTLINE(o)) )

     return;

  if ( o->is_state(o, OB_SF_FOCUSED) ) {
    if ( TEXTLINE(o)->cursor_visible ) {
      TEXTLINE(o)->cursor_visible = 0;
      TEXTLINE(o)->draw_cursor_ex ( TEXTLINE(o), TEXTLINE(o)->line, TEXTLINE(o)->pos, 0);
    } else {
      TEXTLINE(o)->cursor_visible = 1;
      TEXTLINE(o)->draw_cursor_ex ( TEXTLINE(o), TEXTLINE(o)->line, TEXTLINE(o)->pos, 1);
    };
  } else {
    if ( TEXTLINE(o)->cursor_visible ) {
      TEXTLINE(o)->cursor_visible = 0;
      TEXTLINE(o)->draw_cursor_ex ( TEXTLINE(o), TEXTLINE(o)->line, TEXTLINE(o)->pos, 0);
    };
  };
};

void  textline_draw_cursor_ex ( p_textline o, l_int line, l_int pos, l_int active )
{

  p_view  vo = VIEW(o);

  t_rect  r = vo->size_limits(vo);
  t_rect  safe;
  l_int rcpos = FONT_GETSTRWIDTH(vo->font, &o->text[line], pos-line);
  //l_int ecpos = FONT_GETSTRWIDTH(vo->font, &o->text[line], (pos-line)+1);
  //l_int fcolor = COLOR(CO_WHITE); //active?COLOR(CO_WHITE):vo->get_color(vo, 2);
  //l_int bcolor = COLOR(CO_BLACK);
  t_point p;
  BITMAP *out;


  //if ( ecpos == rcpos ) ecpos = rcpos+FONT_GETWIDTH(vo->font, ' ');

  r = rect_assign(max(r.a.x, r.a.x+rcpos), r.a.y, min(r.b.x, r.a.x+rcpos), r.b.y);

  safe = r;

  out = vo->begin_paint(vo, &p, r);

  if ( out ) {

    r = rect_move(r, p.x, p.y);

    if ( active ) {

      rectfill(out, r.a.x, r.a.y, r.b.x, r.b.y, color_flat_text);

    } else {

      vo->background(vo, out, r);

      textout_draw_rect(out, vo->font, &o->text[pos], 1, r.a.x, r.a.y, r.b.x, r.b.y, TX_ALIGN_LEFT, color_flat_text, TX_NOCOLOR, 1);
    };
  };

  vo->end_of_paint(vo, safe);

};



void  textline_draw_cursor ( p_textline o, l_int oldline, l_int oldpos )
{

  if ( !is_wable(o) ) /* is not-rewrite able */

     return;

  if ( oldpos >= 0 && oldpos <= o->limit && oldline == o->line ) {

     o->draw_text ( o );

  };

  if ( o->cursor_visible )

    o->draw_cursor_ex ( o, o->line, o->pos, 1);

};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -