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

📄 dialogs.c

📁 SEAL是DOS 下的32位保护模式的GUI程序
💻 C
📖 第 1 页 / 共 4 页
字号:
/******************************************************************
 * SEAL 2.0                                                       *
 * Copyright (c) 1999-2002 SEAL Developers. All Rights Reserved.  *
 *                                                                *
 * Web site: http://sealsystem.sourceforge.net/                   *
 * E-mail (current maintainer): orudge@users.sourceforge.net      *
 ******************************************************************/

/*
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include <seal.h>
#include <dialogs.h>
#include <math.h>

p_process   (*process_init) ( p_process o, t_rect r, l_dword size, l_dword *where ) = &_process_init;
p_history   (*history_init) ( p_history o, t_rect r, p_list list, l_int limit, l_int flags ) = &_history_init;
p_listbox   (*listbox_init) ( p_listbox o, t_rect r, p_list list, l_byte cells, l_int flags ) = &_listbox_init;
p_listbox   (*worklistbox_init) ( p_listbox o, t_rect r, p_list list, l_byte cells, l_int flags ) = &_worklistbox_init;
p_textline  (*textline_init) ( p_textline o, t_rect r, l_int limit, l_int flags ) = &_textline_init;
p_textline  (*worktextline_init) ( p_textline o, t_rect r, l_int limit ) = &_worktextline_init;

p_textline  (*dyntext_init) ( p_textline o, t_rect r, l_int limit ) = &_dyntext_init;

/* t_process functions */

p_menuitem get_edit_menuitem ( p_object o, l_bool selection ) {
  p_menuitem r;

  r = new_menu_item_ex(TXT_COPY,   0, 0, MSG_COPY,   selection, "Copy text to clipboard", 0, 0, 0, 0, 0,
      new_menu_item_ex(TXT_CUT,    0, 0, MSG_CUT,    selection, "Cut text to clipboard", 0, 0, 0, 0, 0,
      new_menu_item_ex(TXT_PASTE,  0, 0, MSG_PASTE,  (clipboard.data&&l_tag_cmp(clipboard.id, DAT_TEXT)), "Past text from clipboard", 0, 0, 0, 0, 0,
      new_menu_item_ex(TXT_DELETE, 0, 0, MSG_DELETE, selection, "Delete selected text", 0, 0, 0, 0, 0,
      new_menu_line(
      new_menu_item_ex("Select all", 0, 0, MSG_SELECT_ALL, TRUE, "Select all text", 0, 0, 0, 0, 0,
      NULL))))));

  return r;
};

void show_edit_menu ( p_object o, l_bool selection ) {

  t_rect r = rect_assign(mouse->where.x+5,mouse->where.y,mouse->where.x+5,mouse->where.y);
  l_dword msg;

  p_menu m = new_menu(get_edit_menuitem(o,selection) );

  p_menuview menu;

  if ( m ) menu = menuview_init(malloc(sizeof(t_menuview)), r, m);
  if ( menu ) {
    p_event event = malloc(sizeof(t_event));

    clear_event(event);

    msg = desktop->execute_view(desktop, VIEW(menu));

    set_event_info(event, EV_MESSAGE, msg, o, NULL);

    o->put_event(o, event);

    clear_event(event);
  };

};

void   process_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 ) {

    PROCESS(o)->draw_process(PROCESS(o));

  };

  o->end_of_paint(o, r);
};


t_rect process_size_limits ( p_view o )
{

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

};


void   process_draw_process ( p_process o )
{

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

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

  if ( out ) {


      l_int   dx = (l_int)(((double)(rect_sizex(r)-4)/(double)1000)*(double)o->promile);

      vo->background(vo, out, rect_move(r, p.x, p.y));

//    button(out, p.x+r.a.x, p.y+r.a.y, p.x+r.b.x, p.y+r.b.y, color_3d_shadow, color_3d_light);

      if ( dx > 0 ) {

         rectfill(out, r.a.x+p.x+2, r.a.y+p.y+2, r.a.x+p.x+dx-2, r.b.y+p.y-2, color_selected_face);
         //button(out, r.a.x+p.x+1, r.a.y+p.y+1, r.a.x+p.x+dx-1, r.b.y+p.y-1, color_3d_light, color_3d_shadow);

      }

  };

  vo->end_of_paint(vo, r);

};


void   process_rewrite_promile ( p_process o, l_dword where )
{
   l_int  oldp = o->promile;
   l_rect sx   = rect_sizex(VIEW(o)->size_limits(VIEW(o)));

   where = lmax(0, lmin(where, o->size));

   o->promile = max(0, min(1000, (l_int)(((double)where/(double)lmax(1, o->size))*(double)1000)));

   if ( (l_int)(((double)sx/(double)1000)*(double)oldp) !=
        (l_int)(((double)sx/(double)1000)*(double)o->promile) )

       o->draw_process(o);

};


void   process_func_callback ( p_object o )
{

  if ( PROCESS(o)->where )

      PROCESS(o)->rewrite_promile(PROCESS(o), *(PROCESS(o)->where));

};


void   process_translate_event ( p_object o, t_event *event )
{

  RETVIEW(o, event);

};


/* t_history functions */


/*
  change bounds together with history line
*/
void   history_change_bounds ( p_view o, t_rect nr )
{

  view_change_bounds(o, nr);

  if ( HISTORY(o)->button ) { /* exist button */

    p_view vb = VIEW(HISTORY(o)->button);

    t_rect r  = o->bounds; /* get history bounds */

    /* change button bounds */
    vb->change_bounds(vb, rect_assign(r.b.x+1, r.a.y, r.b.x+1+STANDARD_HISTORYBUTTON_SIZE, r.b.y));

  };

};


void   history_setup ( p_object o )
{
   p_object owner;

   view_setup(o);

   owner = o->owner_view(o);

   if ( owner ) {

     p_history his = HISTORY(o);

     if ( HISTORY(o)->list ) /* set text in text line to first item */

        TEXTLINE(o)->set_text(TEXTLINE(o), (l_text)LISTBOX_ITEM_TEXT(HISTORY(o)->list, his->current));

     if ( !his->button ) { /* make history button */

        t_rect r = VIEW(o)->bounds;

        r = rect_assign(r.b.x+1, r.a.y, r.b.x+1+STANDARD_HISTORYBUTTON_SIZE, r.b.y);

        his->button = button_init(BUTTON(malloc(sizeof(t_button))), r, "g", MSG_HISTORY, BF_NORMAL);

        if ( his->button ) {

           OBJECT(his->button)->set_options(OBJECT(his->button), OB_OF_SELECTABLE, false);

           his->button->flags |= BF_DARROUND;

           VIEW(his->button)->font = get_font_in_size("Symbols", 8, 8);

        };

        owner->insert(owner, OBJECT(his->button));

     };

   };

};


void   history_translate_event ( p_object o, t_event *event )
{

  RETVIEW(o, event);

  if ( event->type & EV_MOUSE && !is_wable(TEXTLINE(o)) ) { /* mouse event */

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


      clear_event(event);

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

         o->select(o);

      };

      if ( HISTORY(o)->show_box(HISTORY(o)) == MSG_OK )

        if ( HISTORY(o)->message ) {

          set_event(event, EV_MESSAGE, HISTORY(o)->message, o);

          o->put_event(o, event);

          clear_event(event);

        };

    };

  };

  textline_translate_event(o, event);

                                  /* keyboard events */
  if ( event->type & EV_KEYBOARD && o->is_state(o, OB_SF_FOCUSED) ) {

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

    switch ( KEY_TO(keyb->code) ) {

      case KB_DOWN : {  /* arrow DOWN was pressed */

        clear_event(event);

        if ( HISTORY(o)->show_box(HISTORY(o)) == MSG_OK )

          if ( HISTORY(o)->message ) {

            set_event(event, EV_MESSAGE, HISTORY(o)->message, o);

            o->put_event(o, event);

            clear_event(event);

          };

        clear_event(event);

      }; break;

    };
  };

  /* history button was pressed */
  if ( event->type & EV_MESSAGE && event->message == MSG_HISTORY &&
       event->obj && event->obj == OBJECT(HISTORY(o)->button) ) {

        clear_event(event);

        if ( HISTORY(o)->show_box(HISTORY(o)) == MSG_OK )

          if ( HISTORY(o)->message ) {

            set_event(event, EV_MESSAGE, HISTORY(o)->message, o);

            o->put_event(o, event);

            clear_event(event);

          };

  };

};


l_dword  history_listbox_execute ( p_object o )
{

  p_scroller lb = SCROLLER(o);

  p_view hb  = VIEW(lb->horbar);
  p_view vb  = VIEW(lb->verbar);

  l_int end = 0;

  LISTBOX(lb)->rewrite_item(LISTBOX(lb), LISTBOX(lb)->current);

  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 ( ( hb && hb->is_mouse_in_view(hb) ) ||
              ( vb && vb->is_mouse_in_view(vb) ) ) {

           end = 0;

         } else

         if ( VIEW(lb)->is_mouse_in_view(VIEW(lb)) ) {

             if ( OBJECT(mouse)->state & MO_SF_MOUSEUP )

                end = 4;

        } else

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

      };

      INTMAIN(&event_main);

      if ( end ) {

        clear_event(&event_main);

        if ( end == 2 || end == 4 ) return MSG_OK;

        return MSG_CANCEL;

      };

      listbox_translate_event(o,&event_main);
      if ( lb->verbar ) vscrollbar_translate_event(OBJECT(lb->verbar),&event_main);
      if ( lb->horbar ) hscrollbar_translate_event(OBJECT(lb->horbar),&event_main);


      o->get_event(o, &event_main);

  };

  return MSG_CANCEL;

};


l_dword   history_show_box ( p_history o )
{

  l_dword msg = MSG_CANCEL;

  if ( !o->listbox && o->list ) {

    p_view vo = VIEW(o);

    l_int   by = 3;
    t_rect  r = vo->get_global_bounds(vo, vo->get_local_extent(vo));
    l_long  items = o->list->get_max_item(o->list);
    l_rect  sizey = 0;

    items = lmin((items+1), STANDARD_HISTORYBOX_ITEMS);

    sizey = (max(icon_size(o), FONT_GETHEIGHT(vo->font))+by)*items + 4;


    if ( r.b.y + sizey < desktop->bounds.b.y ) /* max y of listbox is lower then desktop max y */

      r = rect_assign(r.a.x, r.b.y, r.b.x, r.b.y + sizey);

    else /* max y of listbox is greater then desktop max y */

      r = rect_assign(r.a.x, r.a.y - sizey, r.b.x, r.a.y);


    o->listbox = worklistbox_init((p_listbox)malloc(sizeof(t_listbox)), r, o->list, 1, LF_UNDERSEL);

    if ( o->listbox ) {

        OBJECT(o->listbox)->execute = o->listbox_execute;
        OBJECT(o->listbox)->set_options(OBJECT(o->listbox), OB_OF_TOPSELECT, true);

        VIEW(o->listbox)->font = VIEW(o)->font; /* set font of box to history font */

        o->listbox->current = o->current;

        o->listbox->between.y = by;  /* set distance between texts in box */

    };

    OBJECT(desktop)->insert(OBJECT(desktop), OBJECT(o->listbox));

    msg = desktop->execute_view(desktop, VIEW(o->listbox));

    if ( msg == MSG_OK )

       o->rewrite_item(o, o->listbox->current); // set history item to selected listbox item

    o->listbox = LISTBOX(dispose(OBJECT(o->listbox))); // free listbox

  };

  return msg;

};


l_bool history_set_list ( p_history o, p_list p )
{

   o->list = p;

   o->current = 0;

   if ( o->list )

       TEXTLINE(o)->set_text(TEXTLINE(o), (l_text)LISTBOX_ITEM_TEXT(o->list, 0));

   return true;
};


void   history_rewrite_item ( p_history o, l_long item )
{

  if ( o->list ) {

     l_long old_current = o->current;

     item = lmax(0, lmin(o->list->get_max_item(o->list), item));

     o->current = item;

     if ( o->current != old_current )

       TEXTLINE(o)->set_text(TEXTLINE(o), (l_text)LISTBOX_ITEM_TEXT(o->list, item));

  };

};



/* listbox functions */

void   listbox_change_bounds ( p_view o, t_rect nr )
{

   l_long oldc = LISTBOX(o)->current;

   LISTBOX(o)->current = LISTBOX(o)->from = SCROLLER(o)->scrollx = SCROLLER(o)->scrolly = 0;

   scroller_change_bounds(o, nr);

   LISTBOX(o)->rewrite_item(LISTBOX(o), oldc);

};

void   listbox_go_char ( p_listbox o, l_char c ) {
  if ( o->list ) {
    p_item  a  = o->list?o->list->at_item(o->list, o->current ) : NULL;
    p_item  b;
    if ( a ) {
	  a = a->next;
	  b = a;
	  c = tolower(c);
      do {
        p_listbox_item it = (p_listbox_item)a->rec;
        if ( it->name ) if ( tolower(it->name[0]) == c ) {
   	      o->rewrite_item(o, o->list->index_of_item(o->list,a) );
          return;
        };
        a = a->next;
      } while ( a != b );
    };
  };
};


void   listbox_translate_event ( p_object o, t_event *event )
{

  RETVIEW(o, event);

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

  if ( keyb->shifts & KB_SHIFT_FLAG ) {

     if ( !(LISTBOX(o)->shift_flag & 0x01) ) { /* now was pressed shift */

        LISTBOX(o)->shift_flag |= 0x01;

        if ( LISTBOX(o)->shift_flag & 0x02 ) { /* deselect process */

            LISTBOX(o)->shift_flag &= ~0x02;
            LISTBOX(o)->shift_flag |=  0x04;

        } else { /* select proces */

            LISTBOX(o)->shift_flag &= ~0x04;
            LISTBOX(o)->shift_flag |=  0x02;

        };

     };

  } else

    LISTBOX(o)->shift_flag &= ~0x01; /* not shift */

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

    l_long mpos;
    l_bool oksel = ( LISTBOX(o)->flags & LF_UNDERSEL ) ? true : OBJECT(mouse)->state & MO_SF_MOUSELPRESS;

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

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

         clear_event(event);

         o->select(o);

         return;

      };

    };


    if ( oksel && o->is_state(o, OB_SF_FOCUSED) ) {

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

       if ( LISTBOX(o)->flags & LF_SELECTABLE &&
            LISTBOX(o)->shift_flag & 0x01 ) { /* select item */

         p_listbox_item p = (p_listbox_item)LISTBOX_ITEM_AT(LISTBOX(o)->list, mpos);

         if ( p )

            if ( LISTBOX(o)->shift_flag & 0x04 ) p->sel = false;
            else
            if ( LISTBOX(o)->shift_flag & 0x02 ) p->sel = true;

       };

       LISTBOX(o)->rewrite_item(LISTBOX(o), mpos);

       clear_event(event);

    };

  };

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

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

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

    switch ( KEY_TO(keyb->code) ) {

      case KB_DOWN : {  /* arrow DOWN was pressed */

        LISTBOX(o)->rewrite_item(LISTBOX(o), LISTBOX(o)->current+1);

        clear_event(event);

      }; break;

      case KB_UP : {  /* arrow UP was pressed */

        LISTBOX(o)->rewrite_item(LISTBOX(o), LISTBOX(o)->current-1);

        clear_event(event);

      }; break;

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

        LISTBOX(o)->rewrite_item(LISTBOX(o), LISTBOX(o)->current+LISTBOX(o)->get_rows(LISTBOX(o)));

        clear_event(event);

      }; break;

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

        LISTBOX(o)->rewrite_item(LISTBOX(o), LISTBOX(o)->current-LISTBOX(o)->get_rows(LISTBOX(o)));

        clear_event(event);

⌨️ 快捷键说明

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