void OpenWithContainerWindow::NewAttributeMenu(BMenu* menu) { _inherited::NewAttributeMenu(menu); BMessage* message = new BMessage(kAttributeItem); message->AddString("attr_name", kAttrOpenWithRelation); message->AddInt32("attr_type", B_STRING_TYPE); message->AddInt32("attr_hash", (int32)AttrHashString(kAttrOpenWithRelation, B_STRING_TYPE)); message->AddFloat("attr_width", 180); message->AddInt32("attr_align", B_ALIGN_LEFT); message->AddBool("attr_editable", false); message->AddBool("attr_statfield", false); BMenuItem* item = new BMenuItem(B_TRANSLATE("Relation"), message); menu->AddItem(item); message = new BMessage(kAttributeItem); message->AddString("attr_name", kAttrAppVersion); message->AddInt32("attr_type", B_STRING_TYPE); message->AddInt32("attr_hash", (int32)AttrHashString(kAttrAppVersion, B_STRING_TYPE)); message->AddFloat("attr_width", 70); message->AddInt32("attr_align", B_ALIGN_LEFT); message->AddBool("attr_editable", false); message->AddBool("attr_statfield", false); item = new BMenuItem(B_TRANSLATE("Version"), message); menu->AddItem(item); }
void Settings::_SetDefaults() { fMessage.AddRect("file_types_frame", BRect(80.0f, 80.0f, 600.0f, 480.0f)); fMessage.AddRect("app_types_frame", BRect(100.0f, 100.0f, 540.0f, 480.0f)); fMessage.AddBool("show_icons", true); fMessage.AddBool("show_rule", false); fMessage.AddFloat("left_split_weight", 0.2); fMessage.AddFloat("right_split_weight", 0.8); }
status_t VBoxMouse::_ServiceThread() { Log(("VBoxMouse::%s()\n", __FUNCTION__)); fDriverFD = open(VBOXGUEST_DEVICE_NAME, O_RDWR); if (fDriverFD < 0) return ENXIO; /* The thread waits for incoming messages from the host. */ while (!fExiting) { uint32_t cx, cy, fFeatures; int rc; fd_set readSet, writeSet, errorSet; FD_ZERO(&readSet); FD_ZERO(&writeSet); FD_ZERO(&errorSet); FD_SET(fDriverFD, &readSet); if (fDriverFD < 0) break; rc = select(fDriverFD + 1, &readSet, &writeSet, &errorSet, NULL); if (rc < 0) { if (errno == EINTR || errno == EAGAIN) continue; break; } rc = VbglR3GetMouseStatus(&fFeatures, &cx, &cy); if ( RT_SUCCESS(rc) && (fFeatures & VMMDEV_MOUSE_HOST_WANTS_ABSOLUTE)) { float x = cx * 1.0 / 65535; float y = cy * 1.0 / 65535; _debugPrintf("VBoxMouse: at %d,%d %f,%f\n", cx, cy, x, y); /* Send absolute movement */ bigtime_t now = system_time(); BMessage *event = new BMessage(B_MOUSE_MOVED); event->AddInt64("when", now); event->AddFloat("x", x); event->AddFloat("y", y); event->AddFloat("be:tablet_x", x); event->AddFloat("be:tablet_y", y); //event->PrintToStream(); EnqueueMessage(event); //LogRelFlow(("processed host event rc = %d\n", rc)); } } return 0; }
void BColumn::ArchiveToMessage(BMessage &message) const { message.AddInt32(kColumnVersionName, kColumnStateArchiveVersion); message.AddString(kColumnTitleName, fTitle); message.AddFloat(kColumnOffsetName, fOffset); message.AddFloat(kColumnWidthName, fWidth); message.AddInt32(kColumnAlignmentName, fAlignment); message.AddString(kColumnAttrName, fAttrName); message.AddInt32(kColumnAttrHashName, static_cast<int32>(fAttrHash)); message.AddInt32(kColumnAttrTypeName, static_cast<int32>(fAttrType)); message.AddBool(kColumnStatFieldName, fStatField); message.AddBool(kColumnEditableName, fEditable); }
void MainWin::PlayBuffer(void *cookie, void *buffer, size_t size, const media_raw_audio_format &format) { int64 frames = 0; playTrack->ReadFrames(buffer, &frames); MainWin *window = (MainWin *)cookie; bigtime_t now; if (sp->CurrentTime() < time) now = time + sp->CurrentTime(); else now = time = sp->CurrentTime(); char timestamp[64]; MainWin::Timestamp(timestamp, time); BMessage *update = new BMessage(MSG_UPDATE_PROGRESS); update->AddFloat("current", (float) now); update->AddString("time", timestamp); window->PostMessage(update); if (frames <= 0) { sp->SetHasData(false); window->PostMessage(MSG_NEXT); } }
void PackageManager::ReadyToRun() { // Open the main window BRect frame(20, 40, 600, 400); fMainWindow = new ApplicationWindow(frame, true); // Add some test content to the window fMainWindow->AddCategory("Test category", "development", "Thisis a short description of the category"); BMessage entryInfo; // This message is a convenient way of storing various infos about an app. // What's inside : // icon as an archived BBitmap entryInfo.AddString("appname", "Test Application"); entryInfo.AddString("appdesc", "Some text telling what it does"); entryInfo.AddFloat("appver", 1.302); // as a float so it can be compared to decide if there is an update entryInfo.AddInt32("appsize", 123456); // this is in bytes fMainWindow->AddApplication(&entryInfo); fMainWindow->Show(); }
status_t TouchpadPref::UpdateSettings() { if (!fConnected) return B_ERROR; LOG("UpdateSettings of device %s\n", fTouchPad->Name()); BMessage msg; msg.AddBool("scroll_twofinger", fSettings.scroll_twofinger); msg.AddBool("scroll_twofinger_horizontal", fSettings.scroll_twofinger_horizontal); msg.AddFloat("scroll_rightrange", fSettings.scroll_rightrange); msg.AddFloat("scroll_bottomrange", fSettings.scroll_bottomrange); msg.AddInt16("scroll_xstepsize", fSettings.scroll_xstepsize); msg.AddInt16("scroll_ystepsize", fSettings.scroll_ystepsize); msg.AddInt8("scroll_acceleration", fSettings.scroll_acceleration); msg.AddInt8("tapgesture_sensibility", fSettings.tapgesture_sensibility); return fTouchPad->Control(MS_SET_TOUCHPAD_SETTINGS, &msg); }
status_t Settings::SetDefaults() { sSettings.MakeEmpty(); sSettings.AddString(kOutputFile, "/boot/home/outputfile"); sSettings.AddFloat(kClipShrink, 100); sSettings.AddInt32(kClipDepth, B_RGB32); sSettings.AddBool(kIncludeCursor, true); sSettings.AddInt32(kThreadPriority, B_NORMAL_PRIORITY); sSettings.AddBool(kMinimize, false); return B_OK; }
/*static*/ status_t GuiSettingsUtils::ArchiveSplitView(BMessage& settings, BSplitView* view) { settings.MakeEmpty(); for (int32 i = 0; i < view->CountItems(); i++) { if (settings.AddFloat("weight", view->ItemWeight(i)) != B_OK) return B_NO_MEMORY; if (settings.AddBool("collapsed", view->IsItemCollapsed(i)) != B_OK) return B_NO_MEMORY; } return B_OK; }
void Slider::NotifyTarget () { if (!target) { fprintf (stderr, "Slider: Null target\n"); return; } BMessage *changed = new BMessage (*msg); changed->AddFloat ("value", value); // printf ("%f\n", value); target->LockLooper(); target->MessageReceived (changed); target->UnlockLooper(); delete changed; }
BMenuItem* ShowImageWindow::_AddDelayItem(BMenu *menu, const char *label, float value) { BMessage* message = new BMessage(MSG_SLIDE_SHOW_DELAY); message->AddFloat("value", value); BMenuItem* item = new BMenuItem(label, message, 0); item->SetTarget(this); bool marked = fImageView->GetSlideShowDelay() == value; if (marked) item->SetMarked(true); menu->AddItem(item); return item; }
// Saves the application settings file to (saveEntry). Because this is a // non-essential file, errors are ignored when writing the settings. void ShortcutsWindow::_SaveWindowSettings(BEntry& saveEntry) { BFile saveTo(&saveEntry, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); if (saveTo.InitCheck() != B_OK) return; BMessage saveMsg; saveMsg.AddRect("window frame", Frame()); for (int i = 0; i < fColumnListView->CountColumns(); i++) { CLVColumn* column = fColumnListView->ColumnAt(i); saveMsg.AddFloat("column width", column->Width()); } saveMsg.Flatten(&saveTo); }
void TBarApp::SaveSettings() { if (fSettingsFile->InitCheck() == B_OK) { fSettingsFile->Seek(0, SEEK_SET); BMessage prefs; prefs.AddBool("vertical", fSettings.vertical); prefs.AddBool("left", fSettings.left); prefs.AddBool("top", fSettings.top); prefs.AddInt32("state", fSettings.state); prefs.AddFloat("width", fSettings.width); prefs.AddPoint("switcherLoc", fSettings.switcherLoc); prefs.AddBool("showClock", fSettings.showClock); // applications prefs.AddBool("trackerAlwaysFirst", fSettings.trackerAlwaysFirst); prefs.AddBool("sortRunningApps", fSettings.sortRunningApps); prefs.AddBool("superExpando", fSettings.superExpando); prefs.AddBool("expandNewTeams", fSettings.expandNewTeams); prefs.AddBool("hideLabels", fSettings.hideLabels); prefs.AddInt32("iconSize", fSettings.iconSize); // recent items prefs.AddBool("recentDocsEnabled", fSettings.recentDocsEnabled); prefs.AddBool("recentFoldersEnabled", fSettings.recentFoldersEnabled); prefs.AddBool("recentAppsEnabled", fSettings.recentAppsEnabled); prefs.AddInt32("recentDocsCount", fSettings.recentDocsCount); prefs.AddInt32("recentFoldersCount", fSettings.recentFoldersCount); prefs.AddInt32("recentAppsCount", fSettings.recentAppsCount); // window prefs.AddBool("alwaysOnTop", fSettings.alwaysOnTop); prefs.AddBool("autoRaise", fSettings.autoRaise); prefs.AddBool("autoHide", fSettings.autoHide); prefs.Flatten(fSettingsFile); } if (fClockSettingsFile->InitCheck() == B_OK) { fClockSettingsFile->Seek(0, SEEK_SET); BMessage prefs; prefs.AddBool("showSeconds", fClockSettings.showSeconds); prefs.AddBool("showDayOfWeek", fClockSettings.showDayOfWeek); prefs.AddBool("showTimeZone", fClockSettings.showTimeZone); prefs.Flatten(fClockSettingsFile); } }
status_t FloatItem::Invoke(BMessage *message) { BMessage *sendMessage = NULL; BMessage *valueContainer = new BMessage(); if (message==NULL) sendMessage = new BMessage(*Message()); else sendMessage = new BMessage(*message); if (sendMessage != NULL) { sendMessage->FindMessage("valueContainer",valueContainer); valueContainer->AddInt32("type",B_FLOAT_TYPE); valueContainer->AddString("name",label); valueContainer->AddFloat("newValue", GetFloat()); sendMessage->ReplaceMessage("valueContainer",valueContainer); BInvoker::Invoke(sendMessage); } else return B_ERROR; }
status_t DisplayView::Save() { BPath path; if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) return B_ERROR; path.Append(kSettingsDirectory); path.Append(kDisplaySettings); BMessage settings; float width = atof(fWindowWidth->Text()); settings.AddFloat(kWidthName, width); icon_size iconSize = kDefaultIconSize; switch (fIconSize->IndexOf(fIconSize->FindMarked())) { case 0: iconSize = B_MINI_ICON; break; default: iconSize = B_LARGE_ICON; } settings.AddInt32(kIconSizeName, (int32)iconSize); // Save settings file BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); status_t ret = settings.Flatten(&file); if (ret != B_OK) { BAlert* alert = new BAlert("", B_TRANSLATE("Can't save preferenes, you probably don't have " "write access to the settings directory or the disk is full."), B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); (void)alert->Go(); return ret; } return B_OK; }
void TBarApp::SaveSettings() { if (fSettingsFile->InitCheck() == B_OK) { fSettingsFile->Seek(0, SEEK_SET); BMessage storedSettings; storedSettings.AddBool("vertical", fSettings.vertical); storedSettings.AddBool("left", fSettings.left); storedSettings.AddBool("top", fSettings.top); storedSettings.AddBool("ampmMode", fSettings.ampmMode); storedSettings.AddInt32("state", fSettings.state); storedSettings.AddFloat("width", fSettings.width); storedSettings.AddBool("showTime", fSettings.showTime); storedSettings.AddPoint("switcherLoc", fSettings.switcherLoc); storedSettings.AddInt32("recentAppsCount", fSettings.recentAppsCount); storedSettings.AddInt32("recentDocsCount", fSettings.recentDocsCount); storedSettings.AddBool("timeShowSeconds", fSettings.timeShowSeconds); storedSettings.AddInt32("recentFoldersCount", fSettings.recentFoldersCount); storedSettings.AddBool("alwaysOnTop", fSettings.alwaysOnTop); storedSettings.AddBool("timeFullDate", fSettings.timeFullDate); storedSettings.AddBool("trackerAlwaysFirst", fSettings.trackerAlwaysFirst); storedSettings.AddBool("sortRunningApps", fSettings.sortRunningApps); storedSettings.AddBool("superExpando", fSettings.superExpando); storedSettings.AddBool("expandNewTeams", fSettings.expandNewTeams); storedSettings.AddBool("autoRaise", fSettings.autoRaise); storedSettings.AddBool("autoHide", fSettings.autoHide); storedSettings.AddBool("recentAppsEnabled", fSettings.recentAppsEnabled); storedSettings.AddBool("recentDocsEnabled", fSettings.recentDocsEnabled); storedSettings.AddBool("recentFoldersEnabled", fSettings.recentFoldersEnabled); storedSettings.Flatten(fSettingsFile); } }
status_t AttributeMessage::_SetFontAttribute(const char* name, const FontClass& font) { font_family family; font_style style; font.GetFamilyAndStyle(&family, &style); BMessage archivedFont; status_t ret = archivedFont.AddString("family", family); if (ret == B_OK) ret = archivedFont.AddString("style", style); if (ret == B_OK) ret = archivedFont.AddFloat("size", font.Size()); // TODO: Store more properties? if (ret != B_OK) return ret; if (ReplaceMessage(name, &archivedFont) == B_OK) return B_OK; return AddMessage(name, &archivedFont); }
status_t SeqManageRosterWindow::GetConfiguration(BMessage* config) { ArpASSERT(config); config->what = ConfigWhat(); status_t err = GetDimensions(config, this); if (err != B_OK) return err; /* Add the columns */ BColumnListView* table = dynamic_cast<BColumnListView*>( FindView(TABLE_STR) ); if (table) { BColumn* col; for( int32 k = 0; (col = table->ColumnAt(k)); k++ ) { BMessage colMsg; BString colName; col->GetColumnName(&colName); if( colMsg.AddString("name", colName.String() ) == B_OK && colMsg.AddFloat("width", col->Width() ) == B_OK && colMsg.AddBool("visible", col->IsVisible() ) == B_OK ) { config->AddMessage("column", &colMsg); } } } return B_OK; }
void TJerFile::CopyStrucFile(const char *SrcDir, const char *DestDir, BList *Diff) { entry_ref *truc; BEntry *entry; BPath chemin; BPath Destination; char *Relative; char *TheRelativePathAndName; /* printf("------------------------------------\n"); printf("ZIPPathName : %s \n",ZIPPathName); printf("SrcDir : %s \n",SrcDir); printf("DestDir : %s \n",DestDir); printf("------------------------------------\n"); */ BMessage *AMessage; AMessage = new BMessage(B_RESET_STATUS_BAR); AMessage->AddFloat("maximum",Diff->CountItems()); MyInvoker.Invoke(AMessage); delete AMessage; try { for (int ind=0;ind < Diff->CountItems();ind++ ) { truc = (entry_ref *)(Diff->ItemAt(ind)); if (truc!=NULL) { entry = new BEntry(truc); entry->GetPath(&chemin); if (CreateZIP == true) { // printf("Zipping............\n"); char *titi; titi = (char *)malloc(sizeof(char)*(strlen(DestDir) + strlen(FBackupName) +2 )); //count the \0 and the / for the directory! strcpy(titi,DestDir); strcat(titi,"/"); strcat(titi,FBackupName); // string titi(DestDir); /* printf("------------------------------------\n"); printf("ZIPPathName : %s \n",ZIPPathName); printf("chemin : %s \n",chemin.Path()); printf("titi : %s \n",titi.c_str()); printf("SrcDir : %s \n",SrcDir); printf("DestDir : %s \n",DestDir); printf("------------------------------------\n"); */ // titi = titi + "/BeBackup.zip"; // AddFileToZIP(chemin.Path(),titi.c_str()); AddFileToZIP(chemin.Path(),titi); } else { GetRelativePath(SrcDir,chemin.Path(),&Relative); CreateCompletePath(DestDir,Relative); GetRelativePathAndName(SrcDir,chemin.Path(),&TheRelativePathAndName); Destination.SetTo(DestDir); string toto(Destination.Path()); toto = toto + TheRelativePathAndName; CopyFile(chemin.Path(),toto.c_str()); } delete entry; } else printf("Items is null...\n"); } } //Try catch(GeneralException &e) { printf("Exception while copying... %s %s",e.Message.c_str(),e.Location.c_str()); } }
static status_t add_to_message(TReadHelper& source, BMessage& target, tiff_tag& tag, const char* name, type_code type) { type_code defaultType = B_INT32_TYPE; double doubleValue = 0.0; int32 intValue = 0; switch (tag.type) { case TIFF_STRING_TYPE: { if (type != B_ANY_TYPE && type != B_STRING_TYPE) return B_BAD_VALUE; char* buffer = (char*)malloc(tag.length); if (buffer == NULL) return B_NO_MEMORY; source(buffer, tag.length); // remove trailing spaces int32 i = tag.length; while ((--i > 0 && isspace(buffer[i])) || !buffer[i]) { buffer[i] = '\0'; } status_t status = target.AddString(name, buffer); free(buffer); return status; } case TIFF_UNDEFINED_TYPE: { if (type != B_ANY_TYPE && type != B_STRING_TYPE && type != B_RAW_TYPE) return B_BAD_VALUE; char* buffer = (char*)malloc(tag.length); if (buffer == NULL) return B_NO_MEMORY; source(buffer, tag.length); status_t status; if (type == B_STRING_TYPE) status = target.AddString(name, buffer); else status = target.AddData(name, B_RAW_TYPE, buffer, tag.length); free(buffer); return status; } // unsigned case TIFF_UINT8_TYPE: intValue = source.Next<uint8>(); break; case TIFF_UINT16_TYPE: defaultType = B_INT32_TYPE; intValue = source.Next<uint16>(); break; case TIFF_UINT32_TYPE: defaultType = B_INT32_TYPE; intValue = source.Next<uint32>(); break; case TIFF_UFRACTION_TYPE: { defaultType = B_DOUBLE_TYPE; double value = source.Next<uint32>(); doubleValue = value / source.Next<uint32>(); break; } // signed case TIFF_INT8_TYPE: intValue = source.Next<int8>(); break; case TIFF_INT16_TYPE: intValue = source.Next<int16>(); break; case TIFF_INT32_TYPE: intValue = source.Next<int32>(); break; case TIFF_FRACTION_TYPE: { defaultType = B_DOUBLE_TYPE; double value = source.Next<int32>(); doubleValue = value / source.Next<int32>(); break; } // floating point case TIFF_FLOAT_TYPE: defaultType = B_FLOAT_TYPE; doubleValue = source.Next<float>(); break; case TIFF_DOUBLE_TYPE: defaultType = B_DOUBLE_TYPE; doubleValue = source.Next<double>(); break; default: return B_BAD_VALUE; } if (defaultType == B_INT32_TYPE) doubleValue = intValue; else intValue = int32(doubleValue + 0.5); if (type == B_ANY_TYPE) type = defaultType; switch (type) { case B_INT32_TYPE: return target.AddInt32(name, intValue); case B_FLOAT_TYPE: return target.AddFloat(name, doubleValue); case B_DOUBLE_TYPE: return target.AddDouble(name, doubleValue); default: return B_BAD_VALUE; } }
TestApplication::TestApplication() : BApplication("application/x-vnd.ARP-layoutest") { TestWindow *aWindow; // Instantiate the test window, and make it visible. aWindow = new TestWindow(this); aWindow->Show(); fflush(stdout); fflush(stderr); { DB(DBALL,cdb << "Testing messages..." << endl); BMessage testMsg; status_t res = testMsg.AddInt32("A param...",65); DB(DBALL,cdb << "Added an int32; result=" << res << endl); res = testMsg.AddFloat("A param...",103.4); DB(DBALL,cdb << "Added a float; result=" << res << endl); DB(DBALL,cdb << "Final message = " << testMsg << endl); DB(DBALL,cdb.flush()); } { BStopWatch watch("FuncCall StopWatch"); watch.Reset(); printf("Testing virtual function calls...\n"); int64 i; watch.Resume(); const int fcount = 10000000; for( i=0; i<fcount; i++ ) { aWindow->TestFunc("a string",23); } watch.Suspend(); bigtime_t el = watch.ElapsedTime(); printf("Operations per second: %f\n", (((float)fcount)*1000000.0)/(float)el); } { BStopWatch watch("BMessage StopWatch"); watch.Reset(); printf("Testing BMessage invocation...\n"); int64 i; watch.Resume(); const int fcount = 10000000; for( i=0; i<fcount; i++ ) { BMessage testMsg; aWindow->TestMsg(testMsg); } watch.Suspend(); bigtime_t el = watch.ElapsedTime(); printf("Operations per second: %f\n", (((float)fcount)*1000000.0)/(float)el); } { BStopWatch watch("BMessage init StopWatch"); watch.Reset(); printf("Testing BMessage initialization...\n"); int64 i; watch.Resume(); const int fcount = 10000; for( i=0; i<fcount; i++ ) { BMessage testMsg; testMsg.AddInt32("A param...",65); aWindow->TestMsg(testMsg); } watch.Suspend(); bigtime_t el = watch.ElapsedTime(); printf("Operations per second: %f\n", (((float)fcount)*1000000.0)/(float)el); } }
bool CanvasEventStream::EventReceived(CanvasMessage& message) { uint16 code = message.Code(); uint32 what = 0; switch (code) { case RP_MOUSE_MOVED: what = B_MOUSE_MOVED; break; case RP_MOUSE_DOWN: what = B_MOUSE_DOWN; break; case RP_MOUSE_UP: what = B_MOUSE_UP; break; case RP_MOUSE_WHEEL_CHANGED: what = B_MOUSE_WHEEL_CHANGED; break; case RP_KEY_DOWN: what = B_KEY_DOWN; break; case RP_KEY_UP: what = B_KEY_UP; break; case RP_MODIFIERS_CHANGED: what = B_MODIFIERS_CHANGED; break; } if (what == 0) return false; BMessage* event = new BMessage(what); if (event == NULL) return false; event->AddInt64("when", system_time()); switch (code) { case RP_MOUSE_MOVED: case RP_MOUSE_DOWN: case RP_MOUSE_UP: { message.Read(fMousePosition); if (code != RP_MOUSE_MOVED) message.Read(fMouseButtons); event->AddPoint("where", fMousePosition); event->AddInt32("buttons", fMouseButtons); event->AddInt32("modifiers", fModifiers); if (code == RP_MOUSE_DOWN) { int32 clicks; if (message.Read(clicks) == B_OK) event->AddInt32("clicks", clicks); } if (code == RP_MOUSE_MOVED) fLatestMouseMovedEvent = event; break; } case RP_MOUSE_WHEEL_CHANGED: { float xDelta, yDelta; message.Read(xDelta); message.Read(yDelta); event->AddFloat("be:wheel_delta_x", xDelta); event->AddFloat("be:wheel_delta_y", yDelta); break; } case RP_KEY_DOWN: case RP_KEY_UP: { int32 numBytes; if (message.Read(numBytes) != B_OK) break; char* bytes = (char*)malloc(numBytes + 1); if (bytes == NULL) break; if (message.ReadList(bytes, numBytes) != B_OK) { free(bytes); break; } for (int32 i = 0; i < numBytes; i++) event->AddInt8("byte", (int8)bytes[i]); bytes[numBytes] = 0; event->AddData("bytes", B_STRING_TYPE, bytes, numBytes + 1, false); event->AddInt32("modifiers", fModifiers); int32 rawChar; if (message.Read(rawChar) == B_OK) event->AddInt32("raw_char", rawChar); int32 key; if (message.Read(key) == B_OK) event->AddInt32("key", key); free(bytes); break; } case RP_MODIFIERS_CHANGED: { event->AddInt32("be:old_modifiers", fModifiers); message.Read(fModifiers); event->AddInt32("modifiers", fModifiers); break; } } BAutolock lock(fEventListLocker); fEventList.AddItem(event); if (fWaitingOnEvent) { fWaitingOnEvent = false; lock.Unlock(); release_sem(fEventNotification); } return true; }
PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName) : HWindow(BRect(0,0,400,220), "Page setup", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE), fResult(B_ERROR), fSetupMsg(msg), fAdvancedSettings(*msg), fPrinterDirName(printerName) { fExitSem = create_sem(0, "PageSetup"); if (printerName) SetTitle(BString(printerName).Append(" page setup").String()); if (fSetupMsg->FindInt32("orientation", &fCurrentOrientation) != B_OK) fCurrentOrientation = PrinterDriver::PORTRAIT_ORIENTATION; BRect page; float width = letter_width; float height = letter_height; if (fSetupMsg->FindRect("paper_rect", &page) == B_OK) { width = page.Width(); height = page.Height(); } else { page.Set(0, 0, width, height); } BString label; if (fSetupMsg->FindString("pdf_paper_size", &label) != B_OK) label = "Letter"; int32 compression; fSetupMsg->FindInt32("pdf_compression", &compression); int32 units; if (fSetupMsg->FindInt32("units", &units) != B_OK) units = kUnitInch; // re-calculate the margin from the printable rect in points BRect margin = page; if (fSetupMsg->FindRect("printable_rect", &margin) == B_OK) { margin.top -= page.top; margin.left -= page.left; margin.right = page.right - margin.right; margin.bottom = page.bottom - margin.bottom; } else { margin.Set(28.34, 28.34, 28.34, 28.34); // 28.34 dots = 1cm } BString setting_value; if (fSetupMsg->FindString("pdf_compatibility", &setting_value) != B_OK) setting_value = "1.3"; // Load font settings fFonts = new Fonts(); fFonts->CollectFonts(); BMessage fonts; if (fSetupMsg->FindMessage("fonts", &fonts) == B_OK) fFonts->SetTo(&fonts); // add a *dialog* background BRect bounds(Bounds()); BBox *panel = new BBox(bounds, "background", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER); AddChild(panel); bounds.InsetBy(10.0, 10.0); bounds.right = 230.0; bounds.bottom = 160.0; fMarginView = new MarginView(bounds, int32(width), int32(height), margin, MarginUnit(units)); panel->AddChild(fMarginView); fMarginView->SetResizingMode(B_FOLLOW_NONE); BPopUpMenu* m = new BPopUpMenu("Page size"); m->SetRadioMode(true); bounds.OffsetBy(bounds.Width() + 10.0, 5.0); float divider = be_plain_font->StringWidth("PDF compatibility: "); fPageSizeMenu = new BMenuField(bounds, "page_size", "Page size:", m); panel->AddChild(fPageSizeMenu); fPageSizeMenu->ResizeToPreferred(); fPageSizeMenu->SetDivider(divider); fPageSizeMenu->Menu()->SetLabelFromMarked(true); for (int32 i = 0; pageFormat[i].label != NULL; i++) { BMessage* message = new BMessage(PAGE_SIZE_CHANGED); message->AddFloat("width", pageFormat[i].width); message->AddFloat("height", pageFormat[i].height); BMenuItem* item = new BMenuItem(pageFormat[i].label, message); m->AddItem(item); if (label.Compare(pageFormat[i].label) == 0) item->SetMarked(true); } m = new BPopUpMenu("Orientation"); m->SetRadioMode(true); bounds.OffsetBy(0.0, fPageSizeMenu->Bounds().Height() + 10.0); fOrientationMenu = new BMenuField(bounds, "orientation", "Orientation:", m); panel->AddChild(fOrientationMenu); fOrientationMenu->ResizeToPreferred(); fOrientationMenu->SetDivider(divider); fOrientationMenu->Menu()->SetLabelFromMarked(true); for (int32 i = 0; orientation[i].label != NULL; i++) { BMessage* message = new BMessage(ORIENTATION_CHANGED); message->AddInt32("orientation", orientation[i].orientation); BMenuItem* item = new BMenuItem(orientation[i].label, message); m->AddItem(item); if (fCurrentOrientation == orientation[i].orientation) item->SetMarked(true); } m = new BPopUpMenu("PDF compatibility"); m->SetRadioMode(true); bounds.OffsetBy(0.0, fOrientationMenu->Bounds().Height() + 10.0); fPDFCompatibilityMenu = new BMenuField(bounds, "pdf_compatibility", "PDF compatibility:", m); panel->AddChild(fPDFCompatibilityMenu); fPDFCompatibilityMenu->ResizeToPreferred(); fPDFCompatibilityMenu->SetDivider(divider); fPDFCompatibilityMenu->Menu()->SetLabelFromMarked(true); for (int32 i = 0; pdf_compatibility[i] != NULL; i++) { BMenuItem* item = new BMenuItem(pdf_compatibility[i], NULL); m->AddItem(item); if (setting_value == pdf_compatibility[i]) item->SetMarked(true); } bounds.OffsetBy(0.0, fPDFCompatibilityMenu->Bounds().Height() + 10.0); fPDFCompressionSlider = new BSlider(bounds, "pdf_compression", "Compression:", NULL, 0, 9); panel->AddChild(fPDFCompressionSlider); fPDFCompressionSlider->SetLimitLabels("None", "Best"); fPDFCompressionSlider->SetHashMarks(B_HASH_MARKS_BOTTOM); fPDFCompressionSlider->SetValue(compression); fPDFCompressionSlider->ResizeToPreferred(); bounds = Bounds(); bounds.InsetBy(5.0, 0.0); bounds.top = MAX(fPDFCompressionSlider->Frame().bottom, fMarginView->Frame().bottom) + 10.0; BBox *line = new BBox(BRect(bounds.left, bounds.top, bounds.right, bounds.top + 1.0), NULL, B_FOLLOW_LEFT_RIGHT); panel->AddChild(line); bounds.InsetBy(5.0, 0.0); bounds.OffsetBy(0.0, 11.0); BButton *cancel = new BButton(bounds, NULL, "Cancel", new BMessage(CANCEL_MSG)); panel->AddChild(cancel); cancel->ResizeToPreferred(); BButton *ok = new BButton(bounds, NULL, "OK", new BMessage(OK_MSG)); panel->AddChild(ok, cancel); ok->ResizeToPreferred(); bounds.right = fPDFCompressionSlider->Frame().right; ok->MoveTo(bounds.right - ok->Bounds().Width(), ok->Frame().top); bounds = ok->Frame(); cancel->MoveTo(bounds.left - cancel->Bounds().Width() - 10.0, bounds.top); ok->MakeDefault(true); ResizeTo(bounds.right + 10.0, bounds.bottom + 10.0); BButton *button = new BButton(bounds, NULL, "Fonts" B_UTF8_ELLIPSIS, new BMessage(FONTS_MSG)); panel->AddChild(button); button->ResizeToPreferred(); button->MoveTo(fMarginView->Frame().left, bounds.top); bounds = button->Frame(); button = new BButton(bounds, NULL, "Advanced" B_UTF8_ELLIPSIS, new BMessage(ADVANCED_MSG)); panel->AddChild(button); button->ResizeToPreferred(); button->MoveTo(bounds.right + 10, bounds.top); BRect winFrame(Frame()); BRect screenFrame(BScreen().Frame()); MoveTo((screenFrame.right - winFrame.right) / 2, (screenFrame.bottom - winFrame.bottom) / 2); }
PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName) : HWindow(BRect(0, 0, 200, 100), "Page setup", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE), fResult(B_ERROR), fSetupMsg(msg), fAdvancedSettings(*msg), fPrinterDirName(printerName) { fExitSem = create_sem(0, "PageSetup"); if (printerName) SetTitle(BString(printerName).Append(" page setup").String()); if (fSetupMsg->FindInt32("orientation", &fCurrentOrientation) != B_OK) fCurrentOrientation = PrinterDriver::PORTRAIT_ORIENTATION; BRect page; float width = letter_width; float height = letter_height; if (fSetupMsg->FindRect("paper_rect", &page) == B_OK) { width = page.Width(); height = page.Height(); } else { page.Set(0, 0, width, height); } BString label; if (fSetupMsg->FindString("pdf_paper_size", &label) != B_OK) label = "Letter"; int32 compression; fSetupMsg->FindInt32("pdf_compression", &compression); int32 units; if (fSetupMsg->FindInt32("units", &units) != B_OK) units = kUnitInch; // re-calculate the margin from the printable rect in points BRect margin = page; if (fSetupMsg->FindRect("printable_rect", &margin) == B_OK) { margin.top -= page.top; margin.left -= page.left; margin.right = page.right - margin.right; margin.bottom = page.bottom - margin.bottom; } else { margin.Set(28.34, 28.34, 28.34, 28.34); // 28.34 dots = 1cm } BString setting_value; if (fSetupMsg->FindString("pdf_compatibility", &setting_value) != B_OK) setting_value = "1.3"; // Load font settings fFonts = new Fonts(); fFonts->CollectFonts(); BMessage fonts; if (fSetupMsg->FindMessage("fonts", &fonts) == B_OK) fFonts->SetTo(&fonts); fMarginView = new MarginView(int32(width), int32(height), margin, MarginUnit(units)); BPopUpMenu* pageSize = new BPopUpMenu("Page size"); pageSize->SetRadioMode(true); fPageSizeMenu = new BMenuField("page_size", "Page size:", pageSize); fPageSizeMenu->Menu()->SetLabelFromMarked(true); for (int32 i = 0; pageFormat[i].label != NULL; i++) { BMessage* message = new BMessage(PAGE_SIZE_CHANGED); message->AddFloat("width", pageFormat[i].width); message->AddFloat("height", pageFormat[i].height); BMenuItem* item = new BMenuItem(pageFormat[i].label, message); pageSize->AddItem(item); if (label.Compare(pageFormat[i].label) == 0) item->SetMarked(true); } BPopUpMenu* orientationPopUpMenu = new BPopUpMenu("Orientation"); orientationPopUpMenu->SetRadioMode(true); fOrientationMenu = new BMenuField("orientation", "Orientation:", orientationPopUpMenu); fOrientationMenu->Menu()->SetLabelFromMarked(true); for (int32 i = 0; orientation[i].label != NULL; i++) { BMessage* message = new BMessage(ORIENTATION_CHANGED); message->AddInt32("orientation", orientation[i].orientation); BMenuItem* item = new BMenuItem(orientation[i].label, message); orientationPopUpMenu->AddItem(item); if (fCurrentOrientation == orientation[i].orientation) item->SetMarked(true); } BPopUpMenu* compatibility = new BPopUpMenu("PDF compatibility"); compatibility->SetRadioMode(true); fPDFCompatibilityMenu = new BMenuField("pdf_compatibility", "PDF compatibility:", compatibility); fPDFCompatibilityMenu->Menu()->SetLabelFromMarked(true); for (int32 i = 0; pdf_compatibility[i] != NULL; i++) { BMenuItem* item = new BMenuItem(pdf_compatibility[i], NULL); compatibility->AddItem(item); if (setting_value == pdf_compatibility[i]) item->SetMarked(true); } fPDFCompressionSlider = new BSlider("pdf_compression", "Compression:", NULL, 0, 9, B_HORIZONTAL); fPDFCompressionSlider->SetLimitLabels("None", "Best"); fPDFCompressionSlider->SetHashMarks(B_HASH_MARKS_BOTTOM); fPDFCompressionSlider->SetValue(compression); BBox *separator = new BBox("separator"); separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1)); BButton *cancel = new BButton("cancel", "Cancel", new BMessage(CANCEL_MSG)); BButton *ok = new BButton("ok", "OK", new BMessage(OK_MSG)); ok->MakeDefault(true); BButton *fontsButton = new BButton("fonts", "Fonts" B_UTF8_ELLIPSIS, new BMessage(FONTS_MSG)); BButton* advancedButton = new BButton("advanced", "Advanced" B_UTF8_ELLIPSIS, new BMessage(ADVANCED_MSG)); BGridView* settings = new BGridView(); BGridLayout* settingsLayout = settings->GridLayout(); settingsLayout->AddItem(fPageSizeMenu->CreateLabelLayoutItem(), 0, 0); settingsLayout->AddItem(fPageSizeMenu->CreateMenuBarLayoutItem(), 1, 0); settingsLayout->AddItem(fOrientationMenu->CreateLabelLayoutItem(), 0, 1); settingsLayout->AddItem(fOrientationMenu->CreateMenuBarLayoutItem(), 1, 1); settingsLayout->AddItem(fPDFCompatibilityMenu->CreateLabelLayoutItem(), 0, 2); settingsLayout->AddItem(fPDFCompatibilityMenu->CreateMenuBarLayoutItem(), 1, 2); settingsLayout->AddView(fPDFCompressionSlider, 0, 3, 2); settingsLayout->SetSpacing(0, 0); SetLayout(new BGroupLayout(B_VERTICAL)); AddChild(BGroupLayoutBuilder(B_VERTICAL, 0) .AddGroup(B_HORIZONTAL, 5, 1) .AddGroup(B_VERTICAL, 0, 1.0f) .Add(fMarginView) .AddGlue() .End() .AddGroup(B_VERTICAL, 0, 1.0f) .Add(settings) .AddGlue() .End() .End() .Add(separator) .AddGroup(B_HORIZONTAL, 10, 1.0f) .Add(fontsButton) .Add(advancedButton) .AddGlue() .Add(cancel) .Add(ok) .End() .SetInsets(10, 10, 10, 10) ); BRect winFrame(Frame()); BRect screenFrame(BScreen().Frame()); MoveTo((screenFrame.right - winFrame.right) / 2, (screenFrame.bottom - winFrame.bottom) / 2); }
//--------------------------------------------------------------- // Copy File, not only data but also attributes ;-) //--------------------------------------------------------------- void TJerFile::CopyFile( const char *sourcepath, const char *destinationpath ) { BFile *source = 0L, *destination = 0L; entry_ref ref; uint8 data[2048]; int32 len = 2048; char buf[B_ATTR_NAME_LENGTH]; void *buffer = NULL; int32 lengthR,lengthW; attr_info attribute; BEntry entry( sourcepath ); if( B_OK == entry.InitCheck() ) { if( B_OK == entry.GetRef( &ref ) ) { source = new BFile( &ref ,B_READ_ONLY); } else { string truc("Error opening file in read only mode: "); truc = truc + sourcepath; GeneralException excep(truc.c_str(),"BJerFile::CopyFile"); throw(excep); } } else { string truc("Error constructing file object: "); truc = truc + sourcepath; GeneralException excep(truc.c_str(),"BJerFile::CopyFile"); throw(excep); } entry.SetTo( destinationpath ); if( B_OK == entry.InitCheck() ) { if( B_OK == entry.GetRef( &ref ) ) { destination = new BFile( &ref ,B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); } else { string truc("Error opening file in read write mode: "); truc = truc + destinationpath; GeneralException excep(truc.c_str(),"BJerFile::CopyFile"); throw(excep); } } else { string truc("Error destination constructing file object: "); truc = truc + destinationpath; GeneralException excep(truc.c_str(),"BJerFile::CopyFile"); throw(excep); } if( source && destination ) { BMessage *AMessage; AMessage = new BMessage(B_UPDATE_STATUS_BAR); AMessage->AddFloat("delta",1.0); AMessage->AddString("text","Copy..."); AMessage->AddString("trailingtext",destinationpath); MyInvoker.Invoke(AMessage); delete AMessage; while (source->GetNextAttrName(buf) == B_NO_ERROR) { source->GetAttrInfo(buf,&attribute); if (buffer!=NULL) { free(buffer); } buffer = (void *)malloc(sizeof(char)*(attribute.size +1)); lengthR = source->ReadAttr(buf,attribute.type,0,buffer,attribute.size); lengthW = destination->WriteAttr(buf,attribute.type,0,buffer,lengthR); if (lengthR!=lengthW) { string truc("Error copying attribute for file : "); truc = truc + destinationpath; GeneralException excep(truc.c_str(),"BJerFile::CopyFile"); throw(excep); } switch(lengthR) { case B_ENTRY_NOT_FOUND: { GeneralException excep("The attribute doesn't exist.","BJerFile::CopyFile"); throw(excep); break; } case B_FILE_ERROR : { GeneralException excep2("The object is uninitialized.","BJerFile::CopyFile"); throw(excep2); break; } } switch(lengthW) { case B_FILE_ERROR : { GeneralException excep3("This object is a read-only BFile.","BJerFile::CopyFile"); throw(excep3); break; } case B_NOT_ALLOWED : { GeneralException excep4("The node is on a read-only volume.","BJerFile::CopyFile"); throw(excep4); break; } case B_DEVICE_FULL : { GeneralException excep5("Out of disk space.","BJerFile::CopyFile"); throw(excep5); break; } case B_NO_MEMORY : { GeneralException excep6("Not enough memory.","BJerFile::CopyFile"); throw(excep6); break; } } } for( ;; ) { len = source->Read( data, len ); if( len == 0 ) break; destination->Write( data, len ); if( len != 2048 ) break; } //---------- freeing some resources... delete source; delete destination; } }
ScreenWindow::ScreenWindow(ScreenSettings* settings) : BWindow(settings->WindowFrame(), B_TRANSLATE_SYSTEM_NAME("Screen"), B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS, B_ALL_WORKSPACES), fIsVesa(false), fBootWorkspaceApplied(false), fOtherRefresh(NULL), fScreenMode(this), fUndoScreenMode(this), fModified(false) { BScreen screen(this); accelerant_device_info info; if (screen.GetDeviceInfo(&info) == B_OK && !strcasecmp(info.chipset, "VESA")) fIsVesa = true; _UpdateOriginal(); _BuildSupportedColorSpaces(); fActive = fSelected = fOriginal; fSettings = settings; // we need the "Current Workspace" first to get its height BPopUpMenu *popUpMenu = new BPopUpMenu(B_TRANSLATE("Current workspace"), true, true); fAllWorkspacesItem = new BMenuItem(B_TRANSLATE("All workspaces"), new BMessage(WORKSPACE_CHECK_MSG)); popUpMenu->AddItem(fAllWorkspacesItem); BMenuItem *item = new BMenuItem(B_TRANSLATE("Current workspace"), new BMessage(WORKSPACE_CHECK_MSG)); popUpMenu->AddItem(item); fAllWorkspacesItem->SetMarked(true); BMenuField* workspaceMenuField = new BMenuField("WorkspaceMenu", NULL, popUpMenu); workspaceMenuField->ResizeToPreferred(); // box on the left with workspace count and monitor view BBox* screenBox = new BBox("screen box"); BGroupLayout* layout = new BGroupLayout(B_VERTICAL, 5.0); layout->SetInsets(10, 10, 10, 10); screenBox->SetLayout(layout); fMonitorInfo = new BStringView("monitor info", ""); screenBox->AddChild(fMonitorInfo); fMonitorView = new MonitorView(BRect(0.0, 0.0, 80.0, 80.0), "monitor", screen.Frame().IntegerWidth() + 1, screen.Frame().IntegerHeight() + 1); screenBox->AddChild(fMonitorView); fColumnsControl = new BTextControl(B_TRANSLATE("Columns:"), "0", new BMessage(kMsgWorkspaceColumnsChanged)); fRowsControl = new BTextControl(B_TRANSLATE("Rows:"), "0", new BMessage(kMsgWorkspaceRowsChanged)); screenBox->AddChild(BLayoutBuilder::Grid<>(5.0, 5.0) .Add(new BStringView("", B_TRANSLATE("Workspaces")), 0, 0, 3) .AddTextControl(fColumnsControl, 0, 1, B_ALIGN_RIGHT) .AddGroup(B_HORIZONTAL, 0, 2, 1) .Add(_CreateColumnRowButton(true, false)) .Add(_CreateColumnRowButton(true, true)) .End() .AddTextControl(fRowsControl, 0, 2, B_ALIGN_RIGHT) .AddGroup(B_HORIZONTAL, 0, 2, 2) .Add(_CreateColumnRowButton(false, false)) .Add(_CreateColumnRowButton(false, true)) .End() .View()); fBackgroundsButton = new BButton("BackgroundsButton", B_TRANSLATE("Set background" B_UTF8_ELLIPSIS), new BMessage(BUTTON_LAUNCH_BACKGROUNDS_MSG)); fBackgroundsButton->SetFontSize(be_plain_font->Size() * 0.9); screenBox->AddChild(fBackgroundsButton); // box on the right with screen resolution, etc. BBox* controlsBox = new BBox("controls box"); controlsBox->SetLabel(workspaceMenuField); BGroupView* outerControlsView = new BGroupView(B_VERTICAL, 10.0); outerControlsView->GroupLayout()->SetInsets(10, 10, 10, 10); controlsBox->AddChild(outerControlsView); fResolutionMenu = new BPopUpMenu("resolution", true, true); uint16 maxWidth = 0; uint16 maxHeight = 0; uint16 previousWidth = 0; uint16 previousHeight = 0; for (int32 i = 0; i < fScreenMode.CountModes(); i++) { screen_mode mode = fScreenMode.ModeAt(i); if (mode.width == previousWidth && mode.height == previousHeight) continue; previousWidth = mode.width; previousHeight = mode.height; if (maxWidth < mode.width) maxWidth = mode.width; if (maxHeight < mode.height) maxHeight = mode.height; BMessage* message = new BMessage(POP_RESOLUTION_MSG); message->AddInt32("width", mode.width); message->AddInt32("height", mode.height); BString name; name << mode.width << " x " << mode.height; fResolutionMenu->AddItem(new BMenuItem(name.String(), message)); } fMonitorView->SetMaxResolution(maxWidth, maxHeight); fResolutionField = new BMenuField("ResolutionMenu", B_TRANSLATE("Resolution:"), fResolutionMenu); fColorsMenu = new BPopUpMenu("colors", true, false); for (int32 i = 0; i < kColorSpaceCount; i++) { if ((fSupportedColorSpaces & (1 << i)) == 0) continue; BMessage* message = new BMessage(POP_COLORS_MSG); message->AddInt32("bits_per_pixel", kColorSpaces[i].bits_per_pixel); message->AddInt32("space", kColorSpaces[i].space); BMenuItem* item = new BMenuItem(kColorSpaces[i].label, message); if (kColorSpaces[i].space == screen.ColorSpace()) fUserSelectedColorSpace = item; fColorsMenu->AddItem(item); } fColorsField = new BMenuField("ColorsMenu", B_TRANSLATE("Colors:"), fColorsMenu); fRefreshMenu = new BPopUpMenu("refresh rate", true, true); float min, max; if (fScreenMode.GetRefreshLimits(fActive, min, max) != B_OK) { // if we couldn't obtain the refresh limits, reset to the default // range. Constraints from detected monitors will fine-tune this // later. min = kRefreshRates[0]; max = kRefreshRates[kRefreshRateCount - 1]; } if (min == max) { // This is a special case for drivers that only support a single // frequency, like the VESA driver BString name; refresh_rate_to_string(min, name); BMessage *message = new BMessage(POP_REFRESH_MSG); message->AddFloat("refresh", min); BMenuItem *item = new BMenuItem(name.String(), message); fRefreshMenu->AddItem(item); item->SetEnabled(false); } else { monitor_info info; if (fScreenMode.GetMonitorInfo(info) == B_OK) { min = max_c(info.min_vertical_frequency, min); max = min_c(info.max_vertical_frequency, max); } for (int32 i = 0; i < kRefreshRateCount; ++i) { if (kRefreshRates[i] < min || kRefreshRates[i] > max) continue; BString name; name << kRefreshRates[i] << " " << B_TRANSLATE("Hz"); BMessage *message = new BMessage(POP_REFRESH_MSG); message->AddFloat("refresh", kRefreshRates[i]); fRefreshMenu->AddItem(new BMenuItem(name.String(), message)); } fOtherRefresh = new BMenuItem(B_TRANSLATE("Other" B_UTF8_ELLIPSIS), new BMessage(POP_OTHER_REFRESH_MSG)); fRefreshMenu->AddItem(fOtherRefresh); } fRefreshField = new BMenuField("RefreshMenu", B_TRANSLATE("Refresh rate:"), fRefreshMenu); if (_IsVesa()) fRefreshField->Hide(); // enlarged area for multi-monitor settings { bool dummy; uint32 dummy32; bool multiMonSupport; bool useLaptopPanelSupport; bool tvStandardSupport; multiMonSupport = TestMultiMonSupport(&screen) == B_OK; useLaptopPanelSupport = GetUseLaptopPanel(&screen, &dummy) == B_OK; tvStandardSupport = GetTVStandard(&screen, &dummy32) == B_OK; // even if there is no support, we still create all controls // to make sure we don't access NULL pointers later on fCombineMenu = new BPopUpMenu("CombineDisplays", true, true); for (int32 i = 0; i < kCombineModeCount; i++) { BMessage *message = new BMessage(POP_COMBINE_DISPLAYS_MSG); message->AddInt32("mode", kCombineModes[i].mode); fCombineMenu->AddItem(new BMenuItem(kCombineModes[i].name, message)); } fCombineField = new BMenuField("CombineMenu", B_TRANSLATE("Combine displays:"), fCombineMenu); if (!multiMonSupport) fCombineField->Hide(); fSwapDisplaysMenu = new BPopUpMenu("SwapDisplays", true, true); // !order is important - we rely that boolean value == idx BMessage *message = new BMessage(POP_SWAP_DISPLAYS_MSG); message->AddBool("swap", false); fSwapDisplaysMenu->AddItem(new BMenuItem(B_TRANSLATE("no"), message)); message = new BMessage(POP_SWAP_DISPLAYS_MSG); message->AddBool("swap", true); fSwapDisplaysMenu->AddItem(new BMenuItem(B_TRANSLATE("yes"), message)); fSwapDisplaysField = new BMenuField("SwapMenu", B_TRANSLATE("Swap displays:"), fSwapDisplaysMenu); if (!multiMonSupport) fSwapDisplaysField->Hide(); fUseLaptopPanelMenu = new BPopUpMenu("UseLaptopPanel", true, true); // !order is important - we rely that boolean value == idx message = new BMessage(POP_USE_LAPTOP_PANEL_MSG); message->AddBool("use", false); fUseLaptopPanelMenu->AddItem(new BMenuItem(B_TRANSLATE("if needed"), message)); message = new BMessage(POP_USE_LAPTOP_PANEL_MSG); message->AddBool("use", true); fUseLaptopPanelMenu->AddItem(new BMenuItem(B_TRANSLATE("always"), message)); fUseLaptopPanelField = new BMenuField("UseLaptopPanel", B_TRANSLATE("Use laptop panel:"), fUseLaptopPanelMenu); if (!useLaptopPanelSupport) fUseLaptopPanelField->Hide(); fTVStandardMenu = new BPopUpMenu("TVStandard", true, true); // arbitrary limit uint32 i; for (i = 0; i < 100; ++i) { uint32 mode; if (GetNthSupportedTVStandard(&screen, i, &mode) != B_OK) break; BString name = tv_standard_to_string(mode); message = new BMessage(POP_TV_STANDARD_MSG); message->AddInt32("tv_standard", mode); fTVStandardMenu->AddItem(new BMenuItem(name.String(), message)); } fTVStandardField = new BMenuField("tv standard", B_TRANSLATE("Video format:"), fTVStandardMenu); fTVStandardField->SetAlignment(B_ALIGN_RIGHT); if (!tvStandardSupport || i == 0) fTVStandardField->Hide(); } BLayoutBuilder::Group<>(outerControlsView) .AddGrid(5.0, 5.0) .AddMenuField(fResolutionField, 0, 0, B_ALIGN_RIGHT) .AddMenuField(fColorsField, 0, 1, B_ALIGN_RIGHT) .AddMenuField(fRefreshField, 0, 2, B_ALIGN_RIGHT) .AddMenuField(fCombineField, 0, 3, B_ALIGN_RIGHT) .AddMenuField(fSwapDisplaysField, 0, 4, B_ALIGN_RIGHT) .AddMenuField(fUseLaptopPanelField, 0, 5, B_ALIGN_RIGHT) .AddMenuField(fTVStandardField, 0, 6, B_ALIGN_RIGHT) .End(); // TODO: we don't support getting the screen's preferred settings /* fDefaultsButton = new BButton(buttonRect, "DefaultsButton", "Defaults", new BMessage(BUTTON_DEFAULTS_MSG));*/ fApplyButton = new BButton("ApplyButton", B_TRANSLATE("Apply"), new BMessage(BUTTON_APPLY_MSG)); fApplyButton->SetEnabled(false); BLayoutBuilder::Group<>(outerControlsView) .AddGlue() .AddGroup(B_HORIZONTAL) .AddGlue() .Add(fApplyButton); fRevertButton = new BButton("RevertButton", B_TRANSLATE("Revert"), new BMessage(BUTTON_REVERT_MSG)); fRevertButton->SetEnabled(false); BLayoutBuilder::Group<>(this, B_VERTICAL, 10.0) .SetInsets(10, 10, 10, 10) .AddGroup(B_HORIZONTAL, 10.0) .AddGroup(B_VERTICAL) .AddStrut(floor(controlsBox->TopBorderOffset() / 16) - 1) .Add(screenBox) .End() .Add(controlsBox) .End() .AddGroup(B_HORIZONTAL, 10.0) .Add(fRevertButton) .AddGlue(); _UpdateControls(); _UpdateMonitor(); }
void TJerFile::GetDiffFile(const char *ASrcDir,const char *ADestDir,BList *Diff) { //----------------------------------------- // We are looking for files not found in Dest... //----------------------------------------- BList ASrcList; BList ADestList; char name1[B_FILE_NAME_LENGTH]; char name2[B_FILE_NAME_LENGTH]; off_t Size1; off_t Size2; int32 CRC1,CRC2; BPath P1; BPath P2; char *RelativePath1; char *RelativePath2; bool EntryFound = false; entry_ref *buf_entry,*buf_entry2,*copy_entry; BMessage *AMessage; BFile *file2; BFile *file1; GetAllFile(ASrcDir,&ASrcList); GetAllFile(ADestDir,&ADestList); AMessage = new BMessage(B_RESET_STATUS_BAR); AMessage->AddFloat("maximum",ASrcList.CountItems()); MyInvoker.Invoke(AMessage); delete AMessage; for (int ind=0;ind < ASrcList.CountItems();ind++ ) { buf_entry = (entry_ref *)(ASrcList.ItemAt(ind)); if (buf_entry!=NULL) { BEntry E1(buf_entry); E1.GetName(name1); E1.GetPath(&P1); GetRelativePath(ASrcDir,P1.Path(),&RelativePath1); file1 = new BFile(buf_entry,B_READ_ONLY); // printf("Checking file ....%s \n",P1.Path()); // The Message is put here to update when the link files are found too. AMessage = new BMessage(B_UPDATE_STATUS_BAR); AMessage->AddFloat("delta",1.0); AMessage->AddString("text","Checking..."); AMessage->AddString("trailingtext",P1.Path()); MyInvoker.Invoke(AMessage); delete AMessage; if (file1->InitCheck()==B_NO_ERROR) //Because of linkfiles.... { try { file1->GetSize(&Size1); if (CalculateCRC==true) { printf("CRC Calculation First File...\n"); CRC1 = CRCFile(file1); } // printf("Checking file ....%s Size: %d CRC: %d \n",P1.Path(),Size1,CRC1); EntryFound = false; } catch(GeneralException &e) { delete file1; printf("Exception in File1..."); throw; } delete file1; for (int ind2=0;ind2 < ADestList.CountItems();ind2++ ) { buf_entry2 = (entry_ref *)(ADestList.ItemAt(ind2)); if (buf_entry2!=NULL) { BEntry E2(buf_entry2); E2.GetName(name2); E2.GetPath(&P2); GetRelativePath(ADestDir,P2.Path(),&RelativePath2); if ((strcmp(name1,name2)==0) && (strcmp(RelativePath1,RelativePath2)==0)) { // printf("name1 : %s, name2 : %s \n",name1,name2); // printf("RP1 : %s, RP2 : %s \n",RelativePath1,RelativePath2); // printf("PAth1 : %s, Path2 : %s \n",P1.Path(),P2.Path()); file2 = new BFile(buf_entry2,B_READ_ONLY); file2->GetSize(&Size2); // printf("Size2 %d\n",Size2); if (Size1==Size2) { //CRC Test try { if (CalculateCRC==true) { printf("CRC Calculation Second File...\n"); CRC2 = CRCFile(file2); if (CRC1==CRC2) { EntryFound = true; delete file2; break; //Data found... } } } catch(GeneralException &e) { printf("Error in GetDiffFile %s\n",P2.Path()); throw; } } delete file2; } } } if (EntryFound==false) { copy_entry = new entry_ref; *copy_entry = *buf_entry; Diff->AddItem(copy_entry); /* BMessage AMessage(GET_FILES); AMessage.AddRef("ref",copy_entry); int result = MyInvoker.Invoke(&AMessage); if (result!= B_OK) { if (result == B_BAD_PORT_ID) { ShowMessage("Bad Port"); } else if (result == B_TIMED_OUT) { ShowMessage("TIMED_OUT"); } else ShowMessage("Other Error"); } */ } } // End of InitCheck } } // Just to let the main loop that we have finished checking... for the moment we only // use it to test if the OutLineList is void.... /* BMessage AMessage2(END_CHECKING); int result2 = MyInvoker.Invoke(&AMessage2); if (result2!= B_OK) { if (result2 == B_BAD_PORT_ID) { ShowMessage("Bad Port"); } else if (result2 == B_TIMED_OUT) { ShowMessage("TIMED_OUT"); } else ShowMessage("Other Error"); } */ }
PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName) : BlockingWindow(BRect(0, 0, 100, 100), "Page setup", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE), fSetupMsg(msg), fPrinterDirName(printerName) { if (printerName) SetTitle(BString(printerName).Append(" Page setup").String()); // load orientation if (fSetupMsg->FindInt32("orientation", &fCurrentOrientation) != B_OK) fCurrentOrientation = PrinterDriver::PORTRAIT_ORIENTATION; // load page rect BRect page; float width = letter_width; float height = letter_height; if (fSetupMsg->FindRect("preview:paper_rect", &page) == B_OK) { width = page.Width(); height = page.Height(); } else { page.Set(0, 0, width, height); } BString label; if (fSetupMsg->FindString("preview:paper_size", &label) != B_OK) label = "Letter"; // Load units int32 units; if (fSetupMsg->FindInt32("units", &units) != B_OK) units = kUnitInch; // re-calculate the margin from the printable rect in points BRect margin = page; if (fSetupMsg->FindRect("preview:printable_rect", &margin) == B_OK) { margin.top -= page.top; margin.left -= page.left; margin.right = page.right - margin.right; margin.bottom = page.bottom - margin.bottom; } else { margin.Set(28.34, 28.34, 28.34, 28.34); // 28.34 dots = 1cm } fMarginView = new MarginView(int32(width), int32(height), margin, MarginUnit(units)); BPopUpMenu* pageSizePopUpMenu = new BPopUpMenu("Page size"); pageSizePopUpMenu->SetRadioMode(true); fPageSizeMenu = new BMenuField("page_size", "Page size:", pageSizePopUpMenu); fPageSizeMenu->Menu()->SetLabelFromMarked(true); for (int32 i = 0; pageFormat[i].label != NULL; i++) { BMessage* message = new BMessage(PAGE_SIZE_CHANGED); message->AddFloat("width", pageFormat[i].width); message->AddFloat("height", pageFormat[i].height); BMenuItem* item = new BMenuItem(pageFormat[i].label, message); pageSizePopUpMenu->AddItem(item); if (label.Compare(pageFormat[i].label) == 0) item->SetMarked(true); } BPopUpMenu* orientationPopUpMenu = new BPopUpMenu("Orientation"); orientationPopUpMenu->SetRadioMode(true); fOrientationMenu = new BMenuField("orientation", "Orientation:", orientationPopUpMenu); fOrientationMenu->Menu()->SetLabelFromMarked(true); for (int32 i = 0; orientation[i].label != NULL; i++) { BMessage* message = new BMessage(ORIENTATION_CHANGED); message->AddInt32("orientation", orientation[i].orientation); BMenuItem* item = new BMenuItem(orientation[i].label, message); orientationPopUpMenu->AddItem(item); if (fCurrentOrientation == orientation[i].orientation) item->SetMarked(true); } float scale0; BString scale; if (fSetupMsg->FindFloat("scale", &scale0) == B_OK) scale << (int)scale0; else scale = "100"; fScaleControl = new BTextControl("scale", "Scale [%]:", scale.String(), NULL); for (uint32 i = 0; i < '0'; i++) fScaleControl->TextView()->DisallowChar(i); for (uint32 i = '9' + 1; i < 255; i++) fScaleControl->TextView()->DisallowChar(i); fScaleControl->TextView()->SetMaxBytes(3); BBox *separator = new BBox("separator"); separator->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, 1)); BButton *cancel = new BButton("cancel", "Cancel", new BMessage(CANCEL_MSG)); BButton *ok = new BButton("ok", "OK", new BMessage(OK_MSG)); ok->MakeDefault(true); BGridView* settings = new BGridView(); BGridLayout* settingsLayout = settings->GridLayout(); settingsLayout->AddItem(fPageSizeMenu->CreateLabelLayoutItem(), 0, 0); settingsLayout->AddItem(fPageSizeMenu->CreateMenuBarLayoutItem(), 1, 0); settingsLayout->AddItem(fOrientationMenu->CreateLabelLayoutItem(), 0, 1); settingsLayout->AddItem(fOrientationMenu->CreateMenuBarLayoutItem(), 1, 1); settingsLayout->AddItem(fScaleControl->CreateLabelLayoutItem(), 0, 2); settingsLayout->AddItem(fScaleControl->CreateTextViewLayoutItem(), 1, 2); settingsLayout->SetSpacing(0, 0); SetLayout(new BGroupLayout(B_VERTICAL)); AddChild(BGroupLayoutBuilder(B_VERTICAL, 0) .AddGroup(B_HORIZONTAL, 5, 1) .AddGroup(B_VERTICAL, 0, 1.0f) .Add(fMarginView) .AddGlue() .End() .AddGroup(B_VERTICAL, 0, 1.0f) .Add(settings) .AddGlue() .End() .End() .Add(separator) .AddGroup(B_HORIZONTAL, 10, 1.0f) .AddGlue() .Add(cancel) .Add(ok) .End() .SetInsets(10, 10, 10, 10) ); BRect winFrame(Frame()); BRect screenFrame(BScreen().Frame()); MoveTo((screenFrame.right - winFrame.right) / 2, (screenFrame.bottom - winFrame.bottom) / 2); }
BYdpMainWindow::BYdpMainWindow(const char *windowTitle) : BWindow( BRect(64, 64, 585, 480), windowTitle, B_DOCUMENT_WINDOW, B_OUTLINE_RESIZE ) { this->Hide(); config = new bydpConfig(); BView *MainView( new BView(BWindow::Bounds(), NULL, B_FOLLOW_ALL, 0) ); if (MainView == NULL) { AppReturnValue = B_NO_MEMORY; be_app->PostMessage(B_QUIT_REQUESTED); return; } MainView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); BWindow::AddChild(MainView); wordInput = new BTextControl( BRect(5,24,210,45), "wordInput", NULL, "text", new BMessage(MSG_MODIFIED_INPUT)); wordInput->SetModificationMessage(new BMessage(MSG_MODIFIED_INPUT)); MainView->AddChild(wordInput); outputView = new BTextView( BRect(220,24,506,402), "outputView", BRect(10,10,300,200), B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP_BOTTOM, B_WILL_DRAW|B_PULSE_NEEDED); outputView->SetText("output"); outputView->MakeEditable(false); outputView->SetStylable(true); MainView->AddChild(new BScrollView("scrolloutput",outputView,B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP_BOTTOM, 0, true, true)); dictList = new bydpListView("listView", this); MainView->AddChild(new BScrollView("scrollview", dictList, B_FOLLOW_LEFT|B_FOLLOW_TOP_BOTTOM, 0, false, false, B_FANCY_BORDER)); dictList->SetInvocationMessage(new BMessage(MSG_LIST_INVOKED)); dictList->SetSelectionMessage(new BMessage(MSG_LIST_SELECTED)); BRect barr = dictList->Bounds(); barr.left = barr.right-B_V_SCROLL_BAR_WIDTH; scrollBar = new bydpScrollBar(barr, "scrollbar", dictList); dictList->AddChild(scrollBar); dictList->SetScrollBar(scrollBar); ydpConv = new ConvertYDP(); sapConv = new ConvertSAP(); // sq2Conv = new ConvertSQ2(); ydpDict = new EngineYDP(outputView, dictList, config, ydpConv); sapDict = new EngineSAP(outputView, dictList, config, sapConv); // sq2Dict = new EngineSQ2(outputView, dictList, config, sq2Conv); switch(config->dictionarymode) { /* case DICTIONARY_SQ2: myDict = sq2Dict; myConverter = sq2Conv; break; */ case DICTIONARY_YDP: myDict = ydpDict; myConverter = ydpConv; break; case DICTIONARY_SAP: default: myDict = sapDict; myConverter = sapConv; break; } dictList->SetConverter(myConverter); BRect r; r = MainView->Bounds(); r.bottom = 19; BMenuBar *menubar = new BMenuBar(r, "menubar"); MainView->AddChild(menubar); BMenu *menu = new BMenu("File"); menu->AddItem(new BMenuItem("About...", new BMessage(MENU_ABOUT), 'O')); menu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q')); menubar->AddItem(menu); BMenu *engineMenu; menu = new BMenu("Dictionary"); menu->AddItem(new BMenuItem("Switch", new BMessage(MENU_SWITCH), 'J')); menu->AddItem(menuEng = new BMenuItem("Eng -> Pol", new BMessage(MENU_ENG2POL), 'E')); menu->AddItem(menuPol = new BMenuItem("Pol -> Eng", new BMessage(MENU_POL2ENG), 'P')); menu->AddSeparatorItem(); menu->AddItem(engineMenu = new BMenu("Dictionary engine")); engineMenu->AddItem(menuSAP = new BMenuItem("SAP", new BMessage(MENU_ENGINESAP))); engineMenu->AddItem(menuYDP = new BMenuItem("YDP", new BMessage(MENU_ENGINEYDP))); // engineMenu->AddItem(menuSQ2 = new BMenuItem("SQ2", new BMessage(MENU_ENGINESQ2))); menubar->AddItem(menu); menu = new BMenu("Search type"); menu->AddItem(menuPlain = new BMenuItem("Plain", new BMessage(MENU_PLAIN), 'Z')); menu->AddItem(menuFuzzy = new BMenuItem("Fuzzy", new BMessage(MENU_FUZZY), 'R')); menubar->AddItem(menu); menu = new BMenu("Settings"); menu->AddItem(new BMenuItem("Path to dictionary", new BMessage(MENU_PATH), 'S')); menu->AddSeparatorItem(); menu->AddItem(menuCol0 = new BMenuItem(myDict->ColourFunctionName(0), new BMessage(MENU_COLOR0))); menu->AddItem(menuCol1 = new BMenuItem(myDict->ColourFunctionName(1), new BMessage(MENU_COLOR1))); menu->AddItem(menuCol2 = new BMenuItem(myDict->ColourFunctionName(2), new BMessage(MENU_COLOR2))); menu->AddItem(menuCol3 = new BMenuItem(myDict->ColourFunctionName(3), new BMessage(MENU_COLOR3))); menu->AddSeparatorItem(); menu->AddItem(menuClip = new BMenuItem("Clipboard tracking", new BMessage(MENU_CLIP), 'L')); menu->AddItem(menuFocus = new BMenuItem("Popup window", new BMessage(MENU_FOCUS), 'F')); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem("Fuzzy factor", new BMessage(MENU_DISTANCE))); // menu->AddItem(new BMenuItem("SQL data source", new BMessage(MENU_SQL))); menu->AddSeparatorItem(); menubar->AddItem(menu); BMessage *fontMessage; fontMenu = new BMenu("Font"); menu->AddItem(fontMenu); BMenu* fontSizeMenu = new BMenu("Size"); fontSizeMenu->SetRadioMode(true); fontMenu->AddItem(fontSizeMenu); fontMenu->AddSeparatorItem(); fontSizeMenu->AddItem(new BMenuItem("9", fontMessage = new BMessage(FONT_SIZE))); fontMessage->AddFloat("size", 9.0); fontSizeMenu->AddItem(new BMenuItem("10", fontMessage = new BMessage(FONT_SIZE))); fontMessage->AddFloat("size",10.0); fontSizeMenu->AddItem(new BMenuItem("11", fontMessage = new BMessage(FONT_SIZE))); fontMessage->AddFloat("size",11.0); fontSizeMenu->AddItem(new BMenuItem("12", fontMessage = new BMessage(FONT_SIZE))); fontMessage->AddFloat("size",12.0); fontSizeMenu->AddItem(new BMenuItem("14", fontMessage = new BMessage(FONT_SIZE))); fontMessage->AddFloat("size",14.0); fontSizeMenu->AddItem(new BMenuItem("18", fontMessage = new BMessage(FONT_SIZE))); fontMessage->AddFloat("size",18.0); fontSizeMenu->AddItem(new BMenuItem("24", fontMessage = new BMessage(FONT_SIZE))); fontMessage->AddFloat("size",24.0); fontSizeMenu->AddItem(new BMenuItem("36", fontMessage = new BMessage(FONT_SIZE))); fontMessage->AddFloat("size",36.0); fontSizeMenu->AddItem(new BMenuItem("48", fontMessage = new BMessage(FONT_SIZE))); fontMessage->AddFloat("size",48.0); fontSizeMenu->AddItem(new BMenuItem("72", fontMessage = new BMessage(FONT_SIZE))); fontMessage->AddFloat("size",72.0); font_family plain_family; font_style plain_style; config->currentFont.GetFamilyAndStyle(&plain_family,&plain_style); BMenu *subMenu; BMenuItem *menuItem; currentFontItem = 0; int32 numFamilies = count_font_families(); for ( int32 i = 0; i < numFamilies; i++ ) { font_family localfamily; if ( get_font_family ( i, &localfamily ) == B_OK ) { subMenu = new BMenu(localfamily); subMenu->SetRadioMode(true); fontMenu->AddItem(menuItem = new BMenuItem(subMenu, new BMessage(FONT_FAMILY))); if (!strcmp(plain_family,localfamily)) { menuItem->SetMarked(true); currentFontItem = menuItem; } int32 numStyles=count_font_styles(localfamily); for(int32 j = 0;j<numStyles;j++){ font_style style; uint32 flags; if( get_font_style(localfamily,j,&style,&flags)==B_OK){ subMenu->AddItem(menuItem = new BMenuItem(style, new BMessage(FONT_STYLE))); if (!strcmp(plain_style,style)) { menuItem->SetMarked(true); } } } } } this->FrameResized(0.0, 0.0); UpdateMenus(); wordInput->MakeFocus(true); firstStart = true; TryToOpenDict(); BMessenger mesg(this); be_clipboard->StartWatching(mesg); }
PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName) : BlockingWindow(BRect(0,0,400,220), "Page setup", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE), fSetupMsg(msg), fPrinterDirName(printerName) { if (printerName) SetTitle(BString(printerName).Append(" Page setup").String()); // load orientation if (fSetupMsg->FindInt32("orientation", &fCurrentOrientation) != B_OK) fCurrentOrientation = PrinterDriver::PORTRAIT_ORIENTATION; // load page rect BRect page; float width = letter_width; float height = letter_height; if (fSetupMsg->FindRect("preview:paper_rect", &page) == B_OK) { width = page.Width(); height = page.Height(); } else { page.Set(0, 0, width, height); } BString label; if (fSetupMsg->FindString("preview:paper_size", &label) != B_OK) label = "Letter"; // Load units int32 units; if (fSetupMsg->FindInt32("units", &units) != B_OK) units = kUnitInch; // re-calculate the margin from the printable rect in points BRect margin = page; if (fSetupMsg->FindRect("preview:printable_rect", &margin) == B_OK) { margin.top -= page.top; margin.left -= page.left; margin.right = page.right - margin.right; margin.bottom = page.bottom - margin.bottom; } else { margin.Set(28.34, 28.34, 28.34, 28.34); // 28.34 dots = 1cm } BRect bounds(Bounds()); BBox *panel = new BBox(bounds, "background", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER); AddChild(panel); bounds.InsetBy(10.0, 10.0); bounds.right = 230.0; bounds.bottom = 160.0; fMarginView = new MarginView(bounds, int32(width), int32(height), margin, MarginUnit(units)); panel->AddChild(fMarginView); fMarginView->SetResizingMode(B_FOLLOW_NONE); BPopUpMenu* m = new BPopUpMenu("Page size"); m->SetRadioMode(true); bounds.OffsetBy(bounds.Width() + 10.0, 5.0); float divider = be_plain_font->StringWidth("Orientation: "); fPageSizeMenu = new BMenuField(bounds, "page_size", "Page size:", m); panel->AddChild(fPageSizeMenu); fPageSizeMenu->ResizeToPreferred(); fPageSizeMenu->SetDivider(divider); fPageSizeMenu->Menu()->SetLabelFromMarked(true); for (int32 i = 0; pageFormat[i].label != NULL; i++) { BMessage* message = new BMessage(PAGE_SIZE_CHANGED); message->AddFloat("width", pageFormat[i].width); message->AddFloat("height", pageFormat[i].height); BMenuItem* item = new BMenuItem(pageFormat[i].label, message); m->AddItem(item); if (label.Compare(pageFormat[i].label) == 0) item->SetMarked(true); } m = new BPopUpMenu("Orientation"); m->SetRadioMode(true); bounds.OffsetBy(0.0, fPageSizeMenu->Bounds().Height() + 10.0); fOrientationMenu = new BMenuField(bounds, "orientation", "Orientation:", m); panel->AddChild(fOrientationMenu); fOrientationMenu->ResizeToPreferred(); fOrientationMenu->SetDivider(divider); fOrientationMenu->Menu()->SetLabelFromMarked(true); for (int32 i = 0; orientation[i].label != NULL; i++) { BMessage* message = new BMessage(ORIENTATION_CHANGED); message->AddInt32("orientation", orientation[i].orientation); BMenuItem* item = new BMenuItem(orientation[i].label, message); m->AddItem(item); if (fCurrentOrientation == orientation[i].orientation) item->SetMarked(true); } float scale0; BString scale; if (fSetupMsg->FindFloat("scale", &scale0) == B_OK) scale << (int)scale0; else scale = "100"; bounds.OffsetBy(0.0, fOrientationMenu->Bounds().Height() + 10.0); bounds.right -= 30.0; fScaleControl = new BTextControl(bounds, "scale", "Scale [%]:", scale.String(), NULL); panel->AddChild(fScaleControl); fScaleControl->ResizeToPreferred(); fScaleControl->SetDivider(divider); for (uint32 i = 0; i < '0'; i++) fScaleControl->TextView()->DisallowChar(i); for (uint32 i = '9' + 1; i < 255; i++) fScaleControl->TextView()->DisallowChar(i); fScaleControl->TextView()->SetMaxBytes(3); bounds = Bounds(); bounds.InsetBy(5.0, 0.0); bounds.top = MAX(fScaleControl->Frame().bottom, fMarginView->Frame().bottom) + 10.0; BBox *line = new BBox(BRect(bounds.left, bounds.top, bounds.right, bounds.top + 1.0), NULL, B_FOLLOW_LEFT_RIGHT); panel->AddChild(line); bounds.InsetBy(5.0, 0.0); bounds.OffsetBy(0.0, 11.0); BButton *cancel = new BButton(bounds, NULL, "Cancel", new BMessage(CANCEL_MSG)); panel->AddChild(cancel); cancel->ResizeToPreferred(); BButton *ok = new BButton(bounds, NULL, "OK", new BMessage(OK_MSG)); panel->AddChild(ok, cancel); ok->ResizeToPreferred(); bounds.right = fScaleControl->Frame().right; ok->MoveTo(bounds.right - ok->Bounds().Width(), ok->Frame().top); bounds = ok->Frame(); cancel->MoveTo(bounds.left - cancel->Bounds().Width() - 10.0, bounds.top); ok->MakeDefault(true); ResizeTo(bounds.right + 10.0, bounds.bottom + 10.0); BRect winFrame(Frame()); BRect screenFrame(BScreen().Frame()); MoveTo((screenFrame.right - winFrame.right) / 2, (screenFrame.bottom - winFrame.bottom) / 2); }