Click here to Skip to main content
5,788,212 members and growing! (18,835 online)
Email Password   helpLost your password?
Desktop Development » Miscellaneous » Grid Control     Advanced

Full Arabic User Interface GridCtrl

By Tarek Ahmed Abdel Rahmane

GridCtrl which works from right to left to serve Arabic language.
VC6, C++Windows, Win2K, WinXP, MFC, VS6, Visual Studio, Dev

Posted: 1 Feb 2003
Updated: 1 Feb 2003
Views: 51,853
Bookmarked: 13 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
25 votes for this Article.
Popularity: 4.80 Rating: 3.43 out of 5
7 votes, 28.0%
1
1 vote, 4.0%
2
0 votes, 0.0%
3
2 votes, 8.0%
4
15 votes, 60.0%
5

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

About the Author

Tarek Ahmed Abdel Rahmane


* Under Construct *
Occupation: Software Developer
Company: Tatweer For Information Technology
Location: Egypt Egypt

Other popular Miscellaneous articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 13 of 13 (Total in Forum: 13) (Refresh)FirstPrevNext
GeneralPrintmemberBahman Tahayori2:05 27 Dec '05  
Generalcan you help me?member3loop23:48 27 Jun '05  
GeneralRe: can you help me?memberTarek Ahmed Abdel Rahmane3:01 8 Aug '05  
Generalnice.memberzarzor9:05 5 May '05  
GeneralIsaacmemberIsaac_cm12:02 19 Dec '04  
Generalyour code doesn't work in VC7memberhaoshenghan20:26 20 Apr '04  
GeneralVC++ ExamplemembervladFed3:47 31 Mar '03  
GeneralRe: VC++ Examplememberwelo_20001:55 23 Apr '03  
GeneralRe: VC++ Examplememberzizzzz23:18 29 Nov '06  
GeneralRe: VC++ Examplememberzizzzz0:36 30 Nov '06  
GeneralSome suggestionsmemberVictor Boctor20:00 2 Feb '03  
GeneralRe: Some suggestionsmemberTarek Ahmed Mohamed Abdel Rahmane5:34 3 Feb '03  
GeneralRe: Some suggestionsmemberPaolo Messina0:43 4 Feb '03  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 1 Feb 2003
Editor: Sumalatha K.R.
Copyright 2003 by Tarek Ahmed Abdel Rahmane
Everything else Copyright © CodeProject, 1999-2009
Web11 | Advertise on the Code Project