home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Sound / Amster / Source / info.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-14  |  4.1 KB  |  160 lines

  1. /*
  2. ** Amster - Information
  3. ** Copyright © 1999-2000 by Gürer Özen
  4. ** Copyright © 2000-2001 by Jacob Laursen
  5. **
  6. ** This program is free software; you can redistribute it and/or modify
  7. ** it under the terms of the GNU General Public License as published by
  8. ** the Free Software Foundation; either version 2 of the License, or
  9. ** (at your option) any later version.
  10. **
  11. ** This program is distributed in the hope that it will be useful,
  12. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ** GNU General Public License for more details.
  15. **
  16. ** You should have received a copy of the GNU General Public License
  17. ** along with this program; if not, write to the Free Software
  18. ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19. */
  20.  
  21. #include "amster.h"
  22.  
  23. #include <MUI/NListview_mcc.h>
  24.  
  25. #include "amster_Cat.h"
  26.  
  27. #ifdef AMSTER_DEBUG
  28. #include <proto/dos.h>
  29. #endif
  30.  
  31. ULONG info_new(struct IClass *cl, Object *obj, struct opSet *msg);
  32.  
  33. #ifdef AMSTER_DEBUG
  34. BPTR fh;
  35. #endif
  36.  
  37.  
  38. MUI_DISPATCH(info_dispatch)
  39. {
  40.     switch(msg->MethodID) {
  41.         case OM_NEW: return(info_new(cl,obj,(APTR)msg));
  42. #ifdef AMSTER_DEBUG
  43. case OM_DISPOSE:
  44. if (fh) Close(fh);
  45. break;
  46. #endif
  47.         case INFO_MSG:
  48.             {
  49.             struct infodata *data = INST_DATA(cl, obj);
  50. #ifdef AMSTER_DEBUG
  51.             struct DateStamp *ds, *rds;
  52.             char line[1024];
  53.  
  54.             if (strlen((char *)((muimsg)msg)->arg1) > 800) {
  55.                 MUI_Request(gui->app, gui->win, 0L,
  56.                 "Danger!",
  57.                 (char *)MSG_OK_GAD,
  58.                 "Please report this to Laursen immediately:\nINFO_MSG - length: %ld\n(when did it happen and what was\nwritten to the debug window at the time?)",
  59.                 strlen((char *)((muimsg)msg)->arg1));
  60.             }
  61.  
  62.             if (ds = malloc(sizeof(struct DateStamp))) {
  63.                 memset(ds, 0, sizeof(struct DateStamp));
  64.                 if (rds = DateStamp(ds)) {
  65.                     sprintf(line, "[%02d:%02d:%02d.%02d] %s", rds->ds_Minute/60, rds->ds_Minute%60, rds->ds_Tick/50, rds->ds_Tick%50, (char *)((muimsg)msg)->arg1);
  66.  
  67.                     DoMethod(data->msglist, MUIM_NList_InsertSingle, line, MUIV_NList_Insert_Bottom);
  68.                     set(data->msglist, MUIA_NList_First, MUIV_NList_Active_Bottom);
  69.                 }
  70.                 free(ds);
  71.             }
  72.  
  73.             if (fh) {
  74.                 Write(fh, line, strlen(line));
  75.                 Write(fh, "\n", 1);
  76.             }
  77. #else
  78.             DoMethod(data->msglist, MUIM_NList_InsertSingle, (char *)((muimsg)msg)->arg1, MUIV_NList_Insert_Bottom);
  79.             set(data->msglist, MUIA_NList_First, MUIV_NList_Active_Bottom);
  80. #endif
  81.             return(NULL);
  82.             }
  83.     }
  84.     return(DoSuperMethodA(cl, obj, msg));
  85. }
  86.  
  87.  
  88. ULONG info_new(struct IClass *cl, Object *obj, struct opSet *msg)
  89. {
  90.     struct infodata *data;
  91.     Object *msglist,*clrbut;
  92.  
  93.     if (obj = (Object *)DoSuperNew(cl,obj,
  94.         MUIA_HelpNode, "info",
  95.         WindowContents, VGroup,
  96.             Child, NListviewObject,
  97.                 MUIA_NListview_NList, msglist = NListObject,
  98.                     ReadListFrame,
  99.                     MUIA_NList_Input, FALSE,
  100.                     MUIA_NList_AutoCopyToClip, TRUE,
  101.                     MUIA_NList_TypeSelect, MUIV_NList_TypeSelect_Char,
  102.                     MUIA_NList_ConstructHook, MUIV_NList_ConstructHook_String,
  103.                     MUIA_NList_DestructHook, MUIV_NList_DestructHook_String,
  104.                     MUIA_NList_AutoVisible, TRUE,
  105.                 End,
  106.             End,
  107.             Child, HGroup,
  108.                 Child, HSpace(0),
  109.                 Child, clrbut = SimpleButton(MSG_INFO_CLEAR),
  110.             End,
  111.         End,
  112.         TAG_MORE, msg->ops_AttrList))
  113.     {
  114.         data = INST_DATA(cl,obj);
  115.         data->msglist = msglist;
  116.  
  117.         set(obj,MUIA_Window_ID,MAKE_ID('I','N','F','O'));
  118.         set(obj,MUIA_Window_Title,MSG_INFO_TITLE),
  119.  
  120.         DoMethod(obj, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, gui->iconpanel, 1, PANEL_CLOSEDEBUG);
  121.         DoMethod(clrbut, MUIM_Notify, MUIA_Pressed, FALSE, msglist, 1, MUIM_NList_Clear);
  122.  
  123. #ifdef AMSTER_DEBUG
  124. fh = Open("RAM:Amster.debug", MODE_READWRITE);
  125. if (fh) Seek(fh, 0, OFFSET_END);
  126. #endif
  127.  
  128.         return((ULONG)obj);
  129.     }
  130.     return(0);
  131. }
  132.  
  133.  
  134. void gui_debug(char *msg)
  135. {
  136.     DoMethod(gui->iwin, INFO_MSG, msg);
  137. }
  138.  
  139.  
  140. void gui_debugf(char *msg, ...)
  141. {
  142.     static char buf[1024];
  143.     va_list ap;
  144.  
  145. #ifdef AMSTER_DEBUG
  146. if (strlen(msg) > 800) {
  147.     MUI_Request(gui->app, gui->win, 0L,
  148.         "Danger!",
  149.         (char *)MSG_OK_GAD,
  150.         "Please report this to Laursen immediately:\ngui_debugf - length: %ld\n(when did it happen and what was\nwritten to the debug window at the time?)",
  151.         strlen(msg));
  152. }
  153. #endif
  154.  
  155.     va_start(ap,msg);
  156.     vsprintf(buf,msg,ap);
  157.     va_end(ap);
  158.     gui_debug(buf);
  159. }
  160.