Example #1
0
/** DialogControl::getTextSizeDlg()
 *
 *  Gets the size (width and height) in dialog units for any given string.
 *
 *  Since dialog units only have meaning for a specific dialog, normally the
 *  dialog units are calculated using the font of the dialog.  Optionally, this
 *  method will calculate the dialog units using a specified font.
 *
 *  @param  text         The string whose size is needed.
 *
 *  @param  fontName     Optional. If specified, use this font to calculate the
 *                       size.  The default is to use the font of the owner
 *                       dialog of the dialog control.  This would be the normal
 *                       usage.
 *
 *  @param  fontSize     Optional. If specified, use this font size with
 *                       fontName to calculate the size.  The default if omitted
 *                       is 8.  This arg is ignored if fontName is omitted.
 *
 *  @param  hwndFontSrc  Optional. Use this window's font to calculate the size.
 *                       This arg is always ignored if fontName is specified.
 *
 *  @return  A .Size object representing the area (width and height,) in dialog
 *           units, needed for the specified string.
 *
 *  @note  This method, mapped to a dialog control object, does not really make
 *         sense.  It, and its convoluted optional arguments, are maintained
 *         only for backward compatibility.  Its use should be strongly
 *         discouraged.
 */
RexxMethod5(RexxObjectPtr, dlgctrl_getTextSizeDlg, CSTRING, text, OPTIONAL_CSTRING, fontName,
            OPTIONAL_uint32_t, fontSize, OPTIONAL_POINTERSTRING, hwndFontSrc, CSELF, pCSelf)
{
    HWND hwndSrc = NULL;
    if ( argumentExists(2) )
    {
        if ( argumentOmitted(3) )
        {
            fontSize = DEFAULT_FONTSIZE;
        }
    }
    else if ( argumentExists(4) )
    {
        hwndSrc = (HWND)hwndFontSrc;
        if ( hwndFontSrc == NULL )
        {
            nullObjectException(context->threadContext, "window handle", 4);
            return NULLOBJECT;
        }
    }

    SIZE textSize = {0};
    RXCA2T(text);
    RXCA2T(fontName);
    if ( getTextSize(context, textT, fontNameT, fontSize, hwndSrc, getDCownerDlg(pCSelf), &textSize) )
    {
        return rxNewSize(context, textSize.cx, textSize.cy);
    }
    return NULLOBJECT;
}
Example #2
0
void SymbolTable::addProposition(const PropositionNode *propositionNode, bool isRule) {
	std::string name = propositionNode->getName();
	STable::iterator it = table.find(name);
	
	Symbol *symbol;
	if (it != table.end()) {
		symbol = it->second;
		if (symbol->getType() == SYMBOL_TYPE_RELATION) {
			if (isRule) {
				throw Exception("Relation cannot be in the head of if node: " + name);
			} else {
				return;
			}
		} else if (symbol->getType() == SYMBOL_TYPE_PROPOSITION && isRule) {
			symbol->setType(SYMBOL_TYPE_RULE);
		}
		if (symbol->getNumOfArgument() != propositionNode->getArguments().size()) {
			throw Exception(std::string("Different number of arguments in same") + std::string(((isRule) ? "rule" : "proposition")) + std::string(": ") + name);
		}
	} else {
		symbol = new Symbol(name, ((isRule) ? SYMBOL_TYPE_RULE : SYMBOL_TYPE_PROPOSITION), propositionNode->getArguments().size());
		std::pair<std::string, Symbol*> entry(name, symbol);
		table.insert(entry);
	}
	for (size_t i = 0; i < propositionNode->getArguments().size(); ++i) {
		if (propositionNode->getArguments()[i].getType() == TOKENIZER_TOKEN_TYPE_TERM) {
			std::string argument = propositionNode->getArguments()[i].getTokenStr();
			if (!argumentExists(symbol->getArgumentDomain(i), argument)) {
				symbol->addArgument(i, argument);
			}
		}
	}
}
Example #3
0
void SymbolTable::addAction(const PropositionNode *action) {
	std::string name = action->getName();
	STable::iterator it = table.find(name);
	
	Symbol *symbol;
	if (it != table.end()) {
		symbol = it->second;
		if (symbol->getType() != SYMBOL_TYPE_ACTION) {
			throw Exception("Action is already in the table with differnet type: " + name);
		}
		if (symbol->getNumOfArgument() != action->getArguments().size()) {
			throw Exception("Different number of arguments in same action: " + name);
		}
	} else {
		symbol = new Symbol(name, SYMBOL_TYPE_ACTION, action->getArguments().size());
		std::pair<std::string, Symbol*> entry(name, symbol);
		table.insert(entry);
	}
	for (size_t i = 0; i < action->getArguments().size(); ++i) {
		if (action->getArguments()[i].getType() == TOKENIZER_TOKEN_TYPE_TERM) {
			std::string argument = action->getArguments()[i].getTokenStr();
			if (!argumentExists(symbol->getArgumentDomain(i), argument)) {
				symbol->addArgument(i, argument);
			}
		}
	}
}
Example #4
0
/** playSoundFile()
 *
 */
RexxRoutine3(RexxObjectPtr, play_rtn, OPTIONAL_CSTRING, fileName, OPTIONAL_CSTRING, modifier, NAME, routineName)
{
    bool isStopRoutine = strcmp("STOPSOUNDFILE", routineName) == 0;

    if ( (! isStopRoutine && argumentOmitted(1)) || isStopRoutine )
    {
        return (sndPlaySound(NULL, SND_SYNC | SND_NODEFAULT) ? TheZeroObj : TheOneObj);
    }

    char *fullFileName = searchSoundPath(fileName, context);
    if ( fullFileName == NULL )
    {
        return TheOneObj;
    }

    uint32_t opts = SND_NODEFAULT;
    if ( strcmp("PLAYSOUNDFILE", routineName) == 0 )
    {
        opts |= isYes(modifier) ? SND_ASYNC : SND_SYNC;
    }
    else if ( strcmp("PLAYSOUNDFILEINLOOP", routineName) == 0 )
    {
        opts |= SND_ASYNC | SND_LOOP;
    }
    else
    {
        // Must be Play()
        if ( argumentExists(2) )
        {
            if ( stricmp("LOOP", modifier) == 0 )
            {
                opts |= SND_ASYNC | SND_LOOP;
            }
            else
            {
                opts |= isYes(modifier) ? SND_ASYNC : SND_SYNC;
            }
        }
        else
        {
            opts |= SND_SYNC;
        }
    }

    RexxObjectPtr result = sndPlaySound(fullFileName, opts) ? TheZeroObj : TheOneObj;
    free(fullFileName);
    return result;
}
/** Keyboard::getAysncKeyState()     [class]
 *
 *
 * @param _info
 */
RexxMethod2(RexxObjectPtr, kb_getAsyncKeyState_cls, uint8_t, vKey, OPTIONAL_RexxObjectPtr, _info)
{
    int16_t       ret    = GetAsyncKeyState(vKey);
    RexxObjectPtr result = (ret & ISDOWN) ? TheTrueObj : TheFalseObj;

    if ( argumentExists(2) )
    {
        if ( ! requiredClass(context->threadContext, _info, "Directory", 2) )
        {
            goto done_out;
        }
        RexxDirectoryObject info = (RexxDirectoryObject)_info;

        RexxMethodContext *c = context;
        c->DirectoryPut(info, result, "ISDOWN");
        c->DirectoryPut(info, (ret & WASPRESSED) ? TheTrueObj : TheFalseObj, "WASPRESSED");
    }

done_out:
    return result;
}
Example #6
0
/** MessageDialog()
 *
 *
 *  @param  text
 *  @param  hwnd  Handle of owner window.  If the user specifies 0 we do not use
 *                an owner window.  If the user omits hwnd, then we try the to
 *                find and use the topmost dialog.
 *
 *
 *  @note  Sets the .SystemErrorCode.
 *
 */
RexxRoutine6(int, messageDialog_rtn, CSTRING, text, OPTIONAL_CSTRING, hwnd, OPTIONAL_CSTRING, _title,
             OPTIONAL_CSTRING, button, OPTIONAL_CSTRING, icon, OPTIONAL_CSTRING, miscStyles)
{
    oodResetSysErrCode(context->threadContext);

    int result = -1;

    char *uprButton = NULL;
    char *uprIcon = NULL;
    char *uprMiscStyles = NULL;

    HWND hwndOwner = (HWND)string2pointer(hwnd);
    if ( hwndOwner == NULL )
    {
        if ( argumentOmitted(2) && TopDlg != NULL && TopDlg->onTheTop )
        {
            hwndOwner = TopDlg->hDlg;
        }
    }

    CSTRING title = "ooDialog Application Message";
    if ( argumentExists(3) )
    {
        title = _title;
    }

    // Defaults.  These values are all 0.
    uint32_t flags = MB_OK | MB_DEFBUTTON1 | MB_APPLMODAL;

    uint32_t flag;
    if ( argumentExists(4) )
    {
        uprButton = strdupupr(button);
        if ( uprButton == NULL )
        {
            outOfMemoryException(context->threadContext);
            goto done_out;
        }

        flag = winKeyword2ID(uprButton, context->threadContext, 4, "MessageDialog button keyword");
        if ( flag == (int)-1 )
        {
            goto done_out;
        }
        flags |= flag;
    }

    // There is no default for the icon, if omitted there is no icon.
    if ( argumentExists(5) )
    {
        uprIcon = strdupupr(icon);
        if ( uprIcon == NULL )
        {
            outOfMemoryException(context->threadContext);
            goto done_out;
        }

        flag = winKeyword2ID(uprIcon, context->threadContext, 5, "MessageDialog icon keyword");
        if ( flag == (int)-1 )
        {
            goto done_out;
        }
        flags |= flag;
    }

    if ( argumentExists(6) )
    {
        uprMiscStyles = strdupupr(miscStyles);
        if ( uprMiscStyles == NULL )
        {
            outOfMemoryException(context->threadContext);
            goto done_out;
        }

        flag = getMiscMBStyle(uprMiscStyles, context, 6, "MessageDialog style keyword");
        if ( flag == (int)-1 )
        {
            goto done_out;
        }
        flags |= flag;
    }

    result = MessageBox(hwndOwner, text, title, flags);
    if ( result == 0 )
    {
        oodSetSysErrCode(context->threadContext);
    }

done_out:
    safeFree(uprButton);
    safeFree(uprIcon);
    safeFree(uprMiscStyles);

    return result;
}
Example #7
0
/** fileNameDialog()
 *
 *  Displays either the Open File or Save File dialog to the user and returns
 *  their selection to the Rexx programmer.
 *
 *  This serves as the implementation for both the fileNameDialog() and the
 *  getFileNameWindow() public routines.  getFileNameWindow() was documented
 *  prior to 4.0.0 and therefore must be retained for backward compatibility.
 *
 *  All arguments are optional.
 *
 *  @param preselected
 *  @param _hwndOwner
 *  @param fileFilter
 *  @param loadOrSave
 *  @param _title
 *  @param _defExt
 *  @param multi
 *  @param _sep
 *
 *  @return  The selected file name(s) on success, 0 if the user cancelled or on
 *           error.
 *
 *  @remarks  For the Default file extension.  Previous to 4.2.0, .txt was
 *            always used unless  the user specified something else.  There is
 *            no way for the Rexx programmer to specify no extension.  Now, if
 *            the argument is used, but the empty string the programmer can
 *            specify no extension.
 */
RexxRoutine8(RexxObjectPtr, fileNameDlg_rtn,
            OPTIONAL_CSTRING, preselected, OPTIONAL_CSTRING, _hwndOwner, OPTIONAL_RexxStringObject, fileFilter,
            OPTIONAL_CSTRING, loadOrSave,  OPTIONAL_CSTRING, _title,     OPTIONAL_CSTRING, _defExt,
            OPTIONAL_CSTRING, multi,       OPTIONAL_CSTRING, _sep)
{
    // The bulk of the work here is setting up the open file name struct based
    // on the arguements passed by the user.

    OPENFILENAME OpenFileName = {0};
    OpenFileName.lStructSize  = sizeof(OPENFILENAME);
    OpenFileName.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_ENABLEHOOK |
                         OFN_EXPLORER | OFN_ENABLESIZING;

    // Allocate a large buffer for the returned file name(s).
    char * pszFiles = (char *)LocalAlloc(GPTR, FILENAME_BUFFER_LEN);
    if ( pszFiles == NULL )
    {
        outOfMemoryException(context->threadContext);
        return NULLOBJECT;
    }
    OpenFileName.lpstrFile = pszFiles;
    OpenFileName.nMaxFile = FILENAME_BUFFER_LEN;

    // Preselected file name and / or the directory to start in.
    if ( argumentExists(1) && *preselected != '\0' )
    {
        if ( preselected[strlen(preselected) - 1] == '\\' )
        {
            OpenFileName.lpstrInitialDir = preselected;
        }
        else
        {
          StrNCpy(pszFiles, preselected, _MAX_PATH);
        }
    }

    // Possible owner window.
    if ( argumentExists(2) && *_hwndOwner != '\0' )
    {
        OpenFileName.hwndOwner = (HWND)string2pointer(_hwndOwner);
    }

    // File filter string.  Note that the string needs to end with a double
    // null, which has never been documented well to the Rexx user.  This makes
    // it a little tricky if the user sends a string.  There is little chance
    // the user added the extra null.  The need for embedded nulls to separate
    // strings has been documented, so we can expect embedded nulls in the
    // string.  Therefore we have to get the real length of the string data.

    char *filterBuf = NULL;
    OpenFileName.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
    OpenFileName.nFilterIndex = 1L;

    if ( argumentExists(3) )
    {
        size_t len = context->StringLength(fileFilter);
        if ( len > 0 )
        {
            filterBuf = (char *)LocalAlloc(GMEM_FIXED, len + 2);
            if ( filterBuf == NULL )
            {
                outOfMemoryException(context->threadContext);
                LocalFree(pszFiles);
                return NULLOBJECT;
            }

            memcpy(filterBuf, context->StringData(fileFilter), len);
            filterBuf[len] = '\0';
            filterBuf[len + 1] = '\0';

            OpenFileName.lpstrFilter = filterBuf;
        }
        else
        {
            OpenFileName.lpstrFilter = NULL;
            OpenFileName.nFilterIndex = 0;
        }
    }

    // Open or save file dialog.  Allow mutiple file selection on open, or not.
    bool open = true;
    bool multiSelect = false;
    if ( argumentExists(4) && *loadOrSave != '\0' )
    {
        char f = toupper(*loadOrSave);
        if ( f == 'S' || f == '0' )
        {
            open = false;
        }
    }
    if ( open && argumentExists(7) && *multi != '\0' )
    {
        char f = toupper(*multi);
        if ( f == 'M' || f == '1' )
        {
            multiSelect = true;
        }
    }

    // Dialog title.
    if ( argumentExists(5) && *_title != '\0' )
    {
        OpenFileName.lpstrTitle = _title;
    }
    else
    {
        OpenFileName.lpstrTitle = (open ? "Open a File" : "Save File As");
    }

    // Default file extension.
    if ( argumentExists(6) )
    {
        OpenFileName.lpstrDefExt = *_defExt != '\0' ? _defExt : NULL;
    }
    else
    {
        OpenFileName.lpstrDefExt = "txt";
    }

    // Hook procedure to bring dialog to the foreground.
    OpenFileName.lpfnHook = OFNSetForegroundHookProc;

    // Default separator character, can be changed by the user to handle file
    // names with spaces.
    char sepChar = ' ';
    if ( argumentExists(8) && *_sep != '\0' )
    {
        sepChar = *_sep;
    }

    // Okay, show the dialog.
    BOOL success;
    if ( open )
    {
        OpenFileName.Flags |= OFN_FILEMUSTEXIST;
        if ( multiSelect )
        {
            OpenFileName.Flags |= OFN_ALLOWMULTISELECT;
        }

        success = GetOpenFileName(&OpenFileName);

        if ( success && multiSelect )
        {
            // If more than one name selected, names are separated with ASCII 0
            // instead of spaces.
            char *p = pszFiles;

            while ( (*p != '\0') || (*(p+1) != '\0') )
            {
                if ( *p == 0 )
                {
                    *p = sepChar;
                }
                p++;
            }
        }
    }
    else
    {
        OpenFileName.Flags |= OFN_OVERWRITEPROMPT;
        success = GetSaveFileName(&OpenFileName);
    }

    // Return 0 if the user cancelled, or on error.  Otherwise, the return is in
    // the allocated file buffer.
    RexxObjectPtr result = TheZeroObj;
    if ( success )
    {
        result = context->String(pszFiles);
    }

    LocalFree(pszFiles);
    safeLocalFree(filterBuf);

    if ( ! success )
    {
        // Raise an exception if this was a Windows API failure.  Prior to
        // 4.0.0, this was a generic 'routine failed' exception.  We'll try to
        // give the user a little more information.
        DWORD rc = CommDlgExtendedError();
        if ( rc != 0 )
        {
            systemServiceExceptionCode(context->threadContext, API_FAILED_MSG,
                                       open ? "GetOpenFileName" : "GetSaveFileName", rc);
        }
    }

    return result;
}