1 #include <Button.h> 2 #include <CheckBox.h> 3 #include <String.h> 4 #include <TextControl.h> 5 #include <Window.h> 6 #include <Box.h> 7 #include "Constants.h" 8 #include "FindWindow.h" 9 10 // FindWindow::FindWindow() 11 FindWindow::FindWindow(BRect frame, BHandler *_handler, BString *searchString, bool *caseState, bool *wrapState, bool *backState) 12 : BWindow(frame,"FindWindow", B_MODAL_WINDOW, B_NOT_RESIZABLE|B_ASYNCHRONOUS_CONTROLS, B_CURRENT_WORKSPACE) 13 { 14 AddChild(fFindView=new BBox(Bounds(),"FindView",B_FOLLOW_ALL,B_WILL_DRAW,B_PLAIN_BORDER)); 15 fFindView->SetViewColor(221,222,221); 16 17 font_height height; 18 fFindView->GetFontHeight(&height); 19 float lineHeight = height.ascent+height.descent+height.leading; 20 21 float findWidth = fFindView->StringWidth("Find:")+6; 22 23 float searchBottom = 12 + 2 + lineHeight + 2 + 1; 24 float buttonTop = frame.Height()-19-lineHeight; 25 float wrapBoxTop = (buttonTop+searchBottom-lineHeight)/2; 26 float wrapBoxBottom = (buttonTop+searchBottom+lineHeight)/2; 27 float caseBoxTop = (searchBottom+wrapBoxTop-lineHeight)/2; 28 float caseBoxBottom = (searchBottom+wrapBoxTop+lineHeight)/2; 29 float backBoxTop = (buttonTop+wrapBoxBottom-lineHeight)/2; 30 float backBoxBottom = (buttonTop+wrapBoxBottom+lineHeight)/2; 31 32 fFindView->AddChild(fSearchString= new BTextControl(BRect(14,12,frame.Width()-10,searchBottom), "", "Find:", NULL, NULL)); 33 fSearchString->SetDivider(findWidth); 34 35 fFindView->AddChild(fCaseSensBox= new BCheckBox(BRect(16+findWidth,caseBoxTop,frame.Width()-12,caseBoxBottom),"","Case-sensitive", NULL)); 36 fFindView->AddChild(fWrapBox= new BCheckBox(BRect(16+findWidth,wrapBoxTop,frame.Width()-12,wrapBoxBottom),"","Wrap-around search", NULL)); 37 fFindView->AddChild(fBackSearchBox= new BCheckBox(BRect(16+findWidth,backBoxTop,frame.Width()-12,backBoxBottom),"","Search backwards", NULL)); 38 39 fFindView->AddChild(fCancelButton= new BButton(BRect(142,buttonTop,212,frame.Height()-7),"","Cancel",new BMessage(B_QUIT_REQUESTED))); 40 fFindView->AddChild(fSearchButton= new BButton(BRect(221,buttonTop,291,frame.Height()-7),"","Find",new BMessage(MSG_SEARCH))); 41 42 fSearchButton->MakeDefault(true); 43 fHandler=_handler; 44 45 const char *text= searchString->String(); 46 47 fSearchString->SetText(text); 48 fSearchString-> MakeFocus(true); //021021 49 50 if(*caseState== true) 51 fCaseSensBox->SetValue(B_CONTROL_ON); 52 else 53 fCaseSensBox->SetValue(B_CONTROL_OFF); 54 55 if(*wrapState== true) 56 fWrapBox->SetValue(B_CONTROL_ON); 57 else 58 fWrapBox->SetValue(B_CONTROL_OFF); 59 60 if(*backState== true) 61 fBackSearchBox->SetValue(B_CONTROL_ON); 62 else 63 fBackSearchBox->SetValue(B_CONTROL_OFF); 64 65 Show(); 66 } 67 68 void FindWindow::MessageReceived(BMessage *msg){ 69 switch(msg->what){ 70 case B_QUIT_REQUESTED: 71 Quit(); 72 break; 73 case MSG_SEARCH: 74 ExtractToMsg(new BMessage(MSG_SEARCH)); 75 break; 76 default: 77 BWindow::MessageReceived(msg); 78 break; 79 } 80 } 81 82 void FindWindow::DispatchMessage(BMessage *message, BHandler *handler) 83 84 { 85 int8 key; 86 87 if ( message->what == B_KEY_DOWN ) { 88 status_t result; 89 result= message->FindInt8("byte", 0, &key); 90 91 if (result== B_OK){ 92 if (key== B_ESCAPE){ 93 message-> MakeEmpty(); 94 message-> what= B_QUIT_REQUESTED; 95 } 96 } 97 } 98 BWindow::DispatchMessage(message,handler); 99 } 100 101 void FindWindow::ExtractToMsg(BMessage *message){ 102 103 int32 caseBoxState; 104 int32 wrapBoxState; 105 int32 backBoxState; 106 107 caseBoxState= fCaseSensBox-> Value(); 108 wrapBoxState= fWrapBox-> Value(); 109 backBoxState= fBackSearchBox-> Value(); 110 111 bool caseSens; 112 bool wrapIt; 113 bool backSearch; 114 115 if(caseBoxState== B_CONTROL_ON) 116 caseSens=true; 117 else 118 caseSens= false; 119 120 if(wrapBoxState== B_CONTROL_ON) 121 wrapIt= true; 122 else 123 wrapIt= false; 124 125 if(backBoxState== B_CONTROL_ON) 126 backSearch= true; 127 else 128 backSearch= false; 129 130 //Add the string 131 message->AddString("findtext",fSearchString->Text()); 132 133 //Add searchparameters from checkboxes 134 message->AddBool("casesens", caseSens); 135 message->AddBool("wrap", wrapIt); 136 message->AddBool("backsearch", backSearch); 137 138 fHandler->Looper()->PostMessage(message,fHandler); 139 delete(message); 140 PostMessage(B_QUIT_REQUESTED); 141 } 142 143 144