1 /*
2 * KEYBOARD.CPP
3 *
4 * Copyright (C) 1999 Stephen F. White
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program (see the file "COPYING" for details); if
18 * not, write to the Free Software Foundation, Inc., 675 Mass Ave,
19 * Cambridge, MA 02139, USA.
20 */
21
22
23 #include "stdafx.h"
24 #include "Keyboard.h"
25 #include "resource.h"
26
27 //#include <windows.h>
28 //#include <commctrl.h>
29 #include <GL/gl.h>
30
31 #include <stdio.h>
32 #include <sys/types.h>
33 #include <sys/timeb.h>
34 #include <Dialog2.h>
35
36 #include "swt.h"
37 //#include "swt_private.h"
38
39
40
41 // char string[128];
42
Keyboard(SWND parent)43 Keyboard::Keyboard(SWND parent)
44 : Dialog(parent, IDD_KEYBOARD)
45 {
46 shift_value = false;
47 altgr_value = false;
48 LoadData();
49 swnd = swGetDialogItem(_dlg, IDC_KEYBOARD_TEXT);
50 swSetTextCaretPos(swnd, 1);
51 }
52
~Keyboard()53 Keyboard::~Keyboard()
54 {
55 }
56
57 void
SaveData()58 Keyboard::SaveData()
59 {
60 swGetText(swnd, string, 128);
61 }
62
63 bool
Validate()64 Keyboard::Validate()
65 {
66 return true;
67 }
68
69 void
LoadData()70 Keyboard::LoadData()
71 {
72 snprintf(string, 128, "%s" , "off");
73 swSetText(swGetDialogItem(_dlg, IDC_EDIT_SHIFTTEXT), string);
74 snprintf(string, 128, "%s" , "off");
75 swSetText(swGetDialogItem(_dlg, IDC_EDIT_ALTGRTEXT), string);
76 string[0] = 0; // need to
77 }
78
79 int
GetCharacterPositionOfCaret(char * string)80 Keyboard::GetCharacterPositionOfCaret(char* string)
81 {
82 int caretPosition = swGetTextCaretPos(swnd);
83
84 // get character position
85 int str_width=0;
86 int nu_char =0;
87 for (nu_char = 0; str_width < caretPosition - 1; nu_char++)
88 {
89 char buf[128];
90 mystrncpy_secure(buf, string + nu_char, 2);
91 int char_width = swGetStringWidth(swGetDefaultFont(), (const char*) buf);
92 str_width =str_width + char_width;
93 }
94 // number of characters
95 return nu_char;
96 }
97
98
99 void
SetCaretPositionRight(char * string)100 Keyboard::SetCaretPositionRight(char* string)
101 {
102 int i=0;
103 int str_width=0;
104 // Caret position at client window
105 int caretPosition = swGetTextCaretPos(swnd);
106 do
107 {
108 char buf[128];
109 mystrncpy_secure(buf, string + i, 2);
110 int char_width = swGetStringWidth(swGetDefaultFont(), (const char*) buf);
111 str_width = str_width + char_width;
112 i++;
113 } while (str_width < caretPosition);
114
115 swSetTextCaretPos(swnd, str_width + 1);
116 }
117
118
119
120
121 void
Keyboardbutton(const char * asciiChar)122 Keyboard::Keyboardbutton(const char* asciiChar)
123 {
124 char stringLeftCaret[128];
125 swGetText(swnd, string, 128);
126 int nu_char = GetCharacterPositionOfCaret(string);
127 mystrncpy_secure(stringLeftCaret, string + nu_char , 128 - nu_char - 1);
128
129 mystrncpy_secure(string + nu_char , asciiChar, 2);
130
131 mystrncpy_secure(string + nu_char + 1, stringLeftCaret, 128 - nu_char - 1);
132 swSetText(swnd,string);
133 SetCaretPositionRight(string);
134 }
135
136 void
OnCommand(int id)137 Keyboard::OnCommand(int id)
138 {
139 const char* asciiChar;
140 //////////////////////////////////////////////////////////////////////////////////////////
141 // ` ~
142 if (id == IDC_BUTTON_SQUOTATION)
143 {
144 /**~**/ if (shift_value == true) Keyboardbutton("\x7E");
145 /**`**/ else Keyboardbutton("\x60");
146 // swInvalidateWindow(_dlg);
147 }
148 //////////////////////////////////////////////////////////////////////////////////////////
149 //////////////////////////////////////////////////////////////////////////////////////////
150 // 1 !
151 if (id == IDC_BUTTON_1)
152 {
153 /**!**/ if (shift_value == true) Keyboardbutton("\x21");
154 /**1**/ else Keyboardbutton("\x31");
155 // swvalidateWindow(_dlg);
156 }
157 //////////////////////////////////////////////////////////////////////////////////////////
158 //////////////////////////////////////////////////////////////////////////////////////////
159 // 2 @
160 if (id == IDC_BUTTON_2)
161 {
162 /**@**/ if (shift_value == true) Keyboardbutton("\x40");
163 /**2**/ if (shift_value == false) Keyboardbutton("\x32");
164 // swInvalidateWindow(_dlg);
165 }
166 //////////////////////////////////////////////////////////////////////////////////////////
167 //////////////////////////////////////////////////////////////////////////////////////////
168 // 3 #
169 if (id == IDC_BUTTON_3)
170 {
171 /**#**/ if (shift_value == true) Keyboardbutton("\x23");
172 /**3**/ if (shift_value == false) Keyboardbutton("\x33");
173 // swInvalidateWindow(_dlg);
174 }
175 //////////////////////////////////////////////////////////////////////////////////////////
176 //////////////////////////////////////////////////////////////////////////////////////////
177 // 4 $
178 if (id == IDC_BUTTON_4)
179 {
180 /**$**/ if (shift_value == true) Keyboardbutton("\x24");
181 /**4**/ else Keyboardbutton("\x34");
182 // swInvalidateWindow(_dlg);
183 }
184 //////////////////////////////////////////////////////////////////////////////////////////
185 //////////////////////////////////////////////////////////////////////////////////////////
186 // 5 %
187 if (id == IDC_BUTTON_5)
188 {
189 /**%**/ if (shift_value == true) Keyboardbutton("\x25");
190 /**5**/ else Keyboardbutton("\x35");
191 // swInvalidateWindow(_dlg);
192 }
193 //////////////////////////////////////////////////////////////////////////////////////////
194 //////////////////////////////////////////////////////////////////////////////////////////
195 // 6 ^
196 if (id == IDC_BUTTON_6)
197 {
198 /**^**/ if (shift_value == true) Keyboardbutton("\x5E");
199 /**6**/ else Keyboardbutton("\x36");
200 // swInvalidateWindow(_dlg);
201 }
202 //////////////////////////////////////////////////////////////////////////////////////////
203 //////////////////////////////////////////////////////////////////////////////////////////
204 // 7 &
205 if (id == IDC_BUTTON_7)
206 {
207 /** & **/ if (shift_value == true) Keyboardbutton("\x26");
208 /** 7 **/ if (shift_value == false) Keyboardbutton("\x37");
209 // swInvalidateWindow(_dlg);
210 }
211 //////////////////////////////////////////////////////////////////////////////////////////
212 //////////////////////////////////////////////////////////////////////////////////////////
213 // 8 *
214 if (id == IDC_BUTTON_8)
215 {
216 /** * **/ if (shift_value == true) Keyboardbutton("\x2A");
217 /**8**/ if (shift_value == false) Keyboardbutton("\x38");
218 //swInvalidateWindow(_dlg);
219 }
220 //////////////////////////////////////////////////////////////////////////////////////////
221 //////////////////////////////////////////////////////////////////////////////////////////
222 // 9 (
223 if (id == IDC_BUTTON_9)
224 {
225 /**(**/ if (shift_value == true) Keyboardbutton("\x28");
226 /**9**/ if (shift_value == false) Keyboardbutton("\x39");
227 //swInvalidateWindow(_dlg);
228 }
229 //////////////////////////////////////////////////////////////////////////////////////////
230 //////////////////////////////////////////////////////////////////////////////////////////
231 // 0 )
232 if (id == IDC_BUTTON_0)
233 {
234 /**)**/ if (shift_value == true) Keyboardbutton("\x29");
235 /**0**/ if (shift_value == false) Keyboardbutton("\x30");
236 //swInvalidateWindow(_dlg);
237 }
238 //////////////////////////////////////////////////////////////////////////////////////////
239 //////////////////////////////////////////////////////////////////////////////////////////
240 // - _
241 if (id == IDC_BUTTON_MINUS_UNDERLINE)
242 {
243 /**-**/ if (shift_value == true) Keyboardbutton("\x5F");
244 /**_**/ else Keyboardbutton("\x2D");
245 //swInvalidateWindow(_dlg);
246 }
247 //////////////////////////////////////////////////////////////////////////////////////////
248 // + =
249 if (id == IDC_BUTTON_PLUS)
250 {
251 /**=**/ if (shift_value == true) Keyboardbutton("\x3D");
252 /**+**/ if (shift_value == false) Keyboardbutton("\x2B");
253 //swInvalidateWindow(_dlg);
254 }
255 //////////////////////////////////////////////////////////////////////////////////////////
256 //////////////////////////////////////////////////////////////////////////////////////////
257 // Q q@
258 if (id == IDC_BUTTON_Q)
259 {
260 /**Q**/ if (shift_value == true) Keyboardbutton("\x51");
261 /**q**/ if (shift_value == false) Keyboardbutton("\x71");
262 //swInvalidateWindow(_dlg);
263 }
264 ///////////////////////////////////////////////////////////////////////////////////////////
265 // W w
266 if (id == IDC_BUTTON_W)
267 {
268 /**W**/ if (shift_value == true) Keyboardbutton("\x57");
269 /**w**/ else Keyboardbutton("\x77");
270 //swInvalidateWindow(_dlg);
271 }
272 //////////////////////////////////////////////////////////////////////////////////////////
273 // E e
274 if (id == IDC_BUTTON_E)
275 {
276 /**E**/ if (shift_value == true) Keyboardbutton("\x45");
277 /**e**/ if (shift_value == false) Keyboardbutton("\x65");
278 //swInvalidateWindow(_dlg);
279 }
280 //////////////////////////////////////////////////////////////////////////////////////////
281 // R r
282 if (id == IDC_BUTTON_R)
283 {
284 /**R**/ if (shift_value == true) Keyboardbutton("\x52");
285 /**r**/ else Keyboardbutton("\x72");
286 //swInvalidateWindow(_dlg);
287 }
288 //////////////////////////////////////////////////////////////////////////////////////////
289 //////////////////////////////////////////////////////////////////////////////////////////
290 // T t
291 if (id == IDC_BUTTON_T)
292 {
293 /**T**/ if (shift_value == true) Keyboardbutton("\x54");
294 /**t**/ else Keyboardbutton("\x74");
295 //swInvalidateWindow(_dlg);
296 }
297 //////////////////////////////////////////////////////////////////////////////////////////
298 //////////////////////////////////////////////////////////////////////////////////////////
299 // Y y
300 if (id == IDC_BUTTON_Y)
301 {
302 /**Y**/ if (shift_value == true) Keyboardbutton("\x59");
303 /**y**/ else Keyboardbutton("\x79");
304 //swInvalidateWindow(_dlg);
305 }
306 //////////////////////////////////////////////////////////////////////////////////////////
307 //////////////////////////////////////////////////////////////////////////////////////////
308 // U u
309 if (id == IDC_BUTTON_U)
310 {
311 /**U**/ if (shift_value == true) Keyboardbutton("\x55");
312 /**u**/ else Keyboardbutton("\x75");
313 //swInvalidateWindow(_dlg);
314 }
315 //////////////////////////////////////////////////////////////////////////////////////////
316 //////////////////////////////////////////////////////////////////////////////////////////
317 // I i
318 if (id == IDC_BUTTON_I)
319 {
320 /**I**/ if (shift_value == true) Keyboardbutton("\x49");
321 /**i**/ else Keyboardbutton("\x69");
322 //swInvalidateWindow(_dlg);
323 }
324 //////////////////////////////////////////////////////////////////////////////////////////
325 //////////////////////////////////////////////////////////////////////////////////////////
326 // O o
327 if (id == IDC_BUTTON_O)
328 {
329 /**O**/ if (shift_value == true) Keyboardbutton("\x4F");
330 /**o**/ else Keyboardbutton("\x6F");
331 //swInvalidateWindow(_dlg);
332 }
333 //////////////////////////////////////////////////////////////////////////////////////////
334 //////////////////////////////////////////////////////////////////////////////////////////
335 // P p
336 if (id == IDC_BUTTON_P)
337 {
338 /**P**/ if (shift_value == true) Keyboardbutton("\x50");
339 /**p**/ else Keyboardbutton("\x70");
340 //swInvalidateWindow(_dlg);
341 }
342 //////////////////////////////////////////////////////////////////////////////////////////
343 //////////////////////////////////////////////////////////////////////////////////////////
344 // [ {
345 if (id == IDC_BUTTON_LBRACKET)
346 {
347 /**{**/ if (shift_value == true) Keyboardbutton("\x7B");
348 /**[**/ else Keyboardbutton("\x5B");
349 //swInvalidateWindow(_dlg);
350 }
351 //////////////////////////////////////////////////////////////////////////////////////////
352 //////////////////////////////////////////////////////////////////////////////////////////
353 // ] }
354 if (id == IDC_BUTTON_RBRACKET)
355 {
356 /**}**/ if (shift_value == true) Keyboardbutton("\x7D");
357 /**]**/ if (shift_value == false) Keyboardbutton("\x5D");
358 //swInvalidateWindow(_dlg);
359 }
360 //////////////////////////////////////////////////////////////////////////////////////////
361
362 //
363
364 // A a
365 if (id == IDC_BUTTON_A)
366 {
367 /**A**/ if (shift_value == true) Keyboardbutton("\x41");
368 /**a**/ else Keyboardbutton("\x61");
369 //swInvalidateWindow(_dlg);
370 }
371 //////////////////////////////////////////////////////////////////////////////////////////
372 // S s
373 if (id == IDC_BUTTON_S)
374 {
375 /**S**/ if (shift_value == true) Keyboardbutton("\x53");
376 /**s**/ else Keyboardbutton("\x73");
377 //swInvalidateWindow(_dlg);
378 }
379 //////////////////////////////////////////////////////////////////////////////////////////
380 //////////////////////////////////////////////////////////////////////////////////////////
381 // D d
382 if (id == IDC_BUTTON_D)
383 {
384 /**D**/ if (shift_value == true) Keyboardbutton("\x44");
385 /**d**/ else Keyboardbutton("\x64");
386 //swInvalidateWindow(_dlg);
387 }
388 //////////////////////////////////////////////////////////////////////////////////////////
389 //////////////////////////////////////////////////////////////////////////////////////////
390 // F f
391 if (id == IDC_BUTTON_F)
392 {
393 /**F**/ if (shift_value == true) Keyboardbutton("\x46");
394 /**f**/ else Keyboardbutton("\x66");
395 //swInvalidateWindow(_dlg);
396 }
397 //////////////////////////////////////////////////////////////////////////////////////////
398 //////////////////////////////////////////////////////////////////////////////////////////
399 // G g
400 if (id == IDC_BUTTON_G)
401 {
402 /**G**/ if (shift_value == true) Keyboardbutton("\x47");
403 /**g**/ else Keyboardbutton("\x67");
404 //swInvalidateWindow(_dlg);
405 }
406 //////////////////////////////////////////////////////////////////////////////////////////
407 //////////////////////////////////////////////////////////////////////////////////////////
408 // H h
409 if (id == IDC_BUTTON_H)
410 {
411 /**H**/ if (shift_value == true) Keyboardbutton("\x48");
412 /**h**/ else Keyboardbutton("\x68");
413 //swInvalidateWindow(_dlg);
414 }
415 //////////////////////////////////////////////////////////////////////////////////////////
416 //////////////////////////////////////////////////////////////////////////////////////////
417 // J j
418 if (id == IDC_BUTTON_J)
419 {
420 /**J**/ if (shift_value == true) Keyboardbutton("\x4A");
421 /**j**/ else Keyboardbutton("\x6A");
422 //swInvalidateWindow(_dlg);
423 }
424 //////////////////////////////////////////////////////////////////////////////////////////
425 //////////////////////////////////////////////////////////////////////////////////////////
426 // K k
427 if (id == IDC_BUTTON_K)
428 {
429 /**K**/ if (shift_value == true) Keyboardbutton("\x4B");
430 /**k**/ else Keyboardbutton("\x6B");
431 //swInvalidateWindow(_dlg);
432 }
433 //////////////////////////////////////////////////////////////////////////////////////////
434 //////////////////////////////////////////////////////////////////////////////////////////
435 // L l
436 if (id == IDC_BUTTON_L)
437 {
438 /**L**/ if (shift_value == true) Keyboardbutton("\x4C");
439 /**l**/ else Keyboardbutton("\x6C");
440 //swInvalidateWindow(_dlg);
441 }
442 //////////////////////////////////////////////////////////////////////////////////////////
443 //////////////////////////////////////////////////////////////////////////////////////////
444 // ; :
445 if (id == IDC_BUTTON_SEMICOLON)
446 {
447 /**:**/ if (shift_value == true) Keyboardbutton("\x3A");
448 /**;**/ else Keyboardbutton("\x3B");
449 //swInvalidateWindow(_dlg);
450 }
451 //////////////////////////////////////////////////////////////////////////////////////////
452 //////////////////////////////////////////////////////////////////////////////////////////
453 // ' "
454 if (id == IDC_BUTTON_QUOTATIONMARKS)
455 {
456
457 /**"**/ if (shift_value == true) Keyboardbutton("\x22");
458 /**'**/ else Keyboardbutton("\x27");
459 //swInvalidateWindow(_dlg);
460 }
461 //////////////////////////////////////////////////////////////////////////////////////////
462 //////////////////////////////////////////////////////////////////////////////////////////
463 // \ |
464 if (id == IDC_BUTTON_BACKSLASH)
465 {
466 /**|**/ if (shift_value == true) Keyboardbutton("\x7C");
467 /**\**/ else Keyboardbutton("\x5C");
468 //swInvalidateWindow(_dlg);
469 }
470 //////////////////////////////////////////////////////////////////////////////////////////
471
472 //
473
474
475 //////////////////////////////////////////////////////////////////////////////////////////
476 // Z z
477 if (id == IDC_BUTTON_Z)
478 {
479 /**Z**/ if (shift_value == true) Keyboardbutton("\x5A");
480 /**z**/ else Keyboardbutton("\x7A");
481 //swInvalidateWindow(_dlg);
482 }
483 //////////////////////////////////////////////////////////////////////////////////////////
484 //////////////////////////////////////////////////////////////////////////////////////////
485 // X x
486 if (id == IDC_BUTTON_X)
487 {
488 /**X**/ if (shift_value == true) Keyboardbutton("\x58");
489 /**x**/ else Keyboardbutton("\x78");
490 //swInvalidateWindow(_dlg);
491 }
492 //////////////////////////////////////////////////////////////////////////////////////////
493 //////////////////////////////////////////////////////////////////////////////////////////
494 // C c
495 if (id == IDC_BUTTON_C)
496 {
497 /**C**/ if (shift_value == true) Keyboardbutton("\x43");
498 /**c**/ else Keyboardbutton("\x63");
499 //swInvalidateWindow(_dlg);
500 }
501 //////////////////////////////////////////////////////////////////////////////////////////
502 //////////////////////////////////////////////////////////////////////////////////////////
503 // V v
504 if (id == IDC_BUTTON_V)
505 {
506 /**V**/ if (shift_value == true) Keyboardbutton("\x56");
507 /**v**/ else Keyboardbutton("\x76");
508 //swInvalidateWindow(_dlg);
509 }
510 //////////////////////////////////////////////////////////////////////////////////////////
511 //////////////////////////////////////////////////////////////////////////////////////////
512 // B b
513 if (id == IDC_BUTTON_B)
514 {
515 /**B**/ if (shift_value == true) Keyboardbutton("\x42");
516 /**b**/ else Keyboardbutton("\x62");
517 //swInvalidateWindow(_dlg);
518 }
519 //////////////////////////////////////////////////////////////////////////////////////////
520 //////////////////////////////////////////////////////////////////////////////////////////
521 // N n
522 if (id == IDC_BUTTON_N)
523 {
524 /**N**/ if (shift_value == true) Keyboardbutton("\x4E");
525 /**n**/ else Keyboardbutton("\x6E");
526 //swInvalidateWindow(_dlg);
527 }
528 //////////////////////////////////////////////////////////////////////////////////////////
529 //////////////////////////////////////////////////////////////////////////////////////////
530 // M m �
531 if (id == IDC_BUTTON_M)
532 {
533 /**M**/ if (shift_value == true) Keyboardbutton("\x4D");
534 /**�**/ if (shift_value == false && altgr_value == true) Keyboardbutton("\xB5");
535 /**m**/ if (shift_value == false && altgr_value == false) Keyboardbutton("\x6D");
536 //swInvalidateWindow(_dlg);
537 }
538 //////////////////////////////////////////////////////////////////////////////////////////
539 //////////////////////////////////////////////////////////////////////////////////////////
540 // , <
541 if (id == IDC_BUTTON_COMMA)
542 {
543 /**<**/ if (shift_value == true) Keyboardbutton("\x3C");
544 /**,**/ else Keyboardbutton("\x2C");
545 //swInvalidateWindow(_dlg);
546 }
547 //////////////////////////////////////////////////////////////////////////////////////////
548 //////////////////////////////////////////////////////////////////////////////////////////
549 // . >
550 if (id == IDC_BUTTON_POINT)
551 {
552 /**>**/ if (shift_value == true) Keyboardbutton("\x3E");
553 /**:**/ else Keyboardbutton("\x2E");
554 //swInvalidateWindow(_dlg);
555 }
556 //////////////////////////////////////////////////////////////////////////////////////////
557 //////////////////////////////////////////////////////////////////////////////////////////
558 // / ?
559 if (id == IDC_BUTTON_SLASH)
560 {
561 /**?**/ if (shift_value == true) Keyboardbutton("\x3F");
562 /** / **/ else Keyboardbutton("\x2F");
563 //swInvalidateWindow(_dlg);
564 }
565
566 //////////////////////////////////////////////////////////////////////////////////////////
567
568 //
569
570
571 // SPACE
572 if (id == IDC_BUTTON_SPACE)
573 {
574 Keyboardbutton("\x20");
575 //swInvalidateWindow(_dlg);
576 }
577 //////////////////////////////////////////////////////////////////////////////////////////
578 //////////////////////////////////////////////////////////////////////////////////////////
579 //SHIFT
580 if (id == IDC_BUTTON_SHIFT)
581 {
582 shift_value = !shift_value;
583
584 if (shift_value == false)
585 {
586 snprintf(string, 128, "%s" , "off");
587 swSetText(swGetDialogItem(_dlg, IDC_EDIT_SHIFTTEXT), string);
588 }
589 else{
590 snprintf(string, 128, "%s" , "on");
591 swSetText(swGetDialogItem(_dlg, IDC_EDIT_SHIFTTEXT), string);
592 }
593 }
594 //////////////////////////////////////////////////////////////////////////////////////////
595 //AltGr
596 if (id == IDC_BUTTON_ALTGR)
597 {
598 altgr_value = !altgr_value;
599
600 if (altgr_value == false)
601 {
602 snprintf(string, 128, "%s" , "off");
603 swSetText(swGetDialogItem(_dlg, IDC_EDIT_ALTGRTEXT), string);
604 }
605 else{
606 snprintf(string, 128, "%s" , "on");
607 swSetText(swGetDialogItem(_dlg, IDC_EDIT_ALTGRTEXT), string);
608 }
609 }
610 //////////////////////////////////////////////////////////////////////////////////////////
611 /**<--**/if (id == IDC_BUTTON_BACK)
612 {
613 swGetText(swnd, string, 128);
614 //Caret position at client window
615 int caretPosition = swGetTextCaretPos(swnd);
616
617 char stringLeftCaret[128];
618 int str_width=0;
619 int char_width=0;
620 int i;
621 if (caretPosition <= 1) goto NEWPOSITION;
622 //Move caret position
623 for (i=0; str_width < caretPosition - 1; i++)
624 {
625 char buf[128];
626 mystrncpy_secure(buf, string + i, 2);
627 char_width = swGetStringWidth(swGetDefaultFont(), (const char*) buf);
628 str_width = str_width + char_width;
629 }
630
631 caretPosition = str_width + 1 - char_width;
632 mystrncpy_secure(stringLeftCaret, string + i , 128 - i - 1);
633 mystrncpy_secure(string + i - 1, stringLeftCaret, 128 - i - 1);
634 swSetText(swnd,string);
635 NEWPOSITION:if (caretPosition <= 1) caretPosition=1;
636 swSetTextCaretPos(swnd,caretPosition);
637 //swInvalidateWindow(_dlg);
638 }
639
640 /**MOVE_LEFT**/
641 if (id == IDC_BUTTON_MOVE_LEFT)
642 {
643 //Caret position at client window
644 int caretPosition = swGetTextCaretPos(swnd);
645 swGetText(swGetDialogItem(_dlg, IDC_WIDTH), string, 128);
646 //Move caret position
647 int str_width=0;
648 int char_width=0;
649
650 for (int i=0; str_width < caretPosition - 1; i++)
651 {
652 char buf[128];
653 mystrncpy_secure(buf, string + i, 2);
654 char_width = swGetStringWidth(swGetDefaultFont(), (const char*) buf);
655 str_width =str_width + char_width;
656 }
657
658 caretPosition = str_width + 1 - char_width;
659 swSetTextCaretPos(swnd, caretPosition);
660 swInvalidateWindow(_dlg);
661 }
662 //////////////////////////////////////////////////////////////////////////////////////////
663 /**MOVE_RIGHT**/
664 if (id == IDC_BUTTON_MOVE_RIGHT)
665 {
666 char compare_string[128];
667 for(int i=0;i<127;i++)
668 compare_string[i] = 0;
669 swGetText(swGetDialogItem(_dlg, IDC_WIDTH), string, 128);
670 //Caret position at client window
671 int caretPosition = swGetTextCaretPos(swnd);
672 //Move caret position
673 int str_width=0;
674 int char_width=0;
675 int j=0;
676 do
677 {
678 char buf[128];
679 const char *oneChar;
680 mystrncpy_secure(buf, string + j, 2);
681 oneChar = &buf[0];
682 if( *oneChar == compare_string[j]) goto POSITION;
683 char_width = swGetStringWidth(swGetDefaultFont(), (const char*) oneChar);
684 str_width = str_width + char_width;
685 j++;
686 } while (str_width < caretPosition);
687
688 caretPosition = str_width + 1;
689 POSITION:swSetTextCaretPos(swnd,caretPosition);
690 //swInvalidateWindow(_dlg);
691 }
692 //////////////////////////////////////////////////////////////////////////////////////////
693 /**MOVE_UP**/
694 if (id == IDC_BUTTON_MOVE_UP){}
695 //////////////////////////////////////////////////////////////////////////////////////////
696 /**MOVE_DOWN**/
697 if (id == IDC_BUTTON_MOVE_DOWN){}
698 //////////////////////////////////////////////////////////////////////////////////////////
699 /**INSERT**/
700 if (id == IDC_BUTTON_INSERT){}
701 //////////////////////////////////////////////////////////////////////////////////////////
702 //DEL
703 if (id == IDC_BUTTON_DEL)
704 {
705 swGetText(swnd, string, 128);
706
707 //Caret position at client window
708 int caretPosition = swGetTextCaretPos(swnd);
709 //Move caret position
710 int str_width=0;
711 int char_width=0;
712 int k = 0;
713 for (k=0; str_width < caretPosition - 1;k++)
714 {
715 char buf[128];
716 mystrncpy_secure(buf, string + k, 2);
717 char_width = swGetStringWidth(swGetDefaultFont(), (const char*) buf);
718 str_width = str_width + char_width;
719 }
720
721 swSetTextCaretPos(swnd,caretPosition);
722
723 char stringLeftCaret[128];
724 mystrncpy_secure(stringLeftCaret, string + k + 1 , 128 - k - 2);
725 mystrncpy_secure(string + k , stringLeftCaret, 128 - k);
726 swSetText(swnd,string);
727 //swInvalidateWindow(_dlg);
728 }
729 //////////////////////////////////////////////////////////////////////////////////////////
730 /**POS1**/
731 if (id == IDC_BUTTON_POS1){}
732 //////////////////////////////////////////////////////////////////////////////////////////
733 /**END**/
734 if (id == IDC_BUTTON_END){}
735 //////////////////////////////////////////////////////////////////////////////////////////
736 /**PAGEUP**/
737 if (id == IDC_BUTTON_PAGEUP){}
738 //////////////////////////////////////////////////////////////////////////////////////////
739 /**PAGEDOWN**/
740 if (id == IDC_BUTTON_PAGEDOWN){}
741 //////////////////////////////////////////////////////////////////////////////////////////
742 ////CreateCaret(swnd->hWnd, NULL, 1, swGetFontHeight(swGetDefaultFont()));
743 ////ShowCaret(swnd->hWnd);
744 // swInvalidateWindow(_dlg);
745 Dialog::OnCommand(id);
746 }
747
748