/*=============================================================================================*\ | Expand | +-----------------------------------------------------------------------------------------------+ | Effet: Reduire la view, la fenetre mere et deplacer les autre view si necessaire. | \*=============================================================================================*/ void ShrinkView::Expand() { BView * pTempView; //Utiliser pour parcourir les View attacher a la meme fenetre mere. //Agradir la View. ResizeTo(Frame().Width(), m_fFullHeight); m_bShrink = false; //Redimentionner la fenetre mere if( Window() != NULL ) { Window()->ResizeBy(0, m_fFullHeight - 15.0 ); } //Deplacer, si necessaire, les autre View. pTempView = this; while( pTempView->PreviousSibling() != NULL) { pTempView = pTempView->PreviousSibling(); } while(pTempView != NULL) { if(Frame().top + 16.0 <= pTempView->Frame().top ) { pTempView->MoveBy(0, m_fFullHeight - 15.0); } pTempView = pTempView->NextSibling(); } Draw(Bounds()); }//End of Expand.
void CollapsableBox::SetValue(int32 new_value) { if (new_value != Value()) { BRect r = Bounds(); if (!new_value) ResizeTo(r.Width(), m_collapsed_rect.Height()); else ResizeTo(r.Width(), m_expanded_rect.Height()); BView *child; child = ChildAt(0); while (child) { if (new_value) child->Show(); else child->Hide(); child = child->NextSibling(); }; Invalidate(); BControl::SetValue(new_value); Invoke(); }; }
ArpKnobControl* ArpKnobPanel::KnobControl() const { BView* view; for( view = ChildAt(0); view; view = view->NextSibling() ) { ArpKnobControl* knob = dynamic_cast<ArpKnobControl*>( view ); if( knob ) return knob; } return 0; }
/* This is a hack necessary because sometimes this view gets bogus FrameResize() * messages. Not sure what's happening exactly, but fairly frequently I receive * a correct FrameResized() view followed by one that reports the Window()'s frame * to be 140 pixels shorter then the immediately preceding call. Checking the * frame of the child views seems to bypass the bug. */ static float furthest_right(BWindow* window) { float right = 0; for (BView* child = window->ChildAt(0); child; child = child->NextSibling() ) { BRect f = child->Frame(); if (f.right > right) right = f.right; } return right; }
void BRadioButton::SetValue(int32 value) { if (value != Value()) { BControl::SetValueNoUpdate(value); Invalidate(_KnobFrame()); } if (value == 0) return; BView* parent = Parent(); BView* child = NULL; if (parent != NULL) { // If the parent is a BBox, the group parent is the parent of the BBox BBox* box = dynamic_cast<BBox*>(parent); if (box != NULL && box->LabelView() == this) parent = box->Parent(); if (parent != NULL) { BBox* box = dynamic_cast<BBox*>(parent); // If the parent is a BBox, skip the label if there is one if (box != NULL && box->LabelView()) child = parent->ChildAt(1); else child = parent->ChildAt(0); } else child = Window()->ChildAt(0); } else if (Window() != NULL) child = Window()->ChildAt(0); while (child != NULL) { BRadioButton* radio = dynamic_cast<BRadioButton*>(child); if (radio != NULL && (radio != this)) radio->SetValue(B_CONTROL_OFF); else { // If the child is a BBox, check if the label is a radiobutton BBox* box = dynamic_cast<BBox*>(child); if (box != NULL && box->LabelView()) { radio = dynamic_cast<BRadioButton*>(box->LabelView()); if (radio != NULL && (radio != this)) radio->SetValue(B_CONTROL_OFF); } } child = child->NextSibling(); } ASSERT(Value() == B_CONTROL_ON); }
void ArpKnobPanel::GetPreferredSize(float* width, float* height) { float w = 0, h = 0; BView* view; for( view = ChildAt(0); view != 0; view = view->NextSibling() ) { BRect b = view->Frame(); if( b.right > w ) w = b.right; if( b.bottom > h ) h = b.bottom; } *width = w; *height = h; }
void BPrintJob::_RecurseView(BView* view, BPoint origin, BPicture* picture, BRect rect) { ASSERT(picture != NULL); BRegion region; region.Set(BRect(rect.left, rect.top, rect.right, rect.bottom)); view->fState->print_rect = rect; view->AppendToPicture(picture); view->PushState(); view->SetOrigin(origin); view->ConstrainClippingRegion(®ion); if (view->ViewColor() != B_TRANSPARENT_COLOR) { rgb_color highColor = view->HighColor(); view->SetHighColor(view->ViewColor()); view->FillRect(rect); view->SetHighColor(highColor); } view->fIsPrinting = true; view->Draw(rect); view->fIsPrinting = false; view->PopState(); view->EndPicture(); BView* child = view->ChildAt(0); while (child != NULL) { if ((child->Flags() & B_WILL_DRAW) && !child->IsHidden()) { BPoint leftTop(view->Bounds().LeftTop() + child->Frame().LeftTop()); BRect printRect(rect.OffsetToCopy(rect.LeftTop() - leftTop) & child->Bounds()); if (printRect.IsValid()) _RecurseView(child, origin + leftTop, picture, printRect); } child = child->NextSibling(); } if ((view->Flags() & B_DRAW_ON_CHILDREN) != 0) { view->AppendToPicture(picture); view->PushState(); view->SetOrigin(origin); view->ConstrainClippingRegion(®ion); view->fIsPrinting = true; view->DrawAfterChildren(rect); view->fIsPrinting = false; view->PopState(); view->EndPicture(); } }
void TMediaTabView::DeactivateView(EChildID which) { // Take away the control buttons BView* view = ChildAt(which); BView* b = view->ChildAt(0); while (b) { BView* next = b->NextSibling(); if (dynamic_cast<TRadioBitmapButton*>(b) != 0) view->RemoveChild(b); b = next; } // Make sure the view is invisible if (!view->IsHidden()) view->Hide(); }
// Recursively set the resizing mode of a view and its children void OutputFormatView::RecursiveSetMode(BView *view) { // Set the parent view itself view->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); // Now set all its children BView *child; if ((child = view->ChildAt(0)) != 0) { while (child) { RecursiveSetMode(child); child = child->NextSibling(); } } }
void NavigatorEditor::ValueChanged() { TRACE(); BView *child = NULL; NodeListView *nodeListView = NULL; MessageListView *messageListView = NULL; root->ValueChanged(); if ( child = ChildAt(1) ) { while ( child ) { messageListView = dynamic_cast<MessageListView *>(((BScrollView *)child)->Target()); if (messageListView) messageListView->ValueChanged(); child = child->NextSibling(); } } }
void BRadioButton::SetValue(int32 value) { if (value != Value()) { BControl::SetValueNoUpdate(value); Invalidate(); if (value == B_CONTROL_ON) { for (BView *sibling = NextSibling(); sibling != NULL; sibling = sibling->NextSibling()) { BRadioButton *rbtn = cast_as(sibling, BRadioButton); if (rbtn != NULL) rbtn->SetValue(B_CONTROL_OFF); } for (BView *sibling = PreviousSibling(); sibling != NULL; sibling = sibling->PreviousSibling()) { BRadioButton *rbtn = cast_as(sibling, BRadioButton); if (rbtn != NULL) rbtn->SetValue(B_CONTROL_OFF); } } } }
/*************************************************************************** * ARP-KNOB-PANEL * This class constructs a knob along with an optional label and/or int * control. Part of its usefulness is that it hides hooking up the knob * and int controls to each other, which is behaviour that will probably * change at some point. ***************************************************************************/ ArpKnobPanel::ArpKnobPanel( const char* name, const char* label, BMessage* message, int32 minValue, int32 maxValue, bool showIntControl, orientation layout, uint32 knobFlags, float labelWidth, float intControlWidth, uint32 rmask, uint32 flags) : inherited( BRect( 0, 0, 0, 0 ), "knob_panel", rmask, flags ) { if( layout == B_VERTICAL ) LayoutVertical(name, label, message, minValue, maxValue, showIntControl, knobFlags, labelWidth, intControlWidth); else LayoutHorizontal(name, label, message, minValue, maxValue, showIntControl, knobFlags, labelWidth, intControlWidth); float width = 0, height = 0; BView* view; for( view = ChildAt(0); view; view = view->NextSibling() ) { BRect f = view->Frame(); if( f.right > width ) width = f.right; if( f.bottom > height ) height = f.bottom; } ResizeTo( width, height ); }
/************************************************************************* * SEQ-PHRASE-PROPERTY-WINDOW *************************************************************************/ SeqPhrasePropertyWindow::SeqPhrasePropertyWindow( AmSongRef songRef, AmPhraseEvent* event, const BMessage* config) : inherited(BRect(0, 0, 0, 0), "Phrase Properties", B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS), mSongRef(songRef), mEvent(NULL), mBg(NULL), mNameCtrl(NULL), mTimeLabel(NULL), mTimeCtrl(NULL), mColorField(NULL), mColorCtrl(NULL) { AddViews(BRect(0, 0, 50, 50)); float w = 0, h = 0; /* Set my dimensions. */ if (mBg) { for (BView* view = mBg->ChildAt(0); view; view = view->NextSibling() ) { BRect f = view->Frame(); if (f.right > w) w = f.right; if (f.bottom > h) h = f.bottom; } ResizeTo(w + Prefs().Size(BORDER_X), h + Prefs().Size(BORDER_Y)); } /* Set my location. */ BScreen s(this); if (s.IsValid() ) { BRect sf = s.Frame(); float newX = 10, newY = 10; if (w < sf.Width() ) newX = (sf.Width() - w) / 2; if (h < sf.Height() ) newY = (sf.Height() - h) / 2; MoveTo(newX, newY); } if (config) SetConfiguration(config); if (event) SetPhraseEvent(event); }
void ArpKnobPanel::LayoutVertical( const char* name, const char* label, BMessage* message, int32 minValue, int32 maxValue, bool showIntControl, uint32 knobFlags, float labelWidth, float intControlWidth) { const BFont* font = be_plain_font; float fh = arp_get_font_height(font); float spaceY = 3; float top = 0; float widest = 0; // Cache the widest view just to save ourselves an // extra iteration over the views /* Add label */ BStringView* sv = 0; if( label ) { float w = (labelWidth >= 0) ? labelWidth : font->StringWidth( label ); sv = new BStringView( BRect( 0, top, 0 + w, top + fh ), "label", label ); if( sv ) { AddChild( sv ); if( w > widest ) widest = w; } top += fh + spaceY; } /* Add knob */ float knobW, knobH; if( knobFlags&ARP_RING_ADORNMENT ) { knobW = Prefs().Size(KNOB_RING_X); knobH = Prefs().Size(KNOB_RING_Y); } else if( knobFlags&ARP_TIGHT_RING_ADORNMENT ) { knobW = Prefs().Size(KNOB_RING_TIGHT_X); knobH = Prefs().Size(KNOB_RING_TIGHT_Y); } else { knobW = Prefs().Size(KNOB_X); knobH = Prefs().Size(KNOB_Y); } ArpKnobControl* knob = new ArpKnobControl( BRect(0, top, knobW, top + knobH ), name, message, minValue, maxValue, knobFlags); if( knob ) { AddChild( knob ); if( knobW > widest ) widest = knobW; top += knobH + spaceY; } /* Add int control */ ArpIntControl* intCtrl = 0; if( showIntControl ) { float w = (intControlWidth >= 0) ? intControlWidth : knobW; intCtrl = new ArpIntControl( BRect(0, top, w, top + Prefs().Size(INT_CTRL_Y) ), "int_control", 0, 0); if( intCtrl ) { intCtrl->SetLimits( minValue, maxValue ); if( knob ) knob->SetIntControl( intCtrl ); AddChild( intCtrl ); if( w > widest ) widest = w; } } /* Now center everything based on the widest view. */ if( !sv && !intCtrl ) return; if( widest <= 0 ) return; BView* view; for( view = ChildAt(0); view; view = view->NextSibling() ) { BRect f = view->Frame(); if( f.Width() < widest ) view->MoveTo( (widest - f.Width()) / 2, f.top ); } }
void ArpKnobPanel::LayoutHorizontal(const char* name, const char* label, BMessage* message, int32 minValue, int32 maxValue, bool showIntControl, uint32 knobFlags, float labelWidth, float intControlWidth) { const BFont* font = be_plain_font; float fh = arp_get_font_height(font); float spaceX = 8; float left = 0; /* Add label */ BStringView* sv = 0; if( label ) { float w = (labelWidth >= 0) ? labelWidth : font->StringWidth( label ); sv = new BStringView( BRect( left, 0, left + w, 0 + fh ), "label", label ); if( sv ) AddChild( sv ); left += w + spaceX; } /* Add knob */ float knobW, knobH; if( knobFlags&ARP_RING_ADORNMENT ) { knobW = Prefs().Size(KNOB_RING_X); knobH = Prefs().Size(KNOB_RING_Y); } else if( knobFlags&ARP_TIGHT_RING_ADORNMENT ) { knobW = Prefs().Size(KNOB_RING_TIGHT_X); knobH = Prefs().Size(KNOB_RING_TIGHT_Y); } else { knobW = Prefs().Size(KNOB_X); knobH = Prefs().Size(KNOB_Y); } ArpKnobControl* knob = new ArpKnobControl( BRect(left, 0, left + knobW, 0 + knobH ), name, message, minValue, maxValue, knobFlags); if( knob ) { AddChild( knob ); left += knobW + spaceX; } /* Add int control */ ArpIntControl* intCtrl = 0; if( showIntControl ) { float w = (intControlWidth >= 0) ? intControlWidth : knobW; intCtrl = new ArpIntControl( BRect(left, 0, left + w, 0 + Prefs().Size(INT_CTRL_Y) ), "int_control", 0, 0); if( intCtrl ) { intCtrl->SetLimits( minValue, maxValue ); if( knob ) knob->SetIntControl( intCtrl ); AddChild( intCtrl ); } } /* Now center everything based on the tallest view. */ if( !sv && !intCtrl ) return; float tallest = (knobH > fh) ? knobH : fh; BView* view; for( view = ChildAt(0); view; view = view->NextSibling() ) { BRect f = view->Frame(); if( f.Height() < tallest ) view->MoveTo( f.left, (tallest - f.Height()) / 2 ); } }
// -------------------------------------------------------------- void ControlsWindow::MessageReceived ( BMessage * msg ) { switch (msg->what) { case SET_DEVICE_MSG: { ssize_t data_size; SANE_Status status; const SANE_Device * device_info; if ( msg->FindData("device", B_RAW_TYPE, (const void **) &device_info, &data_size) != B_OK ) break; m_device_info = device_info; if ( m_device ) sane_close(m_device); m_device = NULL; ScannerOptionView * option; BView * child; child = m_panel->ChildAt(0); while ( child ) { option = dynamic_cast<ScannerOptionView *>(child); if ( option ) option->RemoveSelf(); child = child->NextSibling(); }; status = sane_open(m_device_info->name, &m_device); if ( status != SANE_STATUS_GOOD ) { fprintf (stderr, "sane_open: %s\n", sane_strstatus (status)); BAlert * alert = new BAlert("sane_open", sane_strstatus(status), "Argh"); alert->Go(); break; }; const SANE_Option_Descriptor * desc; // m_options_lv->MakeEmpty(); printf("Options for device %s:\n", m_device_info->name); int opt = 1; // skip first option (option 0 = number of options) BRect r = m_panel->Bounds(); r.top = 80; r.InsetBy(8, 8); while ( (desc = sane_get_option_descriptor(m_device, opt)) != NULL ) { if (desc->type != SANE_TYPE_GROUP) { ScannerOptionView * ov = new ScannerOptionView(r, desc->name, B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT, 0, m_device, opt); if ( ov->Build() == B_OK ) { m_panel->AddChild(ov); r.top += ov->Bounds().Height(); m_tooltip->SetText(ov, desc->desc); } else delete ov; }; BString label; if (desc->type == SANE_TYPE_GROUP) label << "-- "; label << desc->title; if (desc->type == SANE_TYPE_GROUP) label << " --"; printf(" %d: name = %s\n" " title = %s\n" " desc = %s\n" " type = %d\n" " unit = %s\n" " size = %d\n" " cap = 0x%0x\n", opt, desc->name, desc->title, desc->desc, desc->type, get_unit2(desc->unit), desc->size, desc->cap); // m_options_lv->AddItem(new BStringItem(label.String())); opt++; }; BMessage * msg; msg = new BMessage(MainWindow::DEVICE_CHANGED_MSG); msg->AddString("device_name", m_device_info->name); m_parent_window->PostMessage(msg); delete msg; break; }; case SCAN_MSG: { SANE_Handle device; device = Device(); if ( ! device ) break; if ( m_scan_thread_id != -1 ) { // already launched... m_cancel_scan = true; break; }; m_cancel_scan = false; m_scan_thread_id = spawn_thread(_ScanThread, "scan", B_NORMAL_PRIORITY, this); resume_thread(m_scan_thread_id); break; }; default: inherited::MessageReceived(msg); } }