Author: bonefish Date: 2011-07-07 12:17:15 +0200 (Thu, 07 Jul 2011) New Revision: 42387 Changeset: https://dev.haiku-os.org/changeset/42387 Modified: haiku/trunk/headers/libs/print/libprint/JobSetupDlg.h haiku/trunk/headers/os/support/String.h haiku/trunk/src/kits/support/String.cpp haiku/trunk/src/libs/print/libprint/JobSetupDlg.cpp Log: * Added bool and double BString::operator<<() versions. * Removed the clashing operator in JobSetupDlg. Automatic whitespace cleanup. Modified: haiku/trunk/headers/libs/print/libprint/JobSetupDlg.h =================================================================== --- haiku/trunk/headers/libs/print/libprint/JobSetupDlg.h 2011-07-06 23:34:02 UTC (rev 42386) +++ haiku/trunk/headers/libs/print/libprint/JobSetupDlg.h 2011-07-07 10:17:15 UTC (rev 42387) @@ -29,7 +29,6 @@ class PrinterCap; class PrinterData; -extern BString& operator<<(BString& text, double value); template<typename T, typename R> class Range Modified: haiku/trunk/headers/os/support/String.h =================================================================== --- haiku/trunk/headers/os/support/String.h 2011-07-06 23:34:02 UTC (rev 42386) +++ haiku/trunk/headers/os/support/String.h 2011-07-07 10:17:15 UTC (rev 42387) @@ -307,14 +307,16 @@ BString& operator<<(const char* string); BString& operator<<(const BString& string); BString& operator<<(char c); + BString& operator<<(bool value); BString& operator<<(int value); BString& operator<<(unsigned int value); BString& operator<<(unsigned long value); BString& operator<<(long value); BString& operator<<(unsigned long long value); BString& operator<<(long long value); - // float output hardcodes %.2f style formatting + // float/double output hardcodes %.2f style formatting BString& operator<<(float value); + BString& operator<<(double value); private: class PosVect; Modified: haiku/trunk/src/kits/support/String.cpp =================================================================== --- haiku/trunk/src/kits/support/String.cpp 2011-07-06 23:34:02 UTC (rev 42386) +++ haiku/trunk/src/kits/support/String.cpp 2011-07-07 10:17:15 UTC (rev 42387) @@ -2029,6 +2029,18 @@ BString& +BString::operator<<(bool value) +{ + if (value) + _DoAppend("true", 4); + else + _DoAppend("false", 5); + + return *this; +} + + +BString& BString::operator<<(int i) { char num[32]; @@ -2105,6 +2117,17 @@ } +BString& +BString::operator<<(double value) +{ + char num[64]; + int32 length = snprintf(num, sizeof(num), "%.2f", value); + + _DoAppend(num, length); + return *this; +} + + // #pragma mark - Private or reserved Modified: haiku/trunk/src/libs/print/libprint/JobSetupDlg.cpp =================================================================== --- haiku/trunk/src/libs/print/libprint/JobSetupDlg.cpp 2011-07-06 23:34:02 UTC (rev 42386) +++ haiku/trunk/src/libs/print/libprint/JobSetupDlg.cpp 2011-07-07 10:17:15 UTC (rev 42387) @@ -7,7 +7,7 @@ #include <cstring> #include <cstdlib> #include <string> -#include <fcntl.h> +#include <fcntl.h> #include <unistd.h> #include <sys/stat.h> #include <math.h> @@ -134,12 +134,6 @@ }; -BString& operator<<(BString& text, double value) -{ - text << (float)value; - return text; -} - JobSetupView::JobSetupView(JobData* jobData, PrinterData* printerData, const PrinterCap *printerCap) : @@ -170,7 +164,7 @@ } -BRadioButton* +BRadioButton* JobSetupView::CreatePageSelectionItem(const char* name, const char* label, JobData::PageSelection pageSelection) { @@ -196,7 +190,7 @@ } -void +void JobSetupView::AttachedToWindow() { // quality @@ -210,7 +204,7 @@ fJobData->GetColor()); BMenuField* colorMenuField = new BMenuField("color", "Color:", fColorType); fColorType->SetTargetForItems(this); - + if (IsHalftoneConfigurationNeeded()) CreateHalftoneConfigurationUI(); @@ -316,11 +310,11 @@ fPages->SetReverse(fJobData->GetReverse()); fPages->SetExplicitMinSize(BSize(150, 40)); fPages->SetExplicitMaxSize(BSize(150, 40)); - + // page selection BBox* pageSelectionBox = new BBox("pageSelection"); pageSelectionBox->SetLabel("Page Selection"); - + fAllPages = CreatePageSelectionItem("allPages", "All Pages", JobData::kAllPages); fOddNumberedPages = CreatePageSelectionItem("oddPages", @@ -341,7 +335,7 @@ new BMessage(kMsgCancel)); BButton* ok = new BButton("ok", "OK", new BMessage(kMsgOK)); ok->MakeDefault(true); - + if (IsHalftoneConfigurationNeeded()) { BGroupView* halftoneGroup = new BGroupView(B_VERTICAL, 0); BGroupLayout* halftoneLayout = halftoneGroup->GroupLayout(); @@ -794,8 +788,8 @@ bool pageRangeEnabled = fAll->Value() != B_CONTROL_ON; fFromPage->SetEnabled(pageRangeEnabled); fToPage->SetEnabled(pageRangeEnabled); - - bool pageSelectionEnabled = fDuplex == NULL || + + bool pageSelectionEnabled = fDuplex == NULL || fDuplex->Value() != B_CONTROL_ON; fAllPages->SetEnabled(pageSelectionEnabled); fOddNumberedPages->SetEnabled(pageSelectionEnabled); @@ -803,7 +797,7 @@ } -void +void JobSetupView::MessageReceived(BMessage* message) { switch (message->what) { @@ -820,7 +814,7 @@ case kMsgCollateChanged: fPages->SetCollate(fCollate->Value() == B_CONTROL_ON); break; - + case kMsgReverseChanged: fPages->SetReverse(fReverse->Value() == B_CONTROL_ON); break; @@ -869,7 +863,7 @@ } -JobData::Color +JobData::Color JobSetupView::Color() { const char *label = fColorType->FindMarked()->Label(); @@ -882,7 +876,7 @@ } -Halftone::DitherType +Halftone::DitherType JobSetupView::DitherType() { const char *label = fDitherType->FindMarked()->Label(); @@ -891,7 +885,7 @@ return static_cast<Halftone::DitherType>(id); } -float +float JobSetupView::Gamma() { const float value = (float)fGamma->Value(); @@ -899,7 +893,7 @@ } -float +float JobSetupView::InkDensity() { const float value = (float)(127 - fInkDensity->Value()); @@ -920,7 +914,7 @@ } -bool +bool JobSetupView::UpdateJobData() { fJobData->SetShowPreview(fPreview->Value() == B_CONTROL_ON); @@ -966,7 +960,7 @@ if (fEvenNumberedPages->Value() == B_CONTROL_ON) pageSelection = JobData::kEvenNumberedPages; fJobData->SetPageSelection(pageSelection); - + { std::map<PrinterCap::CapID, BPopUpMenu*>::iterator it = fDriverSpecificPopUpMenus.begin(); @@ -1027,7 +1021,7 @@ { SetResult(B_ERROR); AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED)); - + fJobSetup = new JobSetupView(jobData, printerData, printerCap); SetLayout(new BGroupLayout(B_VERTICAL)); AddChild(BGroupLayoutBuilder(B_VERTICAL, 0) @@ -1037,7 +1031,7 @@ } -void +void JobSetupDlg::MessageReceived(BMessage* message) { switch (message->what) { @@ -1050,7 +1044,7 @@ case kMsgCancel: PostMessage(B_QUIT_REQUESTED); break; - + default: DialogWindow::MessageReceived(message); break;