void ErrorPopUpScreen::Draw(float totalTime, float elapsedTime)
{
    UNREFERENCED_PARAMETER(totalTime);
    UNREFERENCED_PARAMETER(elapsedTime);

    auto screenManager = Manager();
    auto spriteBatch = screenManager->GetSpriteBatch();
    auto spriteFont = screenManager->GetSpriteFont();
    auto blendStates = screenManager->GetCommonStates();
    auto viewportBounds = screenManager->GetScreenBounds();
    float viewportWidth = float(viewportBounds.right);
    float viewportHeight = float(viewportBounds.bottom);
    auto scaleMatrix = DX::GetScaleMatrixForWindow(screenManager->GetWindowBounds());

    // calculate position and size of error message
    XMFLOAT2 errorMsgPosition = XMFLOAT2(0, viewportHeight / 2.0f);
    XMVECTORF32 errorMsgColor = Colors::Yellow;
    XMFLOAT2 origin = XMFLOAT2(0, spriteFont->GetLineSpacing() / 2.0f);
    XMVECTOR size = spriteFont->MeasureString(m_errorMessage.c_str());
    errorMsgPosition.x = viewportWidth / 2.0f - XMVectorGetX(size) / 2.0f;

    // create a rectangle representing the screen dimensions of the error message background rectangle
    long rectangleWidth = long(std::min(std::max(XMVectorGetX(size) + 100.0f, 600.0f), viewportWidth));
    long rectangleHeight = long(spriteFont->GetLineSpacing() * 6.0f);
    long rectangleLeft = long(viewportWidth / 2.0f) - (rectangleWidth / 2);
    long rectangleTop = long(errorMsgPosition.y + spriteFont->GetLineSpacing()) - (rectangleHeight / 2);
    RECT backgroundRectangle = { rectangleLeft, rectangleTop, rectangleLeft + rectangleWidth, rectangleTop + rectangleHeight };

    spriteBatch->Begin(SpriteSortMode_Deferred, blendStates->NonPremultiplied(), nullptr, nullptr, nullptr, nullptr, scaleMatrix);

    // draw a background color for the rectangle
    spriteBatch->Draw(m_backgroundTexture->GetResourceViewTemporary(), backgroundRectangle, BackgroundColor);

    // draw error message in the middle of the screen
    spriteFont->DrawString(spriteBatch.get(), m_errorMessage.c_str(), errorMsgPosition, errorMsgColor, 0, origin);

    // draw continuation prompt
    winrt::hstring continuePrompt = L"Press (A) to Continue";
    if (!InputState::IsAnyGamepadConnected())
    {
        continuePrompt = L"Press Enter to Continue";
    }
    errorMsgPosition.y += spriteFont->GetLineSpacing();
    size = spriteFont->MeasureString(continuePrompt.c_str());
    errorMsgPosition.x = viewportWidth / 2.0f - XMVectorGetX(size) / 2.0f;
    spriteFont->DrawString(spriteBatch.get(), continuePrompt.c_str(), errorMsgPosition, Colors::Yellow, 0, origin);

    spriteBatch->End();
}
Пример #2
0
// Equality test
bool wxTextAttr::operator== (const wxTextAttr& attr) const
{
    return  GetFlags() == attr.GetFlags() &&

            (!HasTextColour() || (GetTextColour() == attr.GetTextColour())) &&
            (!HasBackgroundColour() || (GetBackgroundColour() == attr.GetBackgroundColour())) &&

            (!HasAlignment() || (GetAlignment() == attr.GetAlignment())) &&
            (!HasLeftIndent() || (GetLeftIndent() == attr.GetLeftIndent() &&
                                  GetLeftSubIndent() == attr.GetLeftSubIndent())) &&
            (!HasRightIndent() || (GetRightIndent() == attr.GetRightIndent())) &&
            (!HasTabs() || (TabsEq(GetTabs(), attr.GetTabs()))) &&

            (!HasParagraphSpacingAfter() || (GetParagraphSpacingAfter() == attr.GetParagraphSpacingAfter())) &&
            (!HasParagraphSpacingBefore() || (GetParagraphSpacingBefore() == attr.GetParagraphSpacingBefore())) &&
            (!HasLineSpacing() || (GetLineSpacing() == attr.GetLineSpacing())) &&
            (!HasCharacterStyleName() || (GetCharacterStyleName() == attr.GetCharacterStyleName())) &&
            (!HasParagraphStyleName() || (GetParagraphStyleName() == attr.GetParagraphStyleName())) &&
            (!HasListStyleName() || (GetListStyleName() == attr.GetListStyleName())) &&

            (!HasBulletStyle() || (GetBulletStyle() == attr.GetBulletStyle())) &&
            (!HasBulletText() || (GetBulletText() == attr.GetBulletText())) &&
            (!HasBulletNumber() || (GetBulletNumber() == attr.GetBulletNumber())) &&
            (GetBulletFont() == attr.GetBulletFont()) &&
            (!HasBulletName() || (GetBulletName() == attr.GetBulletName())) &&

            (!HasTextEffects() || (GetTextEffects() == attr.GetTextEffects() &&
                                   GetTextEffectFlags() == attr.GetTextEffectFlags())) &&

            (!HasOutlineLevel() || (GetOutlineLevel() == attr.GetOutlineLevel())) &&

            (!HasFontSize() || (GetFontSize() == attr.GetFontSize())) &&
            (!HasFontItalic() || (GetFontStyle() == attr.GetFontStyle())) &&
            (!HasFontWeight() || (GetFontWeight() == attr.GetFontWeight())) &&
            (!HasFontUnderlined() || (GetFontUnderlined() == attr.GetFontUnderlined())) &&
            (!HasFontStrikethrough() || (GetFontStrikethrough() == attr.GetFontStrikethrough())) &&
            (!HasFontFaceName() || (GetFontFaceName() == attr.GetFontFaceName())) &&
            (!HasFontEncoding() || (GetFontEncoding() == attr.GetFontEncoding())) &&
            (!HasFontFamily() || (GetFontFamily() == attr.GetFontFamily())) &&

            (!HasURL() || (GetURL() == attr.GetURL()));
}
Пример #3
0
// Partial equality test taking flags into account
bool wxTextAttr::EqPartial(const wxTextAttr& attr, int flags) const
{
    if ((flags & wxTEXT_ATTR_TEXT_COLOUR) && GetTextColour() != attr.GetTextColour())
        return false;

    if ((flags & wxTEXT_ATTR_BACKGROUND_COLOUR) && GetBackgroundColour() != attr.GetBackgroundColour())
        return false;

    if ((flags & wxTEXT_ATTR_FONT_FACE) &&
        GetFontFaceName() != attr.GetFontFaceName())
        return false;

    if ((flags & wxTEXT_ATTR_FONT_SIZE) &&
        GetFontSize() != attr.GetFontSize())
        return false;

    if ((flags & wxTEXT_ATTR_FONT_WEIGHT) &&
        GetFontWeight() != attr.GetFontWeight())
        return false;

    if ((flags & wxTEXT_ATTR_FONT_ITALIC) &&
        GetFontStyle() != attr.GetFontStyle())
        return false;

    if ((flags & wxTEXT_ATTR_FONT_UNDERLINE) &&
        GetFontUnderlined() != attr.GetFontUnderlined())
        return false;

    if ((flags & wxTEXT_ATTR_FONT_ENCODING) &&
        GetFontEncoding() != attr.GetFontEncoding())
        return false;

    if ((flags & wxTEXT_ATTR_FONT_FAMILY) &&
        GetFontFamily() != attr.GetFontFamily())
        return false;

    if ((flags & wxTEXT_ATTR_URL) && GetURL() != attr.GetURL())
        return false;

    if ((flags & wxTEXT_ATTR_ALIGNMENT) && GetAlignment() != attr.GetAlignment())
        return false;

    if ((flags & wxTEXT_ATTR_LEFT_INDENT) &&
        ((GetLeftIndent() != attr.GetLeftIndent()) || (GetLeftSubIndent() != attr.GetLeftSubIndent())))
        return false;

    if ((flags & wxTEXT_ATTR_RIGHT_INDENT) &&
        (GetRightIndent() != attr.GetRightIndent()))
        return false;

    if ((flags & wxTEXT_ATTR_PARA_SPACING_AFTER) &&
        (GetParagraphSpacingAfter() != attr.GetParagraphSpacingAfter()))
        return false;

    if ((flags & wxTEXT_ATTR_PARA_SPACING_BEFORE) &&
        (GetParagraphSpacingBefore() != attr.GetParagraphSpacingBefore()))
        return false;

    if ((flags & wxTEXT_ATTR_LINE_SPACING) &&
        (GetLineSpacing() != attr.GetLineSpacing()))
        return false;

    if ((flags & wxTEXT_ATTR_CHARACTER_STYLE_NAME) &&
        (GetCharacterStyleName() != attr.GetCharacterStyleName()))
        return false;

    if ((flags & wxTEXT_ATTR_PARAGRAPH_STYLE_NAME) &&
        (GetParagraphStyleName() != attr.GetParagraphStyleName()))
        return false;

    if ((flags & wxTEXT_ATTR_LIST_STYLE_NAME) &&
        (GetListStyleName() != attr.GetListStyleName()))
        return false;

    if ((flags & wxTEXT_ATTR_BULLET_STYLE) &&
        (GetBulletStyle() != attr.GetBulletStyle()))
         return false;

    if ((flags & wxTEXT_ATTR_BULLET_NUMBER) &&
        (GetBulletNumber() != attr.GetBulletNumber()))
         return false;

    if ((flags & wxTEXT_ATTR_BULLET_TEXT) &&
        (GetBulletText() != attr.GetBulletText()) &&
        (GetBulletFont() != attr.GetBulletFont()))
         return false;

    if ((flags & wxTEXT_ATTR_BULLET_NAME) &&
        (GetBulletName() != attr.GetBulletName()))
         return false;

    if ((flags & wxTEXT_ATTR_TABS) &&
        !TabsEq(GetTabs(), attr.GetTabs()))
        return false;

    if ((flags & wxTEXT_ATTR_PAGE_BREAK) &&
        (HasPageBreak() != attr.HasPageBreak()))
         return false;

    if (flags & wxTEXT_ATTR_EFFECTS)
    {
        if (HasTextEffects() != attr.HasTextEffects())
            return false;
        if (!BitlistsEqPartial(GetTextEffects(), attr.GetTextEffects(), attr.GetTextEffectFlags()))
            return false;
    }

    if ((flags & wxTEXT_ATTR_OUTLINE_LEVEL) &&
        (GetOutlineLevel() != attr.GetOutlineLevel()))
         return false;

    return true;
}
Пример #4
0
// Partial equality test. Only returns false if an attribute doesn't match.
bool wxTextAttr::EqPartial(const wxTextAttr& attr, bool weakTest) const
{
    int flags = attr.GetFlags();

    if (!weakTest &&
        ((!HasTextColour() && attr.HasTextColour()) ||
         (!HasBackgroundColour() && attr.HasBackgroundColour()) ||
         (!HasFontFaceName() && attr.HasFontFaceName()) ||
         (!HasFontSize() && attr.HasFontSize()) ||
         (!HasFontWeight() && attr.HasFontWeight()) ||
         (!HasFontItalic() && attr.HasFontItalic()) ||
         (!HasFontUnderlined() && attr.HasFontUnderlined()) ||
         (!HasFontStrikethrough() && attr.HasFontStrikethrough()) ||
         (!HasFontEncoding() && attr.HasFontEncoding()) ||
         (!HasFontFamily() && attr.HasFontFamily()) ||
         (!HasURL() && attr.HasURL()) ||
         (!HasAlignment() && attr.HasAlignment()) ||
         (!HasLeftIndent() && attr.HasLeftIndent()) ||
         (!HasParagraphSpacingAfter() && attr.HasParagraphSpacingAfter()) ||
         (!HasParagraphSpacingBefore() && attr.HasParagraphSpacingBefore()) ||
         (!HasLineSpacing() && attr.HasLineSpacing()) ||
         (!HasCharacterStyleName() && attr.HasCharacterStyleName()) ||
         (!HasParagraphStyleName() && attr.HasParagraphStyleName()) ||
         (!HasListStyleName() && attr.HasListStyleName()) ||
         (!HasBulletStyle() && attr.HasBulletStyle()) ||
         (!HasBulletNumber() && attr.HasBulletNumber()) ||
         (!HasBulletText() && attr.HasBulletText()) ||
         (!HasBulletName() && attr.HasBulletName()) ||
         (!HasTabs() && attr.HasTabs()) ||
         (!HasTextEffects() && attr.HasTextEffects()) ||
         (!HasOutlineLevel() && attr.HasOutlineLevel())))
    {
        return false;
    }

    if (HasTextColour() && attr.HasTextColour() && GetTextColour() != attr.GetTextColour())
        return false;

    if (HasBackgroundColour() && attr.HasBackgroundColour() && GetBackgroundColour() != attr.GetBackgroundColour())
        return false;

    if (HasFontFaceName() && attr.HasFontFaceName() && GetFontFaceName() != attr.GetFontFaceName())
        return false;

    // This checks whether the two objects have the same font size dimension (px versus pt)
    if (HasFontSize() && attr.HasFontSize() && (flags & wxTEXT_ATTR_FONT) != (GetFlags() & wxTEXT_ATTR_FONT))
        return false;

    if (HasFontPointSize() && attr.HasFontPointSize() && GetFontSize() != attr.GetFontSize())
        return false;

    if (HasFontPixelSize() && attr.HasFontPixelSize() && GetFontSize() != attr.GetFontSize())
        return false;

    if (HasFontWeight() && attr.HasFontWeight() && GetFontWeight() != attr.GetFontWeight())
        return false;

    if (HasFontItalic() && attr.HasFontItalic() && GetFontStyle() != attr.GetFontStyle())
        return false;

    if (HasFontUnderlined() && attr.HasFontUnderlined() && GetFontUnderlined() != attr.GetFontUnderlined())
        return false;

    if (HasFontStrikethrough() && attr.HasFontStrikethrough() && GetFontStrikethrough() != attr.GetFontStrikethrough())
        return false;

    if (HasFontEncoding() && attr.HasFontEncoding() && GetFontEncoding() != attr.GetFontEncoding())
        return false;

    if (HasFontFamily() && attr.HasFontFamily() && GetFontFamily() != attr.GetFontFamily())
        return false;

    if (HasURL() && attr.HasURL() && GetURL() != attr.GetURL())
        return false;

    if (HasAlignment() && attr.HasAlignment() && GetAlignment() != attr.GetAlignment())
        return false;

    if (HasLeftIndent() && attr.HasLeftIndent() &&
        ((GetLeftIndent() != attr.GetLeftIndent()) || (GetLeftSubIndent() != attr.GetLeftSubIndent())))
        return false;

    if (HasRightIndent() && attr.HasRightIndent() && (GetRightIndent() != attr.GetRightIndent()))
        return false;

    if (HasParagraphSpacingAfter() && attr.HasParagraphSpacingAfter() &&
        (GetParagraphSpacingAfter() != attr.GetParagraphSpacingAfter()))
        return false;

    if (HasParagraphSpacingBefore() && attr.HasParagraphSpacingBefore() &&
        (GetParagraphSpacingBefore() != attr.GetParagraphSpacingBefore()))
        return false;

    if (HasLineSpacing() && attr.HasLineSpacing() && (GetLineSpacing() != attr.GetLineSpacing()))
        return false;

    if (HasCharacterStyleName() && attr.HasCharacterStyleName() && (GetCharacterStyleName() != attr.GetCharacterStyleName()))
        return false;

    if (HasParagraphStyleName() && attr.HasParagraphStyleName() && (GetParagraphStyleName() != attr.GetParagraphStyleName()))
        return false;

    if (HasListStyleName() && attr.HasListStyleName() && (GetListStyleName() != attr.GetListStyleName()))
        return false;

    if (HasBulletStyle() && attr.HasBulletStyle() && (GetBulletStyle() != attr.GetBulletStyle()))
         return false;

    if (HasBulletNumber() && attr.HasBulletNumber() && (GetBulletNumber() != attr.GetBulletNumber()))
         return false;

    if (HasBulletText() && attr.HasBulletText() &&
        (GetBulletText() != attr.GetBulletText()) &&
        (GetBulletFont() != attr.GetBulletFont()))
         return false;

    if (HasBulletName() && attr.HasBulletName() && (GetBulletName() != attr.GetBulletName()))
         return false;

    if (HasTabs() && attr.HasTabs() && !TabsEq(GetTabs(), attr.GetTabs()))
        return false;

    if ((HasPageBreak() != attr.HasPageBreak()))
         return false;

    if (HasTextEffects() && attr.HasTextEffects())
    {
        if (!BitlistsEqPartial(GetTextEffects(), attr.GetTextEffects(), attr.GetTextEffectFlags()))
            return false;
    }

    if (HasOutlineLevel() && attr.HasOutlineLevel() && (GetOutlineLevel() != attr.GetOutlineLevel()))
         return false;

    return true;
}
Пример #5
0
/****************************************************************************
    DoDragonMsg:
    Handle message used by dragon speech library.
****************************************************************************/
BOOL DoDragonMsg(PTERWND w, HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam, LRESULT *pResult)
{
    DWORD lresult=0;                                                                                                 
    BOOL result=true;
    int  SaveModified=TerArg.modified;
    bool debug=false;
    typedef struct _charrange
    {
     LONG cpMin;
     LONG cpMax;
    } CHARRANGE;

    switch (message) {
        case WM_CLEAR:        // delete selected text
        if (debug) OurPrintf("WM_CLEAR");
        {
           if (HilightType!=HILIGHT_OFF) TerDeleteBlock(hWnd,TRUE); 
           break;
        }  

        case WM_GETTEXTLENGTH:        // get text length in characters
        if (debug) OurPrintf("WM_GETTEXTLENGTH");
        {
           long len;
           HGLOBAL hMem;
           int SaveFormat=TerArg.SaveFormat;
           int SaveModified;

           if (True(GetWindowLong(hTerWnd,GWL_STYLE)&WS_CAPTION) && False(TerFlags6&TFLAG6_SUPPORT_DRAGON_SPEECH)) return false;

           if (hGetTextMem && GetTextLen>0 && GetTextMod==TerArg.modified) len=GetTextLen;  // data not changed use previous
           else {
              if (hGetTextMem) GlobalFree(hGetTextMem);  // release any previous get text mem data
               
              SaveModified=TerArg.modified;
              TerArg.SaveFormat=SAVE_TEXT;
              
              hMem=GetTerBuffer(hWnd,&len);
              
              TerArg.SaveFormat=SaveFormat;
              TerArg.modified=SaveModified;              // restore modificationall right tanks status

              if (hMem==0) len=0;

              hGetTextMem=hMem;    // save for quick access next time
              GetTextLen=len;
              GetTextMod=TerArg.modified;
           }

           lresult=len;
           break;
        }  
         
        case WM_GETTEXT:        // get all text
        if (debug) OurPrintf("WM_GETTEXT");
        {
           long len=0;
           LPBYTE pMem;
           HGLOBAL hMem=null;
           int SaveFormat=TerArg.SaveFormat;
           int SaveModified;

           if (True(GetWindowLong(hTerWnd,GWL_STYLE)&WS_CAPTION) && False(TerFlags6&TFLAG6_SUPPORT_DRAGON_SPEECH)) return false;

           if (hGetTextMem && GetTextLen>0 && GetTextMod==TerArg.modified) {  // data not changed use previous
              hMem=hGetTextMem;   // use previous data
              len=GetTextLen;
           } 
           else {
              if (hGetTextMem) GlobalFree(hGetTextMem);  // release any previous get text mem data
              
              SaveModified=TerArg.modified;
              TerArg.SaveFormat=SAVE_TEXT;

              hMem=GetTerBuffer(hWnd,&len);
              
              TerArg.SaveFormat=SaveFormat;
              TerArg.modified=SaveModified;              // restore modification status

              if (hMem==NULL) len=0;
              
              hGetTextMem=hMem;    // save for quick access next time
              GetTextLen=len;
              GetTextMod=TerArg.modified;
           }
           
           if (len>0 && hMem!=null) {            // copy text to output
              pMem=GlobalLock(hMem);
              if (len>(long)wParam) len=(long)wParam; // max to be copied
              FarMove(pMem,(LPBYTE)lParam,len);
              GlobalUnlock(hMem);
           }


           lresult=len;
           break;
        }  
         
        case EM_GETSELTEXT:     // get selected text
        if (debug) OurPrintf("EM_GETSELTEXT");
        {
           long len=0;
           LPBYTE pMem;
           HGLOBAL hMem=TerGetTextSel(hWnd,&len);

           if (hMem!=NULL) {
              pMem=GlobalLock(hMem);
           
              FarMove(pMem,(LPBYTE)lParam,len);
           
              GlobalUnlock(hMem);
              GlobalFree(hMem);
           }
           else len=0;
           
           lresult=len;
           break;
        }  
         
        case EM_GETTEXTRANGE:     // get the range of characters
        if (debug) OurPrintf("EM_GETTEXTRANGE");
        {
           TEXTRANGE *pRange=(LPVOID)lParam;
           long len=0;
           LPBYTE pMem;
           HGLOBAL hMem=null;
           long start=pRange->chrg.cpMin;
           long end=pRange->chrg.cpMax;
           long EndLine,BegLine;
           int  BegCol,EndCol;

           DrgAbsToRowCol(w,start,&BegLine,&BegCol);
           DrgAbsToRowCol(w,end,&EndLine,&EndCol);
           SelectTerText(hWnd,BegLine,BegCol,EndLine,EndCol,true);  // can't use absolute because we need to convert assuming cr/lf
           
           hMem=TerGetTextSel(hWnd,&len);
           DeselectTerText(hWnd,false);

           if (hMem!=NULL) {
              pMem=GlobalLock(hMem);
           
              FarMove(pMem,pRange->lpstrText,len);
           
              GlobalUnlock(hMem);
              GlobalFree(hMem);
           }
           else len=0;
           
           lresult=len;
           break;
        }  
         

        case EM_GETSEL:        // get selection begin and end (exclusive) positions
        if (debug) OurPrintf("EM_GETSEL");
        {
           long start=-1,end=-1;

           if (HilightType!=HILIGHT_OFF) {
              start=DrgRowColToAbs(w,HilightBegRow,HilightBegCol);
              end=DrgRowColToAbs(w,HilightEndRow,HilightEndCol);     // position after the selection
           } 
           else {
              start=end=DrgRowColToAbs(w,CurLine,CurCol);
           } 

           if (end<start) SwapInts(&start,&end);   // 20071124: swap so that reverse selection works for Dragon
           
           if (wParam)   *((LPLONG)(wParam))=start;
           if (lParam)   *((LPLONG)(lParam))=end;

           if (start>65535 || end>65535) lresult=(DWORD)(long)-1;
           else lresult=((end)<16)  | start;

           break;
        }  

        case EM_EXGETSEL:        // get selection begin and end (exclusive) positions
        if (debug) OurPrintf("EM_EXGETSEL");
        {
           long start=-1,end=-1;
           CHARRANGE *pRange=(LPVOID)lParam;

           if (HilightType!=HILIGHT_OFF) {
              start=DrgRowColToAbs(w,HilightBegRow,HilightBegCol);
              end=DrgRowColToAbs(w,HilightEndRow,HilightEndCol);     // position after the selection
           } 
           pRange->cpMin=start;
           pRange->cpMax=end;

           break;
        }  

        case EM_SETSEL:        // select text
        if (debug) OurPrintf("EM_SETSEL");
        {
           long start=(long)wParam;
           long end=(long)lParam;
           long EndLine,BegLine;
           int  EndCol,BegCol;

           if (start==-1) DeselectTerText(hWnd,TRUE);      // deselect any text
           else if (start==0 && end==-1) {
              SetTerCursorPos(hWnd,-1,0,false);
              TerCommand(hWnd,ID_SELECT_ALL);
           }
           else {
              // set cursor position
              DrgAbsToRowCol(w,end,&EndLine,&EndCol);
              SetTerCursorPos(hWnd,EndLine,EndCol,false);

              // select text
              if (start>end) SwapInts(&((int)start),&((int)end));
              
              DrgAbsToRowCol(w,start,&BegLine,&BegCol);
              DrgAbsToRowCol(w,end,&EndLine,&EndCol);
              SelectTerText(hWnd,BegLine,BegCol,EndLine,EndCol,true);  // can't use absolute because we need to convert assuming cr/lf
           }     

           break;
        }  

        case EM_EXSETSEL:        // select text
        if (debug) OurPrintf("EM_EXSETSEL");
        {
           CHARRANGE *pRange=(LPVOID)lParam;
           long start=pRange->cpMin;
           long end=pRange->cpMax;
           long EndLine,BegLine;
           int  EndCol,BegCol;

           if (start==-1) DeselectTerText(hWnd,TRUE);      // deselect any text
           else if (start==0 && end==-1) {
              SetTerCursorPos(hWnd,-1,0,false);
              TerCommand(hWnd,ID_SELECT_ALL);
           }
           else {
              // set cursor position
              DrgAbsToRowCol(w,end,&EndLine,&EndCol);
              SetTerCursorPos(hWnd,EndLine,EndCol,false);

              // select text
              if (start>end) SwapInts(&((int)start),&((int)end));
              DrgAbsToRowCol(w,start,&BegLine,&BegCol);
              DrgAbsToRowCol(w,end,&EndLine,&EndCol);
              SelectTerText(hWnd,BegLine,BegCol,EndLine,EndCol,true);  // can't use absolute because we need to convert assuming cr/lf
           }     

           break;
        }  


        case EM_REPLACESEL:        // delete selected text
        if (debug) OurPrintf("EM_REPLACESEL");
        {
           int GrpUndoRef=UndoRef;
           long BegPos=-1;
           
           if (HilightType!=HILIGHT_OFF) {
              BegPos=DrgRowColToAbs(w,HilightBegRow,HilightBegCol);  
              TerDeleteBlock(hWnd,false);   // deleted any selected text before inserting new text
           }
           
           UndoRef=GrpUndoRef;   // connect undo
           if (BegPos!=-1) DrgAbsToRowCol(w,BegPos,&CurLine,&CurCol);

           if (CanInsert(w,CurLine,CurCol)) InsertTerText(hWnd,(LPBYTE)lParam,TRUE);    // 20071113: use CanInsert() so that the etext is not inserted in the protected area

           if (False(wParam)) TerFlushUndo(hWnd);  // repl
           
           break;
        }  

        case EM_GETLINECOUNT:        // get number of lines in the control
        if (debug) OurPrintf("EM_GETLINECOUNT");
        {
           if (PageModifyCount!=TerArg.modified) TerRepaginate(hWnd,TRUE); // repaginate 
           lresult=TotalLines;
           break;
        }  

        case EM_GETFIRSTVISIBLELINE:        // get first visible line
        if (debug) OurPrintf("EM_GETFIRSTVISIBLELINE");
        {
           long line;
           int col;
           TerPixToTextPos(hWnd,REL_TEXT_BOX,0,0,&line,&col);
           lresult=line;
           break;
        }  

        case EM_LINEINDEX:              // get the character position of the first character of the specified line
        if (debug) OurPrintf("EM_LINEINDEX");
        {
           long pos;
           long line=(long)wParam;
           
           if (line<0) line=CurLine;

           if (line<TotalLines) pos=DrgRowColToAbs(w,line,0);
           else                 pos=-1;

           lresult=(DWORD)pos;
           break;
        }  

        case EM_LINEFROMCHAR:        // get line number for a character position
        if (debug) OurPrintf("EM_LINEFROMCHAR");
        {
           long pos=(int)wParam;
           long line;
           int  col;

           if (pos<0) {
              if (HilightType==HILIGHT_OFF) line=CurLine;
              else                          line=HilightBegRow;
           }
           else {
              DrgAbsToRowCol(w,pos,&line,&col);
           }  
           lresult=(DWORD)line;
           break;
        }  

        case EM_POSFROMCHAR:             // implement like Edit control
        if (debug) OurPrintf("EM_POSFROMCHAR");
        {
           long pos=(long)wParam,line;
           int x,y,col,SpcBef,SpcAft;

           if (pos<0) {
              line=CurLine;
              col=CurCol;
           }
           else DrgAbsToRowCol(w,pos,&line,&col);

           TerTextPosToPix(hWnd,REL_WINDOW,line,col,&x,&y);

           // add any paragraph space before
           GetLineSpacing(w,line,0,&SpcBef,&SpcAft,TRUE);
           y+=SpcBef;

           lresult=(((DWORD)y)<<16) | (DWORD)x;
           break;
        }  

        case EM_SETREADONLY:        // set/reset read-only mode.
        if (debug) OurPrintf("EM_SETREADONLY");
        {
           BOOL ReadOnly=(BOOL)wParam;
           TerSetReadOnly(hWnd,TRUE);
           lresult=1;               // successful result
           break;
        }  

        case EM_SETEVENTMASK:      // set event mask
        if (debug) OurPrintf("EM_SETEVENTMASK");
        {
           lresult=EventMask;      // return previous event mask

           EventMask=(DWORD)lParam; // set new
           break;
        }  

        case EM_GETEVENTMASK:      // get event mask
        if (debug) OurPrintf("EM_GETEVENTMASK");
        {
           lresult=EventMask;      // return event mask
           break;
        }  

        case EM_GETCHARFORMAT:
        if (debug) OurPrintf("EM_GETCHARFORMAT");
        {
           CHARFORMAT *pFmt=(LPVOID)lParam;
           int font=0;
           if (wParam==SCF_SELECTION) {
              if (HilightType==HILIGHT_OFF) font=GetCurCfmt(w,CurLine,CurCol);
              else                          font=GetCurCfmt(w,HilightBegRow,HilightBegCol);
           }
            
           if (pFmt->cbSize==sizeof(CHARFORMAT)) {
               pFmt->dwMask=0xFFFFFFFF;    // output all values
               pFmt->dwEffects=0;
               if (TerFont[font].style&BOLD)    pFmt->dwEffects|=CFE_BOLD;
               if (TerFont[font].style&ITALIC)  pFmt->dwEffects|=CFE_ITALIC;
               if (TerFont[font].style&PROTECT) pFmt->dwEffects|=CFE_PROTECTED;
               if (TerFont[font].style&STRIKE)  pFmt->dwEffects|=CFE_STRIKEOUT;
               if (TerFont[font].style&ULINE)   pFmt->dwEffects|=CFE_UNDERLINE;

               pFmt->yHeight=TerFont[font].TwipsSize;
               pFmt->yOffset=TerFont[font].offset;
               pFmt->crTextColor=TerFont[font].TextColor;
               pFmt->bCharSet=TerFont[font].CharSet;
               pFmt->bPitchAndFamily=TerFont[font].FontFamily;
               lstrcpy(pFmt->szFaceName,TerFont[font].TypeFace);
           } 
           else if (pFmt->cbSize==sizeof(CHARFORMAT2)) {
               CHARFORMAT2 *pFmt=(LPVOID)lParam;
            
               pFmt->dwMask=0xFFFFFFFF;    // output all values
               pFmt->dwEffects=0;
               if (TerFont[font].style&BOLD)    pFmt->dwEffects|=CFE_BOLD;
               if (TerFont[font].style&ITALIC)  pFmt->dwEffects|=CFE_ITALIC;
               if (TerFont[font].style&PROTECT) pFmt->dwEffects|=CFE_PROTECTED;
               if (TerFont[font].style&STRIKE)  pFmt->dwEffects|=CFE_STRIKEOUT;
               if (TerFont[font].style&ULINE)   pFmt->dwEffects|=CFE_UNDERLINE;
               if (TerFont[font].style&CAPS)    pFmt->dwEffects|=CFE_ALLCAPS;
               if (TerFont[font].style&HIDDEN)  pFmt->dwEffects|=CFE_HIDDEN;
               if (TerFont[font].style&SCAPS)   pFmt->dwEffects|=CFE_SMALLCAPS;
               if (TerFont[font].style&SUBSCR)  pFmt->dwEffects|=CFE_SUBSCRIPT;
               if (TerFont[font].style&SUPSCR)  pFmt->dwEffects|=CFE_SUPERSCRIPT;
               if (TerFont[font].FieldId==FIELD_HLINK) pFmt->dwEffects|=CFE_LINK;

               pFmt->yHeight=TerFont[font].TwipsSize;
               pFmt->yOffset=TerFont[font].offset;
               pFmt->crTextColor=TerFont[font].TextColor;
               pFmt->bCharSet=TerFont[font].CharSet;
               pFmt->bPitchAndFamily=TerFont[font].FontFamily;
               lstrcpy(pFmt->szFaceName,TerFont[font].TypeFace);

               pFmt->wWeight=(True(TerFont[font].style&BOLD))?700:400;
               pFmt->sSpacing=TerFont[font].expand;
               pFmt->lcid=TerFont[font].lang;
               pFmt->bUnderlineType=CFU_UNDERLINE;
               pFmt->bRevAuthor=(TerFont[font].DelRev)?TerFont[font].DelRev:TerFont[font].InsRev;

               pFmt->dwReserved=0;
               pFmt->sStyle=0;
               pFmt->wKerning=0;
               pFmt->bAnimation=0;
           } 
           
           break;
        }

        case EM_EMPTYUNDOBUFFER:   // flush undo buffer
        if (debug) OurPrintf("EM_EMPTYUNDOBUFFER");
        {
           TerFlushUndo(hWnd);
           break;
        }  
         
        default:
            lresult=(LRESULT)null;
            result=false;                    // not handled
    }
    
         
    (*pResult)=(LRESULT)lresult;

    if (TerArg.modified!=SaveModified) PostMessage(hTerWnd,TER_IDLE,0,0L);

    return result;
}