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