* Made the se-info attribute endian-aware.
* Check in LoadAttrs() if the new frame looks valid, and fits on screen, and ignore it if not. * Moved static helper function out of the class definition. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36659 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
96949a0a8d
commit
9bf722bd79
@ -36,11 +36,13 @@
|
|||||||
#include <PrintJob.h>
|
#include <PrintJob.h>
|
||||||
#include <Rect.h>
|
#include <Rect.h>
|
||||||
#include <Roster.h>
|
#include <Roster.h>
|
||||||
|
#include <Screen.h>
|
||||||
#include <ScrollView.h>
|
#include <ScrollView.h>
|
||||||
#include <TextControl.h>
|
#include <TextControl.h>
|
||||||
#include <TextView.h>
|
#include <TextView.h>
|
||||||
#include <TranslationUtils.h>
|
#include <TranslationUtils.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace BPrivate;
|
using namespace BPrivate;
|
||||||
|
|
||||||
|
|
||||||
@ -52,6 +54,24 @@ const float kLineViewWidth = 30.0;
|
|||||||
#define TR_CONTEXT "StyledEditWindow"
|
#define TR_CONTEXT "StyledEditWindow"
|
||||||
|
|
||||||
|
|
||||||
|
// This is a temporary solution for building BString with printf like format.
|
||||||
|
// will be removed in the future.
|
||||||
|
static void
|
||||||
|
bs_printf(BString* string, const char* format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, format);
|
||||||
|
char* buf;
|
||||||
|
vasprintf(&buf, format, ap);
|
||||||
|
string->SetTo(buf);
|
||||||
|
free(buf);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
StyledEditWindow::StyledEditWindow(BRect frame, int32 id, uint32 encoding)
|
StyledEditWindow::StyledEditWindow(BRect frame, int32 id, uint32 encoding)
|
||||||
: BWindow(frame, "untitled", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS)
|
: BWindow(frame, "untitled", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS)
|
||||||
{
|
{
|
||||||
@ -339,14 +359,21 @@ StyledEditWindow::LoadAttrs()
|
|||||||
if (documentNode.InitCheck() != B_OK)
|
if (documentNode.InitCheck() != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BRect newFrame(Frame());
|
BRect newFrame;
|
||||||
ssize_t bytesRead = documentNode.ReadAttr(ATTRNAME_SE_INFO, B_RECT_TYPE,
|
ssize_t bytesRead = documentNode.ReadAttr(ATTRNAME_SE_INFO, B_RECT_TYPE,
|
||||||
0, &newFrame, sizeof(BRect));
|
0, &newFrame, sizeof(BRect));
|
||||||
if (bytesRead < 0)
|
if (bytesRead != sizeof(BRect))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MoveTo(newFrame.left, newFrame.top);
|
swap_data(B_RECT_TYPE, &newFrame, sizeof(BRect), B_SWAP_BENDIAN_TO_HOST);
|
||||||
ResizeTo(newFrame.Width(), newFrame.Height());
|
|
||||||
|
// Check if the frame in on screen, otherwise, ignore it
|
||||||
|
BScreen screen(this);
|
||||||
|
if (newFrame.Width() > 32 && newFrame.Height() > 32
|
||||||
|
&& screen.Frame().Contains(newFrame)) {
|
||||||
|
MoveTo(newFrame.left, newFrame.top);
|
||||||
|
ResizeTo(newFrame.Width(), newFrame.Height());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -370,6 +397,8 @@ StyledEditWindow::SaveAttrs()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
BRect frame(Frame());
|
BRect frame(Frame());
|
||||||
|
swap_data(B_RECT_TYPE, &frame, sizeof(BRect), B_SWAP_HOST_TO_BENDIAN);
|
||||||
|
|
||||||
documentNode.WriteAttr(ATTRNAME_SE_INFO, B_RECT_TYPE, 0, &frame,
|
documentNode.WriteAttr(ATTRNAME_SE_INFO, B_RECT_TYPE, 0, &frame,
|
||||||
sizeof(BRect));
|
sizeof(BRect));
|
||||||
}
|
}
|
||||||
@ -835,21 +864,6 @@ StyledEditWindow::Quit()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// This is temporary solution for building BString with printf like format.
|
|
||||||
// will be removed in the future.
|
|
||||||
static void
|
|
||||||
bs_printf(BString* string, const char* format, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
va_start(ap, format);
|
|
||||||
char* buf;
|
|
||||||
vasprintf(&buf, format, ap);
|
|
||||||
string->SetTo(buf);
|
|
||||||
free(buf);
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#undef TR_CONTEXT
|
#undef TR_CONTEXT
|
||||||
#define TR_CONTEXT "QuitAlert"
|
#define TR_CONTEXT "QuitAlert"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user