[haiku-commits] r36659 - haiku/trunk/src/apps/stylededit

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 6 May 2010 17:47:55 +0200 (CEST)

Author: axeld
Date: 2010-05-06 17:47:55 +0200 (Thu, 06 May 2010)
New Revision: 36659
Changeset: http://dev.haiku-os.org/changeset/36659/haiku

Modified:
   haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp
Log:
* 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.


Modified: haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp
===================================================================
--- haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp        2010-05-06 
15:42:48 UTC (rev 36658)
+++ haiku/trunk/src/apps/stylededit/StyledEditWindow.cpp        2010-05-06 
15:47:55 UTC (rev 36659)
@@ -36,11 +36,13 @@
 #include <PrintJob.h>
 #include <Rect.h>
 #include <Roster.h>
+#include <Screen.h>
 #include <ScrollView.h>
 #include <TextControl.h>
 #include <TextView.h>
 #include <TranslationUtils.h>
 
+
 using namespace BPrivate;
 
 
@@ -52,6 +54,24 @@
 #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)
        : BWindow(frame, "untitled", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS)
 {
@@ -339,14 +359,21 @@
        if (documentNode.InitCheck() != B_OK)
                return;
 
-       BRect newFrame(Frame());
+       BRect newFrame;
        ssize_t bytesRead = documentNode.ReadAttr(ATTRNAME_SE_INFO, B_RECT_TYPE,
                0, &newFrame, sizeof(BRect));
-       if (bytesRead < 0)
+       if (bytesRead != sizeof(BRect))
                return;
 
-       MoveTo(newFrame.left, newFrame.top);
-       ResizeTo(newFrame.Width(), newFrame.Height());
+       swap_data(B_RECT_TYPE, &newFrame, sizeof(BRect), 
B_SWAP_BENDIAN_TO_HOST);
+
+       // 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 @@
                return;
 
        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,
                sizeof(BRect));
 }
@@ -835,21 +864,6 @@
 }
 
 
-// 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
 #define TR_CONTEXT "QuitAlert"
 


Other related posts: