headers/bsd: Add sys/queue.h.
[haiku.git] / src / kits / print / BeUtilsTranslation.cpp
blobe9c9fbb73f95fda43172cb19c11fd037deac56a1
1 /*****************************************************************************/
2 // BeUtilsTranslation.cpp
3 //
4 // Version: 1.0.0d1
5 //
6 // Several utilities for writing applications for the BeOS. It are small
7 // very specific functions, but generally useful (could be here because of a
8 // lack in the APIs, or just sheer lazyness :))
9 //
11 // Author
12 // Ithamar R. Adema
13 // Michael Pfeiffer
15 // This application and all source files used in its construction, except
16 // where noted, are licensed under the MIT License, and have been written
17 // and are:
19 // Copyright (c) 2001, 2002 OpenBeOS Project
21 // Permission is hereby granted, free of charge, to any person obtaining a
22 // copy of this software and associated documentation files (the "Software"),
23 // to deal in the Software without restriction, including without limitation
24 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
25 // and/or sell copies of the Software, and to permit persons to whom the
26 // Software is furnished to do so, subject to the following conditions:
28 // The above copyright notice and this permission notice shall be included
29 // in all copies or substantial portions of the Software.
31 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
32 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
34 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
36 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
37 // DEALINGS IN THE SOFTWARE.
38 /*****************************************************************************/
40 #include <Application.h>
41 #include <Bitmap.h>
42 #include <Messenger.h>
43 #include <Resources.h>
44 #include <Roster.h>
45 #include <String.h>
47 #include "BeUtils.h"
49 BBitmap* LoadBitmap(const char* name, uint32 type_code) {
50 if (type_code == B_TRANSLATOR_BITMAP) {
51 return BTranslationUtils::GetBitmap(type_code, name);
52 } else {
53 BResources *res = BApplication::AppResources();
54 if (res != NULL) {
55 BMessage m;
56 size_t length;
57 const void *bits = res->LoadResource(type_code, name, &length);
58 if (bits && m.Unflatten((char*)bits) == B_OK) {
59 return (BBitmap*)BBitmap::Instantiate(&m);
62 return NULL;
66 BPicture *BitmapToPicture(BView* view, BBitmap *bitmap) {
67 if (bitmap) {
68 view->BeginPicture(new BPicture());
69 view->DrawBitmap(bitmap);
70 return view->EndPicture();
72 return NULL;
75 BPicture *BitmapToGrayedPicture(BView* view, BBitmap *bitmap) {
76 if (bitmap) {
77 BRect rect(bitmap->Bounds());
78 view->BeginPicture(new BPicture());
79 view->DrawBitmap(bitmap);
80 view->SetHighColor(255, 255, 255, 128);
81 view->SetDrawingMode(B_OP_ALPHA);
82 view->FillRect(rect);
83 return view->EndPicture();
85 return NULL;