home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / odctrl.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  17.1 KB  |  626 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. //
  20. //    This file contains the implementation of 
  21. //        CODNetscapeButton
  22. //        CODMochaListBox
  23. //        CODMochaComboBox
  24. //
  25. //    Why we need the ownerdrawn version ?
  26. //    1. So we could display UTF8 widget
  27. //    2. So we coudl use Unicode Font on US Win95 to display non-Latin 
  28. //        characters.
  29.  
  30.  
  31.  
  32. //    Requried include file
  33. #include "stdafx.h"
  34.  
  35. #include "odctrl.h"
  36. #include "intlwin.h"
  37. #include "intl_csi.h"
  38.  
  39.  
  40. //////////////////////////////////////////////////////////////////////////
  41. //
  42. //    CODNetscapeButton
  43. //
  44. //////////////////////////////////////////////////////////////////////////
  45.  
  46. CODNetscapeButton::CODNetscapeButton(MWContext * context, LO_FormElementStruct * form, CWnd* pParent) :
  47.     CNetscapeButton(context, form, pParent)
  48. {
  49. }
  50.  
  51. void CODNetscapeButton::Draw3DBox(CDC *pDC, CRect& r, BOOL selected)
  52. {
  53.  
  54.     // fill out the rectangle wiht background brush
  55.     CBrush* pBrush = new CBrush ( ::GetSysColor (COLOR_BTNFACE));
  56.  
  57.     pDC->FillRect (r, pBrush);
  58.     delete pBrush;
  59.  
  60.     // decide which color we should use to draw the four edges
  61.     COLORREF color1, color2, color3, color4;
  62.  
  63. #ifdef XP_WIN32
  64.     if(selected)
  65.     {
  66.         color1 = ::GetSysColor(COLOR_3DHILIGHT);
  67.         color2 = ::GetSysColor(COLOR_3DLIGHT);
  68.         color3 = ::GetSysColor(COLOR_3DDKSHADOW);
  69.         color4 = ::GetSysColor(COLOR_3DSHADOW);
  70.     }
  71.     else
  72.     {
  73.         color1 = ::GetSysColor(COLOR_3DDKSHADOW);
  74.         color2 = ::GetSysColor(COLOR_3DSHADOW);
  75.         color3 = ::GetSysColor(COLOR_3DHILIGHT);
  76.         color4 = ::GetSysColor(COLOR_3DLIGHT);
  77.     }
  78. #else
  79.     if(selected)
  80.     {
  81.         color1 = ::GetSysColor(COLOR_BTNHIGHLIGHT);
  82.         color2 = ::GetSysColor(COLOR_BTNHIGHLIGHT);
  83.         color3 = ::GetSysColor(COLOR_BTNSHADOW);
  84.         color4 = ::GetSysColor(COLOR_BTNSHADOW);
  85.     }
  86.     else
  87.     {
  88.         color1 = ::GetSysColor(COLOR_BTNSHADOW);
  89.         color2 = ::GetSysColor(COLOR_BTNSHADOW);
  90.         color3 = ::GetSysColor(COLOR_BTNHIGHLIGHT);
  91.         color4 = ::GetSysColor(COLOR_BTNHIGHLIGHT);
  92.     }
  93. #endif
  94.  
  95.     // 3. create pen and draw them
  96.     CPen* pPen1 = new CPen( PS_SOLID, 0, color1);
  97.     CPen* pOldpen = pDC->SelectObject(pPen1);
  98.  
  99.     POINT seg1[3];
  100.     seg1[0].x = r.left; 
  101.     seg1[0].y = r.bottom-1;
  102.     seg1[1].x = r.right-1;
  103.     seg1[1].y = r.bottom-1;
  104.     seg1[2].x = r.right-1;
  105.     seg1[2].y = r.top;
  106.     pDC->Polyline(seg1, 3);
  107.  
  108.     CPen* pPen2 = new CPen( PS_SOLID, 0, color2);
  109.     pDC->SelectObject(pPen2);
  110.     
  111.     delete pPen1;
  112.  
  113.     POINT seg2[3];
  114.     seg2[0].x =    r.left+1;
  115.     seg2[0].y =    r.bottom-2;
  116.     seg2[1].x =    r.right-2;
  117.     seg2[1].y =    r.bottom-2; 
  118.     seg2[2].x =    r.right-2;
  119.     seg2[2].y =    r.top;
  120.     pDC->Polyline(seg2, 3);
  121.  
  122.     CPen* pPen3 = new CPen( PS_SOLID, 0, color3);
  123.     pDC->SelectObject(pPen3);
  124.     delete pPen2;
  125.  
  126.     POINT seg3[3];
  127.     seg3[0].x =    r.left;    
  128.     seg3[0].y =    r.bottom-2; 
  129.     seg3[1].x =    r.left;
  130.     seg3[1].y =    r.top; 
  131.     seg3[2].x =    r.right-1;
  132.     seg3[2].y =    r.top;
  133.     pDC->Polyline(seg3, 3);
  134.  
  135.     CPen* pPen4 = new CPen( PS_SOLID, 0, color4);
  136.     pDC->SelectObject(pPen4);
  137.     delete pPen3;
  138.  
  139.     POINT seg4[3]; 
  140.     seg4[0].x =    r.left+1;
  141.     seg4[0].y =    r.bottom-3; 
  142.     seg4[1].x =    r.left+1;
  143.     seg4[1].y =    r.top+1; 
  144.     seg4[2].x =    r.right-2;
  145.     seg4[2].y =    r.top+1;
  146.     pDC->Polyline(seg4, 3);
  147.  
  148.     pDC->SelectObject(pOldpen);
  149.     delete pPen4;
  150. }
  151. void CODNetscapeButton::DrawCenterText(CDC *pDC, LPCSTR text, CRect& r)
  152. {
  153.     CSize size;
  154.     int16 wincsid = INTL_GetCSIWinCSID(LO_GetDocumentCharacterSetInfo(m_Context));
  155.  
  156.     LO_TextAttr *text_attr = m_Form->text_attr;
  157.  
  158.     //    Measure what the size of the button should be.
  159.     CyaFont    *pMyFont;
  160.     CXDC(m_Context)->SelectNetscapeFont( pDC->GetSafeHdc(), text_attr, pMyFont );
  161.     // pMyFont->PrepareDrawText(pDC->GetSafeHdc());
  162.  
  163.     CIntlWin::GetTextExtentPointWithCyaFont(pMyFont, wincsid, 
  164.         pDC->GetSafeHdc(), text, XP_STRLEN(text), &size);
  165.  
  166.     CIntlWin::TextOutWithCyaFont(pMyFont, wincsid, pDC->GetSafeHdc(), 
  167.         (r.right + r.left - size.cx) / 2 , 
  168.         (r.top + r.bottom - size.cy) / 2 , 
  169.         text, XP_STRLEN(text));
  170.  
  171.     // pMyFont->EndDrawText( pDC->GetSafeHdc( ));
  172.     CXDC(m_Context)->ReleaseNetscapeFont( pDC->GetSafeHdc(), pMyFont );
  173.  
  174. }
  175. void CODNetscapeButton::DrawContent(CDC *pDC, LPDRAWITEMSTRUCT lpdis)
  176. {
  177.  
  178.     CString text;
  179.     int16 win_csid = INTL_GetCSIWinCSID(LO_GetDocumentCharacterSetInfo(m_Context));
  180.  
  181.     if (CS_UTF8 == win_csid)
  182.     {
  183.         // UTF8 text is broken inside MFC or WINAPI.
  184.         // We need to use original data in form.
  185.         // We should maybe only use this part (not call MFC get a window text).
  186.         // This should be reviewed again for Gromit.
  187.         LO_FormElementStruct* elm = GetElement();
  188.         lo_FormElementMinimalData ele_minimal = elm->element_data->ele_minimal;
  189.         char *cp = (char *) (ele_minimal.value);
  190.         text = CString(cp);
  191.     }
  192.     else
  193.     {
  194.         GetWindowText(text);
  195.     }
  196.  
  197.     // set the mode to TRANSPARENT
  198.     pDC->SetBkMode(TRANSPARENT);
  199.  
  200.     // If it is disabled, draw a ghost one first.
  201.     if(lpdis->itemState & ODS_DISABLED)
  202.     {
  203. #ifdef XP_WIN32
  204.         pDC->SetTextColor(::GetSysColor(COLOR_3DLIGHT));
  205. #else
  206.         // *** Fix me ftang
  207.         pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
  208. #endif
  209.  
  210.         CRect ghostRect = lpdis->rcItem;
  211.         ghostRect.OffsetRect(1,1);
  212.  
  213.         this->DrawCenterText(pDC, (LPCSTR)text, ghostRect);
  214.  
  215.         pDC->SetTextColor(::GetSysColor(COLOR_GRAYTEXT));
  216.     }
  217.     else
  218.     {
  219.         pDC->SetTextColor(::GetSysColor(COLOR_BTNTEXT));
  220.     }
  221.  
  222.     // Find teh rect that we should draw the text
  223.     CRect textrect = lpdis->rcItem;
  224.     if(lpdis->itemState & ODS_SELECTED)
  225.         textrect.OffsetRect(1,1);
  226.  
  227.     // Draw the text
  228.     this->DrawCenterText(pDC, (LPCSTR)text, textrect);
  229.  
  230.     // Draw focus box
  231.     if( (lpdis->itemState & ODS_FOCUS) && 
  232.         !(lpdis->itemState & ODS_DISABLED))
  233.     {
  234.         CRect rect = lpdis->rcItem;
  235.         rect.InflateRect(-3, -3);
  236.         pDC->DrawFocusRect(rect);
  237.     }
  238. }
  239.  
  240. void CODNetscapeButton::DrawItem(LPDRAWITEMSTRUCT lpdis)
  241. {
  242.     CDC dc;
  243.     dc.Attach (lpdis->hDC);
  244.     CRect rect = lpdis->rcItem;
  245.  
  246.     this->Draw3DBox(&dc, rect, (lpdis->itemState & ODS_SELECTED));
  247.     this->DrawContent(&dc, lpdis);
  248.  
  249.     dc.Detach();    
  250. }
  251. //////////////////////////////////////////////////////////////////////////
  252. //
  253. //    CODMochaListBox
  254. //
  255. //////////////////////////////////////////////////////////////////////////
  256. // Helper routine used shared by list box and combo box code
  257. static void
  258. DrawTheItem(LPDRAWITEMSTRUCT lpdis, int16 wincsid, LO_TextAttr* text_attr, MWContext* m_Context)
  259. {
  260. #ifdef _WIN32
  261.     ::FillRect(lpdis->hDC, &lpdis->rcItem, lpdis->itemState & ODS_SELECTED ?
  262.         (HBRUSH)(COLOR_HIGHLIGHT + 1) : (HBRUSH)(COLOR_WINDOW + 1));
  263. #else
  264.     HBRUSH    hBrush;
  265.      
  266.     // Paint the item background
  267.     hBrush = ::CreateSolidBrush(::GetSysColor(lpdis->itemState & ODS_SELECTED ?
  268.         COLOR_HIGHLIGHT : COLOR_WINDOW));
  269.     ::FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
  270.     ::DeleteObject(hBrush);
  271. #endif
  272.  
  273.     //    Measure what the size of the button should be.
  274.     if (lpdis->itemID != (UINT)-1) {
  275.         CyaFont    *pMyFont;
  276.         CXDC(m_Context)->SelectNetscapeFont( lpdis->hDC, text_attr, pMyFont );
  277.         //pMyFont->PrepareDrawText(lpdis->hDC);
  278.     
  279.         ::SetTextColor(lpdis->hDC, ::GetSysColor(lpdis->itemState & ODS_SELECTED ?
  280.             COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT));
  281.         ::SetBkColor(lpdis->hDC, ::GetSysColor(lpdis->itemState & ODS_SELECTED ? 
  282.             COLOR_HIGHLIGHT : COLOR_WINDOW ));
  283.  
  284.         CIntlWin::TextOutWithCyaFont(pMyFont, wincsid, lpdis->hDC, 
  285.             2 + lpdis->rcItem.left, lpdis->rcItem.top,
  286.             (LPCSTR)lpdis->itemData, XP_STRLEN((char*)lpdis->itemData));
  287.  
  288.         //pMyFont->EndDrawText(lpdis->hDC);
  289.         CXDC(m_Context)->ReleaseNetscapeFont( lpdis->hDC, pMyFont );
  290.     }
  291.     
  292.     if (lpdis->itemState & ODS_FOCUS)
  293.         ::DrawFocusRect(lpdis->hDC, &lpdis->rcItem);
  294. }
  295.  
  296. void CODMochaListBox::MeasureItem(LPMEASUREITEMSTRUCT lpmis)
  297. {
  298.     CyaFont    *pMyFont;
  299.     CDC *pDC = GetDC();
  300.     HDC hDC = pDC->GetSafeHdc();
  301.     CXDC(m_Context)->SelectNetscapeFont( hDC, m_Form->text_attr, pMyFont );
  302.     lpmis->itemHeight = pMyFont->GetHeight();
  303.  
  304.     CXDC(m_Context)->ReleaseNetscapeFont( hDC, pMyFont );
  305.     ReleaseDC(pDC);
  306. }
  307.  
  308. void CODMochaListBox::DrawItem(LPDRAWITEMSTRUCT lpdis)
  309. {
  310.     LO_LockLayout();
  311.     INTL_CharSetInfo csi = LO_GetDocumentCharacterSetInfo(m_Context);
  312.     DrawTheItem(lpdis, INTL_GetCSIWinCSID(csi), m_Form->text_attr, m_Context);
  313.     LO_UnlockLayout();
  314. }
  315.  
  316. //////////////////////////////////////////////////////////////////////////
  317. //
  318. //    CODMochaComboBox
  319. //
  320. //////////////////////////////////////////////////////////////////////////
  321.  
  322. void CODMochaComboBox::MeasureItem(LPMEASUREITEMSTRUCT lpmis)
  323. {
  324.     CyaFont    *pMyFont;
  325.     CDC *pDC = GetDC();
  326.     CXDC(m_Context)->SelectNetscapeFont( pDC->GetSafeHdc(), m_Form->text_attr, pMyFont );
  327.     lpmis->itemHeight = pMyFont->GetHeight();
  328.  
  329.  
  330.     CXDC(m_Context)->ReleaseNetscapeFont( pDC->GetSafeHdc(), pMyFont );
  331.     ReleaseDC(pDC);
  332.  
  333. }
  334.  
  335. void CODMochaComboBox::DrawItem(LPDRAWITEMSTRUCT lpdis)
  336. {
  337.     LO_LockLayout();
  338.     INTL_CharSetInfo csi = LO_GetDocumentCharacterSetInfo(m_Context);
  339.     DrawTheItem(lpdis, INTL_GetCSIWinCSID(csi), m_Form->text_attr, m_Context);
  340.     LO_UnlockLayout();
  341. }
  342.  
  343.  
  344. //////////////////////////////////////////////////////////////////////////
  345. //
  346. //    CUTF8NetscapeEdit
  347. //
  348. //////////////////////////////////////////////////////////////////////////
  349. #define ResizeBuffer(b,l,nl)    \
  350.     if((nl) > (l))    {            \
  351.         (b) = ((b) == NULL) ? ((unsigned char*) malloc(      ((l)=(((nl) < 512) ? 512 : (nl)))))    \
  352.                             : ((unsigned char*) realloc((b), ((l)=(((nl) < 512) ? 512 : (nl)))));    \
  353.     }
  354.  
  355.  
  356.  
  357.  
  358. CODNetscapeEdit::CODNetscapeEdit()
  359. {
  360.     m_set_text_wincsid = 0;
  361.     m_convertedBufSize = m_ucs2BufSize = m_gettextBufSize = 0;
  362.     m_ucs2Buf = m_convertedBuf = m_gettextBuf = NULL;
  363. }
  364. CODNetscapeEdit::~CODNetscapeEdit()
  365. {
  366.     if(m_convertedBuf != NULL)
  367.     {
  368.         free(m_convertedBuf);
  369.         m_convertedBuf = NULL;
  370.         m_convertedBufSize = 0;
  371.     }
  372.     if(m_ucs2Buf != NULL)
  373.     {
  374.         free(m_ucs2Buf);
  375.         m_ucs2Buf=NULL;
  376.         m_ucs2BufSize = 0;
  377.     }
  378.     if(m_gettextBuf != NULL)
  379.     {
  380.         free(m_gettextBuf);
  381.         m_gettextBuf=NULL;
  382.         m_gettextBufSize = 0;
  383.     }
  384. }
  385.  
  386.  
  387. void    
  388. CODNetscapeEdit::GetWindowText(CString& rString)
  389. {
  390.  
  391.     if( (CIntlWin::UseUnicodeFontAPI(GetSetWindowTextCSID())) || 
  392.         (sysInfo.m_bWinNT))
  393.     {
  394.         int nLen = GetWindowTextLength();
  395.         GetWindowText (rString.GetBufferSetLength(nLen), nLen+1);
  396.         rString.ReleaseBuffer();
  397.     }
  398.     else
  399.     {
  400.         CNetscapeEdit::GetWindowText(rString);
  401.     }
  402. }
  403. int    
  404. CODNetscapeEdit::GetWindowTextLength()
  405. {
  406.  
  407.     if( (CIntlWin::UseUnicodeFontAPI(GetSetWindowTextCSID())) || 
  408.         (sysInfo.m_bWinNT))
  409.         return GetWindowText(NULL, 0);
  410.     else    
  411.         return CNetscapeEdit::GetWindowTextLength();
  412. }
  413.  
  414. #ifdef XP_WIN32
  415.  
  416. void        
  417. CODNetscapeEdit::SetWindowTextW(HWND hWnd, LPCWSTR lpString)
  418. {
  419.     ::SendMessageW(hWnd, WM_SETTEXT, (WPARAM) 0, (LPARAM) lpString);
  420. }
  421.  
  422. int            
  423. CODNetscapeEdit::GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
  424. {
  425.     if(nMaxCount > 0)
  426.         return ::SendMessageW(hWnd, WM_GETTEXT, (WPARAM) nMaxCount, (LPARAM) lpString);
  427.     else
  428.         return ::SendMessageW(hWnd, WM_GETTEXTLENGTH, 0, 0);
  429. }
  430. #endif
  431.  
  432. void    
  433. CODNetscapeEdit::SetWindowText(LPCTSTR lpszString)
  434. {
  435.     int16 wincsid = GetWinCSID();
  436.     SetSetWindowTextCSID(wincsid);
  437. #ifdef XP_WIN32
  438.     if(sysInfo.m_bWinNT)
  439.     {
  440.         // In case it is NT, we should convert it to Unicode and use 
  441.         // if appropriate SendMessageW
  442.         ASSERT((strlen(lpszString) < 4) || 
  443.                 (!((lpszString[0]=='?') && (lpszString[1]=='?') && (lpszString[2]=='?') && (lpszString[3]=='?')))
  444.                 );
  445.         Convert(wincsid, CS_UCS2, (unsigned char*)lpszString);
  446.  
  447.         SetWindowTextW(m_hWnd, (unsigned short*)m_convertedBuf);
  448.  
  449.         return;
  450.     }
  451. #endif
  452.  
  453.     if(CS_UTF8 == wincsid)
  454.     {
  455.         int16 csid = CIntlWin::GetSystemLocaleCsid();
  456.         Convert(wincsid, csid, (unsigned char*)lpszString);
  457.         CNetscapeEdit::SetWindowText((char*)m_convertedBuf);
  458.     }
  459.     else
  460.     {
  461.         CNetscapeEdit::SetWindowText(lpszString);
  462.     }
  463. }
  464.  
  465. int    
  466. CODNetscapeEdit::GetWindowText(LPTSTR lpszStringBuf, int nMaxCount)
  467. {
  468. #ifdef XP_WIN32
  469.     if(sysInfo.m_bWinNT)
  470.     {
  471.         // In case it is NT, we should convert it to Unicode and use 
  472.         // if appropriate SendMessageW
  473.         int rawLen = (::GetWindowTextLengthW(m_hWnd) + 1) * 2;
  474.         ResizeBuffer(m_gettextBuf, m_gettextBufSize, rawLen);
  475.  
  476.         GetWindowTextW(m_hWnd, (unsigned short*)m_gettextBuf, m_gettextBufSize / 2);
  477.  
  478.         Convert(CS_UCS2, GetSetWindowTextCSID(), (unsigned char*)m_gettextBuf);
  479.         int convertedLen = strlen((char*)m_convertedBuf);
  480.         ASSERT((convertedLen < 4) || 
  481.                 (! ((m_convertedBuf[0]=='?') && (m_convertedBuf[1]=='?') && 
  482.                      (m_convertedBuf[2]=='?') && (m_convertedBuf[3]=='?')))
  483.             );
  484.         if((nMaxCount > 0) && (lpszStringBuf != NULL))
  485.         {
  486.             if(nMaxCount > convertedLen)
  487.             {
  488.                 strcpy(lpszStringBuf, (char*)m_convertedBuf);
  489.             }
  490.             else
  491.             {
  492.                 /*    We should really make sure it return the whole characters */
  493.                 strncpy(lpszStringBuf, (char*)m_convertedBuf, nMaxCount-1);
  494.                 lpszStringBuf[nMaxCount-1] = '\0';
  495.             }
  496.         }
  497.         return convertedLen;
  498.     }
  499. #endif
  500.  
  501.     if(CS_UTF8 == GetWinCSID())
  502.     {
  503.         int rawLen = CNetscapeEdit::GetWindowTextLength();
  504.         if(rawLen == 0)
  505.             return 0;
  506.         ResizeBuffer(m_gettextBuf, m_gettextBufSize, rawLen);
  507.  
  508.         // Currently, I have problem to use GetWindowTextW to get the
  509.         // Unicode text. Try to use DDE CF_UNICODETEXT instead
  510.         CNetscapeEdit::GetWindowText((char*)m_gettextBuf, m_gettextBufSize);
  511.         Convert(CIntlWin::GetSystemLocaleCsid(),GetWinCSID(), m_gettextBuf);
  512.         int convertedLen = strlen((char*)m_convertedBuf);
  513.  
  514.         if((nMaxCount > 0) && (lpszStringBuf != NULL))
  515.         {
  516.             if(nMaxCount > convertedLen)
  517.             {
  518.                 strcpy(lpszStringBuf, (char*)m_convertedBuf);
  519.             }
  520.             else
  521.             {
  522.                 /*    We should really make sure it return the whole characters */
  523.                 strncpy(lpszStringBuf, (char*)m_convertedBuf, nMaxCount-1);
  524.                 lpszStringBuf[nMaxCount-1] = '\0';
  525.             }
  526.         }
  527.         return convertedLen;
  528.     }
  529.     else
  530.     {
  531.         if(0 == nMaxCount)
  532.             return CNetscapeEdit::GetWindowTextLength();
  533.         else
  534.             return CNetscapeEdit::GetWindowText(lpszStringBuf,nMaxCount);
  535.     }
  536. }
  537.  
  538. void CODNetscapeEdit::Convert(int16 from, int16 to, unsigned char* lpszString)
  539. {
  540.     int ucs2bufneeded;
  541.     int ucs2len;
  542.     int mbbufneeded;
  543.     if((lpszString == NULL) || ((lpszString[0] == NULL) && (CS_UCS2 != from)))
  544.     {
  545.         ResizeBuffer(m_convertedBuf, m_convertedBufSize, 2);
  546.         m_convertedBuf[0] = '\0';
  547.         m_convertedBuf[1] = '\0';    // in case the to is UCS2
  548.         return;
  549.     }
  550.     if(CS_UCS2 == from)
  551.     {
  552.         // it the from is UCS2, then we don't need to convert it
  553.         // Just make sure the buffer is big enough and copy to it.
  554.         ucs2len = CASTINT(INTL_UnicodeLen((INTL_Unicode*)lpszString));
  555.         ucs2bufneeded = CASTINT((ucs2len + 1)* 2);
  556.         ResizeBuffer(m_ucs2Buf, m_ucs2BufSize, ucs2bufneeded);
  557.         memcpy((char*)m_ucs2Buf, (char*)lpszString, ucs2bufneeded);
  558.         m_ucs2Buf[ucs2len*2] = '\0';    // NULL terminated UCS2 string
  559.         m_ucs2Buf[ucs2len*2+1] = '\0';    // NULL terminated UCS2 string
  560.     } else { 
  561.         ucs2bufneeded = CASTINT(INTL_StrToUnicodeLen(from, lpszString) * 2);
  562.         ResizeBuffer(m_ucs2Buf, m_ucs2BufSize, ucs2bufneeded);
  563.         ucs2len = CASTINT(INTL_StrToUnicode(from, lpszString, (INTL_Unicode*)m_ucs2Buf, m_ucs2BufSize));
  564.     }
  565.  
  566.     if(CS_UCS2 == to)
  567.     {
  568.         // it the to is UCS2, then we don't need to convert it
  569.         // Just make sure the buffer is big enough and copy to it.
  570.         mbbufneeded = CASTINT((ucs2len+1)*2);
  571.         ResizeBuffer(m_convertedBuf, m_convertedBufSize, mbbufneeded);
  572.         memcpy((char*)m_convertedBuf, (char*)m_ucs2Buf, mbbufneeded);
  573.         m_convertedBuf[ucs2len*2] = '\0';    // NULL terminated UCS2 string
  574.         m_convertedBuf[ucs2len*2+1] = '\0';    // NULL terminated UCS2 string
  575.  
  576.     } else {
  577.         mbbufneeded = CASTINT(INTL_UnicodeToStrLen(to, (INTL_Unicode*)m_ucs2Buf, ucs2len));
  578.         ResizeBuffer(m_convertedBuf, m_convertedBufSize, mbbufneeded);
  579.         INTL_UnicodeToStr(to, (INTL_Unicode*)m_ucs2Buf, ucs2len, m_convertedBuf, m_convertedBufSize);
  580.     }
  581. }
  582.  
  583.  
  584. int16 
  585. CODNetscapeEdit::GetSetWindowTextCSID()
  586. {
  587. //    XP_ASSERT(0 != m_set_text_wincsid);    // Make sure SetWindowText is called after SetWindowText
  588.     if(m_set_text_wincsid != CS_UNKNOWN && m_set_text_wincsid != CS_DEFAULT)
  589.         return m_set_text_wincsid;
  590.     else
  591.         return INTL_DefaultWinCharSetID(0);    // temp use CS_LATIN1
  592. }
  593. int16 CODNetscapeEdit::GetWinCSID()
  594. {
  595.     XP_ASSERT(m_Context);
  596.  
  597.     if(m_Context) 
  598.     {
  599.         return INTL_GetCSIWinCSID(
  600.             LO_GetDocumentCharacterSetInfo(m_Context));
  601.  
  602.     }
  603.     else
  604.     {
  605.         return CS_DEFAULT;    // CS_DEFAULT == 0
  606.     }
  607. }
  608.  
  609. #ifdef XP_WIN32
  610. BOOL CODNetscapeEdit::CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName,
  611.     LPCTSTR lpszWindowName, DWORD dwStyle,
  612.     int x, int y, int nWidth, int nHeight,
  613.     HWND hWndParent, HMENU nIDorHMenu, LPVOID lpParam)
  614. {
  615.     if(sysInfo.m_bWinNT)
  616.     {    
  617.            // Place holder for code deal with Unicode
  618.     }
  619.     
  620.     return CEdit::CreateEx(dwExStyle, lpszClassName, lpszWindowName,
  621.         dwStyle, x, y, nWidth, nHeight, hWndParent, nIDorHMenu, lpParam);
  622. }
  623. #endif
  624.  
  625.  
  626.