CannaIM: style cleanup

This commit is contained in:
Jérôme Duval
2012-02-18 15:17:28 +01:00
parent d8116125d1
commit 484b565ad0
@@ -16,13 +16,14 @@
#include "KouhoWindow.h" #include "KouhoWindow.h"
KouhoWindow::KouhoWindow( BFont *font, BLooper *looper )
KouhoWindow::KouhoWindow(BFont *font, BLooper *looper)
:BWindow( DUMMY_RECT, :BWindow( DUMMY_RECT,
"kouho", B_MODAL_WINDOW_LOOK, "kouho", B_MODAL_WINDOW_LOOK,
B_FLOATING_ALL_WINDOW_FEEL, B_FLOATING_ALL_WINDOW_FEEL,
B_NOT_RESIZABLE | B_NOT_CLOSABLE | B_NOT_RESIZABLE | B_NOT_CLOSABLE |
B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE | B_AVOID_FOCUS | B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE | B_AVOID_FOCUS |
B_NOT_ANCHORED_ON_ACTIVATE ) B_NOT_ANCHORED_ON_ACTIVATE)
{ {
float fontHeight; float fontHeight;
BRect frame; BRect frame;
@@ -33,59 +34,59 @@ KouhoWindow::KouhoWindow( BFont *font, BLooper *looper )
font_family family; font_family family;
font_style style; font_style style;
strcpy( family, "VL PGothic" ); strcpy(family, "VL PGothic");
strcpy( style, "regular" ); strcpy(style, "regular");
indexfont.SetFamilyAndStyle( family, style ); indexfont.SetFamilyAndStyle(family, style);
indexfont.SetSize( 10 ); indexfont.SetSize(10);
#ifdef DEBUG #ifdef DEBUG
SERIAL_PRINT(( "kouhoWindow: Constructor called.\n" )); SERIAL_PRINT(("kouhoWindow: Constructor called.\n"));
#endif #endif
//setup main pane //setup main pane
indexWidth = indexfont.StringWidth( "W" ) + INDEXVIEW_SIDE_MARGIN * 2; indexWidth = indexfont.StringWidth("W") + INDEXVIEW_SIDE_MARGIN * 2;
minimumWidth = indexfont.StringWidth( "ギリシャ 100/100" ); minimumWidth = indexfont.StringWidth("ギリシャ 100/100");
frame = Bounds(); frame = Bounds();
frame.left = indexWidth + 2; frame.left = indexWidth + 2;
frame.bottom -= INFOVIEW_HEIGHT; frame.bottom -= INFOVIEW_HEIGHT;
kouhoView = new KouhoView( frame ); kouhoView = new KouhoView(frame);
BRect screenrect = BScreen( this ).Frame(); BRect screenrect = BScreen(this).Frame();
kouhoView->SetTextRect( screenrect ); //big enough kouhoView->SetTextRect(screenrect); //big enough
kouhoView->SetFontAndColor( kouhoFont ); kouhoView->SetFontAndColor(kouhoFont);
kouhoView->SetWordWrap( false ); kouhoView->SetWordWrap(false);
AddChild( kouhoView ); AddChild(kouhoView);
fontHeight = kouhoView->LineHeight(); fontHeight = kouhoView->LineHeight();
frame = Bounds(); frame = Bounds();
frame.right = indexWidth; frame.right = indexWidth;
frame.bottom = frame.bottom - INFOVIEW_HEIGHT + 1; frame.bottom = frame.bottom - INFOVIEW_HEIGHT + 1;
indexView = new KouhoIndexView( frame, fontHeight ); indexView = new KouhoIndexView(frame, fontHeight);
indexView->SetFont( &indexfont ); indexView->SetFont(&indexfont);
AddChild( indexView ); AddChild(indexView);
frame = Bounds(); frame = Bounds();
frame.top = frame.bottom - INFOVIEW_HEIGHT + 1; frame.top = frame.bottom - INFOVIEW_HEIGHT + 1;
infoView = new KouhoInfoView( frame ); infoView = new KouhoInfoView(frame);
infoView->SetFont( &indexfont ); infoView->SetFont(&indexfont);
infoView->SetAlignment( B_ALIGN_RIGHT ); infoView->SetAlignment(B_ALIGN_RIGHT);
AddChild( infoView ); AddChild(infoView);
} }
void KouhoWindow::MessageReceived( BMessage* msg )
void
KouhoWindow::MessageReceived(BMessage* msg)
{ {
float height, width, x, y, w; float height, width, x, y, w;
BPoint point; BPoint point;
BRect screenrect, frame; BRect screenrect, frame;
switch( msg->what ) switch(msg->what) {
{
case KOUHO_WINDOW_HIDE: case KOUHO_WINDOW_HIDE:
#ifdef DEBUG #ifdef DEBUG
SERIAL_PRINT(( "kouhoWindow: KOUHO_WINDOW_HIDE recieved.\n" )); SERIAL_PRINT(("kouhoWindow: KOUHO_WINDOW_HIDE recieved.\n"));
#endif #endif
if ( !IsHidden() ) if (!IsHidden()) {
{
Hide(); Hide();
standalone_mode = false; standalone_mode = false;
} }
@@ -93,7 +94,7 @@ SERIAL_PRINT(( "kouhoWindow: KOUHO_WINDOW_HIDE recieved.\n" ));
case KOUHO_WINDOW_SHOW: case KOUHO_WINDOW_SHOW:
#ifdef DEBUG #ifdef DEBUG
SERIAL_PRINT(( "kouhoWindow: KOUHO_WINDOW_SHOW recieved.\n" )); SERIAL_PRINT(("kouhoWindow: KOUHO_WINDOW_SHOW recieved.\n"));
#endif #endif
ShowWindow(); ShowWindow();
break; break;
@@ -102,90 +103,88 @@ SERIAL_PRINT(( "kouhoWindow: KOUHO_WINDOW_SHOW recieved.\n" ));
standalone_mode = true; standalone_mode = true;
frame = Frame(); frame = Frame();
screenrect = BScreen().Frame(); screenrect = BScreen().Frame();
frame.OffsetTo( gSettings.standalone_loc.x, gSettings.standalone_loc.y ); frame.OffsetTo(gSettings.standalone_loc.x, gSettings.standalone_loc.y);
x = screenrect.right - frame.right; x = screenrect.right - frame.right;
y = screenrect.bottom - frame.bottom; y = screenrect.bottom - frame.bottom;
if ( x < 0 ) if (x < 0)
frame.OffsetBy( x, 0 ); frame.OffsetBy(x, 0);
if ( y < 0 ) if (y < 0)
frame.OffsetBy( 0, y ); frame.OffsetBy(0, y);
gSettings.standalone_loc.x = frame.left; gSettings.standalone_loc.x = frame.left;
gSettings.standalone_loc.y = frame.top; gSettings.standalone_loc.y = frame.top;
point = frame.LeftTop(); point = frame.LeftTop();
MoveTo( point ); MoveTo(point);
ShowWindow(); ShowWindow();
break; break;
case KOUHO_WINDOW_SHOWAT: case KOUHO_WINDOW_SHOWAT:
#ifdef DEBUG #ifdef DEBUG
SERIAL_PRINT(( "kouhoWindow: KOUHO_WINDOW_SHOWAT recieved.\n" )); SERIAL_PRINT(("kouhoWindow: KOUHO_WINDOW_SHOWAT recieved.\n"));
#endif #endif
msg->FindPoint( "position", &point ); msg->FindPoint("position", &point);
msg->FindFloat( "height", &height ); msg->FindFloat("height", &height);
ShowAt( point, height ); ShowAt(point, height);
break; break;
case KOUHO_WINDOW_SETTEXT: case KOUHO_WINDOW_SETTEXT:
const char* newtext; const char* newtext;
bool hideindex, limitsize; bool hideindex, limitsize;
msg->FindString( "text", &newtext ); msg->FindString("text", &newtext);
kouhoView->SetText( newtext ); kouhoView->SetText(newtext);
msg->FindBool( "index", &hideindex ); msg->FindBool("index", &hideindex);
indexView->HideNumberDisplay( hideindex ); indexView->HideNumberDisplay(hideindex);
msg->FindBool( "limit", &limitsize ); msg->FindBool("limit", &limitsize);
height = kouhoView->TextHeight( 0, kouhoView->TextLength() ); height = kouhoView->TextHeight(0, kouhoView->TextLength());
height += INFOVIEW_HEIGHT; height += INFOVIEW_HEIGHT;
msg->FindString( "info", &newtext ); msg->FindString("info", &newtext);
infoView->SetText( newtext ); infoView->SetText(newtext);
// calculate widest line width // calculate widest line width
width = 0; width = 0;
for ( int32 line = 0, numlines = kouhoView->CountLines() ; for (int32 line = 0, numlines = kouhoView->CountLines();
line < numlines ; line++ ) line < numlines; line++) {
{ w = kouhoView->LineWidth(line);
w = kouhoView->LineWidth( line ); if (w > width)
if ( w > width )
width = w; width = w;
} }
if ( limitsize && width < minimumWidth ) if (limitsize && width < minimumWidth)
width = minimumWidth; width = minimumWidth;
ResizeTo( width + indexWidth + KOUHOVIEW_SIDE_MARGIN, height ); ResizeTo(width + indexWidth + KOUHOVIEW_SIDE_MARGIN, height);
if ( msg->HasBool( "partial" ) ) if (msg->HasBool("partial")) {
{
int32 begin, end; int32 begin, end;
msg->FindInt32( "revbegin", &begin ); msg->FindInt32("revbegin", &begin);
msg->FindInt32( "revend", &end ); msg->FindInt32("revend", &end);
kouhoView->HighlightPartial( begin, end ); kouhoView->HighlightPartial(begin, end);
#ifdef DEBUG #ifdef DEBUG
SERIAL_PRINT(( "kouhoWindow: KOUHO_WINDOW_SETTEXT(partial) received. rev = %d to %d\n", begin, end )); SERIAL_PRINT(("kouhoWindow: KOUHO_WINDOW_SETTEXT(partial) received. rev = %d to %d\n", begin, end));
#endif #endif
} } else {
else
{
int32 kouhorevline; int32 kouhorevline;
msg->FindInt32( "kouhorev", &kouhorevline ); msg->FindInt32("kouhorev", &kouhorevline);
kouhoView->HighlightLine( kouhorevline ); kouhoView->HighlightLine(kouhorevline);
} }
break; break;
case NUM_SELECTED_FROM_KOUHO_WIN: case NUM_SELECTED_FROM_KOUHO_WIN:
cannaLooper->PostMessage( msg ); cannaLooper->PostMessage(msg);
break; break;
default: default:
BWindow::MessageReceived( msg ); BWindow::MessageReceived(msg);
} }
} }
void KouhoWindow::ShowAt( BPoint revpoint, float height )
void
KouhoWindow::ShowAt(BPoint revpoint, float height)
{ {
BRect screenrect; BRect screenrect;
BPoint point; BPoint point;
@@ -194,9 +193,9 @@ void KouhoWindow::ShowAt( BPoint revpoint, float height )
kouhowidth = Frame().IntegerWidth(); kouhowidth = Frame().IntegerWidth();
kouhoheight = Frame().IntegerHeight(); kouhoheight = Frame().IntegerHeight();
screenrect = BScreen( this ).Frame(); screenrect = BScreen(this).Frame();
#ifdef DEBUG #ifdef DEBUG
SERIAL_PRINT(( "KouhoWindow: ShowAt activated. point x= %f, y= %f, height= %f", revpoint.x, revpoint.y, height )); SERIAL_PRINT(("KouhoWindow: ShowAt activated. point x= %f, y= %f, height= %f", revpoint.x, revpoint.y, height));
#endif #endif
//adjust to preferred position - considering window border & index //adjust to preferred position - considering window border & index
//revpoint.y += WINDOW_BORDER_WIDTH; //revpoint.y += WINDOW_BORDER_WIDTH;
@@ -204,71 +203,73 @@ SERIAL_PRINT(( "KouhoWindow: ShowAt activated. point x= %f, y= %f, height= %f",
point.x = revpoint.x - indexView->Frame().IntegerWidth() point.x = revpoint.x - indexView->Frame().IntegerWidth()
- INDEXVIEW_SIDE_MARGIN; - INDEXVIEW_SIDE_MARGIN;
if ( point.y + kouhoheight > screenrect.bottom ) if (point.y + kouhoheight > screenrect.bottom)
point.y = revpoint.y - kouhoheight - WINDOW_BORDER_WIDTH_V; point.y = revpoint.y - kouhoheight - WINDOW_BORDER_WIDTH_V;
// else // else
// point.y = revpoint.y + height; // point.y = revpoint.y + height;
if ( point.x + kouhowidth > screenrect.right ) if (point.x + kouhowidth > screenrect.right)
point.x = point.x - (screenrect.right - (point.x + kouhowidth )); point.x = point.x - (screenrect.right - (point.x + kouhowidth));
// point.x = revpoint.x // point.x = revpoint.x
// - ( revpoint.x + kouhowidth + WINDOW_BORDER_WIDTH - screenrect.right ); // - (revpoint.x + kouhowidth + WINDOW_BORDER_WIDTH - screenrect.right);
// else // else
// point.x = revpoint.x; // point.x = revpoint.x;
MoveTo( point ); MoveTo(point);
ShowWindow(); ShowWindow();
} }
void void
KouhoWindow::FrameMoved( BPoint screenPoint ) KouhoWindow::FrameMoved(BPoint screenPoint)
{ {
if ( standalone_mode ) if (standalone_mode)
gSettings.standalone_loc = screenPoint; gSettings.standalone_loc = screenPoint;
return;
} }
// ShowWindow() shows kouho window on current workspace // ShowWindow() shows kouho window on current workspace
// This is a bug fix for version 1.0 beta 2 // This is a bug fix for version 1.0 beta 2
void void
KouhoWindow::ShowWindow() KouhoWindow::ShowWindow()
{ {
if ( IsHidden() ) if (IsHidden()) {
{ SetWorkspaces(B_CURRENT_WORKSPACE);
SetWorkspaces( B_CURRENT_WORKSPACE );
Show(); Show();
} }
} }
/* /*
KouhoView section KouhoView section
*/ */
KouhoView::KouhoView( BRect rect ) KouhoView::KouhoView(BRect rect)
:BTextView( rect, "kouhoview", rect, B_FOLLOW_ALL, B_WILL_DRAW ) : BTextView(rect, "kouhoview", rect, B_FOLLOW_ALL, B_WILL_DRAW)
{ {
selection_color.red = 203; selection_color.red = 203;
selection_color.green = 152; selection_color.green = 152;
selection_color.blue = 255; selection_color.blue = 255;
} }
void KouhoView::HighlightLine( int32 line )
void
KouhoView::HighlightLine(int32 line)
{ {
//printf( "highlightLine set to :%d\n", line); //printf("highlightLine set to :%d\n", line);
int32 begin, end; int32 begin, end;
BRegion region; BRegion region;
if ( line != -1 ) if (line != -1) {
{ begin = OffsetAt(line);
begin = OffsetAt( line ); if (line == CountLines() - 1)
if ( line == CountLines() - 1 )
end = TextLength() + 1; end = TextLength() + 1;
else else
end = OffsetAt( line + 1 ) - 1; end = OffsetAt(line + 1) - 1;
//printf( "Highlight line:%d, offset %d-%d\n", line,begin,end); //printf("Highlight line:%d, offset %d-%d\n", line,begin,end);
GetTextRegion( begin, end, &region ); GetTextRegion(begin, end, &region);
//as hightlight is just one line, 0 is enough. //as hightlight is just one line, 0 is enough.
highlightRect = region.RectAt( 0 ); highlightRect = region.RectAt(0);
//extend highlihght region to right end //extend highlihght region to right end
highlightRect.right = Bounds().right; highlightRect.right = Bounds().right;
Invalidate(); Invalidate();
@@ -276,67 +277,75 @@ void KouhoView::HighlightLine( int32 line )
} }
void void
KouhoView::HighlightPartial( int32 begin, int32 end ) KouhoView::HighlightPartial(int32 begin, int32 end)
{ {
BRegion region; BRegion region;
GetTextRegion( begin, end, &region ); GetTextRegion(begin, end, &region);
highlightRect = region.RectAt( 0 ); highlightRect = region.RectAt(0);
Invalidate( highlightRect ); Invalidate(highlightRect);
} }
void KouhoView::Draw( BRect rect )
void
KouhoView::Draw(BRect rect)
{ {
BTextView::Draw( rect ); BTextView::Draw(rect);
rgb_color viewcolor = ViewColor(); // rgb_color viewcolor = ViewColor();
SetHighColor( selection_color ); SetHighColor(selection_color);
SetDrawingMode( B_OP_MIN ); SetDrawingMode(B_OP_MIN);
FillRect( highlightRect ); FillRect(highlightRect);
// SetViewColor( viewcolor ); // SetViewColor(viewcolor);
} }
void KouhoView::MouseDown( BPoint point )
void
KouhoView::MouseDown(BPoint point)
{ {
KouhoIndexView *iview; KouhoIndexView *iview;
iview = (KouhoIndexView *)(Window()->FindView( "index" )); iview = (KouhoIndexView *)(Window()->FindView("index"));
if ( iview->IsNumberDisplayHidden() ) if (iview->IsNumberDisplayHidden())
return; return;
int32 number; int32 number;
number = LineAt( point ); number = LineAt(point);
BMessage msg( NUM_SELECTED_FROM_KOUHO_WIN ); BMessage msg(NUM_SELECTED_FROM_KOUHO_WIN);
msg.AddInt32( "modifiers", 0 ); msg.AddInt32("modifiers", 0);
msg.AddInt8( "byte", (int8)number + '1' ); msg.AddInt8("byte", (int8)number + '1');
Window()->PostMessage( &msg ); Window()->PostMessage(&msg);
} }
/* /*
KouhoIndexView section KouhoIndexView section
*/ */
KouhoIndexView::KouhoIndexView( BRect frame, float fontheight ) KouhoIndexView::KouhoIndexView(BRect frame, float fontheight)
:BBox( frame, "index", B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, B_WILL_DRAW ) : BBox(frame, "index", B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, B_WILL_DRAW)
{ {
font_height ht; font_height ht;
float indexfontheight; float indexfontheight;
lineHeight = fontheight; lineHeight = fontheight;
be_plain_font->GetHeight( &ht ); be_plain_font->GetHeight(&ht);
indexfontheight = ht.ascent + ht.descent + ht.leading; indexfontheight = ht.ascent + ht.descent + ht.leading;
if ( indexfontheight < lineHeight ) if (indexfontheight < lineHeight)
fontOffset = (int32)((lineHeight - indexfontheight) / 2 + 1.5); fontOffset = (int32)((lineHeight - indexfontheight) / 2 + 1.5);
//printf("line height=%f, index font height=%f, offset=%d\n", lineHeight, indexfontheight, fontOffset ); //printf("line height=%f, index font height=%f, offset=%d\n", lineHeight, indexfontheight, fontOffset);
} }
void KouhoIndexView::Draw( BRect rect )
void
KouhoIndexView::Draw(BRect rect)
{ {
BBox::Draw( rect ); BBox::Draw(rect);
for ( long i = 1; i < 17 ; i++ ) for (long i = 1; i < 17; i++) {
{ MovePenTo(INDEXVIEW_SIDE_MARGIN + 2, lineHeight * i - fontOffset);
MovePenTo( INDEXVIEW_SIDE_MARGIN + 2, lineHeight * i - fontOffset ); if (hideNumber)
if ( hideNumber ) DrawString("");
DrawString( "" );
else else
DrawChar( '0' + i ); DrawChar('0' + i);
} }
} }
@@ -344,19 +353,21 @@ void KouhoIndexView::Draw( BRect rect )
// InfoView section // InfoView section
// //
KouhoInfoView::KouhoInfoView( BRect frame ) KouhoInfoView::KouhoInfoView(BRect frame)
:BStringView( frame, "infoview", "0/0", : BStringView(frame, "infoview", "0/0",
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM ) B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM)
{ {
} }
void void
KouhoInfoView::Draw( BRect rect ) KouhoInfoView::Draw(BRect rect)
{ {
BPoint start, end; BPoint start, end;
BRect bounds = Bounds(); BRect bounds = Bounds();
start = B_ORIGIN; start = B_ORIGIN;
end.Set( bounds.right, 0 ); end.Set(bounds.right, 0);
StrokeLine( start, end ); StrokeLine(start, end);
BStringView::Draw( rect ); BStringView::Draw(rect);
} }