void MyApp :: ReadyToRun( void) { BResources * appResources = AppResources(); size_t len; char * str = (char *)appResources->FindResource('CSTR', "aResource", &len); printf("%s\n", str); free (str); PostMessage(B_QUIT_REQUESTED); }//end
void ConfigWindow::MakeHowToView() { BResources *resources = BApplication::AppResources(); if (resources) { size_t length; char *buffer = (char *)resources->FindResource('ICON',101,&length); if (buffer) { BBitmap *bitmap = new BBitmap(BRect(0,0,63,63),B_CMAP8); if (bitmap && bitmap->InitCheck() == B_OK) { // copy and enlarge a 32x32 8-bit bitmap char *bits = (char *)bitmap->Bits(); for (int32 i = 0,j = -64;i < length;i++) { if ((i % 32) == 0) j += 64; char *b = bits + (i << 1) + j; b[0] = b[1] = b[64] = b[65] = buffer[i]; } fConfigView->AddChild(new BitmapView(bitmap)); } else delete bitmap; } } BRect rect = fConfigView->Bounds(); BTextView *text = new BTextView(rect,NULL,rect,B_FOLLOW_NONE,B_WILL_DRAW); text->SetViewColor(fConfigView->Parent()->ViewColor()); text->SetAlignment(B_ALIGN_CENTER); text->SetText( MDR_DIALECT_CHOICE ("\n\nCreate a new account using the \"Add\" button.\n\n" "Delete accounts (or only the inbound/outbound) by using the \"Remove\" button on the selected item.\n\n" "Select an item in the list to edit its configuration.", "\n\nアカウントの新規作成は\"追加\"ボタンを\n使います。" "\n\nアカウント自体またはアカウントの\n送受信設定を削除するには\n項目を選択して\"削除\"ボタンを使います。" "\n\nアカウント内容の変更は、\nマウスで項目をクリックしてください。")); rect = text->Bounds(); text->ResizeTo(rect.Width(),text->TextHeight(0,42)); text->SetTextRect(rect); text->MakeEditable(false); text->MakeSelectable(false); fConfigView->AddChild(text); static_cast<CenterContainer *>(fConfigView)->Layout(); }
BBitmap *GetCicnFromResource(const char *theResource) { // Get application info app_info info; be_app->GetAppInfo(&info); BFile file(&info.ref, O_RDONLY); if (file.InitCheck()) return NULL; size_t size; cicn *icon; BResources res; status_t err; if ( (err = res.SetTo(&file)) != B_NO_ERROR ) return NULL; icon = (cicn *)res.FindResource('cicn', theResource, &size); if (!icon) return NULL; // Swap bytes if needed. We do this because the resources are currently // built on Macintosh BeOS if (B_HOST_IS_LENDIAN) { status_t retVal; retVal = swap_data(B_INT16_TYPE, &icon->width, sizeof(int16), B_SWAP_BENDIAN_TO_HOST); retVal = swap_data(B_INT16_TYPE, &icon->height, sizeof(int16), B_SWAP_BENDIAN_TO_HOST); } // Get cicn bounding rect BRect bounds(0, 0, icon->width-1, icon->height-1); // Load bitmap BBitmap *bitmap = new BBitmap(bounds, B_COLOR_8_BIT); ASSERT(bitmap); bitmap->SetBits(&icon->data, size - sizeof(int16)*2, 0, B_COLOR_8_BIT); return (bitmap); }
void ConfigWindow::MakeHowToView() { #ifndef HAIKU_TARGET_PLATFORM_HAIKU BResources *resources = BApplication::AppResources(); if (resources) { size_t length; char *buffer = (char *)resources->FindResource(B_LARGE_ICON_TYPE, 101, &length); if (buffer) { BBitmap *bitmap = new (nothrow) BBitmap(BRect(0, 0, 63, 63), B_CMAP8); if (bitmap && bitmap->InitCheck() == B_OK) { // copy and enlarge a 32x32 8-bit bitmap char *bits = (char *)bitmap->Bits(); for (int32 i = 0, j = -64; i < (int32)length; i++) { if ((i % 32) == 0) j += 64; char *b = bits + (i << 1) + j; b[0] = b[1] = b[64] = b[65] = buffer[i]; } fConfigView->AddChild(new BitmapView(bitmap)); } else delete bitmap; } } #else app_info info; if (be_app->GetAppInfo(&info) == B_OK) { BFile appFile(&info.ref, B_READ_ONLY); BAppFileInfo appFileInfo(&appFile); if (appFileInfo.InitCheck() == B_OK) { BBitmap *bitmap = new (nothrow) BBitmap(BRect(0, 0, 63, 63), B_RGBA32); if (appFileInfo.GetIcon(bitmap, B_LARGE_ICON) == B_OK) { fConfigView->AddChild(new BitmapView(bitmap)); } else delete bitmap; } } #endif // HAIKU_TARGET_PLATFORM_HAIKU BRect rect = fConfigView->Bounds(); BTextView *text = new BTextView(rect, NULL, rect, B_FOLLOW_NONE, B_WILL_DRAW); text->SetViewColor(fConfigView->Parent()->ViewColor()); text->SetAlignment(B_ALIGN_CENTER); text->SetText(B_TRANSLATE( "\n\nCreate a new account with the Add button.\n\n" "Remove an account with the Remove button on the selected item.\n\n" "Select an item in the list to change its settings.")); rect = text->Bounds(); text->ResizeTo(rect.Width(), text->TextHeight(0, 42)); text->SetTextRect(rect); text->MakeEditable(false); text->MakeSelectable(false); fConfigView->AddChild(text); static_cast<CenterContainer *>(fConfigView)->Layout(); }
MyApp :: MyApp() : BApplication("application/x-vnd.EFM5.ResEdgar"),//if this sig changes change it in appStrings.r as well mpTitleWindow(NULL), AppSignature(NULL), FailCreateSemaphore(NULL), CaughtTitleWindowCTOR(NULL), AppMenuLabel(NULL), CloseWindow(NULL), QuitMenuLabel(NULL), TitleWindowTitle(NULL), ReallyQuitApp(NULL), AboutTitleWindowMsg1(NULL), AboutTitleWindowMsg2(NULL), AboutTitleWindowMsg3(NULL), ProgramName(NULL), ProgramNameSubTitle(NULL), EditResOf(NULL), OrigRes(NULL), EdittedRes(NULL), CaughtResEdWindowCTOR(NULL), Save(NULL), FileMenuLabel(NULL), AboutResEdWindowMsg1(NULL), AboutResEdWindowMsg2(NULL), AboutResEdWindowMsg3(NULL), FailAddResource(NULL), FailRemoveResource(NULL), Load(NULL), FailEntryInitCheck(NULL), FailPathInitCheck(NULL), FailPathSetTo(NULL), FailFileInitCheck(NULL), FailFileFindRef(NULL), OpenPanelTitle(NULL), ResEdWindow(NULL), NoStrRes(NULL), FailResourceSetTo(NULL), AppPrefFailInit(NULL), AppPrefSetFailInit(NULL), AppPrefNoSetData(NULL), AppsPrefsNoSave(NULL) { myApp = this; BResources * appResources = AppResources(); size_t len; AppSignature = (const char *)appResources->FindResource('CSTR', "AppSignature", &len); FailCreateSemaphore = (const char *)appResources->FindResource('CSTR', "FailCreateSemaphore", &len); CaughtTitleWindowCTOR = (const char *)appResources->FindResource('CSTR', "CaughtTitleWindowCTOR", &len); AppMenuLabel = (const char *)appResources->FindResource('CSTR', "AppMenuLabel", &len); CloseWindow = (const char *)appResources->FindResource('CSTR', "CloseWindow", &len); QuitMenuLabel = (const char *)appResources->FindResource('CSTR', "QuitMenuLabel", &len); TitleWindowTitle = (const char *)appResources->FindResource('CSTR', "TitleWindowTitle", &len); ReallyQuitApp = (const char *)appResources->FindResource('CSTR', "ReallyQuitApp", &len); AboutTitleWindowMsg1 = (const char *)appResources->FindResource('CSTR', "AboutTitleWindowMsg1", &len); AboutTitleWindowMsg2 = (const char *)appResources->FindResource('CSTR', "AboutTitleWindowMsg2", &len); AboutTitleWindowMsg3 = (const char *)appResources->FindResource('CSTR', "AboutTitleWindowMsg3", &len); ProgramName = (const char *)appResources->FindResource('CSTR', "ProgramName", &len); ProgramNameSubTitle = (const char *)appResources->FindResource('CSTR', "ProgramNameSubTitle", &len); EditResOf = (const char *)appResources->FindResource('CSTR', "EditResOf", &len); OrigRes = (const char *)appResources->FindResource('CSTR', "OrigRes", &len); EdittedRes = (const char *)appResources->FindResource('CSTR', "EdittedRes", &len); CaughtResEdWindowCTOR = (const char *)appResources->FindResource('CSTR', "CaughtResEdWindowCTOR", &len); Save = (const char *)appResources->FindResource('CSTR', "Save", &len); FileMenuLabel = (const char *)appResources->FindResource('CSTR', "FileMenuLabel", &len); AboutResEdWindowMsg1 = (const char *)appResources->FindResource('CSTR', "AboutResEdWindowMsg1", &len); AboutResEdWindowMsg2 = (const char *)appResources->FindResource('CSTR', "AboutResEdWindowMsg2", &len); AboutResEdWindowMsg3 = (const char *)appResources->FindResource('CSTR', "AboutResEdWindowMsg3", &len); FailAddResource = (const char *)appResources->FindResource('CSTR', "FailAddResource", &len); FailRemoveResource = (const char *)appResources->FindResource('CSTR', "FailRemoveResource", &len); Load = (const char *)appResources->FindResource('CSTR', "Load", &len); FailEntryInitCheck = (const char *)appResources->FindResource('CSTR', "FailEntryInitCheck", &len); FailPathInitCheck = (const char *)appResources->FindResource('CSTR', "FailPathInitCheck", &len); FailPathSetTo = (const char *)appResources->FindResource('CSTR', "FailPathSetTo", &len); FailFileInitCheck = (const char *)appResources->FindResource('CSTR', "FailFileInitCheck", &len); FailFileFindRef = (const char *)appResources->FindResource('CSTR', "FailFileFindRef", &len); OpenPanelTitle = (const char *)appResources->FindResource('CSTR', "OpenPanelTitle", &len); ResEdWindow = (const char *)appResources->FindResource('CSTR', "ResEdWindow", &len); NoStrRes = (const char *)appResources->FindResource('CSTR', "NoStrRes", &len); FailResourceSetTo = (const char *)appResources->FindResource('CSTR', "FailResourceSetTo", &len); AppPrefFailInit = (const char *)appResources->FindResource('CSTR', "AppPrefFailInit", &len); AppPrefSetFailInit = (const char *)appResources->FindResource('CSTR', "AppPrefSetFailInit", &len); AppPrefNoSetData = (const char *)appResources->FindResource('CSTR', "AppPrefNoSetData", &len); AppsPrefsNoSave = (const char *)appResources->FindResource('CSTR', "AppsPrefsNoSave", &len); Preferences appsPreferences(AppSignature); PreferenceSet appsPreferenceSet( appsPreferences, "hierarchical/extendable/settings", true); mpPreferences = new Preferences(AppSignature); Preferences& mrPreferences = *mpPreferences; mpPreferenceSet = new PreferenceSet( mrPreferences, "hierarchical/extendable/settings", true); if (mpPreferences->InitCheck()) { puts(AppPrefFailInit); exit(1); } if (mpPreferenceSet->InitCheck()) { puts(AppPrefSetFailInit); exit(2); } BRect screenResolutionRect; {//I do screen like this so it goes away fast BScreen screen(B_MAIN_SCREEN_ID); if(!screen.IsValid()) {//may not be valid, if not, this is not a critical app--bail out as best we can puts(myPrefs->ScreenNotValid); exit(3); } screenResolutionRect = screen.Frame(); } BRect windowPrefArea; const void * windowPrefAreaData; ssize_t windowPrefAreaSize; uint32 windowPrefAreaType = ' '; if ( mpPreferenceSet->GetData( "TitleWindowFrame", windowPrefAreaData, windowPrefAreaSize, windowPrefAreaType) || (windowPrefAreaType != B_RECT_TYPE)) { windowPrefArea.Set( 5, 22, screenResolutionRect.right - 17, screenResolutionRect.bottom - 37); //the - 17 and - 37 were determined based upon trial and error } else { memcpy( &windowPrefArea, windowPrefAreaData, windowPrefAreaSize); } SetPreferredTitleWindowRect(windowPrefArea); if ( mpPreferenceSet->GetData( "ResEdWindowFrame", windowPrefAreaData, windowPrefAreaSize, windowPrefAreaType) || (windowPrefAreaType != B_RECT_TYPE)) { windowPrefArea.Set( 5, 22, screenResolutionRect.right - 17, screenResolutionRect.bottom - 37); //the - 17 and - 37 were determined based upon trial and error } else { memcpy( &windowPrefArea, windowPrefAreaData, windowPrefAreaSize); } SetPreferredResEdWindowRect(windowPrefArea); }//end
int main (int argc, char **argv) { extern bool VerbQuit, VerbAddOns, NoAddOns, EasterEgg, UseMMX, ShowColors, BuiltInTablet, ExportCstruct; extern int DebugLevel, SilentOperation; VerbQuit = false; VerbAddOns = false; NoAddOns = false; ShowColors = false; PatronizeMIME = true; BuiltInTablet = false; ExportCstruct = false; NoSettings = false; WriteSettings = false; EasterEgg = EASTER_EGG; gGlobalAlpha = REGISTERED; DebugLevel = 0; SilentOperation = 0; UseMMX = true; for (int i = 1; i < argc; i++) { if (argv[i][0] == '-') { switch (argv[i][1]) { case 'v': { VerbAddOns = true; break; } case 'q': { VerbQuit = true; break; } case 'x': { NoAddOns = true; break; } case 'e': { EasterEgg = !EASTER_EGG; break; } case 'D': { DebugLevel = atoi (&(argv[i][2])); fprintf (stderr, "Debug level set to %d\n", DebugLevel); break; } case 'd': { NoSettings = true; break; } case 'w': { WriteSettings = true; break; } case 'S': { SilentOperation = atoi (&(argv[i][2]));; break; } case 'M': { UseMMX = false; break; } case 'C': { ExportCstruct = true; break; } case 'c': { ShowColors = true; break; } case 't': { BuiltInTablet = true; break; } case 'h': { fprintf (stderr, "Recognized command line options:\n"); fprintf (stderr, " -v Verbose add-on loading (useful for debugging your own)\n"); fprintf (stderr, " -q Verbose quitting\n"); fprintf (stderr, " -x Don't load add-ons (faster launch time)\n"); fprintf (stderr, " -d Use default settings (don't load settings)\n"); fprintf (stderr, " -w Force saving of settings (use with -d)\n"); fprintf (stderr, " -Dn Debug verbosity level\n"); fprintf (stderr, " -Sn Silence level (scripting operation)\n"); fprintf (stderr, " -M Don't use MMX\n"); fprintf (stderr, " -c Show recognized RGB color names at startup\n"); fprintf (stderr, " -C Enable export as C struct\n"); fprintf (stderr, " -t Switch on builtin Wacom tablet support\n"); fprintf (stderr, " -h Display this message\n"); break; } default: fprintf (stderr, "Unrecognized command line option: '%c'\n(Becasso -h displays command line usage help)\n", argv[i][1]); } } } #if defined (TIME_LIMITED) struct tm *mytime; time_t mytimet = time (NULL); #endif #if defined (__INTEL__) if (UseMMX) UseMMX = mmx_available(); #else UseMMX = false; #endif if (UseMMX) verbose (1, "MMX detected\n"); else verbose (1, "No MMX\n"); if (BuiltInTablet) verbose (1, "Builtin Tablet support enabled\n"); mainapp = new Becasso(); setup_alphabuffer(); if (DebugLevel) { extern const char *Version; fprintf (stderr, "Becasso version %s %s, built %s\n", Version, (gGlobalAlpha ? "(Registered)" : "(Unregistered)"), __DATE__); } size_t bsize, ssize; void *becassodata, *sumdata; app_info info; mainapp->GetAppInfo (&info); BFile file (&info.ref, O_RDONLY); BResources res (&file); if (!(becassodata = res.FindResource ('blog', 128, &bsize))) fprintf (stderr, "Becasso logo resource not found\n"); if (!(sumdata = res.FindResource ('slog', 129, &ssize))) fprintf (stderr, "Sum logo resource not found\n"); BScreen screen; BRect becassorect = BRect (0, 0, 231, 93); BRect sumrect = BRect (0, 0, 63, 83); BBitmap *becasso = new BBitmap (becassorect, (screen.ColorSpace() == B_COLOR_8_BIT) ? B_COLOR_8_BIT : B_RGB32); // This strange color space thing is because we can't store bitmaps in 16 bit depth, so we use // a 32bit version for this screen mode (which doesn't look too bad). BBitmap *sum = new BBitmap (sumrect, B_RGB32); becasso->SetBits (becassodata, bsize, 0, B_RGB32); sum->SetBits (sumdata, ssize, 0, B_RGB32); BRect center = BRect (0, 0, 280, 210); center.OffsetTo (screen.Frame().Width()/2 - 140, screen.Frame().Height()/2 - 105); splash = new SplashWindow (center, becasso, sum); splash->Minimize (SilentOperation >= 3); splash->Show(); mainapp->LoadAddOns(); #if defined (TIME_LIMITED) mytime = localtime (&mytimet); // if (mytime->tm_year == 97 && mytime->tm_mon < 11) if (mytime->tm_year == 97) mainapp->Run(); else { BAlert *alert = new BAlert ("", "This demo version of Becasso has expired.\nOn http://www.sumware.demon.nl you can find info on obtaining a newer version.\nThanks for your interest in Becasso!", "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); alert->Go(); } #else mainapp->Run(); #endif delete mainapp; // delete BTranslatorRoster::Default(); return 0; }
MyApp :: MyApp() : BApplication("application/x-vnd.EFM5.PrefsEDgar"),//if this sig changes change it in appStrings.r as well AppSignature(NULL), CaughtPrefsEDgarWindowCTOR(NULL), AppMenuLabel(NULL), CloseWindow(NULL), QuitMenuLabel(NULL), PrefsEDgarWindowTitle(NULL), ReallyQuitApp(NULL), AboutPrefsEDgarWindowMsg1(NULL), AboutPrefsEDgarWindowMsg2(NULL), AboutPrefsEDgarWindowMsg3(NULL), ProgramName(NULL), ProgramNameSubTitle(NULL), AppPrefFailInit(NULL), AppPrefSetFailInit(NULL), AppPrefNoSetData(NULL), AppsPrefsNoSave(NULL), FailFetchBitmapFile(NULL), FailFetchBitmapBTranslatorRoster(NULL), FailFetchBitmapTranslate(NULL), NoBitmap(NULL) { myApp = this; BResources * appResources = AppResources(); size_t len; AppSignature = (const char *)appResources->FindResource('CSTR', "AppSignature", &len); CaughtPrefsEDgarWindowCTOR = (const char *)appResources->FindResource('CSTR', "CaughtPrefsEDgarWindowCTOR", &len); AppMenuLabel = (const char *)appResources->FindResource('CSTR', "AppMenuLabel", &len); CloseWindow = (const char *)appResources->FindResource('CSTR', "CloseWindow", &len); QuitMenuLabel = (const char *)appResources->FindResource('CSTR', "QuitMenuLabel", &len); PrefsEDgarWindowTitle = (const char *)appResources->FindResource('CSTR', "PrefsEDgarWindowTitle", &len); ReallyQuitApp = (const char *)appResources->FindResource('CSTR', "ReallyQuitApp", &len); AboutPrefsEDgarWindowMsg1 = (const char *)appResources->FindResource('CSTR', "AboutPrefsEDgarWindowMsg1", &len); AboutPrefsEDgarWindowMsg2 = (const char *)appResources->FindResource('CSTR', "AboutPrefsEDgarWindowMsg2", &len); AboutPrefsEDgarWindowMsg3 = (const char *)appResources->FindResource('CSTR', "AboutPrefsEDgarWindowMsg3", &len); ProgramName = (const char *)appResources->FindResource('CSTR', "ProgramName", &len); ProgramNameSubTitle = (const char *)appResources->FindResource('CSTR', "ProgramNameSubTitle", &len); AppPrefFailInit = (const char *)appResources->FindResource('CSTR', "AppPrefFailInit", &len); AppPrefSetFailInit = (const char *)appResources->FindResource('CSTR', "AppPrefSetFailInit", &len); AppPrefNoSetData = (const char *)appResources->FindResource('CSTR', "AppPrefNoSetData", &len); AppsPrefsNoSave = (const char *)appResources->FindResource('CSTR', "AppsPrefsNoSave", &len); FailFetchBitmapFile = (const char *)appResources->FindResource('CSTR', "FailFetchBitmapFile", &len); FailFetchBitmapBTranslatorRoster = (const char *)appResources->FindResource('CSTR', "FailFetchBitmapBTranslatorRoster", &len); FailFetchBitmapTranslate = (const char *)appResources->FindResource('CSTR', "FailFetchBitmapTranslate", &len); NoBitmap = (const char *)appResources->FindResource('CSTR', "NoBitmap", &len); mpPreferences = new Preferences(AppSignature); Preferences& mrPreferences = *mpPreferences; mpPreferenceSet = new PreferenceSet( mrPreferences, "hierarchical/extendable/settings", true); if (mpPreferences->InitCheck()) { puts(AppPrefFailInit); exit(1); } if (mpPreferenceSet->InitCheck()) { puts(AppPrefSetFailInit); exit(2); } BRect screenResolutionRect; {//I do screen like this so it goes away fast BScreen screen(B_MAIN_SCREEN_ID); if(!screen.IsValid()) {//may not be valid, if not, this is not a critical app--bail out as best we can puts(myPrefs->ScreenNotValid); exit(3); } screenResolutionRect = screen.Frame(); } BRect windowPrefArea; const void * windowPrefAreaData; ssize_t windowPrefAreaSize; uint32 windowPrefAreaType = ' '; if ( mpPreferenceSet->GetData( "PrefsEDgarWindowFrame", windowPrefAreaData, windowPrefAreaSize, windowPrefAreaType) || (windowPrefAreaType != B_RECT_TYPE)) { windowPrefArea.Set( 33, 73, screenResolutionRect.right - 17, screenResolutionRect.bottom - 37); } else { memcpy( &windowPrefArea, windowPrefAreaData, windowPrefAreaSize); } preferredPrefsEDgarWindowRect = windowPrefArea; }//end