当前位置: 首页>>代码示例>>C++>>正文


C++ Style::SetName方法代码示例

本文整理汇总了C++中Style::SetName方法的典型用法代码示例。如果您正苦于以下问题:C++ Style::SetName方法的具体用法?C++ Style::SetName怎么用?C++ Style::SetName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Style的用法示例。


在下文中一共展示了Style::SetName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: new

// _AddStyle
status_t
StyledTextImporter::_AddStyle(Icon *icon, text_run *run)
{
	CALLED();
	if (!run)
		return EINVAL;
	rgb_color color = run->color;
	Style* style = new (nothrow) Style(color);
	if (!style) {
		delete style;
		return B_NO_MEMORY;
	}
	char name[30];
	sprintf(name, "Color (#%02x%02x%02x)", color.red, color.green, color.blue);
	style->SetName(name);

	bool found = false;
	for (int i = 0; i < fStyleCount; i++) {
		if (*style == *(fStyleMap[i].style)) {
			delete style;
			style = fStyleMap[i].style;
			found = true;
			break;
		}
	}

	if (!found && !icon->Styles()->AddStyle(style)) {
		delete style;
		return B_NO_MEMORY;
	}

	fStyleMap[fStyleCount].run = run;
	fStyleMap[fStyleCount].style = style;
	fStyleCount++;

	return B_OK;
}
开发者ID:mmanley,项目名称:Antares,代码行数:38,代码来源:StyledTextImporter.cpp

示例2: locker

void
MainWindow::MessageReceived(BMessage* message)
{
    bool discard = false;

    // Figure out if we need the write lock on the Document. For most
    // messages we do, but exporting takes place in another thread and
    // locking is taken care of there.
    bool requiresWriteLock = true;
    switch (message->what) {
    case MSG_SAVE:
    case MSG_EXPORT:
    case MSG_SAVE_AS:
    case MSG_EXPORT_AS:
        requiresWriteLock = false;
        break;
    default:
        break;
    }
    if (requiresWriteLock && !fDocument->WriteLock()) {
        BWindow::MessageReceived(message);
        return;
    }

    if (message->WasDropped()) {
        const rgb_color* color;
        ssize_t length;
        // create styles from dropped colors
        for (int32 i = 0; message->FindData("RGBColor", B_RGB_COLOR_TYPE, i,
                                            (const void**)&color, &length) == B_OK; i++) {
            if (length != sizeof(rgb_color))
                continue;
            char name[30];
            sprintf(name,
                    B_TRANSLATE_CONTEXT("Color (#%02x%02x%02x)",
                                        "Style name after dropping a color"),
                    color->red, color->green, color->blue);
            Style* style = new (nothrow) Style(*color);
            style->SetName(name);
            Style* styles[1] = { style };
            AddStylesCommand* styleCommand = new (nothrow) AddStylesCommand(
                fDocument->Icon()->Styles(), styles, 1,
                fDocument->Icon()->Styles()->CountStyles());
            fDocument->CommandStack()->Perform(styleCommand);
            // don't handle anything else,
            // or we might paste the clipboard on B_PASTE
            discard = true;
        }
    }

    switch (message->what) {

    case B_REFS_RECEIVED:
    case B_SIMPLE_DATA:
        // If our icon is empty, open the file in this window,
        // otherwise forward to the application which will open
        // it in another window, unless we append.
        message->what = B_REFS_RECEIVED;
        if (fDocument->Icon()->Styles()->CountStyles() == 0
                && fDocument->Icon()->Paths()->CountPaths() == 0
                && fDocument->Icon()->Shapes()->CountShapes() == 0) {
            entry_ref ref;
            if (message->FindRef("refs", &ref) == B_OK)
                Open(ref);
            break;
        }
        if (modifiers() & B_SHIFT_KEY) {
            // We want the icon appended to this window.
            message->AddBool("append", true);
            message->AddPointer("window", this);
        }
        be_app->PostMessage(message);
        break;

    case B_PASTE:
    case B_MIME_DATA:
    {
        BMessage* clip = message;
        status_t err;

        if (discard)
            break;

        if (message->what == B_PASTE) {
            if (!be_clipboard->Lock())
                break;
            clip = be_clipboard->Data();
        }

        if (!clip || !clip->HasData("text/plain", B_MIME_TYPE)) {
            if (message->what == B_PASTE)
                be_clipboard->Unlock();
            break;
        }

        Icon* icon = new (std::nothrow) Icon(*fDocument->Icon());
        if (icon != NULL) {
            StyledTextImporter importer;
            err = importer.Import(icon, clip);
            if (err >= B_OK) {
//.........这里部分代码省略.........
开发者ID:yunxiaoxiao110,项目名称:haiku,代码行数:101,代码来源:MainWindow.cpp


注:本文中的Style::SetName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。