File: PROTOCOL\TManageComboboxProtocolDlg.cpp

    1 //******************************************************************************
    2 //Datei     : TManageComboboxProtocolDlg.cpp
    3 //Projekt   : XCTL
    4 //Subsystem : Protokollbuch
    5 //Autor     : Jens Klier <klier@informatik.hu-berlin.de>
    6 //            Institut fuer Informatik,
    7 //            Humboldt-Universitaet Berlin
    8 //Inhalt    : Implementation der Klasse TManageComboboxProtocolDlg
    9 //******************************************************************************
   10 //!neu klier Protokollbuch
   11 
   12 #include "internls\evrythng.h"
   13 #include "protocol\TProtocol.h"
   14 #include "protocol\TManageComboboxProtocolDlg.h"
   15 
   16 //--||--\\--||--//--||--\\--||--//--||--\\--||--//--||--\\--||--//--||--\\--||--
   17 
   18 void TManageComboboxProtocolDlg::InitializeManageComboboxProtocolDlg(TProtocol *Proto)
   19 {
   20         Protocol= Proto;
   21 };
   22 
   23 // Initialisiert eine Combobox mit Werten aus einer ini-Datei/Parameterliste
   24 void TManageComboboxProtocolDlg::InitializeCombobox(HWND hwnd, HWND &hCBoxList, int id, int Nr, LPCSTR Name)
   25 {
   26         char buf[MaxString], CName[MaxString], *token;
   27         int i;
   28 
   29         hCBoxList= GetDlgItem( hwnd, id );
   30         ComboBox_ResetContent(hCBoxList);
   31 
   32         if ( strstr(Name, ",") == NULL )
   33         {
   34                 ComboBox_AddString( hCBoxList, "-" );
   35                 strcpy( CName, Name );
   36                 strcat( CName, itoa(i= 0, buf, 10) );
   37                 if ( (strstr(Name, "Motor") == NULL) && (strstr(Name, "Device") == NULL) )
   38                         GetPrivateProfileString(Protocol->GetProtocolSection(), CName, "", buf, MaxString, GetCFile());
   39                 else
   40                         GetPrivateProfileString(CName, "Name", "", buf, MaxString, GetHWFile());
   41                 while ( strlen(buf) != 0 )
   42                 {
   43                         if (ComboBox_FindString(hCBoxList, -1, buf) == CB_ERR)
   44                                 ComboBox_AddString( hCBoxList, buf );
   45                         strcpy( CName, Name );
   46                         strcat( CName, itoa(++i, buf, 10) );
   47                         if ( (strstr(Name, "Motor") == NULL) && (strstr(Name, "Device") == NULL) )
   48                                 GetPrivateProfileString(Protocol->GetProtocolSection(), CName, "", buf, MaxString, GetCFile());
   49                         else
   50                                 GetPrivateProfileString(CName, "Name", "", buf, MaxString, GetHWFile());
   51                 }
   52         }
   53         else
   54         {
   55                 strcpy(buf, Name);
   56                 token= strtok(buf, ",");
   57                 do
   58                 {
   59                         if (ComboBox_FindString(hCBoxList, -1, token) == CB_ERR)
   60                                 ComboBox_AddString( hCBoxList, token );
   61                 } while ( (token= strtok(NULL, ",")) != NULL);
   62                 ComboBox_SetCurSel( hCBoxList, 0);
   63         }
   64         Edit_LimitText(GetWindow(hCBoxList, GW_CHILD), Protocol->GetParameterMaxLen(Nr));
   65 };
   66 
   67 // Fügt einen Wert in eine Combobox ein
   68 void TManageComboboxProtocolDlg::AddComboboxItem(HWND hCBoxList, LPCSTR Item)
   69 {
   70         int iSel;
   71 
   72         iSel= ComboBox_GetCurSel(hCBoxList);
   73         if (ComboBox_FindString(hCBoxList, -1, Item) != CB_ERR)
   74                 return;
   75         ComboBox_AddString( hCBoxList, Item );
   76         if (iSel == CB_ERR)
   77                 ComboBox_SetCurSel(hCBoxList, 0);
   78         else
   79                 ComboBox_SetCurSel(hCBoxList, iSel);
   80 };
   81 
   82 // Fügt einen Wert in eine Combobox ein und wählt ihn aus
   83 void TManageComboboxProtocolDlg::AddAndSelectComboboxItem(HWND hCBoxList, LPCSTR Item)
   84 {
   85         if (strlen(Item) > 0)
   86                 if ( ComboBox_FindString(hCBoxList, -1, Item) == CB_ERR )
   87                         ComboBox_AddString(hCBoxList, Item);
   88         ComboBox_SetCurSel(hCBoxList, -1);
   89         ComboBox_SelectString(hCBoxList, -1, Item);
   90 };
   91 
   92 // löscht einen Wert aus einer Combobox
   93 void TManageComboboxProtocolDlg::DeleteComboboxItem(HWND hCBoxList, LPCSTR Item)
   94 {
   95         int iSel, iFind;
   96 
   97         iSel= ComboBox_GetCurSel(hCBoxList);
   98         if ((iFind= ComboBox_FindString(hCBoxList, -1, Item)) == CB_ERR)
   99                 return;
  100         ComboBox_DeleteString(hCBoxList, iFind);
  101         if (iSel == CB_ERR)
  102                 ComboBox_SetCurSel(hCBoxList, 0);
  103         else
  104                 if (ComboBox_SetCurSel(hCBoxList, iSel) == CB_ERR)
  105                         ComboBox_SetCurSel(hCBoxList, iSel - 1);
  106 };
  107 
  108 // Speichert die Werte einer Combobox in der Programm-ini-datei
  109 void TManageComboboxProtocolDlg::SaveCombobox(HWND hwnd, int id, LPCSTR Name)
  110 {
  111         char buf[MaxString], buf2[MaxString], CName[MaxString];
  112         int i;
  113         BOOL bFind;
  114 
  115         GetDlgItemText(hwnd, id, buf, MaxString);
  116         if (strlen(buf) > 0)
  117         {
  118                 bFind= FALSE;
  119                 strcpy( CName, Name );
  120                 strcat( CName, itoa(i= 0, buf2, 10) );
  121                 GetPrivateProfileString(Protocol->GetProtocolSection(), CName, "", buf2, MaxString, GetCFile());
  122                 while ( strlen(buf2) != 0 )
  123                 {
  124                         if (strcmp(buf, buf2) == 0)
  125                                 bFind= TRUE;
  126                         strcpy( CName, Name );
  127                         strcat( CName, itoa(++i, buf2, 10) );
  128                         GetPrivateProfileString(Protocol->GetProtocolSection(), CName, "", buf2, MaxString, GetCFile());
  129                 }
  130                 if ( !bFind )
  131                         WritePrivateProfileString(Protocol->GetProtocolSection(), CName, buf, GetCFile());
  132         }
  133 };
  134 
  135 
  136 // LastLine
  137 
  138