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

📄 app.c

📁 SEAL是DOS 下的32位保护模式的GUI程序
💻 C
📖 第 1 页 / 共 3 页
字号:
    o->phase = PH_PREPROCESS;

    APPWIN(o)->app_trans_ev(o, event);

    o->phase = 0;

  };

  if ( event->type & EV_MESSAGE ) { /* message event */

    switch ( event->message ) {

      case MSG_MAXIMIZE : { /* maximize button pressed */
        t_rect rr;

        /* maximize/restore window */

        /*if (WINDOW(o)->flags & WF_MAXSIZE) {
          rr = APPWIN(o)->orig_bounds;
          VIEW(o)->change_bounds(VIEW(o), rr);
          WINDOW(o)->flags -= WF_MAXSIZE;
        } else {
          APPWIN(o)->orig_bounds = VIEW(o)->bounds;
          rr = desktop->bounds;
          rr.a.y += 38;
          VIEW(o)->change_bounds(VIEW(o), rr);
          WINDOW(o)->flags |= WF_MAXSIZE;
        }; */

        /* inform other applications that window has been maximized */

        clear_type(&appinfo, sizeof(t_appinfo));

        appinfo.title = WINDOW(o)->caption;
        appinfo.obj = o;

        set_event_info(event, EV_INFO, MSG_MAXIMIZE, o, &appinfo);

        o->put_event(o, event);

        clear_event(event);

      }; break;

      case MSG_MINIMIZE : {  /* minimize button pressed */

        /* there isn't any minimizing function so... */

        /* ...just inform other applications that window wants to be minimized */

        clear_type(&appinfo, sizeof(t_appinfo));

        appinfo.title = WINDOW(o)->caption;
        appinfo.obj = o;

        set_event_info(event, EV_INFO, MSG_MINIMIZE, o, &appinfo);

        o->put_event(o, event);

        clear_event(event);

      }; break;

      case MSG_RESIZE : {

        clear_event(event);

      }; break;
      case MSG_SYSMENU : {  /* pop up system menu */

        t_rect r = VIEW(o)->bounds;
        l_dword msg;

        p_menu m = new_menu(APPWIN(o)->menu);

        p_menuview menu;

        clear_event(event);

        r.a.y += FONT_GETHEIGHT(VIEW(o)->font)+5;
        r.a.x += 2;
        if (m) menu = menuview_init(malloc(sizeof(t_menuview)), r, m);
        if (menu) {
          msg = desktop->execute_view(desktop, VIEW(menu));

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

          o->put_event(o, event);

          clear_event(event);
        };
        clear_event(event);
      }; break;

      case MSG_OK :
      case MSG_CLOSE : {

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

          clear_event(event);

          APPWIN(o)->app_trans_ev = NULL;

          if ( APPWIN(o)->app_id )

             DLXUnload(APPWIN(o)->app_id); /* function for unloading application */

          dispose(o);

        } else o->end_state = event->message;

        clear_event(event);

      }; break;

    };
  };

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


  if ( APPWIN(o)->app_trans_ev ) {

    o->phase = PH_POSTPROCESS;

    APPWIN(o)->app_trans_ev(o, event);

    o->phase = 0;

  };
};

/* appwin */
p_appwin  _appwin_init ( p_appwin o, t_rect r, l_text caption, l_int flags, hdlx_t id,
                         void (*trans_ev)( p_object o, t_event *e ))
{
  if ( !o ) return NULL;

  clear_type(o, sizeof(t_appwin));

  win_init(&o->obclass, r, caption, flags);

  /* object's functions */

  OBJECT(o)->translate_event = &appwin_translate_event;
  OBJECT(o)->setup = &appwin_setup;

  OBJECT(o)->tag |= TAG_APPWIN;

  /* view's functions */

  VIEW(o)->size_limits = &appwin_size_limits;

  /* windows's functions */

  WINDOW(o)->draw_title = &appwin_draw_title;
  WINDOW(o)->flags |= WF_SYSMENU;

  /* function calling */

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

  VIEW(o)->brush.color = color_3d_face;
  VIEW(o)->draw = &appwin_draw;

  OBJECT(o)->set_state = & appwin_set_state;
  /* appwin's declarations */

  o->app_trans_ev = trans_ev;
  o->app_id = id;
  o->menu = standard_system_menu_items(o, NULL);
  o->icon16 = image_sysmenu;
  o->icon32 = NULL;
  o->pastitle = apppastitle;
  o->acttitle = appacttitle;
  o->body = appbody;

  return o;
};


/* window */

p_appwin  _window_init ( p_appwin o, t_rect r, l_text caption, l_int flags )
{
   return appwin_init(o, r, caption, flags, 0, NULL);
};



#define MSG_FLAGS_SETUP                            \
    switch ( wflags ) {                            \
      case MW_WARNING : {                          \
        iflag = MI_WARNING;                        \
        capt = TXT_WARNING;                        \
      }; break;                                    \
      case MW_INFO    : {                          \
        iflag = MI_INFO;                           \
        capt = TXT_INFO;                           \
      }; break;                                    \
      case MW_ERROR   : {                          \
        iflag = MI_ERROR;                          \
        capt = TXT_ERROR;                          \
      }; break;                                    \
      case MW_QUESTION : {                         \
        iflag = MI_QUESTION;                       \
        capt = TXT_QUESTION;                       \
      }; break;                                    \
      case MW_UNAVAILABLE : {                      \
        iflag = MI_UNAVAILABLE;                    \
        capt = TXT_UNAVAILABLE;                    \
      }; break;                                    \
      case MW_SETUP : {                            \
        iflag = MI_SETUP;                          \
        capt = TXT_SETUP;                          \
      }; break;                                    \
    }


/* message window init function */

p_appwin  _message_init_ex ( p_object owner, p_appwin o, t_rect r, l_text caption, l_int flags,
                             l_char   iflag,
                             l_dword  bflags, void (*trans_ev)( p_object o, t_event *e ),
                             l_text in_text, va_list argp )
{

  t_rect t;
  t_rect ric;
  t_rect sf = r;
  p_stattext st   = NULL;
  p_icon     icn  = NULL;
  BITMAP    *img  = NULL;
  l_int      n  = 2;
  l_int      xf = 0;
  l_dword    i  = 0;
  l_int      bn = 0;  /* number of buttons, gets from bflags */
  l_int      bw = 90; /* width of button */
  l_int      bh = 25; /* height of button */
  l_int      be = 20; /* between place */

  if ( !o || !owner ) return NULL;

  appwin_init(o, r, caption, flags, 0, trans_ev);

  WINDOW(o)->flags -= WF_SYSMENU;

  t = VIEW(o)->size_limits(VIEW(o));

  st = stattext_init_ex(_malloc(sizeof(t_stattext)), t, TX_ALIGN_LEFT, in_text, argp);

  /* get number of buttons */

  while ( i < sizeof(l_dword)*8 ) {

    if ( bflags & ((l_dword)1<<i) ) bn++;

    i++;

  };


  /* no buttons */
  if ( !bflags ) {

     bh = 0; /* there is no button */
     be = 10;

  };


  /* get default place for stattext */
  t.a.x += be;
  t.a.y += 5;
  t.b.y -= bh+be; /* place for buttons */
  t.b.x -= be;

  /* get icon of dialog box ( from app.dlx end of file) */
  img = (iflag<MI_ICONS)?msg_icons(iflag):NULL;

  /* ok, stattext exist => enough memory */
  if ( st ) {

    l_int x;
    l_int y;

    /* get size of formated text in (y) and (x) */
    get_size_of_ftext(st->text, VIEW(st)->font, &x, &y);

    /* image ( icon ) of dialog exist */
    if ( img ) {

      /* get width of the image plus size between buttons */
      xf = IMAGE_WIDTH(img)+be;
      /* make rectangle for icon */
      ric = rect_assign(t.a.x, t.a.y, t.a.x+IMAGE_WIDTH(img), t.a.y+IMAGE_HEIGHT(img));

    };

    t = VIEW(o)->size_limits(VIEW(o));

    /* make sizes of window */
    r.b.x = r.a.x+max(bn*bw+be*2+(bn-1)*10, x+xf+(be*n))+10;
    r.b.y = r.a.y+y+t.a.y+bh+(be*3);

    /* align window to center */
    VIEW(o)->align |= TX_ALIGN_CENTER;

    if ( flags & WF_MINSIZE )

          /* size of window is minimal to (sf) */
          r.b.x = r.a.x+max(rect_sizex(r), rect_sizex(sf));

    /* set right ! bounds of window */
    VIEW(o)->set_bounds(VIEW(o), r);

    /* get limits of window for objects inserted into the window */
    t = VIEW(o)->size_limits(VIEW(o));

    /* allocate place for stattext */
    t.a.x += be+xf;
    t.a.y += be;
    t.b.y -= bh+be; /* place for buttons */
    t.b.x -= be;

    /* set right ! bounds for stattext */
    VIEW(st)->set_bounds(VIEW(st), t);

    /* icon exist ? */
    if ( img ) {

      /* insert icon to the center of (y) */
      ric.a.y += (rect_sizey(t)-IMAGE_HEIGHT(img))/2;
      ric.b.y  = ric.a.y+IMAGE_HEIGHT(img);

      /* allocate icon and enable to stretch it */
      icn = icon_init ( _malloc(sizeof(t_icon)), ric, img, 0, 0);

      if ( icn ) {

        /* icon can't be selected and is disable !!! */
        OBJECT(icn)->set_options(OBJECT(icn), OB_OF_SELECTABLE+OB_OF_ENABLE, false);

        /* icon can't be dragging */
        VIEW(icn)->drag_mode = 0;

      };

    };

  };

  t.a.x -= xf;

  if ( screen_double_buffer && draw_to_2nd_buffer ) {
    mouse->hide(mouse);
    draw_to_2nd_buffer = 0;
    set_clip(screen,0,0,screen_width,screen_height);
    blit(screen_double_buffer, screen, 0, 0, 0, 0, screen_width, screen_height);
    mouse->show(mouse);
  };

  /* insert window to his owner */

  owner->insert(owner, OBJECT(o));

  /* insert stattext to the window */
  OBJECT(o)->insert(OBJECT(o), OBJECT(st));

  /* insert icon to the window */
  OBJECT(o)->insert(OBJECT(o), OBJECT(icn));

  t.a.y  = t.b.y + 5; /* make place between text and buttons */
  t.b.y  = t.a.y + bh;

  /* button FLAGS !!! */

  if ( bflags & MB_YES ) { /* button YES */

    /* move button rectangle for the right place */
    t.b.x = t.a.x+bw;

    /* insert button into the window */
    OBJECT(o)->insert(OBJECT(o), OBJECT(button_init(_malloc(sizeof(t_button)), t, TXT_YES, MSG_YES, BF_NORMAL)));

    t = rect_move(t, bw+10, 0);

  };

  if ( bflags & MB_OK ) { /* button OK */

    /* move button rectangle for the right place */
    t.b.x = t.a.x+bw;

    /* insert button into the window */
    OBJECT(o)->insert(OBJECT(o), OBJECT(button_init(_malloc(sizeof(t_button)), t, TXT_OK, MSG_OK, BF_NORMAL)));

    t = rect_move(t, bw+10, 0);

  };

  if ( bflags & MB_CLOSE ) { /* button CLOSE */

    /* move button rectangle for the right place */
    t.b.x = t.a.x+bw;

⌨️ 快捷键说明

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