#include
<app/Application.h>
#include
<app/Message.h>
#include
<app/Messenger.h>
#include
<interface/Button.h>
#include
<locale/Locale.h>
#include
"MyView.h"
const
char
* BT_NAME_HELLO = "HelloButton"
;
const
char
* BT_LABEL_HELLO = "Hello"
;
const
char
* BT_NAME_HOWAREYOU = "HowAreYouButton"
;
const
char
* BT_LABEL_HOWAREYOU = "How are you"
;
const
char
* BT_NAME_OK = "OkButton"
;
const
char
* BT_LABEL_OK = "Ok"
;
const
char
* BT_NAME_ABOUT = "AboutButton"
;
const
char
* BT_LABEL_ABOUT = "About"
;
const
int
LAYOUT_XOFFSET = 15
;
const
int
LAYOUT_YOFFSET = 15
;
const
int
N_BUTTONS = 4
;
MyView::MyView( BRect frame )
: BView( frame, VIEW_MYVIEW, B_FOLLOW_ALL_SIDES, B_WILL_DRAW )
{
}
MyView::~MyView()
{
}
void
MyView::AttachedToWindow( void
)
{
CreateGUI();
}
void
MyView::CreateGUI( void
)
{
BButton* button;
BRect frame( LAYOUT_XOFFSET, LAYOUT_YOFFSET, 125
, 25
);
button = new
BButton(
frame,
BT_NAME_HELLO,
_T( BT_LABEL_HELLO ),
new
BMessage( MSG_BUTTON_HELLO ) );
AddChild( button);
button = new
BButton(
frame,
BT_NAME_HOWAREYOU,
_T( BT_LABEL_HOWAREYOU ),
new
BMessage( MSG_BUTTON_HAY ) );
AddChild( button);
button = new
BButton(
frame,
BT_NAME_OK,
_T( BT_LABEL_OK ),
new
BMessage( MSG_BUTTON_OK ) );
AddChild( button);
button = new
BButton(
frame,
BT_NAME_ABOUT,
_T( BT_LABEL_ABOUT ),
new
BMessage( B_ABOUT_REQUESTED ) );
button->SetTarget( be_app );
AddChild( button);
this->refreshLayout();
}
void
MyView::refreshLanguage( void
)
{
((BButton*)FindView( BT_NAME_HELLO ))->
SetLabel( _T( BT_LABEL_HELLO ) );
((BButton*)FindView( BT_NAME_HOWAREYOU ))->
SetLabel( _T( BT_LABEL_HOWAREYOU ) );
((BButton*)FindView( BT_NAME_OK ))->
SetLabel( _T( BT_LABEL_OK ) );
((BButton*)FindView( BT_NAME_ABOUT ))->
SetLabel( _T( BT_LABEL_ABOUT ) );
this->refreshLayout();
}
void
MyView::refreshLayout( void
)
{
BButton* buttons[ N_BUTTONS ];
buttons[0
] = (BButton*)FindView( BT_NAME_HELLO );
buttons[1
] = (BButton*)FindView( BT_NAME_HOWAREYOU );
buttons[2
] = (BButton*)FindView( BT_NAME_OK );
buttons[3
] = (BButton*)FindView( BT_NAME_ABOUT );
BPoint aktsize( 0.0
, 0.0
);
BPoint tmpsize( 0.0
, 0.0
);
for
( int
i = 0
; i < N_BUTTONS; i++ )
{
buttons[i]->GetPreferredSize( &(aktsize.x), &(aktsize.y) );
if
( aktsize.x > tmpsize.x )
{
tmpsize = aktsize;
}
}
for
( int
i = 0
; i < N_BUTTONS; i++ )
{
buttons[i]->ResizeTo( tmpsize.x, tmpsize.y );
}
float
tmpX, tmpY;
buttons[0
]->MoveTo( LAYOUT_XOFFSET, LAYOUT_YOFFSET );
tmpX = LAYOUT_XOFFSET + buttons[0
]->Frame().Width() + LAYOUT_XOFFSET;
tmpY = LAYOUT_YOFFSET;
buttons[1
]->MoveTo( tmpX, tmpY );
tmpX = LAYOUT_XOFFSET;
tmpY = LAYOUT_YOFFSET + buttons[1
]->Frame().Height() + LAYOUT_YOFFSET;
buttons[2
]->MoveTo( tmpX, tmpY );
tmpX = LAYOUT_XOFFSET + buttons[2
]->Frame().Width() + LAYOUT_XOFFSET;
tmpY = LAYOUT_YOFFSET + buttons[2
]->Frame().Height() + LAYOUT_YOFFSET;
buttons[3
]->MoveTo( tmpX, tmpY );
tmpX += buttons[3
]->Frame().Width() + LAYOUT_XOFFSET;
tmpY += buttons[3
]->Frame().Height() + LAYOUT_YOFFSET;
this->ResizeTo( tmpX, tmpY );
}