filter_result AutoTextControlFilter::Filter(BMessage* msg, BHandler** target) { int32 rawchar, mod; msg->FindInt32("raw_char", &rawchar); msg->FindInt32("modifiers", &mod); BView* view = dynamic_cast<BView*>(*target); if (view != NULL || view->Name() != NULL && strcmp("_input_", view->Name())) return B_DISPATCH_MESSAGE; AutoTextControl* text = dynamic_cast<AutoTextControl*>(view->Parent()); if (!text || text != fBox) return B_DISPATCH_MESSAGE; fCurrentMessage = msg; filter_result result = KeyFilter(rawchar, mod); fCurrentMessage = NULL; if (fBox->fCharLimit && result == B_DISPATCH_MESSAGE) { // See to it that we still allow shortcut keys if (mod & B_COMMAND_KEY) return B_DISPATCH_MESSAGE; // We don't use strlen() because it is not UTF-8 aware, which can // affect how many characters can be typed. if (isprint(rawchar) && (uint32)BString(text->Text()).CountChars() == text->fCharLimit) return B_SKIP_MESSAGE; } return result; }
// Buttons are enabled or not depending on the selection in the list // so each time you click in the list, this method is called to update the buttons void NetListView::SelectionChanged(void) { int32 index = CurrentSelection(); BView *parent = Parent(); if (index >= 0) { // There are 2 lists that are instances of this class, so we have to see in which list you are clicking if (strcmp(parent->Name(),"Interfaces_Scroller") == 0) { BButton *settings = dynamic_cast <BButton *> ((parent->Parent())->FindView("Settings")); BButton *clear = dynamic_cast <BButton *> ((parent->Parent())->FindView("Clear")); settings->SetEnabled(true); clear->SetEnabled(true); } else if (strcmp(parent->Name(),"Configurations_Scroller") == 0) { BButton *restore = dynamic_cast <BButton *> ((parent->Parent())->FindView("Restore")); BButton *remove = dynamic_cast <BButton *> ((parent->Parent())->FindView("Delete")); restore ->SetEnabled(true); remove ->SetEnabled(true); } } else { // There are 2 lists that are instances of this class, so we have to see in which list you are clicking if (strcmp(parent->Name(),"Interfaces_Scroller") == 0) { BButton *settings=dynamic_cast <BButton *> ((parent->Parent())->FindView("Settings")); BButton *clear=dynamic_cast <BButton *> ((parent->Parent())->FindView("Clear")); settings->SetEnabled(false); clear->SetEnabled(false); } else if (strcmp(parent->Name(),"Configurations_Scroller") == 0) { BButton *restore=dynamic_cast <BButton *> ((parent->Parent())->FindView("Restore")); BButton *remove=dynamic_cast <BButton *> ((parent->Parent())->FindView("Delete")); restore->SetEnabled(false); remove->SetEnabled(false); } } }
BView* TReplicantTray::ViewAt(int32* index, int32* id, const char* name) { *index = -1; *id = -1; BView* view; int32 count = fShelf->CountReplicants()-1; for (int32 repIndex = count ; repIndex >= 0 ; repIndex--) { fShelf->ReplicantAt(repIndex, &view, (uint32*)id); if (view && view->Name() && strcmp(name, view->Name()) == 0) { *index = repIndex; return view; } } return NULL; }
bool AppView::HasAddonView(const char *name) { int32 count = m_pick_list_view->CountViews(); for (; count > 0;) { BView *v = m_pick_list_view->ViewAt(--count); if (!strcmp(v->Name(), name)) return true; } return false; }
status_t TReplicantTray::ItemInfo(int32 index, const char** name, int32* id) { if (index < 0) return B_ERROR; BView* view; fShelf->ReplicantAt(index, &view, (uint32*)id, NULL); if (view) { *name = view->Name(); return B_OK; } return B_ERROR; }
status_t TReplicantTray::ItemInfo(int32 id, const char** name) { if (id < 0) return B_ERROR; int32 index, temp; BView* view = ViewAt(&index, &temp, id, false); if (view) { *name = view->Name(); return B_OK; } return B_ERROR; }
void MixerView::ArrangeChildren() { BRect f1 = channelSelector->Frame(); for (short i=0; i<back->CountChildren(); i++) { BView *v = back->ChildAt(i); if (strcmp(v->Name(), "schedulable") == 0) { v->MoveTo(f1.left,f1.bottom+1); f1 = v->Frame(); } } lastPanelBottom = f1.bottom; BRect f0 = back->Bounds(); float x = lastPanelBottom-(f0.bottom-f0.top); if (x < 0) x = 0; verticalScroll->SetRange(0,x); }
void ArpConfigurePanel::GetPreferredSize(float* width, float* height) { float maxw=0, maxh=0; size_t i; // Get dimensions of all configuration views. for( i=0; i<mConfigViews->size(); i++ ) { BView* view = 0; if( (view=mConfigViews->at(i)) != 0 ) { ArpD(cdb << ADH << "Processing dimens for view #" << i << ", name=" << view->Name() << endl); float vwidth=0, vheight=0; // If this view is not attached to the window (i.e., it // is not currently displayed by the tab view), then it // may not be able to report correct dimensions. To fix // this, we temporarily add it to your view. if( !view->Window() ) { ArpD(cdb << ADH << "Temporarily attaching view to window." << endl); bool hidden = view->IsHidden(); view->Hide(); AddChild(view); view->GetPreferredSize(&vwidth, &vheight); RemoveChild(view); if( !hidden ) view->Show(); } else { view->GetPreferredSize(&vwidth, &vheight); } ArpD(cdb << ADH << "Preferred width=" << vwidth << ", height=" << vheight << endl); if( vwidth > maxw ) maxw = vwidth; if( vheight > maxh ) maxh = vheight; } } ArpD(cdb << ADH << "Final size=(" << (maxw+mTabWidth) << ", " << (maxh+mTabHeight) << ")" << endl); if( width ) *width = maxw + mTabWidth + 2; if( height ) *height = maxh + mTabHeight + 2; }
void BF_GUI_SetupDialog::MessageReceived(BMessage* po_Message) { switch(po_Message->what){ case BF_MSG_MAINVIEW_MAINSETUP_STYLES_UPDATED:{ EnableDialog(true); poMenu->MakeFocus(); // int32 iMenuRes=-1; if(B_OK==po_Message->FindInt32("menu",&iMenuRes)) oSetup.SetMainStyle(iSetupMainStyle); // break;} case BF_MSG_MAINVIEW_MAINSETUP_0:{ EnableDialog(true); poMenu->MakeFocus(); break;} case BF_MSG_DIALOG_PRESSED_OK:{ BView *po; const char *pc; ASSERT(B_OK==po_Message->FindPointer("bf_DlgView_Focus",(void**)&po),"BF_GUI_SetupDialog::MessageReceived"); pc = po->Name(); if(strcmp(pc,"main_menu")==0){ InvokeMenu(-1,poMenu->iNavCursorIndex); }else{ // poSysSetup->UpdateFrom(oSetup); if(poSysSetup->MainStyle() & BF_SETUP_AUTOSAVE) poSysSetup->Save(); // BF_GUI_Dialog::MessageReceived(po_Message); // BMessenger oMessenger(poWin); BMessage oMessage(BF_MSG_SETUP_UPDATED); oMessenger.SendMessage(&oMessage); } break;} default: BF_GUI_Dialog::MessageReceived(po_Message); }; }
static int cdactivate(cdCtxCanvas *ctxcanvas) { BView* view = ctxcanvas->view; BLooper* looper = view->Looper(); const char* ln = ""; if (looper != NULL) { ln = looper->Name(); } printf("CD Activate view %p (%s), looper is %s\n", view, view->Name(), ln); BRect rect = view->Bounds(); ctxcanvas->canvas->w = (int)(rect.Width()); ctxcanvas->canvas->h = (int)(rect.Height()); ctxcanvas->canvas->w_mm = ((double)ctxcanvas->canvas->w) / ctxcanvas->canvas->xres; ctxcanvas->canvas->h_mm = ((double)ctxcanvas->canvas->h) / ctxcanvas->canvas->yres; if (ctxcanvas->canvas->use_matrix) ctxcanvas->canvas->cxTransform(ctxcanvas, ctxcanvas->canvas->matrix); return CD_OK; }
/*! The add-ons must support the exported C function API if they do, they will be loaded and added to deskbar primary function is the Instantiate function */ status_t TReplicantTray::LoadAddOn(BEntry* entry, int32* id, bool addToSettings) { if (!entry) return B_ERROR; node_ref nodeRef; entry->GetNodeRef(&nodeRef); // no duplicates if (NodeExists(nodeRef)) return B_ERROR; BNode node(entry); BPath path; status_t status = entry->GetPath(&path); if (status < B_OK) return status; // load the add-on image_id image = load_add_on(path.Path()); if (image < B_OK) return image; // get the view loading function symbol // we first look for a symbol that takes an image_id // and entry_ref pointer, if not found, go with normal // instantiate function BView* (*entryFunction)(image_id, const entry_ref*); BView* (*itemFunction)(void); BView* view = NULL; entry_ref ref; entry->GetRef(&ref); if (get_image_symbol(image, kInstantiateEntryCFunctionName, B_SYMBOL_TYPE_TEXT, (void**)&entryFunction) >= B_OK) { view = (*entryFunction)(image, &ref); } else if (get_image_symbol(image, kInstantiateItemCFunctionName, B_SYMBOL_TYPE_TEXT, (void**)&itemFunction) >= B_OK) { view = (*itemFunction)(); } else { unload_add_on(image); return B_ERROR; } if (view == NULL || IconExists(view->Name())) { delete view; unload_add_on(image); return B_ERROR; } BMessage* data = new BMessage; view->Archive(data); delete view; AddIcon(data, id, &ref); // add the rep; adds info to list if (addToSettings) { fAddOnSettings.AddString(kReplicantPathField, path.Path()); _SaveSettings(); } return B_OK; }
void BShelf::MessageReceived(BMessage *msg) { if (msg->what == kDeleteReplicant) { BHandler *replicant = NULL; if (msg->FindPointer("_target", (void **)&replicant) == B_OK) { BView *view = dynamic_cast<BView *>(replicant); if (view != NULL) DeleteReplicant(view); } return; } BMessage replyMsg(B_REPLY); status_t err = B_BAD_SCRIPT_SYNTAX; BMessage specifier; int32 what; const char *prop; int32 index; if (msg->GetCurrentSpecifier(&index, &specifier, &what, &prop) != B_OK) return BHandler::MessageReceived(msg); switch (msg->what) { case B_DELETE_PROPERTY: case B_GET_PROPERTY: case B_GET_SUPPORTED_SUITES: if (strcmp(prop, "Replicant") == 0) { BMessage reply; int32 i; uint32 ID; BView *replicant = NULL; BMessage *repMessage = NULL; err = _GetProperty(&specifier, &reply); if (err == B_OK) err = reply.FindInt32("index", &i); if (err == B_OK && msg->what == B_DELETE_PROPERTY) { // Delete Replicant err = DeleteReplicant(i); break; } if (err == B_OK && msg->what == B_GET_SUPPORTED_SUITES) { err = replyMsg.AddString("suites", "suite/vnd.Be-replicant"); if (err == B_OK) { BPropertyInfo propInfo(sReplicantPropertyList); err = replyMsg.AddFlat("messages", &propInfo); } break; } if (err == B_OK ) repMessage = ReplicantAt(i, &replicant, &ID, &err); if (err == B_OK && replicant) { msg->PopSpecifier(); BMessage archive; err = replicant->Archive(&archive); if (err == B_OK && msg->GetCurrentSpecifier(&index, &specifier, &what, &prop) != B_OK) { err = replyMsg.AddMessage("result", &archive); break; } // now handles the replicant suite err = B_BAD_SCRIPT_SYNTAX; if (msg->what != B_GET_PROPERTY) break; if (strcmp(prop, "ID") == 0) { err = replyMsg.AddInt32("result", ID); } else if (strcmp(prop, "Name") == 0) { err = replyMsg.AddString("result", replicant->Name()); } else if (strcmp(prop, "Signature") == 0) { const char *add_on = NULL; err = repMessage->FindString("add_on", &add_on); if (err == B_OK) err = replyMsg.AddString("result", add_on); } else if (strcmp(prop, "Suites") == 0) { err = replyMsg.AddString("suites", "suite/vnd.Be-replicant"); if (err == B_OK) { BPropertyInfo propInfo(sReplicantPropertyList); err = replyMsg.AddFlat("messages", &propInfo); } } } break; } return BHandler::MessageReceived(msg); case B_COUNT_PROPERTIES: if (strcmp(prop, "Replicant") == 0) { err = replyMsg.AddInt32("result", CountReplicants()); break; } return BHandler::MessageReceived(msg); case B_CREATE_PROPERTY: { BMessage replicantMsg; BPoint pos; if (msg->FindMessage("data", &replicantMsg) == B_OK && msg->FindPoint("location", &pos) == B_OK) { err = AddReplicant(&replicantMsg, pos); } } break; } if (err < B_OK) { replyMsg.what = B_MESSAGE_NOT_UNDERSTOOD; if (err == B_BAD_SCRIPT_SYNTAX) replyMsg.AddString("message", "Didn't understand the specifier(s)"); else replyMsg.AddString("message", strerror(err)); } replyMsg.AddInt32("error", err); msg->SendReply(&replyMsg); }
status_t BShelf::_GetProperty(BMessage *msg, BMessage *reply) { uint32 ID; status_t err = B_ERROR; BView *replicant = NULL; switch (msg->what) { case B_INDEX_SPECIFIER: { int32 index = -1; if (msg->FindInt32("index", &index)!=B_OK) break; ReplicantAt(index, &replicant, &ID, &err); break; } case B_REVERSE_INDEX_SPECIFIER: { int32 rindex; if (msg->FindInt32("index", &rindex) != B_OK) break; ReplicantAt(CountReplicants() - rindex, &replicant, &ID, &err); break; } case B_NAME_SPECIFIER: { const char *name; if (msg->FindString("name", &name) != B_OK) break; for (int32 i = 0; i < CountReplicants(); i++) { BView *view = NULL; ReplicantAt(i, &view, &ID, &err); if (err != B_OK || view == NULL) continue; if (view->Name() != NULL && strcmp(view->Name(), name) == 0) { replicant = view; break; } err = B_NAME_NOT_FOUND; } break; } case B_ID_SPECIFIER: { uint32 id; if (msg->FindInt32("id", (int32 *)&id) != B_OK) break; for (int32 i = 0; i < CountReplicants(); i++) { BView *view = NULL; ReplicantAt(i, &view, &ID, &err); if (err != B_OK || view == NULL) continue; if (ID == id) { replicant = view; break; } err = B_NAME_NOT_FOUND; } break; } default: break; } if (replicant) { reply->AddInt32("index", IndexOf(replicant)); reply->AddInt32("ID", ID); } return err; }
/*! The add-ons must support the exported C function API if they do, they will be loaded and added to deskbar primary function is the Instantiate function */ status_t TReplicantTray::LoadAddOn(BEntry* entry, int32* id, bool force) { if (!entry) return B_ERROR; node_ref nodeRef; entry->GetNodeRef(&nodeRef); // no duplicates if (NodeExists(nodeRef)) return B_ERROR; BNode node(entry); if (!force) { status_t error = node.InitCheck(); if (error != B_OK) return error; uint64 deskbarID; ssize_t size = node.ReadAttr(kDeskbarSecurityCodeAttr, B_UINT64_TYPE, 0, &deskbarID, sizeof(fDeskbarSecurityCode)); if (size != sizeof(fDeskbarSecurityCode) || deskbarID != fDeskbarSecurityCode) { // no code or code doesn't match return B_ERROR; } } BPath path; status_t status = entry->GetPath(&path); if (status < B_OK) return status; // load the add-on image_id image = load_add_on(path.Path()); if (image < B_OK) return image; // get the view loading function symbol // we first look for a symbol that takes an image_id // and entry_ref pointer, if not found, go with normal // instantiate function BView* (*entryFunction)(image_id, const entry_ref*); BView* (*itemFunction)(void); BView* view = NULL; entry_ref ref; entry->GetRef(&ref); if (get_image_symbol(image, kInstantiateEntryCFunctionName, B_SYMBOL_TYPE_TEXT, (void**)&entryFunction) >= B_OK) { view = (*entryFunction)(image, &ref); } else if (get_image_symbol(image, kInstantiateItemCFunctionName, B_SYMBOL_TYPE_TEXT, (void**)&itemFunction) >= B_OK) { view = (*itemFunction)(); } else { unload_add_on(image); return B_ERROR; } if (view == NULL || IconExists(view->Name())) { delete view; unload_add_on(image); return B_ERROR; } BMessage* data = new BMessage; view->Archive(data); delete view; AddIcon(data, id, &ref); // add the rep; adds info to list node.WriteAttr(kDeskbarSecurityCodeAttr, B_UINT64_TYPE, 0, &fDeskbarSecurityCode, sizeof(fDeskbarSecurityCode)); return B_OK; }
BView * DefaultMediaTheme::MakeViewFor(BParameterWeb *web, const BRect *hintRect) { CALLED(); if (web == NULL) return NULL; BRect rect; if (hintRect) rect = *hintRect; BRect bestRect; // do we have more than one attached parameter group? // if so, use a tabbed view with a tab for each group TabView *tabView = NULL; if (web->CountGroups() > 1) tabView = new TabView(rect, "web"); rect.OffsetTo(B_ORIGIN); for (int32 i = 0; i < web->CountGroups(); i++) { BParameterGroup *group = web->GroupAt(i); if (group == NULL) continue; BView *groupView = MakeViewFor(*group, hintRect ? &rect : NULL); if (groupView == NULL) continue; if (GroupView *view = dynamic_cast<GroupView *>(groupView)) { // the top-level group views must not be larger than their hintRect, // but unlike their children, they should follow all sides when // their parent is resized if (hintRect != NULL) view->ResizeTo(rect.Width() - 10, rect.Height() - 10); view->SetResizingMode(B_FOLLOW_ALL); } if (tabView == NULL) { // if we don't need a container to put that view into, // we're done here (but the groupView may span over the // whole hintRect) if (groupView->Frame().LeftTop() == BPoint(5, 5)) { // remove insets, as they are not needed groupView->MoveBy(-5, -5); groupView->ResizeBy(10, 10); } return new DynamicScrollView(groupView->Name(), groupView); } DynamicScrollView *scrollView = new DynamicScrollView(groupView->Name(), groupView); tabView->AddTab(scrollView); if (!hintRect) { bestRect = bestRect | scrollView->Bounds(); } } if (tabView != NULL) { // this adjustment must be kept in sync with TabView::FrameResized bestRect.bottom += tabView->TabHeight(); bestRect.InsetBy(-3.0,-3.0); tabView->ResizeTo(bestRect.Width(), bestRect.Height()); tabView->FrameResized(bestRect.Width(), bestRect.Height()); //needed since we're not attached to a window yet } return tabView; }
PrefsWindow::PrefsWindow(uint32 msg) : BWindow(BRect(0, 0, 400, 289), GetString(STR_PREFS_TITLE), B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS), this_messenger(this) { int i; ok_message = msg; send_quit_on_close = true; get_system_info(&sys_info); // Move window to right position Lock(); MoveTo(80, 80); // Set up menus BMenuBar *bar = new BMenuBar(Bounds(), "menu"); BMenu *menu = new BMenu(GetString(STR_PREFS_MENU)); menu->AddItem(new BMenuItem(GetString(STR_PREFS_ITEM_ABOUT), new BMessage(B_ABOUT_REQUESTED))); menu->AddItem(new BSeparatorItem); menu->AddItem(new BMenuItem(GetString(STR_PREFS_ITEM_START), new BMessage(MSG_OK))); menu->AddItem(new BMenuItem(GetString(STR_PREFS_ITEM_ZAP_PRAM), new BMessage(MSG_ZAP_PRAM))); menu->AddItem(new BSeparatorItem); menu->AddItem(new BMenuItem(GetString(STR_PREFS_ITEM_QUIT), new BMessage(MSG_CANCEL), 'Q')); bar->AddItem(menu); AddChild(bar); SetKeyMenuBar(bar); int mbar_height = int(bar->Bounds().bottom) + 1; // Resize window to fit menu bar ResizeBy(0, mbar_height); // Light gray background BRect b = Bounds(); top = new BView(BRect(0, mbar_height, b.right, b.bottom), "top", B_FOLLOW_NONE, B_WILL_DRAW); AddChild(top); top->SetViewColor(fill_color); top_frame = top->Bounds(); // Create panes panes[0] = create_volumes_pane(); panes[1] = create_graphics_pane(); panes[2] = create_serial_pane(); panes[3] = create_memory_pane(); // Prefs item tab view pane_tabs = new BTabView(BRect(10, 10, top_frame.right-10, top_frame.bottom-50), "items", B_WIDTH_FROM_LABEL); for (i=0; i<NUM_PANES; i++) pane_tabs->AddTab(panes[i]); top->AddChild(pane_tabs); volume_list->Select(0); // Create volume file panels add_volume_panel = new BFilePanel(B_OPEN_PANEL, &this_messenger, NULL, B_FILE_NODE | B_DIRECTORY_NODE, false, new BMessage(MSG_ADD_VOLUME_PANEL)); add_volume_panel->SetButtonLabel(B_DEFAULT_BUTTON, GetString(STR_ADD_VOLUME_PANEL_BUTTON)); add_volume_panel->Window()->SetTitle(GetString(STR_ADD_VOLUME_TITLE)); create_volume_panel = new BFilePanel(B_SAVE_PANEL, &this_messenger, NULL, B_FILE_NODE | B_DIRECTORY_NODE, false, new BMessage(MSG_CREATE_VOLUME_PANEL)); create_volume_panel->SetButtonLabel(B_DEFAULT_BUTTON, GetString(STR_CREATE_VOLUME_PANEL_BUTTON)); create_volume_panel->Window()->SetTitle(GetString(STR_CREATE_VOLUME_TITLE)); create_volume_panel->Window()->Lock(); BView *background = create_volume_panel->Window()->ChildAt(0); background->FindView("PoseView")->ResizeBy(0, -30); background->FindView("VScrollBar")->ResizeBy(0, -30); background->FindView("CountVw")->MoveBy(0, -30); BView *v = background->FindView("HScrollBar"); if (v) v->MoveBy(0, -30); else { i = 0; while ((v = background->ChildAt(i++)) != NULL) { if (v->Name() == NULL || v->Name()[0] == 0) { v->MoveBy(0, -30); // unnamed horizontal scroll bar break; } } } BView *filename = background->FindView("text view"); BRect fnr(filename->Frame()); fnr.OffsetBy(0, -30); NumberControl *nc = new NumberControl(fnr, 80, "hardfile_size", GetString(STR_HARDFILE_SIZE_CTRL), 40, NULL); background->AddChild(nc); create_volume_panel->Window()->Unlock(); // "Start" button BButton *button = new BButton(BRect(20, top_frame.bottom-35, 90, top_frame.bottom-10), "start", GetString(STR_START_BUTTON), new BMessage(MSG_OK)); top->AddChild(button); SetDefaultButton(button); // "Quit" button top->AddChild(new BButton(BRect(top_frame.right-90, top_frame.bottom-35, top_frame.right-20, top_frame.bottom-10), "cancel", GetString(STR_QUIT_BUTTON), new BMessage(MSG_CANCEL))); Unlock(); Show(); }