* reordered MarinView.h, MarginView.cpp
* rename private functions to use underscore * rename some public functions to match the usual style * adjust pdf/ preview driver to use the renamed functions * we where leaking a single message in _ConstructGui, otherwise no functional change git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26396 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -124,6 +124,7 @@ THE SOFTWARE.
|
|||||||
#include <InterfaceKit.h>
|
#include <InterfaceKit.h>
|
||||||
#include <Looper.h>
|
#include <Looper.h>
|
||||||
|
|
||||||
|
class BTextControl;
|
||||||
class MarginManager;
|
class MarginManager;
|
||||||
|
|
||||||
// Messages that the MarginManager accepts
|
// Messages that the MarginManager accepts
|
||||||
@@ -149,77 +150,73 @@ class MarginView : public BBox
|
|||||||
{
|
{
|
||||||
friend class MarginManager;
|
friend class MarginManager;
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// GUI components
|
|
||||||
BTextControl *fTop, *fBottom, *fLeft, *fRight;
|
|
||||||
|
|
||||||
// rect that holds the margins for the page as a set of point offsets
|
|
||||||
BRect fMargins;
|
|
||||||
|
|
||||||
// the maximum size of the page view calculated from the view size
|
|
||||||
float fMaxPageWidth;
|
|
||||||
float fMaxPageHeight;
|
|
||||||
|
|
||||||
// the actual size of the page in points
|
|
||||||
float fPageHeight;
|
|
||||||
float fPageWidth;
|
|
||||||
|
|
||||||
// the units used to calculate the page size
|
|
||||||
MarginUnit fMarginUnit;
|
|
||||||
float fUnitValue;
|
|
||||||
|
|
||||||
// the size of the drawing area we have to draw the view in pixels
|
|
||||||
float fViewHeight;
|
|
||||||
float fViewWidth;
|
|
||||||
|
|
||||||
// Calculate the view size for the margins
|
|
||||||
void CalculateViewSize(uint32 msg);
|
|
||||||
|
|
||||||
// performed internally using the supplied popup
|
|
||||||
void SetMarginUnit(MarginUnit unit);
|
|
||||||
|
|
||||||
// performed internally using text fields
|
|
||||||
void SetMargin(BRect margin);
|
|
||||||
|
|
||||||
// utility method
|
|
||||||
void AllowOnlyNumbers(BTextControl *textControl, int maxNum);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MarginView(BRect rect,
|
MarginView(BRect rect, int32 pageWidth = 0,
|
||||||
int32 pageWidth = 0,
|
int32 pageHeight = 0,
|
||||||
int32 pageHeight = 0,
|
BRect margins = BRect(1, 1, 1, 1), // 1 inch
|
||||||
BRect margins = BRect(1, 1, 1, 1), // default to 1 inch
|
MarginUnit unit = kUnitInch);
|
||||||
MarginUnit unit = kUnitInch);
|
|
||||||
|
|
||||||
~MarginView();
|
virtual ~MarginView();
|
||||||
|
|
||||||
/// all the GUI construction code
|
virtual void AttachedToWindow();
|
||||||
void ConstructGUI();
|
virtual void Draw(BRect rect);
|
||||||
|
virtual void FrameResized(float width, float height);
|
||||||
|
virtual void MessageReceived(BMessage *msg);
|
||||||
|
|
||||||
// page size
|
// point.x = width, point.y = height
|
||||||
void SetPageSize(float pageWidth, float pageHeight);
|
BPoint PageSize() const;
|
||||||
// point.x = width, point.y = height
|
void SetPageSize(float pageWidth, float pageHeight);
|
||||||
BPoint GetPageSize(void);
|
|
||||||
|
|
||||||
// margin
|
// margin
|
||||||
BRect GetMargin(void);
|
BRect Margin() const;
|
||||||
|
|
||||||
// orientation
|
// units
|
||||||
// None, this state should be saved elsewhere in the page setup code
|
MarginUnit Unit() const;
|
||||||
// and not here. See the FLIP_PAGE message to perform this function.
|
|
||||||
|
|
||||||
// units
|
// will cause a recalc and redraw
|
||||||
MarginUnit GetMarginUnit(void);
|
void UpdateView(uint32 msg);
|
||||||
|
|
||||||
// will cause a recalc and redraw
|
private:
|
||||||
void UpdateView(uint32 msg);
|
// all the GUI construction code
|
||||||
|
void _ConstructGUI();
|
||||||
|
|
||||||
// BeOS Hook methods
|
// utility method
|
||||||
virtual void AttachedToWindow(void);
|
void _AllowOnlyNumbers(BTextControl *textControl,
|
||||||
void Draw(BRect rect);
|
int32 maxNum);
|
||||||
void FrameResized(float width, float height);
|
|
||||||
void MessageReceived(BMessage *msg);
|
// performed internally using text fields
|
||||||
|
void _SetMargin(BRect margin);
|
||||||
|
|
||||||
|
// performed internally using the supplied popup
|
||||||
|
void _SetMarginUnit(MarginUnit unit);
|
||||||
|
|
||||||
|
// Calculate the view size for the margins
|
||||||
|
void _CalculateViewSize(uint32 msg);
|
||||||
|
|
||||||
|
private:
|
||||||
|
BTextControl* fTop;
|
||||||
|
BTextControl* fBottom;
|
||||||
|
BTextControl* fLeft;
|
||||||
|
BTextControl* fRight;
|
||||||
|
|
||||||
|
// rect that holds the margins for the page as a set of point offsets
|
||||||
|
BRect fMargins;
|
||||||
|
|
||||||
|
// the maximum size of the page view calculated from the view size
|
||||||
|
float fMaxPageWidth;
|
||||||
|
float fMaxPageHeight;
|
||||||
|
|
||||||
|
// the actual size of the page in points
|
||||||
|
float fPageHeight;
|
||||||
|
float fPageWidth;
|
||||||
|
|
||||||
|
// the units used to calculate the page size
|
||||||
|
MarginUnit fMarginUnit;
|
||||||
|
float fUnitValue;
|
||||||
|
|
||||||
|
// the size of the drawing area we have to draw the view in pixels
|
||||||
|
float fViewHeight;
|
||||||
|
float fViewWidth;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _MARGIN_VIEW_H
|
#endif // _MARGIN_VIEW_H
|
||||||
|
|||||||
@@ -403,7 +403,7 @@ PageSetupWindow::UpdateSetupMessage()
|
|||||||
fSetupMsg->ReplaceRect("paper_rect", r);
|
fSetupMsg->ReplaceRect("paper_rect", r);
|
||||||
|
|
||||||
// Save the printable_rect
|
// Save the printable_rect
|
||||||
BRect margin = fMarginView->GetMargin();
|
BRect margin = fMarginView->Margin();
|
||||||
if (orientation == 0) {
|
if (orientation == 0) {
|
||||||
margin.right = w - margin.right;
|
margin.right = w - margin.right;
|
||||||
margin.bottom = h - margin.bottom;
|
margin.bottom = h - margin.bottom;
|
||||||
@@ -414,7 +414,7 @@ PageSetupWindow::UpdateSetupMessage()
|
|||||||
fSetupMsg->ReplaceRect("printable_rect", margin);
|
fSetupMsg->ReplaceRect("printable_rect", margin);
|
||||||
|
|
||||||
// save the units used
|
// save the units used
|
||||||
int32 units = fMarginView->GetMarginUnit();
|
int32 units = fMarginView->Unit();
|
||||||
if (fSetupMsg->HasInt32("units")) {
|
if (fSetupMsg->HasInt32("units")) {
|
||||||
fSetupMsg->ReplaceInt32("units", units);
|
fSetupMsg->ReplaceInt32("units", units);
|
||||||
} else {
|
} else {
|
||||||
@@ -544,7 +544,7 @@ PageSetupWindow::MessageReceived(BMessage *msg)
|
|||||||
// Simon added
|
// Simon added
|
||||||
case 'ornt':
|
case 'ornt':
|
||||||
{
|
{
|
||||||
BPoint p = fMarginView->GetPageSize();
|
BPoint p = fMarginView->PageSize();
|
||||||
int32 orientation;
|
int32 orientation;
|
||||||
msg->FindInt32("orientation", &orientation);
|
msg->FindInt32("orientation", &orientation);
|
||||||
if (orientation == PrinterDriver::LANDSCAPE_ORIENTATION
|
if (orientation == PrinterDriver::LANDSCAPE_ORIENTATION
|
||||||
|
|||||||
@@ -276,7 +276,7 @@ PageSetupWindow::UpdateSetupMessage()
|
|||||||
AddString(fSetupMsg, "preview:paper_size", item->Label());
|
AddString(fSetupMsg, "preview:paper_size", item->Label());
|
||||||
|
|
||||||
// Save the printable_rect
|
// Save the printable_rect
|
||||||
BRect margin = fMarginView->GetMargin();
|
BRect margin = fMarginView->Margin();
|
||||||
if (fCurrentOrientation == PrinterDriver::PORTRAIT_ORIENTATION) {
|
if (fCurrentOrientation == PrinterDriver::PORTRAIT_ORIENTATION) {
|
||||||
margin.right = w - margin.right;
|
margin.right = w - margin.right;
|
||||||
margin.bottom = h - margin.bottom;
|
margin.bottom = h - margin.bottom;
|
||||||
@@ -287,7 +287,7 @@ PageSetupWindow::UpdateSetupMessage()
|
|||||||
SetRect(fSetupMsg, "preview:printable_rect", margin);
|
SetRect(fSetupMsg, "preview:printable_rect", margin);
|
||||||
SetRect(fSetupMsg, "printable_rect", ScaleRect(margin, scaleR));
|
SetRect(fSetupMsg, "printable_rect", ScaleRect(margin, scaleR));
|
||||||
|
|
||||||
SetInt32(fSetupMsg, "units", fMarginView->GetMarginUnit());
|
SetInt32(fSetupMsg, "units", fMarginView->Unit());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,7 +323,7 @@ PageSetupWindow::MessageReceived(BMessage *msg)
|
|||||||
|
|
||||||
if (fCurrentOrientation != orientation) {
|
if (fCurrentOrientation != orientation) {
|
||||||
fCurrentOrientation = orientation;
|
fCurrentOrientation = orientation;
|
||||||
BPoint p = fMarginView->GetPageSize();
|
BPoint p = fMarginView->PageSize();
|
||||||
fMarginView->SetPageSize(p.y, p.x);
|
fMarginView->SetPageSize(p.y, p.x);
|
||||||
fMarginView->UpdateView(MARGIN_CHANGED);
|
fMarginView->UpdateView(MARGIN_CHANGED);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -363,8 +363,8 @@ PageSetupView::UpdateJobData()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// adjust printable rect by margin
|
// adjust printable rect by margin
|
||||||
fJobData->setMarginUnit(fMarginView->GetMarginUnit());
|
fJobData->setMarginUnit(fMarginView->Unit());
|
||||||
BRect margin = fMarginView->GetMargin();
|
BRect margin = fMarginView->Margin();
|
||||||
BRect printable_rect;
|
BRect printable_rect;
|
||||||
printable_rect.left = paper_rect.left + margin.left;
|
printable_rect.left = paper_rect.left + margin.left;
|
||||||
printable_rect.top = paper_rect.top + margin.top;
|
printable_rect.top = paper_rect.top + margin.top;
|
||||||
|
|||||||
@@ -35,12 +35,16 @@ THE SOFTWARE.
|
|||||||
|
|
||||||
#include "MarginView.h"
|
#include "MarginView.h"
|
||||||
|
|
||||||
|
|
||||||
#include <AppKit.h>
|
#include <AppKit.h>
|
||||||
#include <SupportKit.h>
|
#include <SupportKit.h>
|
||||||
|
#include <TextControl.h>
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
/*----------------- MarginView Private Constants --------------------*/
|
/*----------------- MarginView Private Constants --------------------*/
|
||||||
|
|
||||||
const int kOffsetY = 20;
|
const int kOffsetY = 20;
|
||||||
@@ -58,9 +62,7 @@ const static float kMinUnitHeight = 30; // pixels
|
|||||||
|
|
||||||
const static float kUnitFormat[] = { kInchUnits, kCMUnits, kPointUnits };
|
const static float kUnitFormat[] = { kInchUnits, kCMUnits, kPointUnits };
|
||||||
const static char *kUnitNames[] = { "Inch", "cm", "Points", NULL };
|
const static char *kUnitNames[] = { "Inch", "cm", "Points", NULL };
|
||||||
const static MarginUnit kUnitMsg[] = { kUnitInch,
|
const static MarginUnit kUnitMsg[] = { kUnitInch, kUnitCM, kUnitPoint };
|
||||||
kUnitCM,
|
|
||||||
kUnitPoint };
|
|
||||||
|
|
||||||
const pattern kDots = {{ 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55 }};
|
const pattern kDots = {{ 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55 }};
|
||||||
|
|
||||||
@@ -69,7 +71,6 @@ const rgb_color kRed = { 255,0,0,0 };
|
|||||||
const rgb_color kWhite = { 255,255,255,0 };
|
const rgb_color kWhite = { 255,255,255,0 };
|
||||||
const rgb_color kGray = { 220,220,220,0 };
|
const rgb_color kGray = { 220,220,220,0 };
|
||||||
|
|
||||||
/*----------------- MarginView Public Methods --------------------*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@@ -81,13 +82,9 @@ const rgb_color kGray = { 220,220,220,0 };
|
|||||||
* @param units, unit32 enum for units used in view
|
* @param units, unit32 enum for units used in view
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
MarginView::MarginView(BRect frame,
|
MarginView::MarginView(BRect frame, int32 pageWidth, int32 pageHeight,
|
||||||
int32 pageWidth,
|
BRect margins, MarginUnit units)
|
||||||
int32 pageHeight,
|
: BBox(frame, NULL, B_FOLLOW_ALL)
|
||||||
BRect margins,
|
|
||||||
MarginUnit units)
|
|
||||||
|
|
||||||
:BBox(frame, NULL, B_FOLLOW_ALL)
|
|
||||||
{
|
{
|
||||||
fMarginUnit = units;
|
fMarginUnit = units;
|
||||||
fUnitValue = kUnitFormat[units];
|
fUnitValue = kUnitFormat[units];
|
||||||
@@ -103,16 +100,33 @@ MarginView::MarginView(BRect frame,
|
|||||||
fPageHeight = pageHeight;
|
fPageHeight = pageHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor
|
* Destructor
|
||||||
*
|
*
|
||||||
* @param none
|
* @param none
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
MarginView::~MarginView() {
|
MarginView::~MarginView()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AttachToWindow
|
||||||
|
*
|
||||||
|
* @param none
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
MarginView::AttachedToWindow()
|
||||||
|
{
|
||||||
|
if (Parent())
|
||||||
|
SetViewColor(Parent()->ViewColor());
|
||||||
|
|
||||||
|
_ConstructGUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------- MarginView Public BeOS Hook Methods --------------------*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draw
|
* Draw
|
||||||
@@ -176,53 +190,85 @@ MarginView::FrameResized(float width, float height)
|
|||||||
fMaxPageHeight = height - kMinUnitHeight - kOffsetX;
|
fMaxPageHeight = height - kMinUnitHeight - kOffsetX;
|
||||||
fMaxPageWidth = width - kMinFieldWidth - kOffsetY;
|
fMaxPageWidth = width - kMinFieldWidth - kOffsetY;
|
||||||
|
|
||||||
CalculateViewSize(MARGIN_CHANGED);
|
_CalculateViewSize(MARGIN_CHANGED);
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AttachToWindow
|
* MesssageReceived()
|
||||||
*
|
*
|
||||||
* @param none
|
* Receive messages for the view
|
||||||
|
*
|
||||||
|
* @param BMessage* , the message being received
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
MarginView::AttachedToWindow()
|
MarginView::MessageReceived(BMessage *msg)
|
||||||
{
|
{
|
||||||
if (Parent()) {
|
switch (msg->what) {
|
||||||
SetViewColor(Parent()->ViewColor());
|
case CHANGE_PAGE_SIZE: {
|
||||||
|
float w;
|
||||||
|
float h;
|
||||||
|
msg->FindFloat("width", &w);
|
||||||
|
msg->FindFloat("height", &h);
|
||||||
|
SetPageSize(w, h);
|
||||||
|
UpdateView(MARGIN_CHANGED);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case FLIP_PAGE: {
|
||||||
|
BPoint p = PageSize();
|
||||||
|
SetPageSize(p.y, p.x);
|
||||||
|
UpdateView(MARGIN_CHANGED);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case MARGIN_CHANGED:
|
||||||
|
UpdateView(MARGIN_CHANGED);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TOP_MARGIN_CHANGED:
|
||||||
|
UpdateView(TOP_MARGIN_CHANGED);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LEFT_MARGIN_CHANGED:
|
||||||
|
UpdateView(LEFT_MARGIN_CHANGED);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RIGHT_MARGIN_CHANGED:
|
||||||
|
UpdateView(RIGHT_MARGIN_CHANGED);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BOTTOM_MARGIN_CHANGED:
|
||||||
|
UpdateView(BOTTOM_MARGIN_CHANGED);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MARGIN_UNIT_CHANGED: {
|
||||||
|
int32 marginUnit;
|
||||||
|
if (msg->FindInt32("marginUnit", &marginUnit) == B_OK)
|
||||||
|
_SetMarginUnit((MarginUnit)marginUnit);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
BView::MessageReceived(msg);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
ConstructGUI();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*----------------- MarginView Public Methods --------------------*/
|
/*----------------- MarginView Public Methods --------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GetUnits
|
* PageSize
|
||||||
*
|
*
|
||||||
* @param none
|
* @param none
|
||||||
* @return uint32 enum, units in inches, cm, points
|
* @return BPoint, contains actual point values of page in x, y of point
|
||||||
*/
|
*/
|
||||||
MarginUnit
|
BPoint
|
||||||
MarginView::GetMarginUnit(void) {
|
MarginView::PageSize() const
|
||||||
return fMarginUnit;
|
{
|
||||||
|
return BPoint(fPageWidth, fPageHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* UpdateView, recalculate and redraw the view
|
|
||||||
*
|
|
||||||
* @param msg is a message to the calculate size to tell which field caused
|
|
||||||
* the update to occur, or it is a general update.
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
MarginView::UpdateView(uint32 msg)
|
|
||||||
{
|
|
||||||
Window()->Lock();
|
|
||||||
CalculateViewSize(msg); // nur Preview in Margins BBox!
|
|
||||||
Invalidate();
|
|
||||||
Window()->Unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SetPageSize
|
* SetPageSize
|
||||||
@@ -238,25 +284,15 @@ MarginView::SetPageSize(float pageWidth, float pageHeight)
|
|||||||
fPageHeight = pageHeight;
|
fPageHeight = pageHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* GetPageSize
|
|
||||||
*
|
|
||||||
* @param none
|
|
||||||
* @return BPoint, contains actual point values of page in x, y of point
|
|
||||||
*/
|
|
||||||
BPoint
|
|
||||||
MarginView::GetPageSize(void) {
|
|
||||||
return BPoint(fPageWidth, fPageHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GetMargin
|
* Margin
|
||||||
*
|
*
|
||||||
* @param none
|
* @param none
|
||||||
* @return rect, return margin values always in points
|
* @return rect, return margin values always in points
|
||||||
*/
|
*/
|
||||||
BRect
|
BRect
|
||||||
MarginView::GetMargin(void)
|
MarginView::Margin() const
|
||||||
{
|
{
|
||||||
BRect margin;
|
BRect margin;
|
||||||
|
|
||||||
@@ -267,8 +303,7 @@ MarginView::GetMargin(void)
|
|||||||
float fbottom = atof(fBottom->Text());
|
float fbottom = atof(fBottom->Text());
|
||||||
|
|
||||||
// convert to units to points
|
// convert to units to points
|
||||||
switch (fMarginUnit)
|
switch (fMarginUnit) {
|
||||||
{
|
|
||||||
case kUnitInch:
|
case kUnitInch:
|
||||||
// convert to points
|
// convert to points
|
||||||
ftop *= kInchUnits;
|
ftop *= kInchUnits;
|
||||||
@@ -292,75 +327,42 @@ MarginView::GetMargin(void)
|
|||||||
return margin;
|
return margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MesssageReceived()
|
* Unit
|
||||||
*
|
*
|
||||||
* Receive messages for the view
|
* @param none
|
||||||
|
* @return uint32 enum, units in inches, cm, points
|
||||||
|
*/
|
||||||
|
MarginUnit
|
||||||
|
MarginView::Unit() const
|
||||||
|
{
|
||||||
|
return fMarginUnit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UpdateView, recalculate and redraw the view
|
||||||
*
|
*
|
||||||
* @param BMessage* , the message being received
|
* @param msg is a message to the calculate size to tell which field caused
|
||||||
|
* the update to occur, or it is a general update.
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
MarginView::MessageReceived(BMessage *msg)
|
MarginView::UpdateView(uint32 msg)
|
||||||
{
|
{
|
||||||
switch (msg->what)
|
Window()->Lock();
|
||||||
{
|
_CalculateViewSize(msg); // only Preview in Margins BBox!
|
||||||
case CHANGE_PAGE_SIZE: {
|
Invalidate();
|
||||||
float w;
|
Window()->Unlock();
|
||||||
float h;
|
|
||||||
msg->FindFloat("width", &w);
|
|
||||||
msg->FindFloat("height", &h);
|
|
||||||
SetPageSize(w, h);
|
|
||||||
UpdateView(MARGIN_CHANGED);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FLIP_PAGE: {
|
|
||||||
BPoint p;
|
|
||||||
p = GetPageSize();
|
|
||||||
SetPageSize(p.y, p.x);
|
|
||||||
UpdateView(MARGIN_CHANGED);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MARGIN_CHANGED:
|
|
||||||
UpdateView(MARGIN_CHANGED);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TOP_MARGIN_CHANGED:
|
|
||||||
UpdateView(TOP_MARGIN_CHANGED);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case LEFT_MARGIN_CHANGED:
|
|
||||||
UpdateView(LEFT_MARGIN_CHANGED);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RIGHT_MARGIN_CHANGED:
|
|
||||||
UpdateView(RIGHT_MARGIN_CHANGED);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BOTTOM_MARGIN_CHANGED:
|
|
||||||
UpdateView(BOTTOM_MARGIN_CHANGED);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MARGIN_UNIT_CHANGED:
|
|
||||||
{
|
|
||||||
int32 marginUnit;
|
|
||||||
if (msg->FindInt32("marginUnit", &marginUnit) == B_OK) {
|
|
||||||
SetMarginUnit((MarginUnit)marginUnit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
BView::MessageReceived(msg);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*----------------- MarginView Private Methods --------------------*/
|
/*----------------- MarginView Private Methods --------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ConstructGUI()
|
* _ConstructGUI()
|
||||||
*
|
*
|
||||||
* Creates the GUI for the View. MUST be called AFTER the View is attached to
|
* Creates the GUI for the View. MUST be called AFTER the View is attached to
|
||||||
* the Window, or will crash and/or create strange behaviour
|
* the Window, or will crash and/or create strange behaviour
|
||||||
@@ -369,16 +371,10 @@ MarginView::MessageReceived(BMessage *msg)
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
MarginView::ConstructGUI()
|
MarginView::_ConstructGUI()
|
||||||
{
|
{
|
||||||
BMessage *msg;
|
|
||||||
BString str;
|
BString str;
|
||||||
BMenuItem *item;
|
// Create text fields
|
||||||
BMenuField *mf;
|
|
||||||
BPopUpMenu *menu;
|
|
||||||
|
|
||||||
// Create text fields
|
|
||||||
msg = new BMessage(MARGIN_CHANGED);
|
|
||||||
BRect r(Frame().Width() - be_plain_font->StringWidth("Top#") - kWidth,
|
BRect r(Frame().Width() - be_plain_font->StringWidth("Top#") - kWidth,
|
||||||
kOffsetY, Frame().Width() - kOffsetX, kWidth);
|
kOffsetY, Frame().Width() - kOffsetX, kWidth);
|
||||||
|
|
||||||
@@ -390,7 +386,7 @@ MarginView::ConstructGUI()
|
|||||||
fTop->SetModificationMessage(new BMessage(TOP_MARGIN_CHANGED));
|
fTop->SetModificationMessage(new BMessage(TOP_MARGIN_CHANGED));
|
||||||
fTop->SetDivider(be_plain_font->StringWidth("Top#"));
|
fTop->SetDivider(be_plain_font->StringWidth("Top#"));
|
||||||
fTop->SetTarget(this);
|
fTop->SetTarget(this);
|
||||||
AllowOnlyNumbers(fTop, kNumCount);
|
_AllowOnlyNumbers(fTop, kNumCount);
|
||||||
AddChild(fTop);
|
AddChild(fTop);
|
||||||
|
|
||||||
|
|
||||||
@@ -407,7 +403,7 @@ MarginView::ConstructGUI()
|
|||||||
fLeft->SetModificationMessage(new BMessage(LEFT_MARGIN_CHANGED));
|
fLeft->SetModificationMessage(new BMessage(LEFT_MARGIN_CHANGED));
|
||||||
fLeft->SetDivider(be_plain_font->StringWidth("Left#"));
|
fLeft->SetDivider(be_plain_font->StringWidth("Left#"));
|
||||||
fLeft->SetTarget(this);
|
fLeft->SetTarget(this);
|
||||||
AllowOnlyNumbers(fLeft, kNumCount);
|
_AllowOnlyNumbers(fLeft, kNumCount);
|
||||||
AddChild(fLeft);
|
AddChild(fLeft);
|
||||||
|
|
||||||
|
|
||||||
@@ -425,7 +421,7 @@ MarginView::ConstructGUI()
|
|||||||
fBottom->SetDivider(be_plain_font->StringWidth("Bottom#"));
|
fBottom->SetDivider(be_plain_font->StringWidth("Bottom#"));
|
||||||
fBottom->SetTarget(this);
|
fBottom->SetTarget(this);
|
||||||
|
|
||||||
AllowOnlyNumbers(fBottom, kNumCount);
|
_AllowOnlyNumbers(fBottom, kNumCount);
|
||||||
AddChild(fBottom);
|
AddChild(fBottom);
|
||||||
|
|
||||||
|
|
||||||
@@ -442,7 +438,7 @@ MarginView::ConstructGUI()
|
|||||||
fRight->SetModificationMessage(new BMessage(RIGHT_MARGIN_CHANGED));
|
fRight->SetModificationMessage(new BMessage(RIGHT_MARGIN_CHANGED));
|
||||||
fRight->SetDivider(be_plain_font->StringWidth("Right#"));
|
fRight->SetDivider(be_plain_font->StringWidth("Right#"));
|
||||||
fRight->SetTarget(this);
|
fRight->SetTarget(this);
|
||||||
AllowOnlyNumbers(fRight, kNumCount);
|
_AllowOnlyNumbers(fRight, kNumCount);
|
||||||
AddChild(fRight);
|
AddChild(fRight);
|
||||||
|
|
||||||
|
|
||||||
@@ -451,27 +447,26 @@ MarginView::ConstructGUI()
|
|||||||
r.OffsetBy(-kOffsetX, kOffsetY);
|
r.OffsetBy(-kOffsetX, kOffsetY);
|
||||||
r.right += kOffsetY;
|
r.right += kOffsetY;
|
||||||
|
|
||||||
menu = new BPopUpMenu("units");
|
BPopUpMenu *menu = new BPopUpMenu("units");
|
||||||
mf = new BMenuField(r, "units", "Units", menu,
|
BMenuField *mf = new BMenuField(r, "units", "Units", menu,
|
||||||
B_FOLLOW_BOTTOM|B_FOLLOW_RIGHT);
|
B_FOLLOW_BOTTOM | B_FOLLOW_RIGHT);
|
||||||
mf->ResizeToPreferred();
|
mf->ResizeToPreferred();
|
||||||
mf->SetDivider(be_plain_font->StringWidth("Units#"));
|
mf->SetDivider(be_plain_font->StringWidth("Units#"));
|
||||||
|
|
||||||
|
BMenuItem *item;
|
||||||
// Construct menu items
|
// Construct menu items
|
||||||
for (int i=0; kUnitNames[i] != NULL; i++ )
|
for (int32 i = 0; kUnitNames[i] != NULL; i++) {
|
||||||
{
|
BMessage *msg = new BMessage(MARGIN_UNIT_CHANGED);
|
||||||
msg = new BMessage(MARGIN_UNIT_CHANGED);
|
|
||||||
msg->AddInt32("marginUnit", kUnitMsg[i]);
|
msg->AddInt32("marginUnit", kUnitMsg[i]);
|
||||||
menu->AddItem(item = new BMenuItem(kUnitNames[i], msg));
|
menu->AddItem(item = new BMenuItem(kUnitNames[i], msg));
|
||||||
item->SetTarget(this);
|
item->SetTarget(this);
|
||||||
if (fMarginUnit == kUnitMsg[i]) {
|
if (fMarginUnit == kUnitMsg[i])
|
||||||
item->SetMarked(true);
|
item->SetMarked(true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
AddChild(mf);
|
AddChild(mf);
|
||||||
|
|
||||||
// calculate the sizes for drawing page view
|
// calculate the sizes for drawing page view
|
||||||
CalculateViewSize(MARGIN_CHANGED);
|
_CalculateViewSize(MARGIN_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -483,16 +478,16 @@ MarginView::ConstructGUI()
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
MarginView::AllowOnlyNumbers(BTextControl *textControl, int maxNum)
|
MarginView::_AllowOnlyNumbers(BTextControl *textControl, int32 maxNum)
|
||||||
{
|
{
|
||||||
BTextView *tv = textControl->TextView();
|
BTextView *tv = textControl->TextView();
|
||||||
|
|
||||||
for (long i = 0; i < 256; i++) {
|
for (int32 i = 0; i < 256; i++)
|
||||||
tv->DisallowChar(i);
|
tv->DisallowChar(i);
|
||||||
}
|
|
||||||
for (long i = '0'; i <= '9'; i++) {
|
for (int32 i = '0'; i <= '9'; i++)
|
||||||
tv->AllowChar(i);
|
tv->AllowChar(i);
|
||||||
}
|
|
||||||
tv->AllowChar(B_BACKSPACE);
|
tv->AllowChar(B_BACKSPACE);
|
||||||
tv->AllowChar('.');
|
tv->AllowChar('.');
|
||||||
tv->SetMaxBytes(maxNum);
|
tv->SetMaxBytes(maxNum);
|
||||||
@@ -505,10 +500,12 @@ MarginView::AllowOnlyNumbers(BTextControl *textControl, int maxNum)
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
MarginView::SetMargin(BRect margin) {
|
MarginView::_SetMargin(BRect margin)
|
||||||
|
{
|
||||||
fMargins = margin;
|
fMargins = margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SetUnits, called by the MarginMgr when the units popup is selected
|
* SetUnits, called by the MarginMgr when the units popup is selected
|
||||||
*
|
*
|
||||||
@@ -516,7 +513,7 @@ MarginView::SetMargin(BRect margin) {
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
MarginView::SetMarginUnit(MarginUnit unit)
|
MarginView::_SetMarginUnit(MarginUnit unit)
|
||||||
{
|
{
|
||||||
// do nothing if the current units are the same as requested
|
// do nothing if the current units are the same as requested
|
||||||
if (unit == fMarginUnit) {
|
if (unit == fMarginUnit) {
|
||||||
@@ -603,12 +600,13 @@ MarginView::SetMarginUnit(MarginUnit unit)
|
|||||||
fBottom->SetText(str.String());
|
fBottom->SetText(str.String());
|
||||||
|
|
||||||
// update UI
|
// update UI
|
||||||
CalculateViewSize(MARGIN_CHANGED);
|
_CalculateViewSize(MARGIN_CHANGED);
|
||||||
Invalidate();
|
Invalidate();
|
||||||
|
|
||||||
Window()->Unlock();
|
Window()->Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CalculateViewSize
|
* CalculateViewSize
|
||||||
*
|
*
|
||||||
@@ -621,7 +619,7 @@ MarginView::SetMarginUnit(MarginUnit unit)
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
MarginView::CalculateViewSize(uint32 msg)
|
MarginView::_CalculateViewSize(uint32 msg)
|
||||||
{
|
{
|
||||||
// determine page orientation
|
// determine page orientation
|
||||||
if (fPageHeight < fPageWidth) { // LANDSCAPE
|
if (fPageHeight < fPageWidth) { // LANDSCAPE
|
||||||
@@ -664,8 +662,7 @@ MarginView::CalculateViewSize(uint32 msg)
|
|||||||
BString str;
|
BString str;
|
||||||
|
|
||||||
// Bounds calculation rules:
|
// Bounds calculation rules:
|
||||||
if (msg == TOP_MARGIN_CHANGED)
|
if (msg == TOP_MARGIN_CHANGED) {
|
||||||
{
|
|
||||||
// top must be <= bottom
|
// top must be <= bottom
|
||||||
if (ftop > (ph - fbottom)) {
|
if (ftop > (ph - fbottom)) {
|
||||||
ftop = ph - fbottom;
|
ftop = ph - fbottom;
|
||||||
@@ -678,8 +675,7 @@ MarginView::CalculateViewSize(uint32 msg)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg == BOTTOM_MARGIN_CHANGED)
|
if (msg == BOTTOM_MARGIN_CHANGED) {
|
||||||
{
|
|
||||||
// bottom must be <= pageHeight
|
// bottom must be <= pageHeight
|
||||||
if (fbottom > (ph - ftop)) {
|
if (fbottom > (ph - ftop)) {
|
||||||
fbottom = ph - ftop;
|
fbottom = ph - ftop;
|
||||||
@@ -691,8 +687,7 @@ MarginView::CalculateViewSize(uint32 msg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg == LEFT_MARGIN_CHANGED)
|
if (msg == LEFT_MARGIN_CHANGED) {
|
||||||
{
|
|
||||||
// left must be <= right
|
// left must be <= right
|
||||||
if (fleft > (pw - fright)) {
|
if (fleft > (pw - fright)) {
|
||||||
fleft = pw - fright;
|
fleft = pw - fright;
|
||||||
@@ -704,8 +699,7 @@ MarginView::CalculateViewSize(uint32 msg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg == RIGHT_MARGIN_CHANGED)
|
if (msg == RIGHT_MARGIN_CHANGED) {
|
||||||
{
|
|
||||||
// right must be <= fPageWidth
|
// right must be <= fPageWidth
|
||||||
if (fright > (pw - fleft)) {
|
if (fright > (pw - fleft)) {
|
||||||
fright = pw - fleft;
|
fright = pw - fleft;
|
||||||
@@ -724,5 +718,3 @@ MarginView::CalculateViewSize(uint32 msg)
|
|||||||
fMargins.bottom = fbottom * pixelLength;
|
fMargins.bottom = fbottom * pixelLength;
|
||||||
fMargins.left = fleft * pixelLength;
|
fMargins.left = fleft * pixelLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user