void JEApp::ReadyToRun() { // instantiate UI here // preload ICON resources used by UI AppResources()->PreloadResourceType('ICON'); // Window for Source1 source1Win = new VideoWindow(BRect(10.0,75.0, 179.0,204.0), ResString(STRING_SOURCE1), true); // Window for Source2 source2Win = new VideoWindow(BRect(10.0,280.0, 179.0,409.0), ResString(STRING_SOURCE2), true); // Window for default Output defaultOut = new VideoWindow(BRect(510.0,75.0, 839.0,324.0), ResString(STRING_DEFAULT_OUTPUT), false); // Window for Plugins piWindow = new PluginListWindow(BRect(510.0,375.0, 689.0,554.0), ResString(STRING_PLUGINS)); // Main Window mainWin = new MainWindow(BRect(200.0,75.0, 499.0,474.0), "Jeepers Elvis!"); // you need to tell the graphics pipeline about the default output PostMessage(JE_SET_DEFAULT_OUTPUT); // and the sources about their outputs PostMessage(JE_SET_SOURCE_OUTPUTS); }
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
status_t UAE::GetIconResource(char *name,icon_size size,BBitmap *dest) const { if (size != B_LARGE_ICON && size != B_MINI_ICON ) return B_ERROR; size_t len = 0; const void *data = AppResources()->LoadResource(size == B_LARGE_ICON ? 'ICON' : 'MICN',name,&len); if (data == NULL || len != (size_t)(size == B_LARGE_ICON ? 1024 : 256)) return B_ERROR; dest->SetBits(data,(int32)len,0,B_COLOR_8_BIT); return B_OK; }
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
void DjVuApp::InstallMimeType(const char *mimetxt) { // install mime type of documents BMimeType mime(mimetxt); status_t ret = mime.InitCheck(); if (ret != B_OK) { fprintf(stderr, "Could not init native document mime type (%s): %s.\n", mimetxt, strerror(ret)); return; } if (mime.IsInstalled() && !(modifiers() & B_SHIFT_KEY)) { // mime is already installed, and the user is not // pressing the shift key to force a re-install return; } ret = mime.Install(); if (ret != B_OK && ret != B_FILE_EXISTS) { fprintf(stderr, "Could not install native document mime type (%s): %s.\n", mimetxt, strerror(ret)); return; } // set preferred app ret = mime.SetPreferredApp(APPSIGMATURE); if (ret != B_OK) { fprintf(stderr, "Could not set native document preferred app: %s\n", strerror(ret)); } // set descriptions ret = mime.SetShortDescription("DjVu Document"); if (ret != B_OK) { fprintf(stderr, "Could not set short description of mime type: %s\n", strerror(ret)); } ret = mime.SetLongDescription("DjVu Document"); if (ret != B_OK) { fprintf(stderr, "Could not set long description of mime type: %s\n", strerror(ret)); } // set extensions BMessage message('extn'); message.AddString("extensions", "djvu"); message.AddString("extensions", "djv"); ret = mime.SetFileExtensions(&message); if (ret != B_OK) { fprintf(stderr, "Could not set extensions of mime type: %s\n", strerror(ret)); } // set sniffer rule char snifferRule[32]; ret = mime.SetSnifferRule("0.50 (\"AT&TFORM\")"); if (ret != B_OK) { BString parseError; BMimeType::CheckSnifferRule(snifferRule, &parseError); fprintf(stderr, "Could not set sniffer rule of mime type: %s\n", parseError.String()); } // set mime icon BResources* resources = AppResources(); // does not need to be freed (belongs to BApplication base) if (resources != NULL) { size_t size; const void* iconData = resources->LoadResource('VICN', "BEOS:image/x-djvu", &size); if (iconData != NULL && size > 0) { if (mime.SetIcon(reinterpret_cast<const uint8*>(iconData), size) != B_OK) { fprintf(stderr, "Could not set vector icon of mime type.\n"); } } else { fprintf(stderr, "Could not find icon in app resources " "(data: %p, size: %ld).\n", iconData, size); } } else fprintf(stderr, "Could not find app resources.\n"); }
void MainApp::_InstallPlaylistMimeType() { // install mime type of documents BMimeType mime(kBinaryPlaylistMimeString); status_t ret = mime.InitCheck(); if (ret != B_OK) { fprintf(stderr, "Could not init native document mime type (%s): %s.\n", kBinaryPlaylistMimeString, strerror(ret)); return; } if (mime.IsInstalled() && !(modifiers() & B_SHIFT_KEY)) { // mime is already installed, and the user is not // pressing the shift key to force a re-install return; } ret = mime.Install(); if (ret != B_OK && ret != B_FILE_EXISTS) { fprintf(stderr, "Could not install native document mime type (%s): %s.\n", kBinaryPlaylistMimeString, strerror(ret)); return; } // set preferred app ret = mime.SetPreferredApp(kAppSig); if (ret != B_OK) { fprintf(stderr, "Could not set native document preferred app: %s\n", strerror(ret)); } // set descriptions ret = mime.SetShortDescription("MediaPlayer playlist"); if (ret != B_OK) { fprintf(stderr, "Could not set short description of mime type: %s\n", strerror(ret)); } ret = mime.SetLongDescription("MediaPlayer binary playlist file"); if (ret != B_OK) { fprintf(stderr, "Could not set long description of mime type: %s\n", strerror(ret)); } // set extensions BMessage message('extn'); message.AddString("extensions", "playlist"); ret = mime.SetFileExtensions(&message); if (ret != B_OK) { fprintf(stderr, "Could not set extensions of mime type: %s\n", strerror(ret)); } // set sniffer rule char snifferRule[32]; uint32 bigEndianMagic = B_HOST_TO_BENDIAN_INT32(kPlaylistMagicBytes); sprintf(snifferRule, "0.9 ('%4s')", (const char*)&bigEndianMagic); ret = mime.SetSnifferRule(snifferRule); if (ret != B_OK) { BString parseError; BMimeType::CheckSnifferRule(snifferRule, &parseError); fprintf(stderr, "Could not set sniffer rule of mime type: %s\n", parseError.String()); } // set playlist icon BResources* resources = AppResources(); // does not need to be freed (belongs to BApplication base) if (resources != NULL) { size_t size; const void* iconData = resources->LoadResource('VICN', "PlaylistIcon", &size); if (iconData != NULL && size > 0) { if (mime.SetIcon(reinterpret_cast<const uint8*>(iconData), size) != B_OK) { fprintf(stderr, "Could not set vector icon of mime type.\n"); } } else { fprintf(stderr, "Could not find icon in app resources " "(data: %p, size: %ld).\n", iconData, size); } } else fprintf(stderr, "Could not find app resources.\n"); }
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
void CSumItApplication::InstallMimeType() { // install mime type of documents BMimeType mime(kOpenSumItMimeString); status_t ret = mime.InitCheck(); if (ret != B_OK) { fprintf(stderr, "Could not init native document mime type (%s): %s.\n", kOpenSumItMimeString, strerror(ret)); return; } if (mime.IsInstalled() && !(modifiers() & B_SHIFT_KEY)) { // mime is already installed, and the user is not // pressing the shift key to force a re-install printf("Mime is already installed!\n"); return; } ret = mime.Install(); if (ret != B_OK && ret != B_FILE_EXISTS) { fprintf(stderr, "Could not install native document mime type (%s): %s.\n", kOpenSumItMimeString, strerror(ret)); return; } // set preferred app ret = mime.SetPreferredApp(kOpenSumItSignature); if (ret != B_OK) { fprintf(stderr, "Could not set native document preferred app: %s\n", strerror(ret)); } // set descriptions ret = mime.SetShortDescription("OpenSum-It Spreadsheet"); if (ret != B_OK) { fprintf(stderr, "Could not set short description of mime type: %s\n", strerror(ret)); } ret = mime.SetLongDescription("OpenSum-It Spreadsheet File"); if (ret != B_OK) { fprintf(stderr, "Could not set long description of mime type: %s\n", strerror(ret)); } // set sniffer rule // short explanation what 0x565200020300 means: // 0x5652 (chunk type) 'VR' - version // 0x0002 (chunk size) // 0x0300 (chunk value) - version number // More info in sum-it/Source/main/FileSys/FileFormat.h const char* snifferRule = "1.0 (0x565200020300)"; ret = mime.SetSnifferRule(snifferRule); if (ret != B_OK) { BString parseError; BMimeType::CheckSnifferRule(snifferRule, &parseError); fprintf(stderr, "Could not set sniffer rule of mime type: %s\n", parseError.String()); } // set document icon BResources* resources = AppResources(); // does not need to be freed (belongs to BApplication base) if (resources != NULL) { size_t size; const void* iconData = resources->LoadResource('VICN', "OpenSum-It_DocumentIcon", &size); if (iconData != NULL && size > 0) { if (mime.SetIcon(reinterpret_cast<const uint8*>(iconData), size) != B_OK) { fprintf(stderr, "Could not set vector icon of mime type.\n"); } } else { fprintf(stderr, "Could not find icon in app resources " "(data: %p, size: %ld).\n", iconData, size); } } else fprintf(stderr, "Could not find app resources.\n"); }