2 * Copyright 2006, 2011 Haiku.
3 * Distributed under the terms of the MIT License.
6 * Stephan Aßmus <superstippi@gmx.de>
14 #include <Directory.h>
16 #include <FindDirectory.h>
23 load_settings(BMessage
* message
, const char* fileName
, const char* folder
)
25 status_t ret
= B_BAD_VALUE
;
28 if ((ret
= find_directory(B_USER_SETTINGS_DIRECTORY
, &path
)) == B_OK
) {
29 // passing folder is optional
31 ret
= path
.Append( folder
);
32 if (ret
== B_OK
&& (ret
= path
.Append(fileName
)) == B_OK
) {
33 BFile
file(path
.Path(), B_READ_ONLY
);
34 if ((ret
= file
.InitCheck()) == B_OK
) {
35 ret
= message
->Unflatten(&file
);
46 save_settings(BMessage
* message
, const char* fileName
, const char* folder
)
48 status_t ret
= B_BAD_VALUE
;
51 if ((ret
= find_directory(B_USER_SETTINGS_DIRECTORY
, &path
)) == B_OK
) {
52 // passing folder is optional
53 if (folder
&& (ret
= path
.Append(folder
)) == B_OK
)
54 ret
= create_directory(path
.Path(), 0777);
55 if (ret
== B_OK
&& (ret
= path
.Append(fileName
)) == B_OK
) {
56 BFile
file(path
.Path(), B_WRITE_ONLY
| B_CREATE_FILE
58 if ((ret
= file
.InitCheck()) == B_OK
) {
59 ret
= message
->Flatten(&file
);
70 stroke_frame(BView
* v
, BRect r
, rgb_color left
, rgb_color top
, rgb_color right
,
73 if (v
&& r
.IsValid()) {
75 v
->AddLine(BPoint(r
.left
, r
.bottom
),
76 BPoint(r
.left
, r
.top
), left
);
77 v
->AddLine(BPoint(r
.left
+ 1.0, r
.top
),
78 BPoint(r
.right
, r
.top
), top
);
79 v
->AddLine(BPoint(r
.right
, r
.top
+ 1.0),
80 BPoint(r
.right
, r
.bottom
), right
);
81 v
->AddLine(BPoint(r
.right
- 1.0, r
.bottom
),
82 BPoint(r
.left
+ 1.0, r
.bottom
), bottom
);
89 make_sure_frame_is_on_screen(BRect
& frame
, BWindow
* window
)
91 BScreen
* screen
= window
!= NULL
? new BScreen(window
)
92 : new BScreen(B_MAIN_SCREEN_ID
);
95 if (frame
.IsValid() && screen
->IsValid()) {
96 BRect screenFrame
= screen
->Frame();
97 if (!screenFrame
.Contains(frame
)) {
98 // make sure frame fits in the screen
99 if (frame
.Width() > screenFrame
.Width())
100 frame
.right
-= frame
.Width() - screenFrame
.Width() + 10.0;
101 if (frame
.Height() > screenFrame
.Height())
102 frame
.bottom
-= frame
.Height() - screenFrame
.Height() + 30.0;
103 // frame is now at the most the size of the screen
104 if (frame
.right
> screenFrame
.right
)
105 frame
.OffsetBy(-(frame
.right
- screenFrame
.right
), 0.0);
106 if (frame
.bottom
> screenFrame
.bottom
)
107 frame
.OffsetBy(0.0, -(frame
.bottom
- screenFrame
.bottom
));
108 if (frame
.left
< screenFrame
.left
)
109 frame
.OffsetBy((screenFrame
.left
- frame
.left
), 0.0);
110 if (frame
.top
< screenFrame
.top
)
111 frame
.OffsetBy(0.0, (screenFrame
.top
- frame
.top
));