📄 desktop5.c
字号:
/******************************************************************
* 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.
*/
/* Revision History (as of 01/04/2002):
*
* 01/04/2002 - Changed lnk_nice_link to lnk_get_title (orudge)
* 10/04/2002 - Added routine to ignore DESKTOP.INF files from Bad Desktop (orudge)
*/
#include <seal.h>
#include <txts.h>
#include <menus.h>
#include <button.h>
#include <app.h>
#include <cp.h>
#include <colors.h>
#include <bmps.h>
#include <vfile.h>
#include <files.h>
#include <unistd.h>
#include <dir.h>
#include <lnk.h>
#include <screen.h>
#include <stattext.h>
#include <dos.h>
#include <time.h>
#include <dialogs.h>
#include <grfx-f.h>
/* items of program menu */
static p_menuitem program_items = NULL;
/* items of help menu */
static p_menuitem help_items = NULL;
p_view IcoPrg = NULL, IcoSet = NULL, IcoDoc = NULL, IcoSht = NULL, Taskbar = NULL;
/* desktop menu about texts */
p_list Tasklst = NULL;
l_int BarPosition = 1;
p_object init_desktop ( void );
#define DIR_PROGRAMS "./PROGRAMS"
#define DIR_HELP "/documents/"
#define DIR_IGNORE '$'
#define MSG_RUNAPP 100110
#define MSG_xAPPLICATION 100111
#define MSG_xSETTINGS 100112
#define MSG_xHELP 100113
#define ID_SIZE 36 /* desktop icon size */
t_rect its_zone;
/* t_minmenuitem structure */
typedef struct t_minmenuitem *p_minmenuitem;
typedef struct t_minmenuitem {
struct t_menuitem obclass;
t_appinfo appinfo;
} t_minmenuitem;
/* t_filemenuitem structure */
typedef struct t_filemenuitem *p_filemenuitem;
typedef struct t_filemenuitem {
struct t_menuitem obclass;
l_text filename;
} t_filemenuitem;
#define new_minmenu_item(msg,f,next) \
new_minmenu_item_ex(f.title, NULL, 0, msg, true, NULL, 0, NULL, NULL, NULL, 0, f, next)
static p_minmenuitem new_minmenu_item_ex ( l_text name, l_text param, l_int hotkey, l_dword message,
l_bool enable, l_text info_text, l_int flags,
l_font *font, BITMAP *icon, l_font *font_symbol, l_byte chr,
t_appinfo info, p_menuitem next )
{
p_minmenuitem fi = (p_minmenuitem)_malloc(sizeof(t_minmenuitem));
p_menuitem f = new_menu_item_ex(name, param, hotkey, message, enable, info_text, flags, font, icon, font_symbol, chr, next);
if ( f && fi ) {
memcpy(fi, f, sizeof(t_menuitem));
fi->appinfo = info;
};
_free(f);
return fi;
};
#define new_sub_filemenu(name,f,menu,icon,next) \
new_sub_filemenu_ex(name, true, NULL, NULL, icon, NULL, 0, f, menu, next)
#define new_filemenu_item(name,param,hk,msg,it,f,icon,next) \
new_filemenu_item_ex(name, param, hk, msg, true, it, 0, NULL, icon, NULL, 0, f, next)
#define new_filemenu_check_item(name,param,is_check,hk,msg,it,f,next) \
new_filemenu_item_ex(name, param, hk, msg, true, it, MIF_CHECK+(is_check*MIF_CHECKOK), NULL, NULL, NULL, 0, f, next)
static p_filemenuitem new_filemenu_item_ex ( l_text name, l_text param, l_int hotkey, l_dword message,
l_bool enable, l_text info_text, l_int flags,
l_font *font, BITMAP *icon, l_font *font_symbol, l_byte chr,
l_text filename, p_menuitem next )
{
p_filemenuitem fi = (p_filemenuitem)sf_malloc(sizeof(t_filemenuitem));
p_menuitem f = new_menu_item_ex(name, param, hotkey, message, enable, info_text, flags, font, icon, font_symbol, chr, next);
if ( f && fi ) {
memcpy(fi, f, sizeof(t_menuitem));
fi->filename = _strdup(filename);
};
sf_free(f);
return fi;
};
static p_filemenuitem new_sub_filemenu_ex ( l_text name, l_bool enable, l_text info_text,
l_font *font, BITMAP *icon, l_font *font_symbol, l_byte chr,
l_text filename, p_menu menu, p_menuitem next )
{
p_filemenuitem fi = (p_filemenuitem)sf_malloc(sizeof(t_filemenuitem));
p_menuitem f = new_sub_menu_ex(name, enable, info_text, font, icon, font_symbol, chr, menu, next);
if ( f && fi ) {
memcpy(fi, f, sizeof(t_menuitem));
fi->filename = _strdup(filename);
};
sf_free(f);
return fi;
};
p_menuitem menu_load_from_dir ( l_text path, l_text filename )
{
struct t_ffblk f;
p_filemenuitem item = NULL;
p_menuitem first_menu = NULL;
l_int done = 0;
l_text fi = io_realpath(path, "*.*");
done = io_findfirst(fi, &f, FA_DIREC);
while ( !done ) {
if ( f.info.ff_attrib & FA_DIREC && io_isfilename(f.info.ff_name) &&
f.info.ff_name[0] != DIR_IGNORE ) {
l_text alld = io_realpath(path, f.info.ff_name);
if ( io_isdir(alld) ) {
l_text path2 = io_realpath(path, f.info.ff_name);
p_menuitem it = path2?menu_load_from_dir(path2, filename):NULL;
item = new_sub_filemenu(f.info.ff_name, alld, new_menu(it), get_icon_for_file(alld,f.info.ff_attrib,NULL), NULL);
first_menu = add_menu_item_to_menuitem(first_menu, (p_menuitem)item);
sf_free(path2);
};
sf_free(alld);
};
done = io_findnext(&f);
};
sf_free(fi);
fi = io_realpath(path, filename);
done = io_findfirst(fi, &f, FA_ARCH+FA_LINK);
while ( !done ) {
if (stricmp(f.ff_filename, "DESKTOP.INF") != 0) // OCR - 10/04/2002
{
if ( f.info.ff_attrib & FA_ARCH ) {
l_text allf = io_realpath(path, f.ff_filename);
l_text nicename = _strdup(lnk_get_title(allf)); //f.ff_filename); - OCR - 01/04/2002
// l_text nicename = lnk_nice_link(f.ff_filename);
// if ( io_isfile(allf) ) { /* it's file */
l_int mymem = 0;
BITMAP *icon = get_icon_for_file(allf,f.info.ff_attrib,&mymem);
item = new_filemenu_item_ex(nicename, NULL, 0, MSG_RUNAPP,
true, "", mymem?MIF_SELFICON:0, NULL, icon,
NULL, 0, allf, NULL);
first_menu = add_menu_item_to_menuitem(first_menu, (p_menuitem)item);
// };
_free(allf);
_free(nicename);
};
}
done = io_findnext(&f);
};
// DEBUG_printf("Desktop V: Done adding menu items for '%s'\n", path);
sf_free(fi);
return first_menu;
};
////////////////////////////////////////////////////////////////////////////////
void clock_func_callback ( p_object o ) {
struct time tm;
gettime(&tm);
STATTEXT(o)->set_text ( STATTEXT(o), "%02d:%02d",tm.ti_hour,tm.ti_min);
VIEW(o)->draw_me(VIEW(o));
};
BITMAP *memb = NULL;
////////////////////////////////////////////////////////////////////////////////
void dmpi_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 ) {
__dpmi_free_mem_info info;
l_uchar pc = 0;
l_color c;
__dpmi_get_free_memory_information(&info);
pc = info.total_number_of_free_pages*100/info.total_number_of_physical_pages;
if ( pc > 50 ) c = col2col( COLOR(CO_YELLOW),COLOR(CO_LIGHTGREEN), pc-50,50);
else c = col2col( COLOR(CO_LIGHTRED),COLOR(CO_YELLOW), pc,50);;
set_format_text(&o->info_text, "%d%% free memory", pc);
rectfill(out,p.x,p.y,p.x+r.b.x,p.y+r.b.y,color_deskbar_face);
if ( memb ) masked_blit(memb,out,0,0,p.x,p.y,memb->w,memb->h);
rectfill(out,p.x+4,p.y+3,p.x+10,p.y+7,c);
button(out,p.x+4,p.y+3,p.x+10,p.y+7,col2col(c,COLOR(0),1,2),col2col(c,COLOR(15),2,3));
};
o->end_of_paint(o, r);
};
////////////////////////////////////////////////////////////////////////////////
void dmpi_real_func_callback ( p_object o ) {
VIEW(o)->draw_me(VIEW(o));
};
////////////////////////////////////////////////////////////////////////////////
typedef struct t_it *p_it;
typedef struct t_it {
struct t_view obclass;
l_text filename;
l_text caption;
BITMAP *icon;
l_bool ownmem;
} t_it;
#define IT(o) ((p_it)(o))
p_list its = NULL;
#define MSG_IT_REORGANISE 6600
#define MSG_IT_OPEN_ME 6601
#define MSG_IT_DEL_ME 6602
static p_menuitem it_menu_items ( ) {
return new_menu_item_ex("Reorganise icons",NULL,NULL,MSG_IT_REORGANISE,true,NULL,NULL,NULL,NULL,NULL,0,
new_menu_item_ex("Open", NULL,NULL,MSG_IT_OPEN_ME, true,NULL,NULL,NULL,NULL,NULL,0,
new_menu_item_ex("Del" , NULL,NULL,MSG_IT_DEL_ME, true,NULL,NULL,NULL,NULL,NULL,0,
NULL)));
};
void it_save_pos ( p_it o ) {
l_text id = strupr(_strdup(o->filename));
l_long x, y;
x = VIEW(o)->bounds.a.x - its_zone.a.x;
y = VIEW(o)->bounds.a.y - its_zone.a.y;
setini_tofile ("desktop.inf", id, "X", (l_text)&x, INI_DECANUM);
setini_tofile ("desktop.inf", id, "Y", (l_text)&y, INI_DECANUM);
_free(id);
// Else system don't update icons position when move the taskbar
if (inimem) {_free(inimem);inimem=NULL;}
if (inisavefile) {_free(inisavefile);inisavefile=NULL;}
};
void popup_go_menu ( p_it o ) {
t_rect r = rect_assign(mouse->where.x,mouse->where.y,mouse->where.x,mouse->where.y);
t_event event;
p_menu m = new_menu( it_menu_items() );
p_menuview menu;
l_dword msg = NULL;
if ( m )
menu = menuview_init(malloc(sizeof(t_menuview)), r, m);
if ( menu )
msg = desktop->execute_view(desktop, VIEW(menu));
if ( msg == MSG_IT_REORGANISE ) {
t_rect rx = rect_assign(its_zone.a.x, its_zone.a.y, its_zone.a.x + 90, its_zone.a.y + 50);
p_item p = its->first(its);
p_item x = p;
do {
VIEW(p->rec)->change_bounds(VIEW(p->rec),rx);
it_save_pos(IT(p->rec));
rx.a.x += 90;
rx.b.x += 90;
if (rx.b.x > its_zone.b.x ) {
rx.a.x = its_zone.a.x;
rx.b.x = its_zone.a.x + 90;
rx.a.y += 60;
rx.b.y += 60;
};
p = p->next;
} while ( x != p );
} else if ( msg == MSG_IT_OPEN_ME ) {
run_file(o->filename);
} else if ( msg == MSG_IT_DEL_ME ) {
};
};
// Desktop's icons /////////////////////////////////////////////////////////////
void it_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 ) {
stretch_sprite(out, IT(o)->icon, r.a.x+p.x+((r.b.x-r.a.x)/2)-16, r.a.y+p.y, 32 , 32 );
textout_draw_rect_ex(out, o->font, IT(o)->caption, -1,
p.x + r.a.x,
p.y + r.a.y + 34,
p.x + r.b.x,
p.y + r.b.y,
TX_ALIGN_CENTERX, color_desktop_text, color_desktop_face, 1,2);
};
o->end_of_paint(o, r);
};
////////////////////////////////////////////////////////////////////////////////
void it_translate_event ( p_object o, t_event *event )
{
if ( event->type & EV_MOUSE ) {
if ( OBJECT(mouse)->state & MO_SF_MOUSELDOUBLE ) {
clear_event(event);
run_file(IT(o)->filename);
} else if ( OBJECT(mouse)->state & MO_SF_MOUSELDOWN ) {
l_word dm = (VIEW(o)->is_top_view(VIEW(o)) && VIEW(o)->drag_mode & DM_DRAGCONTEXT)?DM_DRAGCONTEXT:0;
t_rect old = VIEW(o)->bounds;
VIEW(o)->drag_view(VIEW(o), DM_DRAGMOVE+dm, event);
VIEW(o)->draw_me(VIEW(o));
if ( !rect_equals(old,VIEW(o)->bounds) ) it_save_pos(IT(o));
clear_event(event);
} else if ( OBJECT(mouse)->state & MO_SF_MOUSERUP ) {
clear_event(event);
popup_go_menu(IT(o));
};
};
};
l_bool it_done ( p_object o ) {
if ( IT(o)->filename ) _free(IT(o)->filename);
if ( IT(o)->caption ) _free(IT(o)->caption);
if ( IT(o)->ownmem && IT(o)->icon ) destroy_bitmap(IT(o)->icon);
return view_done(o);
};
////////////////////////////////////////////////////////////////////////////////
p_it _it_init ( p_it o, t_rect r, l_text filename , l_text caption , BITMAP *icon, l_bool ownmem )
{
if ( !o ) return NULL;
clear_type(o, sizeof(t_it));
view_init(VIEW(o), r);
o->filename = _strdup(filename);
o->caption = _strdup(caption);
o->icon = icon;
o->ownmem = ownmem;
VIEW(o)->drag_mode |= DM_DRAGMOVE+drag_context_ok*DM_DRAGCONTEXT;
VIEW(o)->draw_mode &= ~(DWM_CANTACCELMOVE*accel_moving_ok);
OBJECT(o)->translate_event = &it_translate_event;
OBJECT(o)->done = &it_done;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -