diff --git a/src/servers/print/BeUtils.cpp b/src/servers/print/BeUtils.cpp index 567a88fecd..6aafbfc442 100644 --- a/src/servers/print/BeUtils.cpp +++ b/src/servers/print/BeUtils.cpp @@ -36,7 +36,10 @@ // DEALINGS IN THE SOFTWARE. /*****************************************************************************/ +#include +#include #include +#include #include #include @@ -108,3 +111,42 @@ bool AddFields(BMessage* to, const BMessage* from) { } } } + +BBitmap* LoadBitmap(const char* name, uint32 type_code = B_TRANSLATOR_BITMAP) { + if (type_code == B_TRANSLATOR_BITMAP) { + return BTranslationUtils::GetBitmap(type_code, name); + } else { + BResources *res = BApplication::AppResources(); + if (res != NULL) { + BMessage m; + size_t length; + const void *bits = res->LoadResource(type_code, name, &length); + if (bits && m.Unflatten((char*)bits) == B_OK) { + return (BBitmap*)BBitmap::Instantiate(&m); + } + } + return NULL; + } +} + +BPicture *BitmapToPicture(BView* view, BBitmap *bitmap) { + if (bitmap) { + view->BeginPicture(new BPicture()); + view->DrawBitmap(bitmap); + return view->EndPicture(); + } + return NULL; +} + +BPicture *BitmapToGrayedPicture(BView* view, BBitmap *bitmap) { + if (bitmap) { + BRect rect(bitmap->Bounds()); + view->BeginPicture(new BPicture()); + view->DrawBitmap(bitmap); + view->SetHighColor(255, 255, 255, 128); + view->SetDrawingMode(B_OP_ALPHA); + view->FillRect(rect); + return view->EndPicture(); + } + return NULL; +} diff --git a/src/servers/print/BeUtils.h b/src/servers/print/BeUtils.h index 8a12f5a144..6aee43a00f 100644 --- a/src/servers/print/BeUtils.h +++ b/src/servers/print/BeUtils.h @@ -42,6 +42,10 @@ #include #include #include +#include +#include +#include +#include status_t TestForAddonExistence(const char* name, directory_which which, const char* section, BPath& outPath); @@ -86,6 +90,12 @@ public: // mimetype from sender bool MimeTypeForSender(BMessage* sender, BString& mime); +// adds fields to message or replaces existing fields bool AddFields(BMessage* to, const BMessage* from); - +// load bitmap from application resources +BBitmap* LoadBitmap(const char* name, uint32 type_code = B_TRANSLATOR_BITMAP); +// convert bitmap to picture; view must be attached to a window! +// returns NULL if bitmap is NULL +BPicture *BitmapToPicture(BView* view, BBitmap *bitmap); +BPicture *BitmapToGrayedPicture(BView* view, BBitmap *bitmap); #endif diff --git a/src/servers/print/ConfigWindow.cpp b/src/servers/print/ConfigWindow.cpp index 75a9520a05..52c7c385e3 100644 --- a/src/servers/print/ConfigWindow.cpp +++ b/src/servers/print/ConfigWindow.cpp @@ -64,8 +64,9 @@ ConfigWindow::ConfigWindow(config_setup_kind kind, Printer* defaultPrinter, BMes AddChild(panel); - float left = 10, top = 5, width; + float left = 10, top = 5; BRect r(left, top, 160, 15); + BStringView* string; // print selection popup menu BPopUpMenu* menu = new BPopUpMenu("Select a Printer"); @@ -75,25 +76,24 @@ ConfigWindow::ConfigWindow(config_setup_kind kind, Printer* defaultPrinter, BMes fPrinters->SetDivider(40); panel->AddChild(fPrinters); top += fPrinters->Bounds().Height() + 10; - width = fPrinters->Bounds().Width(); // page format button r.OffsetTo(left, top); - fPageSetup = new BButton(r, "Page Format", "Page Format", new BMessage(MSG_PAGE_SETUP)); - panel->AddChild(fPageSetup); - fPageSetup->ResizeToPreferred(); + fPageSetup = AddPictureButton(panel, r, "Page Format", "PAGE_SETUP_ON", "PAGE_SETUP_OFF", MSG_PAGE_SETUP); + // add description to button + r.OffsetTo(left + fPageSetup->Bounds().Width() + 5, top + fPageSetup->Bounds().Height()/2-5); + AddStringView(panel, r, "Setup page format"); top += fPageSetup->Bounds().Height() + 5; - if (fPageSetup->Bounds().Width() > width) width = fPageSetup->Bounds().Width(); // page selection button fJobSetup = NULL; if (kind == kJobSetup) { r.OffsetTo(left, top); - fJobSetup = new BButton(r, "Page Selection", "Page Selection", new BMessage(MSG_JOB_SETUP)); - panel->AddChild(fJobSetup); - fJobSetup->ResizeToPreferred(); + fJobSetup = AddPictureButton(panel, r, "Page Selection", "JOB_SETUP_ON", "JOB_SETUP_OFF", MSG_JOB_SETUP); + // add description to button + r.OffsetTo(left + fJobSetup->Bounds().Width() + 5, top + fJobSetup->Bounds().Width()/2-5); + AddStringView(panel, r, "Setup print job"); top += fJobSetup->Bounds().Height() + 5; - if (fJobSetup->Bounds().Width() > width) width = fJobSetup->Bounds().Width(); } top += 5; @@ -117,11 +117,6 @@ ConfigWindow::ConfigWindow(config_setup_kind kind, Printer* defaultPrinter, BMes panel->AddChild(fOk); fOk->ResizeToPreferred(); top += fOk->Bounds().Height() + 10; - - // resize buttons to equal width - float height = fOk->Bounds().Height(); - fPageSetup->ResizeTo(width, height); - if (fJobSetup) fJobSetup->ResizeTo(width, height); // resize window ResizeTo(fOk->Frame().right + 10, top); @@ -239,6 +234,45 @@ void ConfigWindow::SetWindowFrame(BRect r) { } } +BPictureButton* ConfigWindow::AddPictureButton(BView* panel, BRect frame, const char* name, const char* on, const char* off, uint32 what) { + BBitmap* onBM = LoadBitmap(on); + BBitmap* offBM = LoadBitmap(off); + + BPicture* onPict = BitmapToPicture(panel, onBM); + BPicture* offPict = BitmapToPicture(panel, offBM); + + BPictureButton* button = NULL; + + if (onPict != NULL && offPict != NULL) { + button = new BPictureButton(frame, name, onPict, offPict, new BMessage(what)); + button->SetViewColor(B_TRANSPARENT_COLOR); + panel->AddChild(button); + onBM->Lock(); + button->ResizeTo(onBM->Bounds().Width(), onBM->Bounds().Height()); + onBM->Unlock(); + + BPicture* disabled = BitmapToGrayedPicture(panel, offBM); + button->SetDisabledOn(disabled); + delete disabled; + + disabled = BitmapToGrayedPicture(panel, onBM); + button->SetDisabledOff(disabled); + delete disabled; + } + + delete onPict; delete offPict; + delete onBM; delete offBM; + + return button; +} + +void ConfigWindow::AddStringView(BView* panel, BRect frame, const char* text) { + BStringView* string = new BStringView(frame, "", text); + string->SetViewColor(panel->ViewColor()); + string->SetLowColor(panel->ViewColor()); + panel->AddChild(string); +} + void ConfigWindow::PrinterForMimeType() { BAutolock lock(gLock); if (fCurrentPrinter) { diff --git a/src/servers/print/ConfigWindow.h b/src/servers/print/ConfigWindow.h index 4bd232e22f..8ea08bedcc 100644 --- a/src/servers/print/ConfigWindow.h +++ b/src/servers/print/ConfigWindow.h @@ -64,6 +64,8 @@ public: static void SetWindowFrame(BRect frame); private: + BPictureButton* AddPictureButton(BView* panel, BRect frame, const char* name, const char* on, const char* off, uint32 what); + void AddStringView(BView* panel, BRect frame, const char* text); void PrinterForMimeType(); void SetupPrintersMenu(BMenu* menu); void UpdateAppSettings(const char* mime, const char* printer); @@ -85,8 +87,8 @@ private: sem_id fFinished; BMenuField* fPrinters; - BButton* fPageSetup; - BButton* fJobSetup; + BPictureButton* fPageSetup; + BPictureButton* fJobSetup; BButton* fOk; }; diff --git a/src/servers/print/Jamfile b/src/servers/print/Jamfile index 3b0bd107e5..0ac9dd2f04 100644 --- a/src/servers/print/Jamfile +++ b/src/servers/print/Jamfile @@ -28,5 +28,6 @@ LinkSharedOSLibs print_server : be - root + root + translation ; diff --git a/src/servers/print/PrintServer.FileTypes.rsrc b/src/servers/print/PrintServer.FileTypes.rsrc index 7749f73064..6e9fa46406 100644 Binary files a/src/servers/print/PrintServer.FileTypes.rsrc and b/src/servers/print/PrintServer.FileTypes.rsrc differ