void AboutView::MessageReceived(BMessage* msg) { switch (msg->what) { case SCROLL_CREDITS_VIEW: { BScrollBar* scrollBar = fCreditsView->ScrollBar(B_VERTICAL); if (scrollBar == NULL) break; float max, min; scrollBar->GetRange(&min, &max); if (scrollBar->Value() < max) fCreditsView->ScrollBy(0, 1); break; } case 'eegg': { printf("Easter egg\n"); PickRandomHaiku(); break; } default: BView::MessageReceived(msg); break; } }
void ChatWindow::FrameResized( float width, float height ) { BWindow::FrameResized( width, height ); BRect r = iChat->Bounds(); r.InsetBy( 10, 10 ); iChat->SetTextRect( r ); BScrollBar *scrollBar = iScrollView->ScrollBar( B_VERTICAL ); if( scrollBar->LockLooper() ) { float min, max; scrollBar->GetRange( &min, &max ); scrollBar->SetValue( max ); scrollBar->UnlockLooper(); } }
void _UpdateScrollBarVisibility() { BScrollBar* verticalBar = ScrollBar(B_VERTICAL); if (verticalBar != NULL) { float min; float max; verticalBar->GetRange(&min, &max); if (min == max) { if (!verticalBar->IsHidden(verticalBar)) verticalBar->Hide(); } else { if (verticalBar->IsHidden(verticalBar)) verticalBar->Show(); } } }
void WrappingTextView::KeyDown(const char *bytes, int32 numBytes) { if (IsEditable() && numBytes==1) { m_last_key_was_del = (bytes[0]==B_DELETE); switch( bytes[0]) { case B_RIGHT_ARROW: { // implement word-wise movement: int32 mods = Window()->CurrentMessage()->FindInt32("modifiers"); if (mods & (B_LEFT_CONTROL_KEY | B_RIGHT_OPTION_KEY)) { int32 len=TextLength(); int32 startPos, endPos; GetSelection( &startPos, &endPos); if (endPos==len) break; if (startPos==endPos && (mods & B_SHIFT_KEY)) m_selection_start=B_RIGHT_ARROW; int32 wordStart, wordEnd; if (mods & B_SHIFT_KEY && m_selection_start==B_LEFT_ARROW) { do { FindWord( startPos, &wordStart, &wordEnd); if (wordEnd > wordStart+1) break; if (wordEnd == wordStart+1 && ByteAt( wordStart)!=' ') break; } while( ++startPos < len); Select( MIN(endPos, wordEnd), endPos); } else { do { FindWord( endPos, &wordStart, &wordEnd); if (wordEnd > wordStart+1) break; if (wordEnd == wordStart+1 && ByteAt( wordStart)!=' ') break; } while( ++endPos < len); if (mods & B_SHIFT_KEY) { Select( startPos, wordEnd); } else Select( wordEnd, wordEnd); } ScrollToSelection(); } else inherited::KeyDown( bytes, numBytes); break; } case B_LEFT_ARROW: { // implement word-wise movement: int32 mods = Window()->CurrentMessage()->FindInt32("modifiers"); if (mods & (B_LEFT_CONTROL_KEY | B_RIGHT_OPTION_KEY)) { int32 startPos, endPos; GetSelection( &startPos, &endPos); if (!startPos) break; if (startPos==endPos && (mods & B_SHIFT_KEY)) m_selection_start=B_LEFT_ARROW; int32 wordStart, wordEnd; if (mods & B_SHIFT_KEY && m_selection_start==B_RIGHT_ARROW) { --endPos; do { FindWord( endPos, &wordStart, &wordEnd); if (wordEnd > wordStart+1) break; if (wordEnd == wordStart+1 && ByteAt( wordStart)!=' ') break; } while( --endPos > 0); Select( startPos, MAX( startPos, wordStart)); } else { --startPos; do { FindWord( startPos, &wordStart, &wordEnd); if (wordEnd > wordStart+1) break; if (wordEnd == wordStart+1 && ByteAt( wordStart)!=' ') break; } while( --startPos > 0); if (mods & B_SHIFT_KEY) Select( wordStart, endPos); else Select( wordStart, wordStart); } ScrollToSelection(); } else inherited::KeyDown( bytes, numBytes); break; } default: inherited::KeyDown( bytes, numBytes); break; } } else if ( numBytes == 1 ) { // in read-only mode, we use cursor-keys to move scrollbar, and // we remap HOME / END to the vertical scrollbar (not the horizontal, // which is default). switch( bytes[0]) { case B_PAGE_UP: case B_PAGE_DOWN: case B_UP_ARROW: case B_DOWN_ARROW: case B_HOME: case B_END: { // move vertical scrollbar: float min, max, smallStep, bigStep, value; BScrollBar* bar = ScrollBar( B_VERTICAL); if (!bar) return; bar->GetRange( &min, &max); bar->GetSteps( &smallStep, &bigStep); value = bar->Value(); if (bytes[0] == B_UP_ARROW) { value = MAX( value-smallStep, min); } else if (bytes[0] == B_DOWN_ARROW) { value = MIN( value+smallStep, max); } else if (bytes[0] == B_PAGE_UP) { value = MAX( value-bigStep, min); } else if (bytes[0] == B_PAGE_DOWN) { value = MIN( value+bigStep, max); } else if (bytes[0] == B_HOME) { value = min; } else if (bytes[0] == B_END) { value = max; } bar->SetValue( value); break; } default: BTextView::KeyDown( bytes, numBytes); break; } } else inherited::KeyDown( bytes, numBytes); }
void ChatWindow::MessageReceived( BMessage* aMessage ) { switch( aMessage->what ) { case SHOW_MESSAGE: { const char *msg; aMessage->FindString( "msg", &msg ); time_t _now = time( NULL ); struct tm *now = localtime( &_now ); BString *str = NULL; BString *str2 = NULL; char *string = NULL; Person *person = NULL; for( int i = 0; i < iWindow->GetProfile()->GetUserlist()->GetList()->CountItems(); i++ ) { person = ( Person* ) iWindow->GetProfile()->GetUserlist()->GetList()->ItemAt( i ); if( iWho == person->GetUIN() ) { str = new BString(); str->SetTo( person->GetDisplay() ); break; } } if( !str ) { str = new BString(); *str << ( int32 ) iWho; } BFont *font = new BFont( be_plain_font ); font->SetSize( 16.0 ); font->SetEncoding( B_ISO_8859_2 ); rgb_color yellow = { 255, 255, 0, 0 }; rgb_color red = { 255, 0, 0, 0 }; rgb_color white = { 255, 255, 255, 0 }; string = ( char* ) calloc( strlen( "[00:00] " ), 1 ); sprintf( string, "[%02d:%02d] ", now->tm_hour, now->tm_min); str2 = new BString(); str2->SetTo( string ); free( string ); iChat->SetFontAndColor( iChat->TextLength(), iChat->TextLength() + str2->Length(), font, B_FONT_ALL, &yellow ); iChat->Insert( iChat->TextLength(), str2->String(), str2->Length() ); str->Append( ": " ); iChat->SetFontAndColor( iChat->TextLength(), iChat->TextLength() + str->Length(), font, B_FONT_ALL, &red ); iChat->Insert( iChat->TextLength(), str->String(), str->Length() ); str2->SetTo( msg ); str2->Append( "\n" ); iChat->SetFontAndColor( iChat->TextLength(), iChat->TextLength() + str2->Length(), font, B_FONT_ALL, &white ); iChat->Insert( iChat->TextLength(), str2->String(), str2->Length() ); BScrollBar * scrollBar = iScrollView->ScrollBar( B_VERTICAL ); if( scrollBar->LockLooper() ) { float max,min; scrollBar->GetRange( &min, &max ); scrollBar->SetValue( max ); scrollBar->UnlockLooper(); } delete str; delete str2; break; } case BEGG_SEND: { if( iSayControl->LockLooper()) { if( !(*iSayControl->Text() ) ) { /* nothing to send */ iSayControl->UnlockLooper(); break; } /* first we add message into chat window */ time_t _now = time( NULL ); struct tm * now = localtime( &_now ); BString str; BString str2; char *string; // int id = iNetwork->GetIdent(); BFont *font = new BFont( be_plain_font ); font->SetSize( 16.0 ); font->SetEncoding( B_ISO_8859_2 ); rgb_color yellow = { 255, 255, 0, 0 }; rgb_color green = { 0, 255, 0, 0 }; rgb_color white = { 255, 255, 255, 0 }; string = ( char* ) calloc( strlen( "[00:00] " ), 1 ); sprintf( string, "[%02d:%02d] ", now->tm_hour, now->tm_min ); str2.SetTo( string ); free( string ); iChat->SetFontAndColor( iChat->TextLength(), iChat->TextLength() + str2.Length(), font, B_FONT_ALL, &yellow ); iChat->Insert( iChat->TextLength(), str2.String(), str2.Length() ); str.SetTo( iWindow->GetProfile()->GetProfileName() ); str.Append( ": " ); iChat->SetFontAndColor( iChat->TextLength(), iChat->TextLength() + str.Length(), font, B_FONT_ALL, &green ); iChat->Insert( iChat->TextLength(), str.String(), str.Length() ); str2.SetTo( iSayControl->Text() ); str2.Append( "\n" ); iChat->SetFontAndColor( iChat->TextLength(), iChat->TextLength() + str2.Length(), font, B_FONT_ALL, &white ); iChat->Insert( iChat->TextLength(), str2.String(), str2.Length() ); /* scroll down */ BScrollBar * scrollBar = iScrollView->ScrollBar( B_VERTICAL ); if( scrollBar->LockLooper() ) { float max,min; scrollBar->GetRange( &min, &max ); scrollBar->SetValue( max ); scrollBar->UnlockLooper(); } /* sending... */ BMessage *newmessage; newmessage = new BMessage( SEND_MESSAGE ); newmessage->AddInt32( "who", iWho ); newmessage->AddString( "msg", iSayControl->Text()); BMessenger( iNetwork ).SendMessage( newmessage ); delete newmessage; /* clearing edit box */ iSayControl->SetText( NULL ); iSayControl->UnlockLooper(); } break; } default: BWindow::MessageReceived( aMessage ); break; } }