@@ -41,12 +41,12 @@ char* MonthNames[12] =
4141
4242bool InitEclipseFinderColumns (HWND listView)
4343{
44- LVCOLUMN lvc;
45- LVCOLUMN columns[5 ];
44+ LVCOLUMNW lvc;
45+ LVCOLUMNW columns[5 ];
4646
4747 lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM ;
4848 lvc.fmt = LVCFMT_CENTER ;
49- lvc.pszText = " " ;
49+ lvc.pszText = L "" ;
5050
5151 int nColumns = sizeof (columns) / sizeof (columns[0 ]);
5252 int i;
@@ -55,22 +55,28 @@ bool InitEclipseFinderColumns(HWND listView)
5555 columns[i] = lvc;
5656
5757 bind_textdomain_codeset (" celestia" , CurrentCP ());
58- columns[0 ].pszText = _ (" Planet" );
58+ wstring header0 = CurrentCPToWide (_ (" Planet" ));
59+ wstring header1 = CurrentCPToWide (_ (" Satellite" ));
60+ wstring header2 = CurrentCPToWide (_ (" Date" ));
61+ wstring header3 = CurrentCPToWide (_ (" Start" ));
62+ wstring header4 = CurrentCPToWide (_ (" Duration" ));
63+
64+ columns[0 ].pszText = const_cast <wchar_t *>(header0.c_str ());
5965 columns[0 ].cx = 50 ;
60- columns[1 ].pszText = _ ( " Satellite " );
66+ columns[1 ].pszText = const_cast < wchar_t *>(header1. c_str () );
6167 columns[1 ].cx = 65 ;
62- columns[2 ].pszText = _ ( " Date " );
68+ columns[2 ].pszText = const_cast < wchar_t *>(header2. c_str () );
6369 columns[2 ].cx = 80 ;
64- columns[3 ].pszText = _ ( " Start " );
70+ columns[3 ].pszText = const_cast < wchar_t *>(header3. c_str () );
6571 columns[3 ].cx = 55 ;
66- columns[4 ].pszText = _ ( " Duration " );
72+ columns[4 ].pszText = const_cast < wchar_t *>(header4. c_str () );
6773 columns[4 ].cx = 55 ;
6874 bind_textdomain_codeset (" celestia" , " UTF8" );
6975
7076 for (i = 0 ; i < nColumns; i++)
7177 {
7278 columns[i].iSubItem = i;
73- if (ListView_InsertColumn (listView, i, &columns[i]) == -1 )
79+ if (SendMessage (listView, LVM_INSERTCOLUMNW , ( WPARAM ) i, ( LPARAM ) &columns[i]) == -1 )
7480 return false ;
7581 }
7682
@@ -99,38 +105,33 @@ bool InitEclipseFinderItems(HWND listView, const vector<Eclipse>& eclipses)
99105}
100106
101107
102- static char callbackScratch[256 ];
103- void EclipseFinderDisplayItem (LPNMLVDISPINFOA nm)
108+ static wchar_t callbackScratch[256 ];
109+ void EclipseFinderDisplayItem (LPNMLVDISPINFOW nm)
104110{
105111
106112 Eclipse* eclipse = reinterpret_cast <Eclipse*>(nm->item .lParam );
107113 if (eclipse == NULL )
108114 {
109- nm->item .pszText = " " ;
115+ nm->item .pszText = L "" ;
110116 return ;
111117 }
112118
119+ size_t maxCount = sizeof (callbackScratch) / sizeof (wchar_t ) - 1 ;
113120 switch (nm->item .iSubItem )
114121 {
115122 case 0 :
116123 {
117- strncpy (callbackScratch, UTF8ToCurrentCP (_ (eclipse->planete .c_str ())).c_str (), sizeof (callbackScratch) - 1 );
124+ wcsncpy (callbackScratch, UTF8ToWide (_ (eclipse->planete .c_str ())).c_str (), maxCount );
118125 nm->item .pszText = callbackScratch;
119126 }
120127 break ;
121128
122129 case 1 :
123130 {
124131 if (!strcmp (eclipse->planete .c_str ()," None" ))
125- {
126- sprintf (callbackScratch," " );
127- nm->item .pszText = callbackScratch;
128- }
132+ wcsncpy (callbackScratch, L" " , maxCount);
129133 else
130- {
131- strncpy (callbackScratch, UTF8ToCurrentCP (_ (eclipse->sattelite .c_str ())).c_str (), sizeof (callbackScratch) - 1 );
132- nm->item .pszText = callbackScratch;
133- }
134+ wcsncpy (callbackScratch, UTF8ToWide (_ (eclipse->sattelite .c_str ())).c_str (), maxCount);
134135 }
135136 break ;
136137
@@ -139,13 +140,12 @@ void EclipseFinderDisplayItem(LPNMLVDISPINFOA nm)
139140 bind_textdomain_codeset (" celestia" , CurrentCP ());
140141 astro::Date startDate (eclipse->startTime );
141142 if (!strcmp (eclipse->planete .c_str ()," None" ))
142- sprintf (callbackScratch," " );
143+ wcsncpy (callbackScratch, L" " , maxCount );
143144 else
144- sprintf (callbackScratch, " %2d %s %4d" ,
145- startDate.day ,
146- _ (MonthNames[startDate.month - 1 ]),
147- startDate.year );
148- nm->item .pszText = callbackScratch;
145+ swprintf (callbackScratch, L" %2d %s %4d" ,
146+ startDate.day ,
147+ CurrentCPToWide (_ (MonthNames[startDate.month - 1 ])).c_str (),
148+ startDate.year );
149149 bind_textdomain_codeset (" celestia" , " UTF8" );
150150 }
151151 break ;
@@ -154,33 +154,27 @@ void EclipseFinderDisplayItem(LPNMLVDISPINFOA nm)
154154 {
155155 astro::Date startDate (eclipse->startTime );
156156 if (!strcmp (eclipse->planete .c_str ()," None" ))
157- sprintf (callbackScratch," " );
157+ wcsncpy (callbackScratch, L" " , maxCount );
158158 else
159- {
160- sprintf (callbackScratch, " %02d:%02d" ,
159+ swprintf (callbackScratch, L" %02d:%02d" ,
161160 startDate.hour , startDate.minute );
162- }
163- nm->item .pszText = callbackScratch;
164161 }
165162 break ;
166163
167164 case 4 :
168165 {
169166 if (!strcmp (eclipse->planete .c_str ()," None" ))
170- {
171- sprintf (callbackScratch," " );
172- nm->item .pszText = callbackScratch;
173- }
167+ wcsncpy (callbackScratch, L" " , maxCount);
174168 else
175169 {
176170 int minutes = (int ) ((eclipse->endTime - eclipse->startTime ) *
177171 24 * 60 );
178- sprintf (callbackScratch, " %02d:%02d" , minutes / 60 , minutes % 60 );
179- nm->item .pszText = callbackScratch;
172+ swprintf (callbackScratch, L" %02d:%02d" , minutes / 60 , minutes % 60 );
180173 }
181174 }
182175 break ;
183176 }
177+ nm->item .pszText = callbackScratch;
184178}
185179
186180
@@ -308,6 +302,7 @@ BOOL APIENTRY EclipseFinderProc(HWND hDlg,
308302 // SetWindowLong(hDlg, DWL_USER, lParam);
309303 SetWindowLongPtr (hDlg, DWLP_USER , lParam);
310304 HWND hwnd = GetDlgItem (hDlg, IDC_ECLIPSES_LIST );
305+ ListView_SetUnicodeFormat (hwnd, TRUE );
311306 InitEclipseFinderColumns (hwnd);
312307 SendDlgItemMessage (hDlg, IDC_ECLIPSES_LIST , LVM_SETEXTENDEDLISTVIEWSTYLE , 0 , LVS_EX_FULLROWSELECT );
313308
@@ -446,8 +441,8 @@ BOOL APIENTRY EclipseFinderProc(HWND hDlg,
446441 {
447442 switch (hdr->code )
448443 {
449- case LVN_GETDISPINFO :
450- EclipseFinderDisplayItem ((LPNMLVDISPINFOA ) lParam);
444+ case LVN_GETDISPINFOW :
445+ EclipseFinderDisplayItem ((LPNMLVDISPINFOW ) lParam);
451446 break ;
452447 case LVN_ITEMCHANGED :
453448 {
0 commit comments