Developers – Window Library (old version 0.7)

THE VISOPSYS WINDOW LIBRARY (Version 0.7)

The window library is a set of functions to aid GUI development on the Visopsys platform. At present the list of functions is small, but it does provide very useful functionality. This includes an interface for registering window event callbacks for GUI components, and a ‘run’ function to poll for such events.

The functions are defined in the header file <sys/window.h> and the code is contained in libwindow.a (link with ‘-lwindow’).

objectKey windowNewBannerDialog(objectKey parentWindow, const char *title, const char *message)

Create a ‘banner’ dialog box, with the parent window ‘parentWindow’, and the given titlebar text and main message. This is the very simplest kind of dialog; it just contains the supplied message with no acknowledgement mechanism for the user. If ‘parentWindow’ is NULL, the dialog box is actually created as an independent window that looks the same as a dialog. This is a non-blocking call that returns the object key of the dialog window. The caller must destroy the window when finished with it.

void windowCenterDialog(objectKey parentWindow, objectKey dialogWindow)

Center a dialog window. The first object key is the parent window, and the second is the dialog window. This function can be used to center a regular window on the screen if the first objectKey argument is NULL.

int windowNewChoiceDialog(objectKey parentWindow, const char *title, const char *message, char *choiceStrings[], int numChoices, int defaultChoice)

Create a ‘choice’ dialog box, with the parent window ‘parentWindow’, the given titlebar text and main message, and ‘numChoices’ choices, as specified by the ‘choiceStrings’. ‘default’ is the default focussed selection. The dialog will have a button for each choice. If the user chooses one of the choices, the function returns the 0-based index of the choice. Otherwise it returns negative. If ‘parentWindow’ is NULL, the dialog box is actually created as an independent window that looks the same as a dialog. This is a blocking call that returns when the user closes the dialog window (i.e. the dialog is ‘modal’).

int windowNewColorDialog(objectKey parentWindow, color *pickedColor)

Create an ‘color chooser’ dialog box, with the parent window ‘parentWindow’, and a pointer to the color structure ‘pickedColor’. Currently the window consists of red/green/blue sliders and a canvas displaying the current color. The initial color displayed will be whatever is supplied in ‘pickedColor’. If ‘parentWindow’ is NULL, the dialog box is actually created as an independent window that looks the same as a dialog. This is a blocking call that returns when the user closes the dialog window (i.e. the dialog is ‘modal’).

int windowNewFileDialog(objectKey parentWindow, const char *title, const char *message, const char *startDir, char *fileName, unsigned maxLength, int thumb)

Create a ‘file’ dialog box, with the parent window ‘parentWindow’, and the given titlebar text and main message. If ‘startDir’ is a non-NULL directory name, the dialog will initially display the contents of that directory. If ‘fileName’ contains data (i.e. the string’s first character is non-NULL), the file name field of the dialog will contain that string. If ‘thumb’ is non-zero, an area will display image thumbnails when image files are clicked. The dialog will have a file selection area, a file name field, an ‘OK’ button and a ‘CANCEL’ button. If the user presses OK or ENTER, the function returns the value 1 and copies the file name into the fileName buffer. Otherwise it returns 0 and puts a NULL string into fileName. If ‘parentWindow’ is NULL, the dialog box is actually created as an independent window that looks the same as a dialog. This is a blocking call that returns when the user closes the dialog window (i.e. the dialog is ‘modal’).

windowFileList *windowNewFileList(objectKey parent, windowListType type, int rows, int columns, const char *directory, int flags, void *callback, componentParameters *params)

Create a new file list widget with the parent window ‘parent’, the window list type ‘type’ (windowlist_textonly or windowlist_icononly is currently supported), of height ‘rows’ and width ‘columns’, the name of the starting location ‘directory’, flags (such as WINFILEBROWSE_CAN_CD or WINFILEBROWSE_CAN_DEL — see sys/window.h), a function ‘callback’ for when the status changes, and component parameters ‘params’.

int windowClearEventHandlers(void)

Remove all the callback event handlers registered with the windowRegisterEventHandler() function.

int windowRegisterEventHandler(objectKey key, void (*function)(objectKey, windowEvent *))

Register a callback function as an event handler for the GUI object ‘key’. The GUI object can be a window component, or a window for example. GUI components are typically the target of mouse click or key press events, whereas windows typically receive ‘close window’ events. For example, if you create a button component in a window, you should call windowRegisterEventHandler() to receive a callback when the button is pushed by a user. You can use the same callback function for all your objects if you wish — the objectKey of the target component can always be found in the windowEvent passed to your callback function. It is necessary to use one of the ‘run’ functions, below, such as windowGuiRun() or windowGuiThread() in order to receive the callbacks.

int windowClearEventHandler(objectKey key)

Remove a callback event handler registered with the windowRegisterEventHandler() function.

void windowGuiRun(void)

Run the GUI windowEvent polling as a blocking call. In other words, use this function when your program has completed its setup code, and simply needs to watch for GUI events such as mouse clicks, key presses, and window closures. If your program needs to do other processing (independently of windowEvents) you should use the windowGuiThread() function instead.

int windowGuiThread(void)

Run the GUI windowEvent polling as a non-blocking call. In other words, this function will launch a separate thread to monitor for GUI events and return control to your program. Your program can then continue execution — independent of GUI windowEvents. If your program doesn’t need to do any processing after setting up all its window components and event callbacks, use the windowGuiRun() function instead.

int windowGuiThreadPid(void)

Returns the current GUI thread PID, if applicable, or else 0.

void windowGuiStop(void)

Stop GUI event polling which has been started by a previous call to one of the ‘run’ functions, such as windowGuiRun() or windowGuiThread().

int windowNewNumberDialog(objectKey parentWindow, const char *title, const char *message, int minVal, int maxVal, int defaultVal, int *value)

Create a ‘number’ dialog box, with the parent window ‘parentWindow’, and the given titlebar text and main message. The dialog will have a text field for the user to enter data using the keyboard, and a slider component for adjusting it with the mouse. Minimum, maximum, and default values should be supplied. If ‘parentWindow’ is NULL, the dialog box is actually created as an independent window that looks the same as a dialog. This is a blocking call that returns when the user closes the dialog window (i.e. the dialog is ‘modal’).

int windowNewInfoDialog(objectKey parentWindow, const char *title, const char *message)

Create an ‘info’ dialog box, with the parent window ‘parentWindow’, and the given titlebar text and main message. The dialog will have a single ‘OK’ button for the user to acknowledge. If ‘parentWindow’ is NULL, the dialog box is actually created as an independent window that looks the same as a dialog. This is a blocking call that returns when the user closes the dialog window (i.e. the dialog is ‘modal’).

int windowNewErrorDialog(objectKey parentWindow, const char *title, const char *message)

Create an ‘error’ dialog box, with the parent window ‘parentWindow’, and the given titlebar text and main message. The dialog will have a single ‘OK’ button for the user to acknowledge. If ‘parentWindow’ is NULL, the dialog box is actually created as an independent window that looks the same as a dialog. This is a blocking call that returns when the user closes the dialog window (i.e. the dialog is ‘modal’).

objectKey windowNewProgressDialog(objectKey parentWindow, const char *title, progress *tmpProg)

Create a ‘progress’ dialog box, with the parent window ‘parentWindow’, and the given titlebar text and progress structure. The dialog creates a thread which monitors the progress structure for changes, and updates the progress bar and status message appropriately. If the operation is interruptible, it will show a ‘CANCEL’ button. If ‘parentWindow’ is NULL, the dialog box is actually created as an independent window that looks the same as a dialog. This is a non-blocking call that returns immediately (but the dialog box itself is ‘modal’). A call to this function should eventually be followed by a call to windowProgressDialogDestroy() in order to destroy and deallocate the window.

int windowProgressDialogDestroy(objectKey window)

Given the objectKey for a progress dialog ‘window’ previously returned by windowNewProgressDialog(), destroy and deallocate the window.

int windowNewPromptDialog(objectKey parentWindow, const char *title, const char *message, int rows, int columns, char *buffer)

Create a ‘prompt’ dialog box, with the parent window ‘parentWindow’, and the given titlebar text and main message. The dialog will have a single text field for the user to enter data. If ‘parentWindow’ is NULL, the dialog box is actually created as an independent window that looks the same as a dialog. This is a blocking call that returns when the user closes the dialog window (i.e. the dialog is ‘modal’).

int windowNewPasswordDialog(objectKey parentWindow, const char *title, const char *message, int columns, char *buffer)

Create a ‘password’ dialog box, with the parent window ‘parentWindow’, and the given titlebar text and main message. The dialog will have a single password field. If ‘parentWindow’ is NULL, the dialog box is actually created as an independent window that looks the same as a dialog. This is a blocking call that returns when the user closes the dialog window (i.e. the dialog is ‘modal’).

int windowNewQueryDialog(objectKey parentWindow, const char *title, const char *message)

Create a ‘query’ dialog box, with the parent window ‘parentWindow’, and the given titlebar text and main message. The dialog will have an ‘OK’ button and a ‘CANCEL’ button. If the user presses OK, the function returns the value 1. Otherwise it returns 0. If ‘parentWindow’ is NULL, the dialog box is actually created as an independent window that looks the same as a dialog. This is a blocking call that returns when the user closes the dialog window (i.e. the dialog is ‘modal’).

int windowNewRadioDialog(objectKey parentWindow, const char *title, const char *message, char *choiceStrings[], int numChoices, int defaultChoice)

Create a dialog window with a radio button widget with the parent window ‘parentWindow’, the given titlebar text and main message, and ‘numChoices’ choices, as specified by the ‘choiceStrings’. ‘default’ is the default focussed selection. The dialog’s radio button widget will have items for each choice. If the user chooses one of the choices, the function returns the 0-based index of the choice. Otherwise it returns negative. If ‘parentWindow’ is NULL, the dialog box is actually created as an independent window that looks the same as a dialog. This is a blocking call that returns when the user closes the dialog window (i.e. the dialog is ‘modal’).

objectKey windowNewThumbImage(objectKey parent, const char *fileName, unsigned maxWidth, unsigned maxHeight, componentParameters *params)

Create a new window image component from the supplied image file name ‘fileName’, with the given ‘parent’ window or container, and component parameters ‘params’. Dimension values ‘maxWidth’ and ‘maxHeight’ constrain the maximum image size. The resulting image will be scaled down, if necessary, with the aspect ratio intact. If ‘fileName’ is NULL, a blank image will be created.

int windowThumbImageUpdate(objectKey thumbImage, const char *fileName, unsigned maxWidth, unsigned maxHeight)

Update an existing window image component ‘thumbImage’, previously created with a call to windowNewThumbImage(), from the supplied image file name ‘fileName’. Dimension values ‘maxWidth’ and ‘maxHeight’ constrain the maximum image size. The resulting image will be scaled down, if necessary, with the aspect ratio intact. If ‘fileName’ is NULL, the image will become blank.

Visual Operating System