Click here to Skip to main content
Click here to Skip to main content
Go to top

Full Arabic User Interface GridCtrl

, 1 Feb 2003
Rate this:
Please Sign up or sign in to vote.
GridCtrl which works from right to left to serve Arabic language.

Introduction

I tried to use many grids of different types in Arabic mode but I failed, until I found GridCtrl with source. And then I worked to adapt it to work with Arabic mode in different types of Views or Dialogs.

/////////////////////////////////////////////////////////////////////////////
// Tarek Ahmed

// Disable inheritence of mirroring by children
#define WS_EX_NOINHERITLAYOUT   0x00100000L 
#define WS_EX_LAYOUT_RTL        0x00400000L
// Right to left mirroring
#define WS_EX_LAYOUTRTL         0x00400000L 
// Disable inheritence of mirroring by children 
#define WS_EX_NOINHERITLAYOUT   0x00100000L 
// Disable inheritence of mirroring by children
#define WS_EX_NOINHERIT_LAYOUT  0x00100000L 


BOOL CGridCtrl::Initialise()
{
..............
..............
..............

    if (::IsWindow(m_hWnd))
    {
        // Tarek Ahmed
        ModifyStyleEx(0, 0x00400000L, 0);
        ModifyStyleEx(0, WS_EX_RTLREADING, 0);
        ModifyStyleEx(0, WS_EX_RIGHT, 0);
        ModifyStyleEx(0, WS_EX_CLIENTEDGE, 0);
    }
..............
..............
..............
..............
    return TRUE;
}


// creates the control - use like any other window create control
BOOL CGridCtrl::Create(const RECT& rect, CWnd* pParentWnd, 
                       UINT nID, DWORD dwStyle)
{
..............
..............
..............

    DWORD dwExStyle;

    if ( bCreateOnView )
    {
        if (!CWnd::Create(GRIDCTRL_CLASSNAME, NULL, dwStyle, 
                                rect, pParentWnd, nID))
            return FALSE;

        Initialise();
    }
    else
    {
        // Tarek Ahmed
        dwExStyle ^= 0x00400000L;    
        dwExStyle ^= WS_EX_RTLREADING;
        dwExStyle ^= WS_EX_RIGHT;
        if (!CWnd::CreateEx(dwExStyle, GRIDCTRL_CLASSNAME, GRIDCTRL_CLASSNAME, 
                                 dwStyle, rect, pParentWnd, nID, NULL))
            return FALSE;
    }

..............
..............
..............

    return TRUE;
}

void CGridCtrl::OnTimer(UINT nIDEvent)
{
..............
..............
..............

    if (pt.y > rect.bottom)
    {
        //SendMessage(WM_VSCROLL, SB_LINEDOWN, 0); org code
        SendMessage(WM_KEYDOWN, VK_DOWN, 0);

        if (pt.x < rect.left)
            pt.x = rect.left;
        if (pt.x > rect.right)
            pt.x = rect.right;
        pt.y = rect.bottom;
        OnSelecting(GetCellFromPt(pt));
    }
    else if (pt.y < nFixedRowHeight)
    {
        //SendMessage(WM_VSCROLL, SB_LINEUP, 0);  org code
        SendMessage(WM_KEYDOWN, VK_UP, 0);

        if (pt.x < rect.left)
            pt.x = rect.left;
        if (pt.x > rect.right)
            pt.x = rect.right;
        pt.y = nFixedRowHeight + 1;
        OnSelecting(GetCellFromPt(pt));
    }

    pt = origPt;
    if (pt.x > rect.right)
    {
       // Tarek Ahmed
        // SendMessage(WM_HSCROLL, SB_LINERIGHT, 0);
        SendMessage(WM_KEYDOWN, VK_RIGHT, 0);

        if (pt.y < rect.top)
            pt.y = rect.top;
        if (pt.y > rect.bottom)
            pt.y = rect.bottom;
        pt.x = rect.right;
        OnSelecting(GetCellFromPt(pt));
    }
    else if (pt.x < nFixedColWidth)
    {
       // Tarek Ahmed
        //SendMessage(WM_HSCROLL, SB_LINELEFT, 0);
        SendMessage(WM_KEYDOWN, VK_LEFT, 0);

        if (pt.y < rect.top)
            pt.y = rect.top;
        if (pt.y > rect.bottom)
            pt.y = rect.bottom;
        pt.x = nFixedColWidth + 1;
        OnSelecting(GetCellFromPt(pt));
    }
..............
..............
..............
}

// move about with keyboard
void CGridCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
..............
..............
..............
        if (!IsCellVisible(next))
        {

            switch (nChar)
            {
            case VK_LEFT:  
                // Tarek Ahmed
                SendMessage(WM_HSCROLL, SB_LINERIGHT, 0); 
                bHorzScrollAction = TRUE;
                break;
                
            case VK_RIGHT:   
                // Tarek Ahmed
                SendMessage(WM_HSCROLL, SB_LINELEFT, 0);  
                bHorzScrollAction = TRUE;
                break;
                
        }

..............
..............
..............
}

Working with views:

void CSomeClassToWorkAsView::OnInitialUpdate() 
{
    CView::OnInitialUpdate();

    // TODO: Add your specialized code here and/or call the base class

    if (!m_InitOn)
    {
        // Create the Gridctrl window
        m_pGridCtrl = new CGridCtrl;
        if (!m_pGridCtrl) return;

        m_pGridCtrl->bCreateOnView = true;

        CRect rect;
        GetClientRect(rect);
        m_pGridCtrl->Create(rect, this, 1001);

        m_InitOn = true;
    }
    if (m_InitOn)
    {
        ReGetData();
    }
}

Working with cells' merge:

            for (col = 0; col < m_Grid.GetColumnCount(); col++)
            { 
                m_Grid.SetItemBkColour(iRowCur, col, RGB(165, 27, 30));
                m_Grid.SetItemFgColour(iRowCur, col, RGB(255, 255, 0));
            }
            m_Grid.SetSelectedRange(iRowCur, ID_QUTNAME, iRowCur, ID_SELX);
            m_Grid.MergeSelectedCells();

Initialize normal control:

#define ID_COL_COUNT        0
#define ID_COL_DOCNO        1
#define ID_COL_DAYCOUNT        2
#define ID_COL_TDATESTART    3
#define ID_COL_TDATEEND        4
#define ID_COL_UAMTCHARGE    5
#define ID_COL_UAMTMOVE        6
#define ID_COL_UAMTENTRY    7
#define ID_COL_UAMTOTHER    8
#define ID_COL_UAMTTOTAL    9
#define ID_COL_COSTCNTR        10
#define ID_COL_MEMO            11


    m_Grid.DeleteAllItems();
    UpdateWindow();
    m_Grid.GetDefaultCell(FALSE, FALSE)->SetBackClr(RGB(0xFF, 0xFF, 0xE0));
    m_Grid.SetFixedColumnSelection(false);
                m_Grid.SetFixedRowSelection(false);
    m_Grid.SetHeaderSort(TRUE);
    m_Grid.EnableColumnHide();
    m_Grid.SetColumnCount(12);

    m_Grid.SetRowCount(1);    

    m_Grid.SetAutoSizeStyle();

    m_Grid.SetCompareFunction(CGridCtrl::pfnCellNumericCompare);

    m_Grid.SetFixedRowCount(1);
    m_Grid.SetFixedColumnCount(1);

    GV_ITEM Item;
    
    Item.mask = GVIF_TEXT|GVIF_PARAM|GVIF_FORMAT;
    Item.nFormat = DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS;
    Item.nState = 0;
    Item.row = 0;
    Item.col = ID_COL_COUNT;
    Item.strText = "ã";
    m_Grid.SetItem(&Item);

    Item.row = 0;
    Item.col = ID_COL_DOCNO;
    Item.strText = "ÑÞã ÇáÃíÕÇá";
    m_Grid.SetItem(&Item);

    Item.row = 0;
    Item.col = ID_COL_DAYCOUNT;
    Item.strText = "ÚÏÏ ÇáÃíÇã";
    m_Grid.SetItem(&Item);

    Item.row = 0;
    Item.col = ID_COL_TDATESTART;
    Item.strText = "ÈÏÃ ãä         ";
    m_Grid.SetItem(&Item);

    Item.row = 0;
    Item.col = ID_COL_TDATEEND;
    Item.strText = "ÃäÊåÇÁ Ýì      ";
    m_Grid.SetItem(&Item);

    Item.row = 0;
    Item.col = ID_COL_UAMTCHARGE;
    Item.strText = "ÈÏá ÇáÓÝÑ";
    m_Grid.SetItem(&Item);

    Item.row = 0;
    Item.col = ID_COL_UAMTMOVE;
    Item.strText = "ã. ÅäÊÞÇá";
    m_Grid.SetItem(&Item);

    Item.row = 0;
    Item.col = ID_COL_UAMTENTRY;
    Item.strText = "ã. ÏÇÎáíÉ";
    m_Grid.SetItem(&Item);

    Item.row = 0;
    Item.col = ID_COL_UAMTOTHER;
    Item.strText = "ßíáæãÊÑ";
    m_Grid.SetItem(&Item);

    Item.row = 0;
    Item.col = ID_COL_UAMTTOTAL;
    Item.strText = "ÃÌãÇáì";
    m_Grid.SetItem(&Item);

    Item.row = 0;
    Item.col = ID_COL_COSTCNTR;
    Item.strText = "ãÑßÒ ÊßáÝÉ";
    m_Grid.SetItem(&Item);

    Item.row = 0;
    Item.col = ID_COL_MEMO;
    Item.strText = _T("ãáÇÍÙÇÊ                          ");
    m_Grid.SetItem(&Item);


    m_Grid.AutoSize();
    m_Grid.ExpandLastColumn();    
    m_Grid.SetEditable(true);
    m_Grid.SetRowResize(false);    


void CSomeClassToWork::SetRowColItem(int row)
{
    for (int col = 0; col < m_Grid.GetColumnCount(); col++)
    { 
        CString str;

        GV_ITEM Item;

        Item.mask = GVIF_TEXT|GVIF_PARAM|GVIF_FORMAT;
        Item.nFormat = DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS;
        Item.nState = 0;
        Item.row = row;
        Item.col = col;

        if ( col == ID_COL_COUNT )
        {
            CString sTemp;
            sTemp.Format("%d", row);
            Item.strText = sTemp;
        }

        if ( col == ID_COL_DOCNO ) 
            Item.strText = _T("");

        if ( col == ID_COL_DAYCOUNT ) 
            Item.strText = _T("00");

        if ( ( col >= ID_COL_COSTCNTR )  && ( col <= ID_COL_MEMO ) )
            Item.strText = _T("");

        if ( ( col >= ID_COL_UAMTCHARGE ) && ( col <= ID_COL_UAMTTOTAL ) ) 
            Item.strText = _T("0.00");


        if ( ( col >= ID_COL_TDATESTART ) && ( col <= ID_COL_TDATEEND ) )
            Item.strText = _T("  -  -    ");

        m_Grid.SetItem(&Item);

        m_Grid.SetItemState(row, col,
                m_Grid.GetItemState(row, col) & ~GVIS_READONLY);

        if ( col == ID_COL_DOCNO ) 
        {
            m_Grid.SetItemState(row, col, 
                  m_Grid.GetItemState(row, col) & ~GVIS_READONLY);

            if (!m_Grid.SetCellType(row, col, RUNTIME_CLASS(CGridCellNormal)))
                return;
        }

        if ( ( col >= ID_COL_COSTCNTR )  && ( col <= ID_COL_MEMO ) )
        {
            m_Grid.SetItemState(row, col, 
                   m_Grid.GetItemState(row, col) & ~GVIS_READONLY);

            if (!m_Grid.SetCellType(row, col, RUNTIME_CLASS(CGridCellNormal)))
                return;
        }

        if ( ( col >= ID_COL_TDATESTART ) && ( col <= ID_COL_TDATEEND ) )
        {
            if (!m_Grid.SetCellType(row, col, RUNTIME_CLASS(CGridCellDateTime)))
                return;

            CGridCellDateTime *pCell = 
                 (CGridCellDateTime*) m_Grid.GetCell(row, col);
            COleDateTime m_cTime;
            m_cTime = COleDateTime::GetCurrentTime();
            pCell->m_cTime = m_cTime;
            CString sTDate;
            sTDate = m_cTime.Format("%Y-%m-%d");
            m_Grid.SetItemText(row, col, sTDate);
        }
    }
    m_Grid.SetItemText(row, ID_COL_DOCNO        , sDocNo        );
    m_Grid.SetItemText(row, ID_COL_DAYCOUNT        , sDayCount        );
    m_Grid.SetItemText(row, ID_COL_TDATESTART    , sTDateStart    );
    m_Grid.SetItemText(row, ID_COL_TDATEEND        , sTDateEnd        );
    m_Grid.SetItemText(row, ID_COL_UAMTCHARGE    , suAmtTCharge    );
    m_Grid.SetItemText(row, ID_COL_UAMTMOVE        , suAmtTMove    );
    m_Grid.SetItemText(row, ID_COL_UAMTENTRY    , suAmtTEntry    );
    m_Grid.SetItemText(row, ID_COL_UAMTOTHER    , suAmtTOther    );
    m_Grid.SetItemText(row, ID_COL_UAMTTOTAL    , suAmtTTotal    );
    m_Grid.SetItemText(row, ID_COL_COSTCNTR        , sCostCnt        );
    m_Grid.SetItemText(row, ID_COL_MEMO            , sHMemo        );
}

Have fun!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Tarek Ahmed Abdel Rahmane
Software Developer Tatweer For Information Technology
Egypt Egypt
* Under Construct *

Comments and Discussions

 
GeneralPrint PinmemberBahman Tahayori27-Dec-05 1:05 
Questioncan you help me? Pinmember3loop27-Jun-05 22:48 
AnswerRe: can you help me? PinmemberTarek Ahmed Abdel Rahmane8-Aug-05 2:01 
Generalnice. Pinmemberzarzor5-May-05 8:05 
GeneralIsaac PinmemberIsaac_cm19-Dec-04 11:02 
Generalyour code doesn't work in VC7 Pinmemberhaoshenghan20-Apr-04 19:26 
GeneralVC++ Example PinmembervladFed31-Mar-03 2:47 
GeneralRe: VC++ Example Pinmemberwelo_200023-Apr-03 0:55 
GeneralRe: VC++ Example Pinmemberzizzzz29-Nov-06 22:18 
GeneralRe: VC++ Example Pinmemberzizzzz29-Nov-06 23:36 
GeneralSome suggestions PinmemberVictor Boctor2-Feb-03 19:00 
GeneralRe: Some suggestions PinmemberTarek Ahmed Mohamed Abdel Rahmane3-Feb-03 4:34 
GeneralRe: Some suggestions PinmemberPaolo Messina3-Feb-03 23:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 2 Feb 2003
Article Copyright 2003 by Tarek Ahmed Abdel Rahmane
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid