Exemplo n.º 1
0
filter_result
AutoTextControlFilter::Filter(BMessage* msg, BHandler** target)
{
	int32 rawchar, mod;
	msg->FindInt32("raw_char", &rawchar);
	msg->FindInt32("modifiers", &mod);

	BView* view = dynamic_cast<BView*>(*target);
	if (view != NULL || view->Name() != NULL && strcmp("_input_", view->Name()))
		return B_DISPATCH_MESSAGE;
	
	AutoTextControl* text = dynamic_cast<AutoTextControl*>(view->Parent());
	if (!text || text != fBox)
		return B_DISPATCH_MESSAGE;

	fCurrentMessage = msg;
	filter_result result = KeyFilter(rawchar, mod);
	fCurrentMessage = NULL;

	if (fBox->fCharLimit && result == B_DISPATCH_MESSAGE) {
		// See to it that we still allow shortcut keys
		if (mod & B_COMMAND_KEY)
			return B_DISPATCH_MESSAGE;

		// We don't use strlen() because it is not UTF-8 aware, which can
		// affect how many characters can be typed.
		if (isprint(rawchar) && 
				(uint32)BString(text->Text()).CountChars() == text->fCharLimit)
			return B_SKIP_MESSAGE;
	}

	return result;
}
Exemplo n.º 2
0
void
EngineBase::gen_sql_delete(String &sql, TypeCodes &type_codes_out,
        const Table &table, const SqlGeneratorOptions &options)
{
    if (!table.pk_fields().size())
        throw BadSQLOperation(_T("cannot build update statement: no key in table"));
    SqlGeneratorContext ctx;
    String sql_query = _T("DELETE FROM ") + table.name();
    TypeCodes type_codes;
    Key sample_key;
    table.mk_sample_key(type_codes, sample_key);
    sql_query += _T(" WHERE ")
        + KeyFilter(sample_key).generate_sql(options, &ctx);
    type_codes_out.swap(type_codes);
    str_swap(sql, sql_query);
}
Exemplo n.º 3
0
void
EngineBase::gen_sql_update(String &sql, TypeCodes &type_codes_out,
        ParamNums &param_nums_out, const Table &table,
        const SqlGeneratorOptions &options)
{
    if (!table.pk_fields().size())
        throw BadSQLOperation(_T("cannot build update statement: no key in table"));
    SqlGeneratorContext ctx;
    String sql_query = _T("UPDATE ") + table.name() + _T(" SET ");
    TypeCodes type_codes;
    type_codes.reserve(table.size());
    ParamNums param_nums;
    size_t i;
    for (i = 0; i < table.size(); ++i) {
        const Column &col = table[i];
        if (!col.is_pk() && !col.is_ro()) {
            if (!type_codes.empty())
                sql_query += _T(", ");
            sql_query += col.name() + _T(" = ");
            ++ctx.counter_;
            if (options.numbered_params_)
                sql_query += _T(":") + to_string(ctx.counter_);
            else
                sql_query += _T("?");
            param_nums[col.name()] = type_codes.size();
            type_codes.push_back(col.type());
        }
    }
    for (i = 0; i < table.pk_fields().size(); ++i) {
        const String &col_name = table.pk_fields()[i];
        param_nums[col_name] = type_codes.size();
        type_codes.push_back(table[col_name].type());
    }
    type_codes_out.swap(type_codes);
    param_nums_out.swap(param_nums);
    Key sample_key;
    table.mk_sample_key(type_codes, sample_key);
    sql_query += _T(" WHERE ")
        + KeyFilter(sample_key).generate_sql(options, &ctx);
    str_swap(sql, sql_query);
}