From 1d7af7aad407cd94e3553a0442d8a9a1cb902f7a Mon Sep 17 00:00:00 2001 From: Michael Pfeiffer Date: Mon, 4 Nov 2002 23:58:32 +0000 Subject: [PATCH] Changed GUI of configuration window a little (bitmaps will be designed by CDT). git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1843 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/print/BeUtils.cpp | 42 ++++++++++++ src/servers/print/BeUtils.h | 12 +++- src/servers/print/ConfigWindow.cpp | 64 ++++++++++++++----- src/servers/print/ConfigWindow.h | 6 +- src/servers/print/Jamfile | 3 +- src/servers/print/PrintServer.FileTypes.rsrc | Bin 4209 -> 20829 bytes 6 files changed, 108 insertions(+), 19 deletions(-) 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 7749f73064af7cad169fa70953abe5e844ebd957..6e9fa464066e49ddc4b3699d4be5076409ca045c 100644 GIT binary patch literal 20829 zcmeHPO-~$05N(nrUns!(GANhu2aF+y9DG^vv5PhWcEw;sPRQ6uA&M}vk(FbV@rD24 zgR{yZzah#sKVa{<}>DM1ZhT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