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

📄 desktop5.c

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

static p_menuitem  get_programs_items ( void )
{

   if ( !program_items ) program_items = menu_load_from_dir(DIR_PROGRAMS, "*.*");
//   DEBUG_printf("Desktop V: get_programs_items() finished\n");
   return program_items;

};


static p_menuitem  get_help_items ( void )
{

   if ( !help_items ) help_items = menu_load_from_dir(DIR_HELP, "*.*");

   return help_items;

};

/*
  translate application menu, that return right application that was

  pushed in application menu.
*/

void   filemenu_trans ( p_object o, p_event event )
{
       l_dword msg = desktop->execute_view(desktop, VIEW(o));

       if ( msg != MSG_NOTHING && msg != MSG_CANCEL ) {

          if ( msg == MSG_RUNAPP ) { /* run application was pressed */

              p_filemenuitem i = (p_filemenuitem)menu_get_lastitem_called(MENUVIEW(o)->menu);

              clear_event(event);

              if ( i ) {
				  DEBUG_printf("DESKTOP V :: try to run \"%s\"\n",i->filename);
                  if ( !run_file(i->filename) )  /* run application */

                      seal_error(ERR_INFO, "%s \n\n%s", "Can't run file", i->filename);  /* error in application running */

              };

          } else { /* other message */

               set_event(event, EV_MESSAGE, msg, o);

               o->put_event(o, event);

               clear_event(event);
          };

       };
};

////////////////////////////////////////////////////////////////////////////////

void deskbar_setup ( p_object o ) {
  t_rect   r;
  t_rect   br;
  p_object b;
  l_int i;
  view_setup(o);

  r = VIEW(o)->get_local_extent(VIEW(o));

  if ( BarPosition == 0 || BarPosition == 2 )
    br = rect_assign(2, 2, r.b.y-2, r.b.y-2);
  else if ( BarPosition == 1 )
    br = rect_assign( r.b.x - 37, 2, r.b.x-2, 37);
  else
    br = rect_assign( 2, 2, 37, 37);

  b = OBJECT(icobutton_init( _malloc(sizeof(t_icobutton)),
                            br,
                            GETBMP("ICO_xPROGRAMS"),
                            TXT_PROGRAMS,
                            MSG_xAPPLICATION,
                            BF_NORMAL | BF_UNDERSEL) );

  if ( b ) {
     VIEW(b)->brush.color = color_deskbar_face;
     o->insert(o,b);
     if ( BarPosition == 0 || BarPosition == 2 )
       br = rect_move(br,r.b.y+2,0);
     else
       br = rect_move(br,0,38);
     IcoPrg = VIEW(b);
  };

  b = OBJECT(icobutton_init( _malloc(sizeof(t_icobutton)),
                            br,
                            GETBMP("ICO_xSETTINGS"),
                            TXT_CONTROL_PANEL,
                            MSG_xSETTINGS,
                            BF_NORMAL | BF_UNDERSEL) );

  if ( b ) {
     VIEW(b)->brush.color = color_deskbar_face;
     o->insert(o,b);

     if ( BarPosition == 0 || BarPosition == 2 )
       br = rect_move(br,r.b.y+2,0);
     else
       br = rect_move(br,0,38);

     IcoSet = VIEW(b);
  };

  b = OBJECT(icobutton_init( _malloc(sizeof(t_icobutton)),
                            br,
                            GETBMP("ICO_xHELP"),
                            TXT_DOCUMENTS,
                            MSG_xHELP,
                            BF_NORMAL | BF_UNDERSEL) );

  if ( b ) {
     VIEW(b)->brush.color = color_deskbar_face;
     o->insert(o,b);
     if ( BarPosition == 0 || BarPosition == 2 )
       br = rect_move(br,r.b.y+2,0);
     else
       br = rect_move(br,0,38);

     IcoDoc = VIEW(b);
  };

  b = OBJECT(icobutton_init( _malloc(sizeof(t_icobutton)),
                            br,
                            GETBMP("ICO_xSHUTDOWN"),
                            TXT_SHUT_DOWN,
                            MSG_QUIT,
                            BF_NORMAL | BF_UNDERSEL) );

  if ( b ) {
     VIEW(b)->brush.color = color_deskbar_face;
     o->insert(o,b);
     if ( BarPosition == 0 || BarPosition == 2 )
       br = rect_move(br,r.b.y+2,0);
     else
       br = rect_move(br,0,38);

     IcoSht = VIEW(b);
  };

  i = ( r.b.y - 20 ) / 2;

  if ( BarPosition == 0 || BarPosition == 2 )
    br = rect_assign(br.a.x,r.a.y+i,r.b.x - 8,r.b.y-i);
  else
    br = rect_assign( 3, br.a.y + 2, r.b.x - 3, r.b.y - 2);

  b = OBJECT(taskbar_init(_malloc(sizeof(t_taskbar)),br,OBJECT(desktop)));

  if ( b ) {
    o->insert(o,b);
    Taskbar = VIEW(b);
  };

  if ( BarPosition == 0 || BarPosition == 2 )
    br = rect_assign(br.b.x+2,br.a.y,r.b.x-4,br.b.y);
  else if ( BarPosition == 1 )
    br = rect_assign(2,2,r.b.x - 40,6);
  else
    br = rect_assign(40,2,r.b.x-2,6);

  if ( !userbox ) userbox = userbox_init(_malloc(sizeof(t_userbox)), br);
  else VIEW(userbox)->bounds = br;

  if ( userbox ) {
	o->insert(o,OBJECT(userbox));
	refresh_userbox();
  };

};
////////////////////////////////////////////////////////////////////////////////
void    deskbar_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 ) {

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

    button(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, color_deskbar_light, color_deskbar_shadow);

  };

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

////////////////////////////////////////////////////////////////////////////////
void  deskbar_translate_event ( p_object o, p_event event )
{
  RETVIEW(o, event);

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

  if ( event->type == EV_INFO ) {
     switch ( event->message ) {
        case MSG_MINIMIZE : if ( event->info ) {
            p_object  m = ((p_appinfo)(event->info))->obj;
            clear_event(event);
            if ( m ) VIEW(m)->hide(VIEW(m));
        }; break;
        case MSG_MAXIMIZE : if ( event->info ) {

            t_appinfo a = *((p_appinfo)(event->info));
            p_object  m = ((p_appinfo)(event->info))->obj;

            clear_event(event);

            if ( m ) {
              if (WINDOW(m)->flags & WF_MAXSIZE) {  /* if is already maximized... */
                t_rect rr = APPWIN(m)->orig_bounds;
                VIEW(m)->change_bounds(VIEW(m), rr);
                WINDOW(m)->flags -= WF_MAXSIZE;
              } else {                              /* ... or if isn't maximized... */
                t_rect   r = rect_assign ( ( BarPosition == 1 ) ? VIEW(o)->bounds.b.x + 1 : 0,
                                           ( BarPosition == 0 ) ? VIEW(o)->bounds.b.y + 1 : 0,
                                           ( BarPosition == 3 ) ? VIEW(o)->bounds.a.x - 1 : screen_width - 1,
                                           ( BarPosition == 2 ) ? VIEW(o)->bounds.a.y - 1 : screen_height - 1);
                APPWIN(m)->orig_bounds = VIEW(m)->bounds;
                VIEW(m)->change_bounds(VIEW(m), r);

                WINDOW(m)->flags |= WF_MAXSIZE;
              };
            };
        }; break;
     };
  };

  if ( event->type == EV_MESSAGE )

     switch ( event->message ) {

        case MSG_xAPPLICATION : {

            t_rect r = VIEW(IcoPrg)->get_global_bounds(VIEW(IcoPrg),VIEW(IcoPrg)->get_local_extent(VIEW(IcoPrg)));

            p_menu m = new_menu(get_programs_items());

            p_menuview menu;

            if ( BarPosition != 2 )
              r.a.y = r.b.y+1;
            else
              r.a.y -= menu_get_ver_size(m, standard_menuitem_size).y+1;

            clear_event(event);

            if ( m )

               menu = menuview_init(malloc(sizeof(t_menuview)), r, m);

            if ( menu ) filemenu_trans(OBJECT(menu), event);

        }; break;

        case MSG_xSETTINGS : {

             load_cp();

             clear_event(event);
        }; break;

        case MSG_xHELP : {

            t_rect r = VIEW(IcoDoc)->get_global_bounds(VIEW(IcoDoc),VIEW(IcoDoc)->get_local_extent(VIEW(IcoDoc)));

            p_menu m = new_menu(get_help_items());

            p_menuview menu;

            if ( BarPosition != 2 )
              r.a.y = r.b.y+1;
            else
              r.a.y -= menu_get_ver_size(m, standard_menuitem_size).y+1;

            clear_event(event);

            if ( m )

               menu = menuview_init(malloc(sizeof(t_menuview)), r, m);

            if ( menu ) filemenu_trans(OBJECT(menu), event);

        }; break;

     };
  if ( event->type & EV_MOUSE  &&  OBJECT(mouse)->state & MO_SF_MOUSELDOUBLE ) {

    if ( its ) dispose_list(&its, true);

    clear_event(event);

    obj_remove(o,OBJECT(userbox));

    dispose(o);

    desktop->draw_me(desktop);

    BarPosition++;
    if ( BarPosition == 4 ) BarPosition = 0;

    set_key_integer("current/desktop/barpos",BarPosition);

    o = init_desktop();

    if ( OBJECT(desktop) && OBJECT(desktop)->last ) {
     p_object p = OBJECT(desktop)->first_view(OBJECT(desktop));
     p_object f = p;
     do {
       if ( p->tag & TAG_WINDOW  ) if ( WINDOW(p)->flags & WF_MAXSIZE ) {
         t_rect   r = rect_assign ( ( BarPosition == 1 ) ? VIEW(o)->bounds.b.x + 1 : 0,
                                    ( BarPosition == 0 ) ? VIEW(o)->bounds.b.y + 1 : 0,
                                    ( BarPosition == 3 ) ? VIEW(o)->bounds.a.x - 1 : screen_width - 1,
                                    ( BarPosition == 2 ) ? VIEW(o)->bounds.a.y - 1 : screen_height - 1);
         VIEW(p)->change_bounds(VIEW(p), r);
       };
       p = p->next_view(p);
     } while(f != p);
    };

    Taskbar->draw_me(Taskbar);
  };

};
////////////////////////////////////////////////////////////////////////////////
p_view deskbar_init ( p_view o, t_rect r ) {

  if (!o) return NULL;

  clear_type(o, sizeof(t_view));

  view_init(o, r);

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

  VIEW(o)->draw = &deskbar_draw;

  OBJECT(o)->translate_event = &deskbar_translate_event;

  OBJECT(o)->setup = &deskbar_setup;

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

  return o;
};
////////////////////////////////////////////////////////////////////////////////
l_dword    program_valid ( p_object o, l_dword msg )
{

   if ( msgbox( MW_QUESTION, MB_YES|MB_NO, TXT_AREYOUSURETOQUITSEAL ) == MSG_YES ) {
     if ( its ) dispose_list(&its, true);
     return 0;
   };
   return 1;
};

p_object init_desktop ( void ) {


          p_view o;
          t_rect r;

          switch ( BarPosition ) {
            case 0 : r = rect_assign(0,0,screen_width-1,38); break;
            case 1 : r = rect_assign(0,0,100,screen_height-1); break;
            case 2 : r = rect_assign(0,screen_height-39,screen_width-1,screen_height-1); break;
            case 3 : r = rect_assign(screen_width-101,0,screen_width-1,screen_height-1); break;
          };

          o = deskbar_init(_malloc(sizeof(t_view)),r);

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

          its = load_it_from_dir_in_object( OBJECT(desktop),
                                            rect_assign( ( BarPosition == 1 ) ? r.b.x+10 : 10,
                                            ( BarPosition == 0 ) ? r.b.y+10 : 10,
                                            ( BarPosition == 3 ) ? r.a.x-10 : screen_width - 10,
                                            ( BarPosition == 2 ) ? r.a.y-10 : screen_height - 10 ) , "/");

          program.valid = &program_valid;

          o->draw_view(o);

          return OBJECT(o);
};

////////////////////////////////////////////////////////////////////////////////
SetInfoAppName("Desktop V");
SetInfoDesciption("A new desktop with taskbar and cool stuff");
SetInfoCopyright("(c) Copyright 2001 Point Mad. All rights reserved");
SetInfoManufacturer("Point Mad");

DLXUSE_BEGIN
  LIBLOADS_BEGIN
  LIBLOADS_END
  LIBEXPORT_BEGIN
    LIBEXPORT(add_to_userbox)
    LIBEXPORT(remove_from_userbox)
  LIBEXPORT_END
DLXUSE_END

////////////////////////////////////////////////////////////////////////////////
lib_begin ( void ) {

  if ( ap_process == AP_ALLOC ) {

          AP_EXPORTLIB(); /* export table defined by lib_exportable you find in seal.h */

  } else

  if ( ap_process == AP_INIT ) {

          p_stattext st;
          p_view br = NULL;
          struct time tm;

          AP_SETNUMOFCALLS(1); /* set max num of calls */

          if ( !key_exists("current/desktop/barpos") ) create_key("current/desktop","barpos");

          else BarPosition = get_key_integer("current/desktop/barpos");

          OBJECT(desktop)->insert = &dsk_insert;
          OBJECT(desktop)->remove = &dsk_remove;
          OBJECT(desktop)->insert_before = &dsk_insert_before;

          view_init = &dsk_view_init;



          init_desktop();

          get_programs_items();
          get_help_items();

          gettime(&tm);
          st = stattext_init(_malloc(sizeof(t_stattext)),rect_assign(0, 0, 30, 16),TX_ALIGN_CENTER,"%02d:%02d",tm.ti_hour,tm.ti_min);
          VIEW(st)->brush.color = color_deskbar_face;
          OBJECT(st)->func_callback = &clock_func_callback;
          st->color_text = color_deskbar_text;
          add_to_userbox(OBJECT(st));

          memb = load_image("bmp/mem.bmp");

          br = view_init( _malloc(sizeof(t_view)),rect_assign(0, 0, 16, 16) );
          VIEW(br)->draw = &dmpi_draw;
          OBJECT(br)->func_callback = &dmpi_real_func_callback;

          add_to_userbox(OBJECT(br));

          init_stillprocess ( OBJECT(st), 1000 );
          init_stillprocess ( OBJECT(br), 1000 );



  } else

  if ( ap_process == AP_FREE ) { /* releasing of library */


  };


} lib_end;

⌨️ 快捷键说明

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