/*
**
**      Project     : CustomListDemo - bring up a special requester
**      Version     : 1.0
**      File        : CustomListDemo
**
**      Author      : David Göhler, Hannover
**      Date   Init : 16. Juni 1993
**             Last : 16. Juni 1993
**      Company     : VillageTronic Marketing GmbH, Hannover, Germany
**
**      Purpose     : Shows, how to program a special ScreenMode
**                    requester with a supplied custom list.
**
**      Type "make" to compile it with DICE.
**      For other compilers you may have to do minor changes.
**
**      This programm will only run, if the monitor file supplied
**      with your graphics card is installed and running.
**
**      THIS IS NOT PD. THIS IS COMMERCIAL SOFTWARE.
**
*/

#include <exec/types.h>
#include <exec/lists.h>
#include <utility/tagitem.h>
#include <graphics/displayinfo.h>

#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/intuition_protos.h>

#include "vilintuisup.h"
#include "vilintuisup/vilintuisup_protos.h"
#include "vilintuisup/ScreenMode.h"

/*
 * Search for all 24 bit color depth resoltions. For this
 * set TAVIS_MINDEPTH to 24, so you will get only resolutions
 * with 24 bit or higher. If you want exactly only 24 bit res...
 * supply TAVIS_MAXDEPTH with a value of 24, too.
 */

struct TagItem ti1[] = {
   { TAVIS_MINDEPTH, 24 },
   { TAG_DONE, 0 }
};

/*
 * The second TagItem specifies getting only resolutions
 * with 8 bit maximum and a customlist. The custom list
 * pointer will be set later by a call to VillageModeList.
 */

struct TagItem ti2[] = {
   { TAVIS_MAXDEPTH, 8    },
   { TAVIS_CUSTOM_LIST, 0L },
   { TAG_DONE, 0 }
};

/*
 * here starts the program ...
 */

struct Library *VilIntuiBase;
struct Library *IntuitionBase;

int main(int argc, char *argv[])
{
   struct List     *l;             // pointer to a List
   struct Remember *Key = 0;       // a key for AllocRemember/FreeRemember
   ULONG           DisplayID = 0L; // Var for the value we want to get

   if (VilIntuiBase = OpenLibrary("vilintuisup.library",2))
   {if (IntuitionBase = OpenLibrary("intuition.library",37))
    {
      /*
       * first get only a list with special nodes for the
       * ScreenMode requester
       */
      if (l = VillageModeList(&Key,ti1))
      {
	 /*
	  * Now, set the pointer to the list in ti2.
	  */
	 if (ti2[1].ti_Tag == TAVIS_CUSTOM_LIST)
	 {  ti2[1].ti_Data = (ULONG)l; }

	 /*
	  * O.K., all set. Display the ScreenMode requester
	  */

	 DisplayID = VillageModeRequest(ti2);

	 /*
	  * You will get a valid ID only, if the User clicked on O.K.
	  */

	 if (DisplayID != INVALID_ID)
	 {  Printf("Display ID is %8lx\n",DisplayID);
	 }

	 /*
	  * THAT IS IMPORTANT:
	  * Last, free the memory allocated by VillageModeList
	  */

	 if (Key != 0)
	 {  FreeRemember(&Key,TRUE); }
      }
      else
      {  PutStr("Can't read screenmode database?!?\n");
      }
      CloseLibrary(IntuitionBase);
    }
    CloseLibrary(VilIntuiBase);
   }

   return 0;
}
