Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Objective Edit User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

6.5 Working with the Gutter

In Objective Edit version 6.x and later, the gutter is more customizable than it was in earlier versions. The gutter area is potentially divided into two regions, the index region and the mark region. In the index region, a zero-based line number for each text line is displayed; the mark region is comparable to the old gutter, where bookmarks, breakpoints, or other mark types are displayed. For backward compatibility, the default setting only displays the mark region. Use the SetGutterAlignment() function to customize the gutter display.


Section 6.5.6, "Methods Related to the Gutter," contains two reference tables that list all of the relevant gutter-related methods in the SECEditController and SECEditViewport classes.

SECEditController::SetGutterAlignment(UINT nAlign)

6.5.1 Customizing the Index Region

As described above, the SetGutterAlignment() function can be used with the following nAlign values to display the index area:

If you choose to make the index area visible, the following functions can be used to further customize the index region:

SECEditController::SetGutterIndexDigits(int nDigits)
SECEditController::SetGutterIndexWidth(int nWidth)
SECEditController::SetGutterIndexColor(COLORREF rgb)
SECEditController::GetGutterIndexFont()
SECEditController::UpdateGutterIndexFont()

6.5.1.1 Changing the Step Value and Format

The numbers on the gutter bar usually advance by one:

It is possible to change the step to any value, for example:

It is also possible to change the format of the numbers to:

Accomplish both of these tasks by overriding the same virtual function:

You can change the ''//PadZero'' routine to:

To override GetGutterIndexText() in an SECEditCtrl-derived class:

  1. Create a class derived from SECEditController. Let's call it CMyController.

  2. In the SECEditCtrl-derived class you can override the CreateController() function:

      BOOL CMySECEditCtrl::CreateController()
      {
        m_pCtlr = new CMyController;
        m_bAutoDelCtlr = TRUE;
      
        return (m_pCtlr != NULL);
        
      }
      
  3. Override GetGutterIndexText() in CMyController.

6.5.1.2 Allow Toggling Between Normal Gutter and Line Numbers

When overriding the DrawMarks() function, you need to keep track of the gutter width if you are going to resize it to draw other things.

If you want to allow the user to toggle between a normal gutter and line numbers, take a look at this sample code from the JEDPlus freeware application, which does just that:


Java is not one of the languages supported by Objective Edit. Support for C++, C#, HTML, XML, VB, VBScript, and JavaScript is standard. Other languages (including Java) require customization.

6.5.2 Changing the Width of the Gutter

SECEditController::SetGutterWidth(int nWidth)
SECEditController::GetGutterWidth()

6.5.3 Changing Gutter Painting

If you want to change the way the gutter paints, you'll need to reinitialize the gutter brush. Remember that the gutter is actually painted by the CBrush m_pGutterBrush. It is initialized in SECEditViewport::CreateGutterBrush() and it defaults to using a patterned brush using the IDB_SECEDIT_GUTTER bitmap resource. The overridden function can be added in your SECEditView-derived class.


Since CreateGutterBrush() is protected and not a virtual function, you will need to add a copy of OnCreate() in your View class as well.

Here is a example of how to use a custom defined IDB_CUSTOM_PATTERN bitmap to replace the default bitmap. We are using the SDI sample implementation for this demonstration:

6.5.4 Changing the Background Color of the Gutter Area

The background color for text appearing in the gutter area is not derived from the gutter text font. Instead, it is derived from the background color specified for the gutter area. To customize the gutter background color, override the SECEditViewport::RenderGutter() method.

SECEditViewport::RenderGutter()

The following code segment is taken from the Gutter sample project. It demonstrates how to change the gutter background color by overriding the RenderGutter() method. Figure 20 shows the result of the following code, which specifies a white background and draws a line down the right side of the gutter area.

Figure 20: Index Region on Left of Gutter and Mark Region (with Breakpoints) on Right

6.5.5 Drawing Custom Breakpoints and Bookmarks

Figure 21 shows how to identify the default appearance of breakpoints and bookmarks.

Figure 21: Breakpoints (circles) and Bookmarks (rounded rectangles) in the Gutter

When it comes to drawing the gutter (and items in the gutter), the SECEditViewport methods involved include:

DrawGutter()
DrawMarks()

Table 5 defines the arguments associated with the DrawMarks() method.

Table 5: Arguments for SECEditViewport::DrawMarks() and Related Methods

Argument Purpose
nLine The line index for which to draw the marks.
pDC A pointer to an SECMemDC that is a wrapper for a back buffer DC. (The Device Context on which to draw the marks.)
rcMark The CRect in which we should render the mark.

By default, DrawMarks() calls the following functions in this order:

PreDrawMarks()
DrawBookmark()
DrawBreakpoint()
PostDrawMarks()

Figure 22 summarizes the SECEditViewport methods involved in drawing the gutter and gutter objects.

Figure 22: How the Gutter Gets Drawn

6.5.5.1 Implementing Three Breakpoint States

Ordinarily you can toggle the breakpoint and clear it. In some cases you might want a third state—deactivating it.

You can set three states (even more in fact) for a break point. To implement three state breakpoints (no breakpoint, breakpoint set, breakpoint set but not active), use another DataFlag value (other than 16 - 18) to define a new data flag. Once you check the breakpoint status, check both flags. With the combination of two booleans, you can have four states from which to choose.

To place a proper indicator in the gutter on the left side of SECEditView-derived views (where the bookmarks and breakpoints indicators appear), define your own Data Item Flag type (with a value 0-15) and override SECEditViewport::DrawMarks(). For example,

  1. Define the bookmark:

      #define ID_ITEMDATA_MYMARK  // needs an int value
      
  2. Override DrawMarks():

      void CMyViewport::DrawMarks(int nLine, CDC* pDC, const CRect& rcMark) const
      {
        // called before gutter items are drawn
        PreDrawMarks(nLine, pDC, rcMark); 
        
        // draws bookmark in gutter
        DrawBookmark(nLine, pDC, rcMark); 
        
        //draws breakpoint in the gutter
        DrawBreakpoint(nLine, pDC, rcMark); 
        
        DrawMyMark(nLine, pDC, rcMark);
        
        // called after gutter items have been drawn
        PostDrawMarks(nLine, pDC, rcMark);
      }
      
  3. Add a function implementation for DrawMyMark().

  4. From then on, you can add this new mark to any line by calling:

      SECEdit::SetItemDataFlag(int nLine, unsigned int nFlag, BOOL bAdd);
      

6.5.5.2 Inserting Bookmarks vs. Marking Found Text

Suppose that by pressing <Ctrl>+<F2> you can insert a bookmark into a file and by choosing Mark All in the Find in Files dialog, you can mark all occurrences of the given text. The problem is that both procedures set the line flag to ID_SECEDIT_ITEMDATA_BOOKMARK.

You can customize this to enable differentiating between inserting bookmarks and marking found text occurrences.

  1. Register new resource, say ID_SECEDIT_ITEMDATA_MULTIFIND.

  2. Override virtualBOOL SECEditController::OnMarkAll(_SEC_FIND_REPLACE_STATE* pState), replacing ID_SECEDIT_ITEMDATA_BOOKMARK with ID_SECEDIT_ITEMDATA_MULTIFIND in call pEdit->SetItemDataFlag(nResultLine, ID_SECEDIT_ITEMDATA_BOOKMARK, TRUE);

  3. Override virtual void SECEditViewport::DrawBookmark(int nLine, CDC* pDC, CRect rcMark) const, replacing resource ID and action. For instance, you can change the color of bookmarks.

6.5.6 Methods Related to the Gutter

Table 6 and Table 7 provide a handy reference for functions that can be used to manipulate the gutter. For additional information about these methods, please refer to the Objective Edit Class Reference.

Table 6: SECEditController Methods Related to the Gutter

Method Definition
SetGutterAlignment() Sets the gutter format according to the nAlign value (e.g. mark region only, index only, or both).
GetGutterAlignment() Retrieves the alignment style for the mark and index regions of the gutter.
SetGutterWidth() Sets the width of the gutter's mark region (in pixels). The mark region is where bookmarks and breakpoints are displayed.
GetGutterWidth() Returns the width (in logical units) of the gutter on the left side of the viewport.
GetGutterMarkWidth() Retrieves the width of the mark region of the gutter (in pixels). The mark region is where breakpoints and bookmarks are displayed.
SetGutterIndexWidth() Sets the index region of the gutter (in pixels). The index region is where line numbers are displayed.
GetGutterIndexWidth() Retrieves the index region of the gutter (in pixels). The index region is where line numbers are displayed. The value -1 indicates that the width is being managed automatically.
SetGutterIndexDigits() Sets the number of numerical digits the index area of the gutter can display. A value of -1 indicates that this number will be managed automatically.
GetGutterIndexDigits() Retrieves the number of numerical digits the index area of the gutter can display.
SetGutterIndexColor() Sets the index text color.
GetGutterIndexColor() Retrieves the index text color.
GetGutterIndexFont() Returns a pointer to the SECEditFontInfo object, which defines font information for the index region.
UpdateGutterIndexFont() This function must be called to update the font for the gutter region after making changes to the m_pGutterIndexFont member.
GetGutterIndexText() Retrieves the number displayed in the index area of gutter as text.

Table 7: SECEditViewport Methods Related to the Gutter

Method Definition
CreateGutterBrush() Sets up the gutter bitmap.
GetGutterBrush() Retrieves the brush used to paint the gutter.
DrawGutter() Draws the gutter area to the left of the editing window and then calls the DrawMarks() function to draw any marks that may be in the gutter.
RenderGutter() Fills the background of the gutter area.
DrawMarks() Is called to draw any items in the gutter (such as breakpoints). The default implementation calls the next four functions in the order they appear.
PreDrawMarks() Is called before any items in the gutter (such as breakpoints) are drawn.
DrawBookmark() Draws a bookmark in the gutter for lines that have a bookmark.
DrawBreakpoint() Draws a breakpoint in the gutter for lines that have a breakpoint.
PostDrawMarks() Is called after the predefined items in the gutter (such as breakpoints) are drawn.


Previous fileTop of DocumentContentsNo linkNext file

Copyright © Rogue Wave Software, Inc. All Rights Reserved.

The Rogue Wave name and logo, and Stingray, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.