home *** CD-ROM | disk | FTP | other *** search
- /* $Id: wgrab.c,v 1.2 1995/10/29 10:50:38 aris Exp aris $
- */
- #define CATCOMP_ARRAY
- #include "wgrab.h"
- #include "wgrab_cat.h"
- #include <clib/commodities_protos.h>
- #include <libraries/commodities.h>
- #include <clib/locale_protos.h>
- #include <libraries/locale.h>
- #include <time.h>
-
-
- #define _DEFPOPUP_ "lalt w"
- #define _DEFWGRAB_ "lalt g"
- #define _DEFSGRAB_ "lalt c"
-
- #ifdef IFFBASE
- #define MYLIBBASE IFFBase
- #endif
- #ifdef DATATYPES
- #define MYLIBBASE DataTypesBase
- #endif
-
- struct Library *MYLIBBASE,*IconBase;
- struct Library *CxBase;
- struct LocaleBase *LocaleBase;
-
- enum {EID_AMODE=1,EID_DMODE,EID_FILENAME,EID_MHOTKEY,EID_GWHOTKEY,EID_GSHOTKEY,};
- enum {ID_SAVE=1,
- ID_USE,
- ID_HIDE,
- ID_ABOUT,
- ID_QUIT,
- ID_AMODEON,ID_AMODEOFF,
- ID_DMODEON,ID_DMODEOFF,
- MN_PROJECT,MN_SETTINGS,
- ID_LOAD,ID_LOADENV,ID_LOADDEF,};
- enum {HOTKEY_MAIN,HOTKEY_WGRAB,HOTKEY_SGRAB,};
-
- APTR App,mwin,fname,dmode,amode,mhotkey,pfname,mn_main;
- APTR gwhotkey,gshotkey,bt_save,bt_use,bt_quit,helptx;
-
- CxObj *broker;
- struct MsgPort *broker_port;
- CxObj *cmhotkey,*cgwhotkey,*cgshotkey;
- struct Catalog *mycatalog;
-
- #define setmnlabel(number,label,comm) mn_data[number].nm_Label=lgetstring(label);\
- mn_data[number].nm_CommKey=((comm)?lgetstring(comm):0)
- #define menuBAR {NM_ITEM,NM_BARLABEL,0,0,0,(APTR)0}
-
- /*FOLDER Compute Hotkey String
- */
- char *mhotkeystr(void)
- {
- char *str=(char *)malloc(sizeof(char)*30);
- char *ht=(char *)malloc(sizeof(char)*30);
- get(mhotkey,MUIA_String_Contents,&ht);
- sprintf(str,"rawkey %s",ht);
- return(str);
- }
- char *gwhotkeystr(void)
- {
- char *str=(char *)malloc(sizeof(char)*30);
- char *ht=(char *)malloc(sizeof(char)*30);
- get(gwhotkey,MUIA_String_Contents,&ht);
- sprintf(str,"rawkey %s",ht);
- return(str);
- }
- char *gshotkeystr(void)
- {
- char *str=(char *)malloc(sizeof(char)*30);
- char *ht=(char *)malloc(sizeof(char)*30);
- get(gshotkey,MUIA_String_Contents,&ht);
- sprintf(str,"rawkey %s",ht);
- return(str);
- }
- /*END*/
- void setnewhotkeys(void)
- {
- RemoveCxObj(cmhotkey);
- RemoveCxObj(cgwhotkey);
- RemoveCxObj(cgshotkey);
- DeleteCxObj(cmhotkey);
- DeleteCxObj(cgwhotkey);
- DeleteCxObj(cgshotkey);
- cmhotkey=HotKey(mhotkeystr(),broker_port,HOTKEY_MAIN);
- cgwhotkey=HotKey(gwhotkeystr(),broker_port,HOTKEY_WGRAB);
- cgshotkey=HotKey(gshotkeystr(),broker_port,HOTKEY_SGRAB);
- AttachCxObj(broker,cmhotkey);
- AttachCxObj(broker,cgwhotkey);
- AttachCxObj(broker,cgshotkey);
- }
-
- /*FOLDER DoGrab
- */
- void dograb(BOOL screen)
- {
- APTR req;
- long ask,dmod;
- char *filename=(char *)malloc(sizeof(char)*256);
- char *file;
- char *dir=(char *)malloc(sizeof(char)*256);
- char *sfile;
- struct TagItem AslTags[]={ASLFR_DoSaveMode,(ULONG)TRUE,
- ASLFR_TitleText,(ULONG)"Chose Filename to Save to!",
- ASLFR_InitialDrawer,(ULONG)NULL,
- TAG_DONE,0};
- Object *picture;
-
- picture=GetPicture(screen);
-
- if (picture) {
-
- get(fname,MUIA_String_Contents,&sfile);
- get(amode,MUIA_Selected,&ask);
-
- if (ask) {
-
- if (req=MUI_AllocAslRequest(0,NULL)) {
-
- if (sfile) {
-
- stcgfp(dir,sfile);
- AslTags[2].ti_Data=(ULONG)dir;
-
- }
-
- if (MUI_AslRequest(req,AslTags)) {
-
- filename=((struct FileRequester *)req)->fr_Drawer;
- file=((struct FileRequester *)req)->fr_File;
- AddPart(filename,file,256);
- SavePicture(picture,filename);
- MUI_FreeAslRequest(req);
- return;
- }
- MUI_FreeAslRequest(req);
- }
- }
- get(dmode,MUIA_Selected,&dmod);
-
- if (dmod) {
-
- struct tm *p;
- long t;
-
- time(&t);
- p=localtime(&t);
- stcgfp(filename,sfile);
- sprintf(dir,"pic%d.%d.%d.iff",p->tm_hour,p->tm_min,p->tm_sec);
- AddPart(filename,dir,256);
- SavePicture(picture,filename);
- return;
- }
- SavePicture(picture,sfile);
- return;
- }
- MUI_Request(App,NULL,0,NULL,"*_OK","I Can`t Get Active Window !!",TAG_END);
- }
- /*END*/
- /*FOLDER Locale lgetstring Function
- */
- static STRPTR lgetstring(long id)
- {
- STRPTR builtin;
- builtin=malloc(sizeof(char)*255);
- strcpy(builtin,CatCompArray[id].cca_Str);
- if (LocaleBase) {
- strcpy(builtin,GetCatalogStr(mycatalog,id,builtin));
- }
- return(builtin);
- }
- /*END*/
-
- /*FOLDER Broker Hook
- */
- _HOOK_FUNC (long,cxhook,struct Hook *hook,APTR obj,CxMsg *cm)
- {
-
- switch (CxMsgType(cm)) {
- case CXM_COMMAND:
- switch (CxMsgID(cm)) {
- case CXCMD_DISABLE:
- case CXCMD_ENABLE:
- break;
- case CXCMD_KILL:
- DoMethod(obj,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
- break;
- case CXCMD_APPEAR:
- set(mwin,MUIA_Window_Open,TRUE);
- break;
- case CXCMD_DISAPPEAR:
- set(mwin,MUIA_Window_Open,FALSE);
- set(App,MUIA_Application_Iconified,TRUE);
- break;
- }
- break;
- case CXM_IEVENT:
- switch (CxMsgID(cm)) {
- case HOTKEY_MAIN:
- DoMethod(obj,MUIM_Application_ReturnID,ID_HIDE);
- break;
- case HOTKEY_WGRAB:
- dograb(FALSE);
- break;
- case HOTKEY_SGRAB:
- dograb(TRUE);
- break;
- }
- break;
- }
- return(0);
- }
- struct Hook cx_hook={
- {NULL,NULL},
- (void *)cxhook,
- NULL,NULL
- };
- /*END*/
- _HOOK_FUNC(void,HelpFunc,struct Hook *hook,Object *help,Object **objptr)
- {
- LONG udata=NULL;
- if (*objptr) get(*objptr,MUIA_UserData,&udata);
- set(helptx,MUIA_Text_Contents,udata);
- }
- /*FOLDER ReadArgs
- */
- BOOL popup(long argc, UBYTE **argv)
- {
- UBYTE **tt;
- BOOL retval=FALSE;
- struct RDArgs *rarg;
- long vnp;
- long args[]={0};
-
- if (argc==0) {
- if (IconBase=OpenLibrary("icon.library",0)) {
- tt=ArgArrayInit(argc,argv);
- vnp=ArgInt(tt,"POPUP",-5);
- if (vnp>-5) retval=TRUE;
- ArgArrayDone();
- CloseLibrary(IconBase);
- }
- }
- else {
- if (rarg=ReadArgs("POPUP/S",args,NULL)) {
- retval=args[0];
- FreeArgs(rarg);
- }
- }
- return(retval);
- }
- /*END*/
-
-
- void main(long argc,UBYTE **argv)
- {
- BOOL running=TRUE,pop;
- long active,on;
- ULONG signals;
- static struct Hook help_hook={{0,0},(void *)HelpFunc,0,0};
- struct NewMenu mn_data[]={
- {NM_TITLE,"",0,0,0,(APTR)MN_PROJECT},
- {NM_ITEM,"","",0,0,(APTR)ID_ABOUT},
- menuBAR,
- {NM_ITEM,"","",0,0,(APTR)ID_HIDE},
- menuBAR,
- {NM_ITEM,"","",0,0,(APTR)ID_QUIT},
- {NM_TITLE,"",0,0,0,(APTR)MN_SETTINGS},
- {NM_ITEM,"","",0,0,(APTR)ID_LOAD},
- {NM_ITEM,"","",0,0,(APTR)ID_LOADENV},
- {NM_ITEM,"","",0,0,(APTR)ID_LOADDEF},
- menuBAR,
- {NM_ITEM,"","",0,0,(APTR)ID_USE},
- {NM_ITEM,"","",0,0,(APTR)ID_SAVE},
- {NM_END,NULL,0,0,0,(APTR)0},
- };
-
-
- init();
- if (!(MYLIBBASE=OpenLibrary(MYLIBNAME,0)))
- fail(NULL,"Can`t Open library!!");
- if (!(CxBase=OpenLibrary("commodities.library",0))) {
- CloseLibrary(MYLIBBASE);
- fail(NULL,"Can`t Open commodities.library!!");
- }
- if (LocaleBase=(struct LocaleBase *)OpenLibrary("locale.library",0)) {
- mycatalog=OpenCatalog(NULL,"wgrab.catalog",OC_BuiltInLanguage,(ULONG)"english",
- OC_Version,(ULONG)1,
- TAG_DONE,(ULONG)NULL);
- }
-
- setmnlabel(0,MSG_PROJECT,NULL);
- setmnlabel(1,MSG_ABOUT,MSG_ABOUT_SC);
- setmnlabel(3,MSG_HIDE,MSG_HIDE_SC);
- setmnlabel(5,MSG_QUIT,MSG_QUIT_SC);
- setmnlabel(6,MSG_SETTINGS,NULL);
- setmnlabel(7,MSG_LOAD,NULL);
- setmnlabel(8,MSG_LOADENV,NULL);
- setmnlabel(9,MSG_LOADDEF,NULL);
- setmnlabel(11,MSG_USE,NULL);
- setmnlabel(12,MSG_SAVE,NULL);
-
- pop=popup(argc,argv);
-
- App = ApplicationObject,
- MUIA_Application_Title,"WGrab",
- MUIA_Application_Version,"$VER: WGrab 01.30 (29.10.95)",
- MUIA_Application_Copyright,"© 1995 Aris Basic",
- MUIA_Application_Author,"Aris Basic",
- MUIA_Application_Description,"Saves Active Window As IFF Picture",
- MUIA_Application_Base,"WGRAB",
- MUIA_Application_BrokerHook,&cx_hook,
- MUIA_Application_SingleTask,TRUE,
- MUIA_Application_Window,mwin=WindowObject,
- MUIA_Window_ID,MAKE_ID('M','A','I','N'),
- MUIA_Window_Title,"WGrab 01.30",
- MUIA_Window_NeedsMouseObject,TRUE,
- MUIA_Window_Menustrip,mn_main=MUI_MakeObject(MUIO_MenustripNM,mn_data,0),
- WindowContents,VGroup,
- Child,HGroup,
- Child,Label(lgetstring(MSG_ASK_BEFORE)),
- Child,amode=ImageObject,
- ImageButtonFrame,
- MUIA_InputMode,MUIV_InputMode_Toggle,
- MUIA_Image_Spec,MUII_CheckMark,
- MUIA_Image_FreeVert,TRUE,
- MUIA_Selected,TRUE,
- MUIA_Background,MUII_ButtonBack,
- MUIA_ShowSelState,FALSE,
- MUIA_ExportID,EID_AMODE,
- MUIA_UserData,lgetstring(MSG_ASK_HELP),
- End,
- Child,Label(lgetstring(MSG_FILENAME)),
- Child,pfname=PopaslObject,
- MUIA_Popstring_String,fname=StringObject,
- StringFrame,
- MUIA_String_MaxLen,256,
- MUIA_String_Contents,"RAM:",
- MUIA_ExportID,EID_FILENAME,
- End,
- MUIA_Popstring_Button,PopButton(MUII_PopFile),
- MUIA_Disabled,TRUE,
- MUIA_UserData,lgetstring(MSG_FILENAME_HELP),
- ASLFR_SleepWindow,TRUE,
- End,
- Child,Label(lgetstring(MSG_DIR_MODE)),
- Child,dmode=ImageObject,
- ImageButtonFrame,
- MUIA_InputMode,MUIV_InputMode_Toggle,
- MUIA_Image_Spec,MUII_CheckMark,
- MUIA_Image_FreeVert,TRUE,
- MUIA_Selected,FALSE,
- MUIA_Background,MUII_ButtonBack,
- MUIA_ShowSelState,FALSE,
- MUIA_ExportID,EID_DMODE,
- MUIA_Disabled,TRUE,
- MUIA_UserData,lgetstring(MSG_DIR_MODE_HELP),
- End,
- End,
- Child,ColGroup(2),
- Child,Label(lgetstring(MSG_HOTKEY_POPUP)),
- Child,mhotkey=StringObject,
- StringFrame,
- MUIA_String_MaxLen,20,
- MUIA_String_Contents,_DEFPOPUP_,
- MUIA_ExportID,EID_MHOTKEY,
- MUIA_UserData,lgetstring(MSG_HOTKEY_POPUP_HELP),
- End,
- Child,Label(lgetstring(MSG_HOTKEY_WGRAB)),
- Child,gwhotkey=StringObject,
- StringFrame,
- MUIA_String_MaxLen,20,
- MUIA_String_Contents,_DEFWGRAB_,
- MUIA_ExportID,EID_GWHOTKEY,
- MUIA_UserData,lgetstring(MSG_HOTKEY_WGRAB_HELP),
- End,
- Child,Label(lgetstring(MSG_HOTKEY_SGRAB)),
- Child,gshotkey=StringObject,
- StringFrame,
- MUIA_String_MaxLen,20,
- MUIA_String_Contents,_DEFSGRAB_,
- MUIA_ExportID,EID_GSHOTKEY,
- MUIA_UserData,lgetstring(MSG_HOTKEY_SGRAB_HELP),
- End,
- End,
- Child,helptx=TextObject,
- TextFrame,
- MUIA_Text_PreParse,"\033c\033b",
- MUIA_UserData,lgetstring(MSG_HELP_HELP),
- End,
- Child,HGroup,
- Child,bt_save=SimpleButton(lgetstring(MSG_GUI_SAVE)),
- Child,bt_use=SimpleButton(lgetstring(MSG_GUI_USE)),
- Child,bt_quit=SimpleButton(lgetstring(MSG_GUI_QUIT)),
- End,
- End,
- End,
- End;
-
- if (!App) {
- if (mycatalog) CloseCatalog(mycatalog);
- if (LocaleBase) CloseLibrary((struct Library *)LocaleBase);
- if (CxBase) CloseLibrary(CxBase);
- if (MYLIBBASE) CloseLibrary(MYLIBBASE);
- fail(App,"Could Not Create Application");
- }
-
- DoMethod(App,MUIM_Application_Load,MUIV_Application_Load_ENV);
-
- get(amode,MUIA_Selected,&active);
- if (!active) {
- set(pfname,MUIA_Disabled,FALSE);
- set(dmode,MUIA_Disabled,FALSE);
- }
- get(dmode,MUIA_Selected,&active);
- if (active) set(amode,MUIA_Disabled,TRUE);
-
-
- DoMethod(bt_quit,MUIM_Notify,MUIA_Pressed,FALSE,App,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
- DoMethod(bt_save,MUIM_Notify,MUIA_Pressed,FALSE,App,2,MUIM_Application_ReturnID,ID_SAVE);
- DoMethod(bt_use,MUIM_Notify,MUIA_Pressed,FALSE,App,2,MUIM_Application_ReturnID,ID_USE);
- DoMethod(mwin,MUIM_Notify,MUIA_Window_MouseObject,MUIV_EveryTime,helptx,3,MUIM_CallHook,&help_hook,MUIV_TriggerValue);
- DoMethod(amode,MUIM_Notify,MUIA_Selected,TRUE,App,2,MUIM_Application_ReturnID,ID_AMODEON);
- DoMethod(amode,MUIM_Notify,MUIA_Selected,FALSE,App,2,MUIM_Application_ReturnID,ID_AMODEOFF);
- DoMethod(dmode,MUIM_Notify,MUIA_Selected,TRUE,App,2,MUIM_Application_ReturnID,ID_DMODEON);
- DoMethod(dmode,MUIM_Notify,MUIA_Selected,FALSE,App,2,MUIM_Application_ReturnID,ID_DMODEOFF);
- DoMethod(mwin,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,App,2,MUIM_Application_ReturnID,ID_HIDE);
-
- get(App,MUIA_Application_Broker,&broker);
- get(App,MUIA_Application_BrokerPort,&broker_port);
-
- if (NULL==(cmhotkey=HotKey(mhotkeystr(),broker_port,HOTKEY_MAIN))) {
- CloseLibrary(CxBase);
- CloseLibrary(MYLIBBASE);
- fail(App,"Cannot Create Hotkeys!!");
- }
- if (NULL==(cgwhotkey=HotKey(gwhotkeystr(),broker_port,HOTKEY_WGRAB))) {
- CloseLibrary(CxBase);
- CloseLibrary(MYLIBBASE);
- fail(App,"Cannot Create Hotkeys!!");
- }
- if (NULL==(cgshotkey=HotKey(gshotkeystr(),broker_port,HOTKEY_SGRAB))) {
- CloseLibrary(CxBase);
- CloseLibrary(MYLIBBASE);
- fail(App,"Cannot Create Hotkeys!!");
- }
-
- AttachCxObj(broker,cmhotkey);
- AttachCxObj(broker,cgwhotkey);
- AttachCxObj(broker,cgshotkey);
-
- if (pop) set(mwin,MUIA_Window_Open,TRUE);
- else set(App,MUIA_Application_Iconified,TRUE);
-
- while (running) {
- switch (DoMethod(App,MUIM_Application_Input,&signals))
- {
- case MUIV_Application_ReturnID_Quit:
- running=FALSE;
- break;
- case ID_AMODEON:
- get(dmode,MUIA_Selected,&active);
- if (active) set(dmode,MUIA_Selected,FALSE);
- set(dmode,MUIA_Disabled,TRUE);
- set(pfname,MUIA_Disabled,TRUE);
- break;
- case ID_AMODEOFF:
- set(dmode,MUIA_Disabled,FALSE);
- set(pfname,MUIA_Disabled,FALSE);
- break;
- case ID_DMODEON:
- get(amode,MUIA_Selected,&active);
- if (active) set(amode,MUIA_Selected,FALSE);
- set(amode,MUIA_Disabled,TRUE);
- break;
- case ID_DMODEOFF:
- set(amode,MUIA_Disabled,FALSE);
- break;
- case ID_SAVE:
- DoMethod(App,MUIM_Application_Save,MUIV_Application_Save_ENVARC);
- case ID_USE:
- DoMethod(App,MUIM_Application_Save,MUIV_Application_Save_ENV);
- setnewhotkeys();
- case ID_HIDE:
- get(App,MUIA_Application_Iconified,&on);
- if(!on) {
- set(mwin,MUIA_Window_Open,FALSE);
- set(App,MUIA_Application_Iconified,TRUE);
- }
- else {
- set(App,MUIA_Application_Iconified,FALSE);
- set(mwin,MUIA_Window_Open,TRUE);
- }
- break;
- case ID_LOAD:
- DoMethod(App,MUIM_Application_Load,MUIV_Application_Load_ENV);
- case ID_LOADENV:
- DoMethod(App,MUIM_Application_Load,MUIV_Application_Load_ENVARC);
- setnewhotkeys();
- break;
- case ID_LOADDEF:
- set(amode,MUIA_Selected,TRUE);
- set(dmode,MUIA_Disabled,TRUE);
- set(amode,MUIA_Disabled,FALSE);
- set(dmode,MUIA_Selected,FALSE);
- set(pfname,MUIA_Disabled,TRUE);
- break;
- case ID_ABOUT:
- MUI_Request(App,mwin,0,NULL,"*_OK","\033c\033bWGrab 01.30\n\033n"
- "© Aris Basic\n\n"
- "This Program Uses MUI \n© Stefan Stuntz",TAG_DONE);
- break;
- }
- if (running && signals) Wait(signals);
- }
- set(mwin,MUIA_Window_Open,FALSE);
- if (mycatalog) CloseCatalog(mycatalog);
- if (LocaleBase) CloseLibrary((struct Library *)LocaleBase);
- if (CxBase) CloseLibrary(CxBase);
- if (MYLIBBASE) CloseLibrary(MYLIBBASE);
- fail(App,NULL);
- }
-
-
-
-
-