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
This commit is contained in:
parent
4b710559dc
commit
1d7af7aad4
@ -36,7 +36,10 @@
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
/*****************************************************************************/
|
||||
|
||||
#include <Application.h>
|
||||
#include <Bitmap.h>
|
||||
#include <Messenger.h>
|
||||
#include <Resources.h>
|
||||
#include <Roster.h>
|
||||
#include <String.h>
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
@ -42,6 +42,10 @@
|
||||
#include <FindDirectory.h>
|
||||
#include <Path.h>
|
||||
#include <SupportDefs.h>
|
||||
#include <Picture.h>
|
||||
#include <PictureButton.h>
|
||||
#include <TranslatorFormats.h>
|
||||
#include <TranslationUtils.h>
|
||||
|
||||
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
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -28,5 +28,6 @@ LinkSharedOSLibs
|
||||
print_server
|
||||
:
|
||||
be
|
||||
root
|
||||
root
|
||||
translation
|
||||
;
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user