home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / CIT.v4 / Demo / StringDemo.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  2.6 KB  |  130 lines

  1. #include <CITGroup.h>
  2. #include <CITButton.h>
  3. #include <CITString.h>
  4.  
  5. #include <intuition/sghooks.h>
  6. #include <stdlib.h>
  7.  
  8. #define PASSWORDCHAR '*'
  9.  
  10. char Password[64];
  11.  
  12. CITApp Application;
  13.  
  14. CITWorkbench DemoScreen;
  15. CITWindow    DemoWindow;
  16. CITVGroup    winGroup;
  17. CITButton    quitButton;
  18. CITString    stringInput1;
  19. CITString    stringInput2;
  20.  
  21. void CloseEvent();
  22. void QuitEvent(ULONG ID);
  23. ULONG PasswordHook(struct SGWork *sgw,ULONG *msg,ULONG myData);
  24.  
  25. int main(void)
  26. {
  27.   BOOL Error=FALSE;
  28.  
  29.   DemoScreen.InsObject(DemoWindow,Error);
  30.     DemoWindow.Position(WPOS_CENTERSCREEN);
  31.     DemoWindow.CloseGadget();
  32.     DemoWindow.DragBar();
  33.     DemoWindow.SizeGadget();
  34.     DemoWindow.DepthGadget();
  35.     DemoWindow.IconifyGadget();
  36.     DemoWindow.Activate();
  37.     DemoWindow.Caption("CITString Example");
  38.     DemoWindow.CloseEventHandler(CloseEvent);
  39.     DemoWindow.InsObject(winGroup,Error);
  40.       winGroup.SpaceOuter();
  41.       winGroup.InsObject(stringInput1,Error);
  42.         stringInput1.LabelText("String _1");
  43.         stringInput1.TextVal("Testing");
  44.         stringInput1.MinVisible(10);
  45.         stringInput1.MaxChars(24);
  46.         stringInput1.TabCycle();
  47.       winGroup.InsObject(stringInput2,Error);
  48.         stringInput2.LabelText("String _2");
  49.         stringInput2.MinVisible(10);
  50.         stringInput2.MaxChars(24);
  51.         stringInput2.TabCycle();
  52.         stringInput2.EditHook(&PasswordHook,0);
  53.       winGroup.InsObject(quitButton,Error);
  54.         quitButton.Text("Quit");
  55.         quitButton.EventHandler(QuitEvent);
  56.  
  57.   Application.InsObject(DemoScreen,Error);
  58.  
  59.   // Ok?
  60.   if( Error )
  61.     return 11;
  62.  
  63.   Application.Run();
  64.  
  65.   return 0;
  66. }
  67.  
  68. void QuitEvent(ULONG ID)
  69. {
  70.   Application.Stop();
  71. }
  72.  
  73.  
  74. int repeatCount = 0;
  75.  
  76. void CloseEvent()
  77. {
  78.   char* text;
  79.  
  80.   repeatCount++;
  81.  
  82.   switch( repeatCount )
  83.   {
  84.     case 1:
  85.       stringInput1.TextVal(Password);
  86.       break;
  87.     case 2:
  88.       text = stringInput1.TextVal();
  89.       break;
  90.     default:
  91.       Application.Stop();
  92.       break;
  93.   }
  94. }
  95.  
  96. //
  97. // Password Edit Hook
  98. //
  99. ULONG PasswordHook(struct SGWork *sgw,ULONG *msg,ULONG myData)
  100. {
  101.   sgw->BufferPos = sgw->NumChars;
  102.  
  103.   if(*msg == SGH_KEY)
  104.   {
  105.     switch (sgw->EditOp)
  106.     {
  107.       case EO_INSERTCHAR:
  108.         Password[sgw->BufferPos - 1] = sgw->WorkBuffer[sgw->BufferPos - 1];
  109.         Password[sgw->BufferPos] = '\0';
  110.         sgw->WorkBuffer[sgw->BufferPos - 1] = (UBYTE)PASSWORDCHAR;
  111.         break;
  112.       case EO_DELBACKWARD:
  113.         Password[sgw->BufferPos] = '\0';
  114.         break;
  115.       default:
  116.         sgw->Actions &= ~SGA_USE;
  117.         break;
  118.     }
  119.  
  120.     sgw->Actions |= SGA_REDISPLAY;
  121.     return( ULONG(~0L) );
  122.   }
  123.   if(*msg == SGH_CLICK)
  124.   {
  125.     sgw->BufferPos = sgw->NumChars;
  126.     return( ULONG(~0L) );
  127.   }
  128.   return(0L);
  129. }
  130.