1#include <StringView.h> 2#include "InterfaceWin.h" 3#include "NetListView.h" 4 5InterfaceWin::InterfaceWin(const BRect &frame, const InterfaceData &data) 6 : BWindow(frame,"Interface Win",B_MODAL_WINDOW, 7 B_NOT_ANCHORED_ON_ACTIVATE | B_NOT_RESIZABLE,B_CURRENT_WORKSPACE), 8 fData(data.fName.String()) 9{ 10 AddShortcut('W',B_COMMAND_KEY,new BMessage(B_QUIT_REQUESTED)); 11 AddShortcut('Q',B_COMMAND_KEY,new BMessage(B_QUIT_REQUESTED)); 12 13 BRect r(Bounds()); 14 15 fData=data; 16 BView *view=new BView(r,"Interface_View",B_FOLLOW_ALL,B_WILL_DRAW); 17 view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 18 AddChild(view); 19 20 float width,height; 21 22 fName=new BStringView(BRect(5,5,6,6),"Interface_Name",data.fPrettyName.String()); 23 fName->GetPreferredSize(&width,&height); 24 fName->ResizeTo(width,height); 25 view->AddChild(fName); 26 27 // There is a serious possibility that the name of the interface may be 28 // longer than the current width of the window, especially at larger font 29 // settings. If this is the case, we will end up resizing the window to fit it 30 // all 31 float maxwidth = MAX(width, r.right); 32 33 float ypos = 5 + height + 20; 34 fEnabled=new BCheckBox(BRect(5,ypos,6,ypos + 1), 35 "Enabled","Interface enabled", 36 new BMessage(kSOMETHING_HAS_CHANGED), 37 B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); 38 fEnabled->GetPreferredSize(&width,&height); 39 fEnabled->ResizeTo(width,height); 40 view->AddChild(fEnabled); 41 42 ypos += height + 10; 43 fDHCP=new BRadioButton(BRect(5,ypos,6,ypos+1),"DHCP", 44 "Obtain settings automatically", 45 new BMessage(kSOMETHING_HAS_CHANGED)); 46 fDHCP->GetPreferredSize(&width,&height); 47 fDHCP->ResizeTo(width,height); 48 view->AddChild(fDHCP); 49 50 ypos += height + 1; 51 fManual=new BRadioButton(BRect(5,ypos,6,ypos+1),"Manual","Specify settings", 52 new BMessage(kSOMETHING_HAS_CHANGED)); 53 fManual->GetPreferredSize(&width,&height); 54 fManual->ResizeTo(width,height); 55 view->AddChild(fManual); 56 57 ypos += height + 10; 58 59 fIPAddress=new BTextControl(BRect(10,10,6,6),"IP address","IP address:",NULL, 60 new BMessage(kSOMETHING_HAS_CHANGED), 61 B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); 62 fIPAddress->GetPreferredSize(&width,&height); 63 width = r.right - 15; 64 65 fNetMask=new BTextControl(BRect(10,20 + height,width - 5,15 + (height*2)), 66 "Subnet mask","Subnet mask:",NULL, 67 new BMessage(kSOMETHING_HAS_CHANGED), 68 B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); 69 70 fGateway=new BTextControl(BRect(10,30 + (height*2),width - 5,25 + (height*3)), 71 "Gateway","Gateway:",NULL, 72 new BMessage(kSOMETHING_HAS_CHANGED), 73 B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); 74 75 fBox=new BBox(BRect(5,ypos,r.right - 5, ypos + fGateway->Frame().bottom + 10), 76 "IP",B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); 77 view->AddChild(fBox); 78 79 fBox->AddChild(fIPAddress); 80 fBox->AddChild(fNetMask); 81 fBox->AddChild(fGateway); 82 83 // We have to place the ResizeTo() call down here because in R5, these calls 84 // apparently don't do anything unless attached to a window. Grrr.... 85 fIPAddress->ResizeTo(width - 15, height); 86 87 float dividersize = fIPAddress->StringWidth("Subnet mask:") + 10; 88 fIPAddress->SetDivider(dividersize); 89 fNetMask->SetDivider(dividersize); 90 fGateway->SetDivider(dividersize); 91 92 fIPAddress->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT); 93 fNetMask->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT); 94 fGateway->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT); 95 96 97 ypos = fBox->Frame().bottom + 10; 98 99 // TODO: Finish the Configure code 100 fConfig=new BButton(BRect(5,ypos,6,ypos+1),"Config","Configure", NULL); 101 fConfig->GetPreferredSize(&width,&height); 102 fConfig->ResizeTo(width,height); 103 view->AddChild(fConfig); 104 105 106 fDone=new BButton(BRect(0,0,1,1),"Done","Done", new BMessage(kDone_inter_M), 107 B_FOLLOW_RIGHT | B_FOLLOW_TOP); 108 109 fDone->ResizeToPreferred(); 110 fDone->MoveTo(r.right - 5 - fDone->Bounds().right,ypos); 111 112 fCancel=new BButton(BRect(0,0,1,1),"Cancel","Cancel", 113 new BMessage(B_QUIT_REQUESTED), B_FOLLOW_RIGHT | B_FOLLOW_TOP); 114 115 fCancel->ResizeToPreferred(); 116 fCancel->MoveTo(fDone->Frame().left - 10 - fCancel->Bounds().right,ypos); 117 view->AddChild(fCancel); 118 view->AddChild(fDone); 119 fDone->MakeDefault(true); 120 121 ypos += height + 10; 122 if(r.bottom < ypos || r.right < maxwidth) 123 ResizeTo( MAX(r.right,maxwidth), MAX(ypos, r.bottom) ); 124} 125 126void InterfaceWin::MessageReceived(BMessage *message) 127{ 128 switch(message->what) { 129 130 case kDone_inter_M: { 131 // TODO: Re-enable 132/* if (fChanged==true){ 133 fParentWindow->PostMessage(fParentWindow->kSOMETHING_HAS_CHANGED_M); 134 135 NetListItem *item=dynamic_cast <NetListItem *> (fParentWindow->fInterfacesList->ItemAt(fParentWindow->fInterfacesList->CurrentSelection())); 136 137 item->fIPADDRESS=fIPAddress->Text(); 138 item->fNETMASK =fNetMask->Text(); 139 140 if (fEnabled->Value()==0) 141 item->fENABLED =0; 142 else 143 item->fENABLED =1; 144 145 if (fDHCP->Value()==0) 146 item->fDHCP=0; 147 else 148 item->fDHCP=1; 149 } 150 Quit(); 151*/ break; 152 } 153 case kSOMETHING_HAS_CHANGED: { 154 155 fChanged=true; 156 break; 157 } 158 } 159} 160