Chapter 3. ReqTools Requesters

What ReqTools Can Do For You

In this chapter, we'll overview all ReqTools requesters in detail. As you should already know, ReqTools offers you a lot of different requesters to choose from, that will ease your programming life.

Easy Requester

This is the classic requester that prompts the user to choose among some different options, or shows an error message with just an OK or Cancel button.

Figure 3-1. Easy Requester At Work

Example 3-1. Reqtools Easy Request demo

void demo_easy_request ( Reqtools * rt )
{
	int res;    /* Here we'll store the ReqTools EasyRequester return value */

	/* Create the requester and gets the user input */
	res = reqtools_requester ( rt, REQTOOLS_EASY_REQUEST,                       /* We want an Easy Request */

	                               /* Requester Titke */
	                                REQTOOLS_TAG_TITLE, "Easy Requester",        

	                               /* This is the text of the requester. Please note that the text can spawn on 
	                                  multiple lines, using the "\n" char. */
	                                REQTOOLS_TAG_TEXT,  "This is en Easy Reqyester. It is the standard requester\n"
	                                                    "where the user is prompt to choose between some options\n"
	                                                    "like this:\n"
	                                                    "Do you like Reqtools's Easy Requester?"  ,

	                               /* ALWAYS and a tag list with TAG_END!!! */
	                                REQTOOLS_TAG_END );

	printf ( "EasyRequest result: %d\n", res );
}
	    

Input Requester

This requester lets the user insert a brief text. At the moment, you can use ReqTools Input in these ways:

Alphabetic mode

This mode lets the user input any valid alphabetic chars, excluding numbers and punctuation. This mode can be ORed with other modes to enhance the range of chars that an user can input.

Figure 3-2. An Example of Input Requester (text mode)

Numeric mode

This mode lets the user input any valid number, excluding all alphabetic chars and punctiation. This mode can be ORed with other modes to enhance the range of chars that an user can input.

Figure 3-3. An Example of Input Requester (numeric mode)

As you can see from the picture above, in numeric mode it is also possible to set a range of valid values, so that the user cannot insert a numeric value bigger or smaller than the ones expected by your application.

Filtered mode

This mode lets the user input any char that is present inside a characters list. All others chars will be simply ignored. This mode cannot be ORed with others.

Figure 3-4. An Example of Input Requester (fixed mode)

Other chars mode

This mode lets the user input any valid char that is not alphabetic nor numeric. This mode can be ORed with other modes to enhance the range of chars that an user can input.

All these modes (excluding the filtered one) can be ORed together to allow a wide range of chars to be inserted by the user. For example, the default ReqTools Input Requester mode allows all alphabetic, numeric and punctiation chars to be inserted at once.

Please refer to the ReqTools Input Requester Tags section to see how to enable all these features.

Example 3-2. Reqtools Input Request (Text Mode) demo

void demo_input_text ( Reqtools * rt )
{
	int res;

	/* Create the requester and gets the user input */
	res = reqtools_requester ( rt, REQTOOLS_INPUT_REQUEST,   /* We want an input requester */

	                               /* Sets the default text in the input field */
	                               REQTOOLS_INPUT_TAG_DEFAULT_TEXT, "Hello World!",         

	                               /* Requester Titke */
	                                REQTOOLS_TAG_TITLE, "Input Requester (Text Mode)",

	                               /* This is the text of the requester. Please note that the text can spawn on 
	                                  multiple lines, using the "\n" char. */
	                               REQTOOLS_TAG_TEXT, "Please, type some text",

	                               REQTOOLS_TAG_TEXT_BORDER, TRUE,

	                               /* ALWAYS and a tag list with TAG_END!!! */
	                               REQTOOLS_TAG_END );

	printf ( "Input Requester result: %d - Text: \"%s\"\n", res, rt->return_string );
}
	      

File Requester

This is one of the most complex (and useful) requesters. It will allow the developer to prompt the user for one or more files inside a directory. The requester is able to create new directories, to rename files and dirs and also to delete files and directories (double confirmation before deleting files and dirs is prompted before performing the real operation).

Figure 3-5. An Example of File Requester (Single selection)

Example 3-3. Reqtools Input Request (Text Mode) demo

void demo_single_file ( Reqtools * rt )
{
	int res;

	/* Create the requester and gets the user input */
	res = reqtools_requester ( rt, REQTOOLS_SINGLE_FILE,  /* We want a single file requester */

	                               /* Default file name is "file_name" */
	                               REQTOOLS_FILE_TAG_FILE_NAME, "file_name", 

	                               /* Starting path is "/tmp" */
	                               REQTOOLS_FILE_TAG_PATH, "/tmp",

	                               /* Requester Title */
	                                REQTOOLS_TAG_TITLE, "File Requester (Single File Mode)",        

	                               /* This is the text of the requester. Please note that the text can spawn on 
	                                  multiple lines, using the "\n" char. */
	                               REQTOOLS_TAG_TEXT, "Please, select one single file",

	                               /* File requester is quite large, so we start with a bigger window */
	                               REQTOOLS_TAG_WINDOW_WIDTH, 400,
	                               REQTOOLS_TAG_WINDOW_HEIGHT, 450,

	                               /* ALWAYS and a tag list with TAG_END!!! */
	                               REQTOOLS_TAG_END );

	printf ( "File Requester result: %d\nPath: \"%s\"\nFile: \"%s\"\n", res, rt->return_path, rt->return_string );
}
	      

Path Requester

Based on the same code of the File Requester, this requester prompts the user for a specific path and does not show any file.

Figure 3-6. An Example of Path Requester

Example 3-4. Reqtools Path Request demo

void demo_path_req ( Reqtools * rt )
{
	int res;

	/* Create the requester and gets the user input */
	res = reqtools_requester ( rt, REQTOOLS_PATH_REQUEST, /* We want a Path Requester */

	                               /* Starting dir is always /tmp :-) */
	                               REQTOOLS_FILE_TAG_PATH, "/tmp",

	                               /* Requester Title */
	                                REQTOOLS_TAG_TITLE, "Path Requester",  

	                               /* This is the text of the requester. Please note that the text can spawn on 
	                                  multiple lines, using the "\n" char. */
	                               REQTOOLS_TAG_TEXT, "Please, select a path",

	                               /* ALWAYS and a tag list with TAG_END!!! */
	                               REQTOOLS_TAG_END );

	printf ( "Path Requester result: %d\nPath: \"%s\"\n", res, rt->return_path );
}
	      

Color Requester

This requester lets the user choose a color from a palette.

Figure 3-7. An Example of Color Requester

Example 3-5. Reqtools Color Request demo

void demo_color_req ( Reqtools * rt )
{
	int res;

	/* Create the requester and gets the user input */
	res = reqtools_requester ( rt, REQTOOLS_COLOR_REQUEST,

	                               /* Requester Title */
	                                REQTOOLS_TAG_TITLE, "Color Requester",  

	                               /* This is the text of the requester. Please note that the text can spawn on 
	                                  multiple lines, using the "\n" char. */
	                               REQTOOLS_TAG_TEXT, "Please, select a color",

	                               /* Since the Color Requester is smaller than File Requester, we set the window
	                                  width and height to 0, so it will get the best size automatically */
	                               REQTOOLS_TAG_WINDOW_WIDTH, 0,
	                               REQTOOLS_TAG_WINDOW_HEIGHT, 0,

	                               /* ALWAYS and a tag list with TAG_END!!! */
	                               REQTOOLS_TAG_END );

	printf ( "Color Requester result: %d\n", res );
	printf ( "R: %f\nG: %f\nB: %f\n", rt->color[0], rt->color[1], rt->color[2] );
}