home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / c / intuitionpp / ipp / cwindow.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-05  |  5.8 KB  |  284 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. ///////////////////////////////////////////////////////////////////////////////
  3. ///////////////////                                        ////////////////////
  4. ///////////////////           file : cwindow.cc            ////////////////////
  5. ///////////////////                                        ////////////////////
  6. ///////////////////////////////////////////////////////////////////////////////
  7. ///////////////////////////////////////////////////////////////////////////////
  8.  
  9.  
  10. #include <intuition/intuitionbase.h>
  11. #include <graphics/gfxbase.h>
  12. #include <graphics/gfxmacros.h>
  13. #include <clib/graphics_protos.h>
  14. #include <clib/intuition_protos.h>
  15. #include <string.h>
  16.  
  17. //extern struct Library *OpenLibrary(char *, long);
  18. //extern void *CloseLibrary(struct Library *);
  19. //struct IntuitionBase *IntuitionBase=NULL;
  20. //struct GfxBase *GfxBase=NULL;
  21.  
  22.  
  23. struct ExtNewWindow WindowData = {
  24.     50,50,
  25.     200,200,
  26.     0,1,
  27.     CLOSEWINDOW,
  28.     WINDOWSIZING+WINDOWDRAG+WINDOWDEPTH+WINDOWCLOSE+ACTIVATE+NOCAREREFRESH+GIMMEZEROZERO,
  29.     (struct Gadget *)NULL,
  30.     (struct Image *)NULL,
  31.     (UBYTE *)"CWindow",
  32.     (struct Screen *)NULL,
  33.     (struct BitMap *)NULL,
  34.     50,50,
  35.     100,100,
  36.     WBENCHSCREEN,
  37.     (struct TagItem *)NULL
  38. };
  39.  
  40.  
  41.  
  42. #include "cwindow.h"
  43. #include "cscreen.h"
  44.  
  45. BOOL CWindow :: initlibs()
  46. {
  47. //    IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 0);
  48. //    if (IntuitionBase == NULL) return FALSE;
  49. //    GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0);
  50. //    if (GfxBase == NULL)
  51. //    {
  52. //        CloseLibrary((struct Library *)IntuitionBase);
  53. //        return FALSE;
  54. //    }
  55.     return TRUE;
  56. }
  57.  
  58.  
  59. CWindow :: CWindow()
  60. {
  61.     if (!initlibs()) return;
  62.     newwind=NULL;
  63.     wind=NULL;
  64.     newwind=new ExtNewWindow;
  65.     if (newwind==NULL) return;
  66.     *newwind=WindowData;
  67. }
  68.  
  69.  
  70. CWindow :: CWindow(struct NewWindow *neww)
  71. {
  72.     if (!initlibs()) return;
  73.     newwind=NULL;
  74.     wind=NULL;
  75.     newwind=new ExtNewWindow;
  76.     if (newwind==NULL) return;
  77.     memcpy((void *)newwind,(void *)neww,sizeof(struct NewWindow));
  78.     newwind->Extension=NULL;
  79. }
  80.  
  81. CWindow :: CWindow(struct ExtNewWindow *neww)
  82. {
  83.     if (!initlibs()) return;
  84.     newwind=NULL;
  85.     wind=NULL;
  86.     newwind=new ExtNewWindow;
  87.     if (newwind==NULL) return;
  88.     *newwind=*neww;
  89. }
  90.  
  91.  
  92. CWindow :: CWindow(struct NewWindow *neww ,struct TagItem *tags)
  93. {
  94.     if (!initlibs()) return;
  95.     newwind=NULL;
  96.     wind=NULL;
  97.     newwind=new ExtNewWindow;
  98.     if (newwind==NULL) return;
  99.     if (neww) memcpy((void *)newwind,(void *)neww,sizeof(struct NewWindow));
  100.     else *newwind=WindowData;    
  101.     newwind->Extension=tags;
  102. }
  103.  
  104.  
  105. CWindow :: ~CWindow()
  106. {
  107.     close();
  108.     if (screen) screen->rmwindow(*this);
  109.     if (newwind) delete newwind;
  110. //    if (GfxBase) CloseLibrary((struct Library *)GfxBase);
  111. //    if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
  112. }
  113.  
  114.  
  115. BOOL CWindow :: open()
  116. {
  117.     if (wind) CloseWindow(wind);
  118.     newwind->Screen=NULL;
  119.     newwind->Type=WBENCHSCREEN;
  120.     if (screen)
  121.     {
  122.         if (screen->isopen())
  123.         {
  124.             newwind->Screen=screen->scr;
  125.             newwind->Type=CUSTOMSCREEN;
  126.         }
  127.     }
  128.     wind=(struct Window *)OpenWindowTagList((struct NewWindow *)newwind, newwind->Extension);
  129.     return isopen();
  130. }
  131.  
  132.  
  133. BOOL CWindow :: isopen() { return (wind!=NULL); }
  134.  
  135.  
  136. void CWindow :: close()
  137. {
  138.     if (isopen())
  139.     {
  140.         newwind->LeftEdge=wind->LeftEdge;
  141.         newwind->TopEdge=wind->TopEdge;
  142.         newwind->Width=wind->Width;
  143.         newwind->Height=wind->Height;
  144.         newwind->MinWidth=wind->MinWidth;
  145.         newwind->MinHeight=wind->MinHeight;
  146.         newwind->MaxWidth=wind->MaxWidth;
  147.         newwind->MaxHeight=wind->MaxHeight;
  148.         newwind->Flags=wind->Flags;
  149.         CloseWindow(wind);
  150.         wind=NULL;
  151.     }
  152. }
  153.  
  154.  
  155. void CWindow :: update()
  156. {
  157.     if (isopen())
  158.     {
  159.         CloseWindow(wind);
  160.         wind=(struct Window *)OpenWindowTagList((struct NewWindow *)newwind, newwind->Extension);
  161.     }    
  162. }
  163.  
  164. void CWindow :: resize(int x, int y)
  165. {
  166.     newwind->Width=x;
  167.     newwind->Height=y;
  168.     if (isopen()) SizeWindow(wind,x,y);
  169. }
  170.  
  171.  
  172. void CWindow :: move(int x, int y)
  173. {
  174.     newwind->LeftEdge+=x;
  175.     newwind->TopEdge+=y;
  176.     if (isopen()) MoveWindow(wind,x,y);
  177. }
  178.  
  179.  
  180. void CWindow :: setpos(int x, int y)
  181. {
  182.     newwind->LeftEdge=x;
  183.     newwind->TopEdge=y;
  184.     if (isopen()) MoveWindow(wind,x-wind->LeftEdge,y-wind->TopEdge);
  185. }
  186.  
  187.  
  188. void CWindow :: settitle(char *Wtitle)
  189. {
  190.     newwind->Title=(UBYTE *)Wtitle;
  191.     if (wind) SetWindowTitles(wind,(UBYTE *)Wtitle,(UBYTE *)Wtitle);
  192. }
  193.  
  194.  
  195. BOOL CWindow :: setlimit(int minw, int minh, int maxw, int maxh)
  196. {
  197.     newwind->MinWidth=minw;
  198.     newwind->MinHeight=minh;
  199.     newwind->MaxWidth=maxw;
  200.     newwind->MaxHeight=maxh;
  201.     return WindowLimits(wind,minw, minh, maxw, maxh);
  202. }
  203.  
  204.  
  205. ULONG CWindow :: setflags(ULONG flags)
  206. {
  207. ULONG oldf;
  208.     oldf=newwind->Flags;
  209.     newwind->Flags=(ULONG)flags;
  210.     update();
  211.     return oldf;
  212. }
  213.  
  214.  
  215. void CWindow :: setpointer(UWORD *sprite, int h, int w, int xo, int yo)
  216. {
  217.     if (isopen()) SetPointer(wind,sprite,h,w,xo,yo);
  218. }
  219.  
  220.  
  221. void CWindow :: clearpointer()
  222. {
  223.     if (isopen()) ClearPointer(wind);
  224. }
  225.  
  226.  
  227. void CWindow :: refreshframe()
  228. {
  229.     if (isopen()) RefreshWindowFrame(wind);
  230. }
  231.  
  232.  
  233. void CWindow :: tofront()
  234. {
  235.     if (isopen()) WindowToFront(wind);
  236. }
  237.  
  238.  
  239. void CWindow :: toback()
  240. {
  241.     if (isopen()) WindowToBack(wind);
  242. }
  243.  
  244.  
  245. void CWindow :: activate()
  246. {
  247.     if (isopen()) ActivateWindow(wind);
  248. }
  249.  
  250.  
  251. int CWindow :: leftedge() { return isopen()?wind->LeftEdge:newwind->LeftEdge; }
  252.  
  253. int CWindow :: topedge() { return isopen()?wind->TopEdge:newwind->TopEdge; }
  254.  
  255. int CWindow :: width() { return isopen()?wind->Width:newwind->Width; }
  256.  
  257. int CWindow :: height() { return isopen()?wind->Height:newwind->Height; }
  258.  
  259. int CWindow :: minwidth() { return isopen()?wind->MinWidth:newwind->MinWidth; }
  260.  
  261. int CWindow :: minheight() { return isopen()?wind->MinHeight:newwind->MinHeight; }
  262.  
  263. int CWindow :: maxwidth() { return isopen()?wind->MaxWidth:newwind->MaxWidth; }
  264.  
  265. int CWindow :: maxheight() { return isopen()?wind->MaxHeight:newwind->MaxHeight; }
  266.  
  267. unsigned long CWindow :: flags() { return isopen()?wind->Flags:newwind->Flags; }
  268.  
  269. int CWindow :: mousex()
  270. {
  271.     if (!isopen()) return 0;
  272.     return wind->MouseX;
  273. }
  274.  
  275. int CWindow :: mousey()
  276. {
  277.     if (!isopen()) return 0;
  278.     return wind->MouseY;
  279. }
  280.  
  281.  
  282.  
  283.  
  284.