static void dialog_rename(void *arg) { dialog *d = static_cast<dialog *>(arg); w_saves *saves_w = static_cast<w_saves *>(d->get_widget_by_id(iDIALOG_SAVES_W)); QuickSave sel = saves_w->selected_save(); dialog rd; vertical_placer *placer = new vertical_placer; horizontal_placer* name_placer = new horizontal_placer; w_text_entry *rename_w = new w_save_name(&rd, utf8_to_mac_roman(sel.name).c_str()); rename_w->enable_mac_roman_input(); name_placer->dual_add(rename_w->label("Name: "), rd); name_placer->dual_add(rename_w, rd); placer->add(name_placer, true); placer->add(new w_spacer(), true); horizontal_placer* button_placer = new horizontal_placer; w_button* accept_w = new w_button("RENAME", dialog_ok, &rd); button_placer->dual_add(accept_w, rd); w_button* cancel_w = new w_button("CANCEL", dialog_cancel, &rd); button_placer->dual_add(cancel_w, rd); placer->add(button_placer, true); rd.set_widget_placer(placer); rd.activate_widget(rename_w); if (rd.run() == 0) { sel.name = mac_roman_to_utf8(rename_w->get_text()); create_updated_save(sel); saves_w->update_selected(sel); } }
OSErr BuildCatalogKeyUTF8(ExtendedVCB *volume, HFSCatalogNodeID parentID, const unsigned char *name, u_int32_t nameLength, CatalogKey *key, u_int32_t *textEncoding) { OSErr err = 0; if ( name == NULL) nameLength = 0; else if (nameLength == kUndefinedStrLen) nameLength = strlen((const char *)name); if ( volume->vcbSigWord == kHFSPlusSigWord ) { size_t unicodeBytes = 0; key->hfsPlus.keyLength = kHFSPlusCatalogKeyMinimumLength; // initial key length (4 + 2) key->hfsPlus.parentID = parentID; // set parent ID key->hfsPlus.nodeName.length = 0; // null CName length if ( nameLength > 0 ) { err = utf8_decodestr(name, nameLength, key->hfsPlus.nodeName.unicode, &unicodeBytes, sizeof(key->hfsPlus.nodeName.unicode), ':', UTF_DECOMPOSED); key->hfsPlus.nodeName.length = unicodeBytes / sizeof(UniChar); key->hfsPlus.keyLength += unicodeBytes; } if (textEncoding && (*textEncoding != kTextEncodingMacUnicode)) *textEncoding = hfs_pickencoding(key->hfsPlus.nodeName.unicode, key->hfsPlus.nodeName.length); } else { key->hfs.keyLength = kHFSCatalogKeyMinimumLength; // initial key length (1 + 4 + 1) key->hfs.reserved = 0; // clear unused byte key->hfs.parentID = parentID; // set parent ID key->hfs.nodeName[0] = 0; // null CName length if ( nameLength > 0 ) { err = utf8_to_hfs(volume, nameLength, name, &key->hfs.nodeName[0]); /* * Retry with MacRoman in case that's how it was exported. * When textEncoding != NULL we know that this is a create * or rename call and can skip the retry (ugly but it works). */ if (err && (textEncoding == NULL)) err = utf8_to_mac_roman(nameLength, name, &key->hfs.nodeName[0]); key->hfs.keyLength += key->hfs.nodeName[0]; // add CName size to key length } if (textEncoding) *textEncoding = 0; } if (err) { if (err == ENAMETOOLONG) err = bdNamErr; /* name is too long */ else err = paramErr; /* name has invalid characters */ } return err; }
void w_saves::draw_item(QuickSaves::iterator it, SDL_Surface* s, int16 x, int16 y, uint16 width, bool selected) const { std::ostringstream oss; oss << it->save_time; SDL_Surface *image = QuickSaveImageCache::instance()->get(oss.str()); SDL_Rect r = {x + 3, y + 3, PREVIEW_WIDTH, PREVIEW_HEIGHT}; SDL_BlitSurface(image, NULL, s, &r); x += PREVIEW_WIDTH + 12; width -= PREVIEW_WIDTH + 12; uint32 color; if (selected) { color = get_theme_color(ITEM_WIDGET, ACTIVE_STATE); } else { color = get_theme_color(ITEM_WIDGET, DEFAULT_STATE); } set_drawing_clip_rectangle(0, x, static_cast<short>(s->h), x + width); y += font->get_ascent(); if (it->name.length()) { draw_text(s, utf8_to_mac_roman(it->name).c_str(), x, y, color, font, style); y += font->get_ascent() + 1; } draw_text(s, it->formatted_time.c_str(), x, y, color, font, style); y += font->get_ascent() + 1; draw_text(s, utf8_to_mac_roman(it->level_name).c_str(), x, y, color, font, style); y += font->get_ascent() + 1; std::string game_time = it->formatted_ticks; if (it->players > 1) { game_time += " (Cooperative Play)"; } draw_text(s, game_time.c_str(), x, y, color, font, style); set_drawing_clip_rectangle(SHRT_MIN, SHRT_MIN, SHRT_MAX, SHRT_MAX); }
static void dialog_export(void *arg) { dialog *d = static_cast<dialog *>(arg); w_saves *saves_w = static_cast<w_saves *>(d->get_widget_by_id(iDIALOG_SAVES_W)); QuickSave sel = saves_w->selected_save(); std::string name = sel.name; if (!name.length()) name = sel.level_name; FileSpecifier dstFile; dstFile.SetToSavedGamesDir(); dstFile += "unused.sgaA"; char prompt[256]; if (dstFile.WriteDialog(_typecode_savegame, getcstr(prompt, strPROMPTS, _save_replay_prompt), utf8_to_mac_roman(name).c_str())) { dstFile.CopyContents(sel.save_file); int error = dstFile.GetError(); if (error) alert_user(infoError, strERRORS, fileError, error); } }