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