Ticket #199: 199-2.patch

File 199-2.patch, 13.1 KB (added by Niels.Reedijk@…, 18 years ago)

Updated GUI patch

  • src/apps/terminal/TermWindow.cpp

     
    2727#include "CodeConv.h"
    2828#include "ColorWindow.h"
    2929#include "MenuUtil.h"
     30#include "FindDlg.h"
    3031#include "PrefDlg.h"
    3132#include "PrefView.h"
    3233#include "PrefHandler.h"
     
    219220    fEditmenu->AddSeparatorItem ();
    220221    fEditmenu->AddItem (new BMenuItem ("Select All", new BMessage (B_SELECT_ALL), 'A'));
    221222    fEditmenu->AddItem (new BMenuItem ("Clear All", new BMessage (MENU_CLEAR_ALL), 'L'));
     223    fEditmenu->AddSeparatorItem ();
     224    fEditmenu->AddItem (new BMenuItem ("Find", new BMessage (MENU_FIND_STRING),'F'));
     225    fEditmenu->AddItem (new BMenuItem ("Find Again", new BMessage (MENU_FIND_AGAIN), ']'));
    222226
    223 /*
    224   // TODO: Implement Finding
    225   fEditmenu->AddSeparatorItem ();
    226   fEditmenu->AddItem (new BMenuItem ("Find", new BMessage (MENU_FIND_STRING),'F'));
    227   fEditmenu->AddItem (new BMenuItem ("Find Again", new BMessage (MENU_FIND_AGAIN), ']'));
    228 */
    229227    fMenubar->AddItem (fEditmenu);
    230228 
    231229    // Make Help Menu.
     
    277275  BRect r;
    278276  BFont halfFont;
    279277  BFont fullFont;
     278  BString findstring;
     279  bool forwardsearch, matchcase, matchword, regexp, findresult;
    280280 
    281281    switch (message->what) {
    282282        case MENU_SWITCH_TERM: {
     
    303303            fPrefWindow = NULL;
    304304            break;
    305305        }
     306        case MENU_FIND_STRING: {
     307            if (!fFindPanel) {
     308                BRect r = Frame();
     309                r.left += 20;
     310                r.top += 20;
     311                r.right = r.left + 260;
     312                r.bottom = r.top + 220;
     313                fFindPanel = new FindDlg(r, this);
     314            }
     315            else
     316                fFindPanel->Activate();
     317            break;
     318        }
     319        case MSG_FIND: {
     320            fFindPanel->QuitRequested();
     321            message->FindString("findstring", &findstring);
     322            message->FindBool("forwardsearch", &forwardsearch);
     323            message->FindBool("matchcase", &matchcase);
     324            message->FindBool("matchword", &matchword);
     325            message->FindBool("regexp", &regexp);
     326            findresult = fTermView->Find(findstring, forwardsearch, matchcase, matchword, regexp);
     327            if (!findresult)
     328                ; //Display error
     329            break;
     330        }
     331        case MSG_FIND_CLOSED: {
     332            fFindPanel = NULL;
     333            break;
     334        }
    306335        case MENU_FILE_QUIT: {
    307336            be_app->PostMessage(B_QUIT_REQUESTED);
    308337            break;
     
    522551{
    523552    delete fTermParse;
    524553    delete fCodeConv;
    525     if(fPrefWindow) fPrefWindow->PostMessage (B_QUIT_REQUESTED);
    526         be_app->PostMessage (B_QUIT_REQUESTED, be_app);
     554    if (fPrefWindow) fPrefWindow->PostMessage (B_QUIT_REQUESTED);
     555    if (fFindPanel) fFindPanel->PostMessage(B_QUIT_REQUESTED);
     556   
     557    be_app->PostMessage (B_QUIT_REQUESTED, be_app);
    527558    BWindow::Quit ();
    528559}
    529560
  • src/apps/terminal/TermView.cpp

     
    22482248     *height = fFontHeight;
    22492249}
    22502250
     2251// Find a string, and select it if found
     2252bool
     2253TermView::Find (const BString &str, bool forwardSearch, bool matchCase, bool matchWord, bool regexp)
     2254{
     2255    uchar buffercontent[fTextBuffer->GetArraySize() + 1];
     2256    ushort attr;
     2257    int count;
     2258
     2259    //Get the buffer contents
     2260    count = fTextBuffer->GetString(0, 0, fTextBuffer->GetArraySize(), buffercontent, &attr);
     2261
     2262    BString buffer((const char *)&buffercontent);
     2263
     2264    return false;
     2265}
     2266
    22512267// Send DrawRect data to Draw Engine thread.
    22522268inline void
    22532269TermView::SendDataToDrawEngine(int x1, int y1, int x2, int y2)
  • src/apps/terminal/Changelog

     
    1313Terminal window supports scrolling
    1414
    1515TODO:
    16 Make a Jamfile
    17 Make Find work
    1816Fix titling (-t works already, its the Terminal 1, 2, 3, etc...)
    1917Fix the Colour menu
    2018Move Fonts and font sizes to the "Right Place"
    2119Kill the Preferences Panel
    22 Move to .rdef source resources
  • src/apps/terminal/FindDlg.h

     
    3333#include <Window.h>
    3434#include <TextView.h>
    3535
    36 #include "CurPos.h"
    37 
     36const ulong MSG_FIND = 'msgf';
    3837const ulong MSG_FIND_START = 'msac';
     38const ulong MSG_FIND_CLOSED = 'mfcl';
    3939
    4040class BRect;
    4141class BBitmap;
    4242class BMessage;
    4343class TermWindow;
     44class BTextControl;
     45class BRadioButton;
     46class BCheckBox;
    4447
    4548class FindDlg : public BWindow
    4649{
    4750public:
    48   FindDlg(BRect frame, TermWindow *win);
    49   ~FindDlg ();
     51    FindDlg (BRect frame, TermWindow *win);
     52    ~FindDlg ();
    5053
    51   void      Find (CurPos *start, CurPos *end);
     54private:
     55    virtual void    Quit (void);
     56    void            MessageReceived (BMessage *msg);
    5257
    53  private:
    54   virtual void  Quit (void);
    55  
    56   BString   *fFindString;
    57   TermWindow    *fWindow;
     58    void            SendFindMessage (void);
    5859
     60    BView           *fFindView;
     61    BTextControl    *fFindLabel;
     62    BRadioButton    *fTextRadio;
     63    BRadioButton    *fSelectionRadio;
     64    BBox            *fSeparator;
     65    BCheckBox       *fForwardSearchBox;
     66    BCheckBox       *fMatchCaseBox;
     67    BCheckBox       *fMatchWordBox;
     68    BCheckBox       *fRegexpBox;
     69    BButton         *fFindButton;
     70
     71    BString *fFindString;
     72    TermWindow  *fWindow;
    5973};
    6074
    6175
  • src/apps/terminal/Jamfile

     
    77    AppearPrefView.cpp
    88    CodeConv.cpp
    99    CurPos.cpp
     10    FindDlg.cpp
    1011    MenuUtil.cpp
    1112    Terminal.cpp
    1213    PrefDlg.cpp
  • src/apps/terminal/FindDlg.cpp

     
    3131#include <Window.h>
    3232#include <Rect.h>
    3333#include <TextControl.h>
     34#include <Box.h>
     35#include <CheckBox.h>
    3436#include <Button.h>
     37#include <RadioButton.h>
    3538#include <Message.h>
    3639#include <stdio.h>
    3740#include <File.h>
    3841#include <String.h>
    3942
     43#include "TermWindow.h"
    4044#include "FindDlg.h"
    4145#include "TermApp.h"
    4246#include "MenuUtil.h"
     
    4448
    4549// message define
    4650
    47 const uint32 FPANEL_HIDE = 'Fhid';
     51const uint32 MSG_FIND_HIDE = 'Fhid';
    4852
    4953//////////////////////////////////////////////////////////////////////////////
    5054// FindDlg
    5155//  Constructer
    5256//////////////////////////////////////////////////////////////////////////////
    5357FindDlg::FindDlg (BRect frame, TermWindow *win)
    54   : BWindow(frame, "Find",
    55         B_FLOATING_WINDOW, B_NOT_RESIZABLE|B_NOT_ZOOMABLE)
     58    : BWindow(frame, "Find",
     59        B_FLOATING_WINDOW, B_NOT_RESIZABLE|B_NOT_ZOOMABLE)
    5660{
    57   PrefHandler title;
    58   LoadLocaleFile (&title);
     61    fWindow = win;
     62    SetTitle("Find");
    5963
    60   fWindow = win;
    61   this->SetTitle (title.getString ("Find"));
     64    AddShortcut ((ulong)'W', (ulong)B_COMMAND_KEY, new BMessage (MSG_FIND_HIDE));
    6265
    63   AddShortcut ((ulong)'Q', (ulong)B_COMMAND_KEY, new BMessage (FPANEL_HIDE));
    64   AddShortcut ((ulong)'W', (ulong)B_COMMAND_KEY, new BMessage (FPANEL_HIDE));
     66    //Build up view
     67    fFindView = new BView(Bounds(), "FindView", B_FOLLOW_ALL, B_WILL_DRAW);
     68    fFindView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
     69    AddChild(fFindView);
    6570
    66   BRect r (10, 10, 120, 20);
    67  
    68   BTextControl *text_ctl = new BTextControl (r, "text", NULL, NULL, NULL);
    69   AddChild (text_ctl);
     71    font_height height;
     72    fFindView->GetFontHeight(&height);
     73    float lineHeight = height.ascent + height.descent + height.leading;
    7074
    71   r.Set (100, 40, 130, 60);
    72   BButton *button = new BButton (r, NULL, "Find", new BMessage (MSG_FIND_START));
    73   AddChild (button);
    74  
     75    //These labels are from the bottom up
     76    float buttonsTop = frame.Height() - 19 - lineHeight;
     77    float regexpBottom = buttonsTop - 4;
     78    float regexpTop = regexpBottom - lineHeight - 8;
     79    float matchwordBottom = regexpTop - 4;
     80    float matchwordTop = matchwordBottom - lineHeight - 8;
     81    float matchcaseBottom = matchwordTop - 4;
     82    float matchcaseTop = matchcaseBottom - lineHeight - 8;
     83    float forwardsearchBottom = matchcaseTop - 4;
     84    float forwardsearchTop = forwardsearchBottom - lineHeight - 10;
     85
     86    //These things are calculated from the top
     87    float textRadioTop = 12;
     88    float textRadioBottom = textRadioTop + 2 + lineHeight + 2 + 1;
     89    float textRadioRight = fFindView->StringWidth("Use Text: ") + 30;
     90    float selectionRadioTop = textRadioBottom + 4;
     91    float selectionRadioBottom = selectionRadioTop + lineHeight + 8;
     92
     93    //Divider
     94    float dividerHeight = (selectionRadioBottom + forwardsearchTop) / 2;
     95   
     96    //Button Coordinates
     97    float searchbuttonLeft = (frame.Width() - fFindView->StringWidth("Find") - 60) / 2;
     98    float searchbuttonRight = searchbuttonLeft + fFindView->StringWidth("Find") + 60;
     99   
     100    //Build the Views
     101    fTextRadio = new BRadioButton(BRect(14, textRadioTop, textRadioRight, textRadioBottom),
     102        "fTextRadio", "Use Text: ", NULL);
     103    fFindView->AddChild(fTextRadio);
     104   
     105    fFindLabel = new BTextControl(BRect(textRadioRight + 4, textRadioTop, frame.Width() - 14, textRadioBottom),
     106        "fFindLabel", "", "", NULL);
     107    fFindLabel->SetDivider(0);
     108    fFindView->AddChild(fFindLabel);
     109
     110    fTextRadio->SetValue(1);    //enable first option
     111   
     112    fSelectionRadio = new BRadioButton(BRect(14, selectionRadioTop, frame.Width() - 14, selectionRadioBottom),
     113        "fSelectionRadio", "Use Selection", NULL);
     114    fFindView->AddChild(fSelectionRadio);
     115
     116    fSeparator = new BBox(BRect(6, dividerHeight, frame.Width() - 6, dividerHeight + 1));
     117    fFindView->AddChild(fSeparator);
     118   
     119    fForwardSearchBox = new BCheckBox(BRect(14, forwardsearchTop, frame.Width() - 14, forwardsearchBottom),
     120        "fForwardSearchBox", "Search Forward", NULL);
     121    fFindView->AddChild(fForwardSearchBox);
     122   
     123    fMatchCaseBox = new BCheckBox(BRect(14, matchcaseTop, frame.Width() - 14, matchcaseBottom),
     124        "fMatchCaseBox", "Match Case", NULL);
     125    fFindView->AddChild(fMatchCaseBox);
     126   
     127    fMatchWordBox = new BCheckBox(BRect(14, matchwordTop, frame.Width() - 14, matchwordBottom),
     128        "fMatchWordBox", "Match Word", NULL);
     129    fFindView->AddChild(fMatchWordBox);
     130   
     131    fRegexpBox = new BCheckBox(BRect(14, regexpTop, frame.Width() - 14, regexpBottom),
     132        "fRegexpBox", "Use Regular Expression", NULL);
     133    fFindView->AddChild(fRegexpBox);
     134   
     135    fFindButton = new BButton(BRect(searchbuttonLeft, buttonsTop, searchbuttonRight, frame.Height() - 14),
     136        "fFindButton", "Find", new BMessage(MSG_FIND));
     137    fFindButton->MakeDefault(true);
     138    fFindView->AddChild(fFindButton);
     139   
     140    Show();
    75141}
    76142
    77143FindDlg::~FindDlg (void)
     
    80146}
    81147
    82148void
     149FindDlg::MessageReceived (BMessage *msg)
     150{
     151    switch (msg->what) {
     152        case B_QUIT_REQUESTED:
     153            Quit();
     154            break;
     155        case MSG_FIND:
     156            SendFindMessage();
     157            break;
     158        case MSG_FIND_HIDE:
     159            Quit();
     160            break;
     161        default:
     162            BWindow::MessageReceived(msg);
     163            break;
     164    }
     165}
     166
     167void
    83168FindDlg::Quit (void)
    84169{
    85   BWindow::Quit ();
     170    fWindow->PostMessage(MSG_FIND_CLOSED);
     171    BWindow::Quit ();
    86172}
    87173
     174void
     175FindDlg::SendFindMessage (void)
     176{
     177    BMessage message(MSG_FIND);
     178
     179    //Add the search string
     180    message.AddString("findstring", fFindLabel->Text());
     181   
     182    //Add the other parameters
     183    message.AddBool("usetext", fTextRadio->Value() == B_CONTROL_ON);
     184    message.AddBool("forwardsearch", fForwardSearchBox->Value() == B_CONTROL_ON);
     185    message.AddBool("matchcase", fMatchCaseBox->Value() == B_CONTROL_ON);
     186    message.AddBool("matchword", fMatchWordBox->Value() == B_CONTROL_ON);
     187    message.AddBool("regexp", fRegexpBox->Value() == B_CONTROL_ON);
     188   
     189    fWindow->PostMessage(MSG_FIND);
     190}
  • src/apps/terminal/TermView.h

     
    184184  void  ScrollScreenDraw (void);
    185185  void  GetFrameSize (float *width, float *height);
    186186  void  GetFontInfo (int *, int*);
     187  bool  Find(const BString &str, bool forwardSearch, bool matchCase, bool matchWord, bool regexp);
    187188
    188189  /*
    189190   *    PRIVATE MEMBER.
  • src/apps/terminal/Constants.h

     
    1 /*Terminal: constants*/
    2 #ifndef CONSTANTS_H
    3 #define CONSTANTS_H
    4 
    5 #include <GraphicsDefs.h>
    6 #include <SupportDefs.h>
    7 
    8 #define APP_SIGNATURE  "application/x-vnd.obos.terminal"
    9 
    10 const float TEXT_INSET = 3.0;
    11 
    12 // Application messages
    13 
    14 const uint32 OPEN_TERMINAL              ='OTRM';
    15 
    16 // Messages for menu commands
    17 
    18 // Terminal
    19 const uint32 TERMINAL_SWITCH_TERMINAL   ='TSWT';
    20 const uint32 TERMINAL_START_NEW_TERMINAL='TSNT';
    21 const uint32 TERMINAL_LOG_TO_FILE       ='TLTF';
    22 // Edit
    23 const uint32 EDIT_WRITE_SELECTION       ='EWSL';
    24 const uint32 EDIT_CLEAR_ALL             ='ECLA';
    25 const uint32 EDIT_FIND                  ='EFND';
    26 const uint32 EDIT_FIND_BACKWARD         ='EFBK';
    27 const uint32 EDIT_FIND_FORWARD          ='EFFD';
    28 // Settings
    29 const uint32 SETTINGS_WINDOW_SIZE       ='SWSZ';
    30 const uint32 SETTINGS_FONT              ='SFNT';
    31 const uint32 SETTINGS_FONT_SIZE         ='SFSZ';
    32 const uint32 SETTINGS_FONT_ENCODING     ='SFEN';
    33 const uint32 SETTINGS_TAB_WIDTH         ='STBW';
    34 const uint32 SETTINGS_COLOR             ='SCLR';
    35 const uint32 SETTINGS_SAVE_AS_DEFAULT   ='SSAD';
    36 const uint32 SETTINGS_SAVE_AS_SETTINGS  ='SSAS';
    37 
    38 // Edit menu toggle
    39 const uint32 ENABLE_ITEMS               ='EDON';
    40 const uint32 DISABLE_ITEMS              ='EDOF';
    41 
    42 #endif // CONSTANTS_H