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

📄 dialogs.c

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


void    textline_sel_all ( p_textline o, l_int selfrom, l_int selto )
{

  if ( selto == -1 ) selto = strlen(o->text);

  if ( selfrom || selto )

    o->sel_ok = 4;

  else

    o->sel_ok = 0;

  o->pos = o->line = 0;

  o->sel_from = selfrom;
  o->sel_to = selto;
  o->sel_first_from = selto;
  o->sel_first_to = selto;

};


void  textline_show_cursor ( p_textline o, l_bool show )
{
  o->cursor_visible = show;

  o->draw_cursor(o, o->line, o->pos);
};


void  textline_draw_text ( p_textline o )
{
  p_view  vo = VIEW(o);

  t_rect  r = vo->size_limits(vo);
  t_rect  safe = r;
  t_point p;

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

  if ( out ) {

    l_color fcolor = color_flat_text;
    l_color fscolor = color_selected_text;
    l_color bscolor = color_selected_face;

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

    if ( OBJECT(o)->is_options(OBJECT(o), OB_OF_ENABLE) ) {

      /* is not-rewrite able */
      if ( !is_wable(o) && OBJECT(o)->is_state(OBJECT(o), OB_SF_SELECTED) ) {
         rectfill(out, r.a.x, r.a.y, r.b.x, r.b.y, color_flat_face);
      } else vo->background(vo, out, r);

    } else

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

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

       sel_clear(o);

    draw_selected_text (out, vo->font, &(o->text[o->line]), -1, max(0, o->sel_from-o->line), max(0, o->sel_to-o->line),
                        r.a.x, r.a.y, r.b.x, r.b.y, (o->flags & TF_ALIGN_RIGHT)?TX_ALIGN_RIGHT:TX_ALIGN_LEFT,
                        fcolor, TX_NOCOLOR, fscolor, bscolor, 1);


  };

  vo->end_of_paint(vo, safe);

};


void  textline_redraw_text ( p_textline o, l_int newpos, l_int keycode )
{

  l_int oldpos = o->pos;
  l_int oldline = o->line;

  l_bool can_draw_cursor = false;
  l_bool can_del = true;
  l_bool must_write = true;

  l_int  redraw_text = 0;

  if ( newpos >= 0 && newpos < o->limit ) {

    if ( !keycode ) o->pos = max(0, min(strlen(o->text), newpos));

    else

      o->pos = newpos;

    can_draw_cursor = true;

  };

  if ( o->pos == oldpos ) can_draw_cursor = false;

  if ( keycode ) {

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

      return;

    if ( is_sel(o) ) {

      o->del_text(o, o->sel_from, o->sel_to-o->sel_from);
      o->pos = min(strlen(o->text), o->sel_from+newpos-oldpos);
      oldpos = o->sel_from;
      o->line = o->pos-o->charsin(o, o->pos, -1);

      can_del = false;

    };

    sel_clear(o);

    if ( keycode == TO_KEY(KB_DEL) ) {

      if ( strlen(o->text) > 0 || !can_del ) { /* can delete character */

        if ( can_del ) o->del_char(o, o->pos);

        redraw_text = 0x03;

        can_draw_cursor = false;

      } else {

//        if ( can_del ) seal_error(ERR_NONREGULAR, "");

      };

    } else {

      if ( !can_del ) o->pos = oldpos+1;

      if ( strlen(o->text) < o->limit-1 ) { /* can put next char */

        if ( o->pos != oldpos || must_write ) {

           o->ins_char(o, oldpos, (l_char)TO_CHAR(keycode));

           redraw_text = 0x03;

           can_draw_cursor = false;

        };

      } else {

        o->pos = oldpos;

//        seal_error(ERR_NONREGULAR, "");

      };
    };

  };

  if ( !o->sel_ok ) /* control selected text */

    sel_clear(o);

  else
  if ( o->pos != oldpos ) { /* control selected text */

    if ( o->sel_ok == 3 ) {  /* for mouse */

      o->sel_first_from = o->sel_from = o->pos;
      o->sel_first_to = o->sel_to = o->pos;

      o->sel_ok = 2;

    } else if ( o->sel_ok == 1 ) { /* for arrows */

      o->sel_from = min(oldpos, o->pos);
      o->sel_to = max(oldpos, o->pos);

      o->sel_first_from = oldpos;
      o->sel_first_to = oldpos;

      o->sel_ok = 2;

    } else if ( o->sel_ok == 2 ) { /* continue */

      o->sel_from = min(o->pos, o->sel_first_from);
      o->sel_to = max(o->pos, o->sel_first_to);

    };

    redraw_text = 0x01;

  };

  if ( o->pos != oldpos || redraw_text )

    if ( o->pos < o->line ) {

      o->line = o->pos;

      redraw_text = 0x03;
      can_draw_cursor = false;

    } else
    if ( o->pos - o->line >= o->charsin(o, o->line, 1) ) {

      o->line = o->pos-o->charsin(o, o->pos, -1);

      redraw_text = 0x03;
      can_draw_cursor = false;

    };


  if ( redraw_text ) {

    if ( redraw_text & 0x01 ) o->draw_text(o);
    if ( redraw_text & 0x02 ) o->draw_cursor(o, -1, -1);

  };


  if ( can_draw_cursor ) o->draw_cursor(o, oldline, oldpos);


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

};



/* t_workline */

t_rect worktextline_size_limits ( p_view o )
{

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

};


void  worktextline_draw ( p_view o )
{

  t_rect  r = o->get_local_extent(o);
  t_point p;

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

  if ( out ) {

    rect(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, COLOR(CO_BLACK));

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

  };

  o->end_of_paint(o, r);

};



/* listbox item functions */

p_listbox_item   new_listbox_item ( l_text name, BITMAP *icon, l_bool sel, l_int flags )
{

  p_listbox_item i = (p_listbox_item)malloc(sizeof(t_listbox_item));

  if ( i ) {

     clear_type(i, sizeof(t_listbox_item));

     i->name  = strdup(name);
     i->icon  = icon;
     i->sel   = sel;
     i->flags = flags;

  };

  return i;

};



void  free_listbox_item ( void* t )
{

  if ( t ) {

     if ( ((p_listbox_item)t)->name && *(((p_listbox_item)t)->name)  ) free(((p_listbox_item)t)->name);

     if ( ((p_listbox_item)t)->flags & LIF_MEMORY && ((p_listbox_item)t)->icon ) /* own memory */

        destroy_bitmap(((p_listbox_item)t)->icon);

     free(t);

  };

};


/* process */

p_process   _process_init ( p_process o, t_rect r, l_dword size, l_dword *where )
{
  if ( !o ) return NULL;

  clear_type(o, sizeof(t_process));

  view_init(VIEW(o), r);


  /* object's declarations */

  OBJECT(o)->translate_event = &process_translate_event;
  OBJECT(o)->func_callback = &process_func_callback;


  /* view's declarations */

  VIEW(o)->draw = &process_draw;
  VIEW(o)->size_limits = &process_size_limits;


  /* process's declarations */

  o->where = where;
  o->size  = size;

  o->draw_process = &process_draw_process;
  o->rewrite_promile = &process_rewrite_promile;

  OBJECT(o)->set_options(OBJECT(o), OB_OF_SELECTABLE+OB_OF_ENABLE, false);
  OBJECT(o)->set_options(OBJECT(o), OB_OF_STILLPROCESS, true);

  //VIEW(o)->set_palette(VIEW(o), pal_process);

  VIEW(o)->brush.color = color_3d_face;
  //VIEW(o)->brush.color2 = color_3d_shadow;
  //VIEW(o)->brush.state |= BRUSH_GRADIENT;

  VIEW(o)->brush.state &= ~BRUSH_LARGE3D;
  VIEW(o)->brush.state |= BRUSH_LIGHT3D|BRUSH_DRAWBORDER|BRUSH_DOWNBORDER;

  return o;

};



/* history */

p_history   _history_init ( p_history o, t_rect r, p_list list, l_int limit, l_int flags )
{
  if ( !o ) return NULL;

  clear_type(o, sizeof(t_history));

  textline_init(TEXTLINE(o), r, limit, flags);


  /* object's declarations */

  OBJECT(o)->translate_event = &history_translate_event;
  OBJECT(o)->setup = &history_setup;


  /* view's declarations */

  VIEW(o)->change_bounds = &history_change_bounds;


  /* history's declarations */

  o->list = list;

  o->rewrite_item = &history_rewrite_item;
  o->listbox_execute = &history_listbox_execute;
  o->show_box = &history_show_box;
  o->set_list = &history_set_list;

  o->message = 0;


  return o;
};




/* listbox */

p_listbox  _listbox_init ( p_listbox o, t_rect r, p_list list, l_byte cells, l_int flags )
{
  if ( !o ) return NULL;

  clear_type(o, sizeof(t_listbox));

  cells = max(1, cells);

  scroller_init(SCROLLER(o), r, (cells == 1) ? SF_VERSCROLLBAR : SF_HORSCROLLBAR);


  /* object's declarations */

  OBJECT(o)->translate_event = &listbox_translate_event;
  OBJECT(o)->set_state = &listbox_set_state;
  OBJECT(o)->set_options = &listbox_set_options;
  OBJECT(o)->get_data = &listbox_get_data;
  OBJECT(o)->set_data = &listbox_set_data;
  OBJECT(o)->done = &listbox_done;


  /* view's declarations */

  VIEW(o)->draw = &listbox_draw;
  VIEW(o)->size_limits = &listbox_size_limits;
  VIEW(o)->change_bounds = &listbox_change_bounds;

  /* scroller's declarations */

  SCROLLER(o)->scroll_size = &listbox_scroll_size;
  SCROLLER(o)->scroll_limits = &listbox_scroll_limits;
  SCROLLER(o)->recalc_positions = &listbox_recalc_positions;


  /* listbox's declarations */

  o->cells = cells;
  o->flags = flags;
  o->list = list;
  o->between.y = 2;
  o->between.x = 4;

  o->get_pos_from_xy = &listbox_get_pos_from_xy;
  o->draw_item_ptr = &listbox_draw_item_ptr;
  o->draw_item = &listbox_draw_item;
  o->draw_box = &listbox_draw_box;
  o->rewrite_item = &listbox_rewrite_item;
  o->get_max_in_box = &listbox_get_max_in_box;
  o->get_item_rect = &listbox_get_item_rect;
  o->get_max = &listbox_get_max;
  o->get_rows = &listbox_get_rows;
  o->get_item_size = &listbox_get_item_size;
  o->get_selected_items = &listbox_get_selected_items;
  o->set_list = &listbox_set_list;


  //VIEW(o)->set_palette(VIEW(o), pal_listbox);

  VIEW(o)->brush.color =color_flat_face;

  return o;
};



/* worklistbox */

p_listbox  _worklistbox_init ( p_listbox o, t_rect r, p_list list, l_byte cells, l_int flags )
{

  if ( !o ) return NULL;

  listbox_init(o, r, list, cells, flags);

  /* retype draw */

  VIEW(o)->draw = &worklistbox_draw;
  VIEW(o)->size_limits = &worklistbox_size_limits;

  return o;
};




/* textline */

p_textline  _textline_init ( p_textline o, t_rect r, l_int limit, l_int flags )
{

  if ( !o ) return NULL;

  clear_type(o, sizeof(t_textline));

  view_init(VIEW(o), r);


  /* object's declarations */

  OBJECT(o)->translate_event = &textline_translate_event;
  OBJECT(o)->execute = &textline_execute;

  OBJECT(o)->set_state = &textline_set_state;
  OBJECT(o)->set_options = &textline_set_options;
  OBJECT(o)->get_data = &textline_get_data;
  OBJECT(o)->set_data = &textline_set_data;
  OBJECT(o)->select_data = &textline_select_data;
  OBJECT(o)->done = &textline_done;

  OBJECT(o)->func_callback = &textline_timer;
  OBJECT(o)->process_tick = 1000;
  OBJECT(o)->set_options(OBJECT(o), OB_OF_STILLPROCESS, true);

  l_tag_cpy(OBJECT(o)->data_type, DAT_TEXT);


  /* view's declarations */

  if ( !(flags & TF_REWRITEUNABLE) )

       VIEW(o)->cursor = CUR_TEXT;

  VIEW(o)->draw = &textline_draw;
  VIEW(o)->drag_where = &textline_drag_where;
  VIEW(o)->size_limits = &textline_size_limits;


  /* textline's declarations */

  o->limit = limit+1;
  o->flags = flags;

  o->ins_text = &textline_ins_text;
  o->ins_char = &textline_ins_char;
  o->del_text = &textline_del_text;
  o->del_char = &textline_del_char;
  o->draw_cursor_ex = &textline_draw_cursor_ex;
  o->draw_cursor = &textline_draw_cursor;
  o->show_cursor = &textline_show_cursor;
  o->draw_text = &textline_draw_text;
  o->redraw_text = &textline_redraw_text;
  o->sel_all = &textline_sel_all;
  o->charsin = &textline_charsin;
  o->set_text = &textline_set_text;
  o->charsin_size = &textline_charsin_size;
  o->get_pos_from_xy = &textline_get_pos_from_xy;

 // VIEW(o)->set_palette(VIEW(o), pal_textline);

  VIEW(o)->brush.color = color_flat_face;

  return o;
};




/* worktextline */

p_textline  _worktextline_init ( p_textline o, t_rect r, l_int limit )
{

  if ( !o ) return NULL;

  textline_init(o, r, limit, TF_NONE);

  /* retype draw */

  VIEW(o)->draw = &worktextline_draw;
  VIEW(o)->size_limits = &worktextline_size_limits;

  return o;
};

void  dyntext_draw_text ( p_textline o )
{
  p_view  vo = VIEW(o);
  t_point p;
  t_rect  r = vo->size_limits(vo);
  t_rect  safe = r;


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

  if ( out ) {

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

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

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

       sel_clear(o);

    draw_selected_text (out, vo->font, &(o->text[o->line]), -1, max(0, o->sel_from-o->line), max(0, o->sel_to-o->line),
                        r.a.x, r.a.y, r.b.x, r.b.y, (o->flags & TF_ALIGN_RIGHT)?TX_ALIGN_RIGHT:TX_ALIGN_LEFT,
                        color_flat_text, TX_NOCOLOR, color_selected_text, color_selected_face, 1);

  };

  vo->end_of_paint(vo, safe);

};

t_rect dyntext_size_limits ( p_view o )
{

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

};
void  dyntext_draw ( p_view o )
{

    TEXTLINE(o)->draw_text(TEXTLINE(o));


};


p_textline  _dyntext_init ( p_textline o, t_rect r, l_int limit )
{

  if ( !o ) return NULL;

  textline_init(o, r, limit, TF_REWRITEUNABLE);

  /* retype draw */
  o->draw_text = &dyntext_draw_text;
  VIEW(o)->draw = &dyntext_draw;
  VIEW(o)->size_limits = &dyntext_size_limits;

  VIEW(o)->brush.color = color_flat_face;




  return o;
};

⌨️ 快捷键说明

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