[Previous] [Contents] [Index] [Next]


Create an item for a PtFileSel widget


PtFileSelItem_t * PtFSAllocItem(
                      PtFileSelWidget_t *fs, 
                      int type, 
                      char const *info );


This function can be used to create a PtFileSelItem_t for the PtFileSel widget. It's useful if your application can display items that aren't physically part of the filesystem. The parameters are as follows:

The type of item you're creating:

This must contain a valid file type and is used to display the item's image.

The string that's displayed in the tree for the item. It should contain all the information required, such as name, size, and date. The information should be separated by tabs and in the same order as the format string. For example, if your format is "nso" (name, size, owner), you should pass something like "bob\t100\towner" as info.

An item pointer is returned. If you wish to store any information in the item, use the item->fullpath character pointer. It's used in most items to store the full path of the item, but it will be set to NULL by this function.


The allocated item pointer if successful, or NULL if an error occurred.


Suppose you wish to add your own item. In the state callback you can check the item's fullpath to see if it's the one you want to deal with and if so, add your own items afterwards. Just return Pt_END from the Pt_FS_STATE_START callback to prevent the widget from doing the expansion.

// state callback, will use the reason to block the widget for
// large directory opens
int state_cb( PtWidget_t *widget, 
              struct fs_dialog_modal *user, 
              PtCallbackInfo_t *info)
    PtArg_t args[3];
    PtFileSelCallback_t *it;
    PtFileSelItem_t *new_item;

    it = (PtFileSelCallback_t *)(info->cbdata);

    if (it->reason == Pt_FS_STATE_START) {
        PtSetArg(&args[0], Pt_ARG_FLAGS, Pt_BLOCKED, 
        PtSetArg(&args[1], Pt_ARG_CURSOR_TYPE, 
                 Ph_CURSOR_CLOCK, 0);

        if ((strcmp(it->item->fullpath, "/Gamma") == 0) && 
            (info->reason_subtype == Pt_TREE_EXPANDING)) {
            it->item->type = Pt_FS_DIR_OP;
            PtFSDamageItem(fs, it->item);
            new_item = PtFSAllocItem(fs, Pt_FS_FILE, 
                                     "Fred Flintstone");
            PtFSAddFirst(fs, new_item, it->item);
            return (Pt_END);
    } else {
        PtSetArg(&args[0], Pt_ARG_FLAGS, ~Pt_BLOCKED, 
        PtSetArg(&args[1], Pt_ARG_CURSOR_TYPE, 
                 Ph_CURSOR_INHERIT, 0);
    PtSetResources(widget, 2, args);
    return (Pt_CONTINUE);



Interrupt handler No
Signal handler No
Thread No

[Previous] [Contents] [Index] [Next]