File: PROTOCOL\TProtocolDlg.cpp

    1 //******************************************************************************
    2 //Datei     : TProtocolDlg.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 TProtocolDlg
    9 //******************************************************************************
   10 //!neu klier Protokollbuch
   11 
   12 #include "internls\evrythng.h"
   13 #include "winresrc\rc_prtow.h" // Ressourcen-IDs
   14 #include "help\help_def.h"     // Help-IDs
   15 #include <commdlg.h>
   16 #include <commctrl.h>
   17 
   18 #include "protocol\TProtocolLanguage.h"
   19 #include "protocol\TProtocol.h"
   20 #include "protocol\TProtocolDlg.h"
   21 #include "protocol\TProtocolManagePrintDlg.h"
   22 #include "protocol\TProtocolPasswortDlg.h"
   23 
   24 //--||--\\--||--//--||--\\--||--//--||--\\--||--//--||--\\--||--//--||--\\--||--
   25 
   26 extern TProtocolLanguage *ProtocolLanguage;
   27 TProtocolDlg *ProtocolDlg;
   28 TProtocolManagePrintDlg *ProtocolManagePrintDlg;
   29 
   30 //Datum: 27.07.2002 extern TModelessDlg* TheModeless;
   31 extern TModelessDlg *ProtoPrintDlg; //! neu Kullmann+Reinecker
   32 
   33 // Subclass procedure
   34 LRESULT WINAPI SkizzeSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
   35 {
   36         if (uMsg == WM_PAINT)
   37         {
   38                 ProtocolDlg->RefreshPic();
   39                 ValidateRect(hwnd, NULL);
   40                 return TRUE;
   41         }
   42 
   43         return CallWindowProc(ProtocolDlg->wpOrigProc, hwnd, uMsg, wParam, lParam);
   44 }
   45 
   46 TProtocolDlg::TProtocolDlg() : bOkStatus(ENABLE), bReadOnlyStatus(ENABLE)
   47 {}
   48 
   49 
   50 TProtocolDlg::~TProtocolDlg()
   51 {
   52         Protocol->freePic();
   53         //! neu Kullmann+Reinecker: TheModeless durch ProtoPrintDlg ersetzt
   54         _FREEOBJ(ProtoPrintDlg);
   55 }
   56 
   57 // Aktivieren/Deaktivieren eines Dialogelementes
   58 void TProtocolDlg::EnableDlgItem( int id , BOOL Status)
   59 {
   60         EnableDlgItem(hwndDlg, id , Status);
   61 };
   62 
   63 // Aktivieren/Deaktivieren eines Dialogelementes
   64 void TProtocolDlg::EnableDlgItem( HWND hwnd, int id , BOOL Status)
   65 {
   66         EnableWindow( GetDlgItem(hwnd, id), Status);
   67 };
   68 
   69 // Sichtbarmachen/Verstecken eines Dialogelementes
   70 void TProtocolDlg::ShowDlgItem( int id , int idShow)
   71 {
   72         ShowDlgItem( hwndDlg, id , idShow);
   73 };
   74 
   75 // Sichtbarmachen/Verstecken eines Dialogelementes
   76 void TProtocolDlg::ShowDlgItem( HWND hwnd, int id , int idShow)
   77 {
   78         ShowWindow( GetDlgItem(hwnd, id), idShow );
   79 };
   80 
   81 // Ermittelt die Koordinaten des Rechteckes eines Dialogelementes
   82 void TProtocolDlg::GetDlgItemRect( HWND hwnd, int id, LPRECT Rect )
   83 {
   84         int dx, dy, dx1, dy1;
   85         RECT tmpRect;
   86 
   87         GetWindowRect(hwnd, &tmpRect);
   88         dx1= tmpRect.left;
   89         dy1= tmpRect.top;
   90         dx= tmpRect.right - tmpRect.left;
   91         dy= tmpRect.bottom - tmpRect.top;
   92         GetClientRect(hwnd, &tmpRect);
   93         dx= dx - tmpRect.right;
   94         dy= dy - tmpRect.bottom;
   95         dx= (dx / 2) + dx1;
   96         dy= (dy - (dx - dx1)) + dy1;
   97         GetWindowRect(GetDlgItem(hwnd, id), &tmpRect);
   98         Rect->left= tmpRect.left - dx;
   99         Rect->top= tmpRect.top - dy;
  100         Rect->right= tmpRect.right - dx;
  101         Rect->bottom= tmpRect.bottom - dy;
  102 };
  103 
  104 void TProtocolDlg::SaveDlg(HWND hwnd, int id)
  105 {
  106         char buf[MaxString];
  107 
  108         if ( (id == ProbeSkizzeDlg) && (IsDlgButtonChecked(hwnd, id_ReadOnly) == 1) )
  109                 Protocol->SetProtocolValue(GetStatusId(), itoa(1, buf , 10));
  110         ManageDlg(hwnd, id, Save);
  111 };
  112 
  113 void TProtocolDlg::RefreshDlg(HWND hwnd, int id)
  114 {
  115         ManageDlg(hwnd, id, Refresh);
  116 };
  117 
  118 BOOL TProtocolDlg::TestDlg(HWND hwnd, int id)
  119 {
  120         char buf[3*MaxParameterString];
  121 
  122         if (id == ProbeSkizzeDlg)
  123         {
  124                 if (IsDlgButtonChecked(hwnd, id_ReadOnly) == 1)
  125                 {
  126                         sprintf(buf, ProtocolLanguage->GetMessage(20), "Passwortschutz",
  127                                         "Nicht Aktiv", "Aktiv");
  128                         SetDlgItemText(hwnd, id_StatusLine, buf);
  129                         MessageBox(GetFocus(), buf, ProtocolLanguage->GetWarning(), MBINFO);
  130                         return FALSE;
  131                 }
  132                 if (bChangeSkizze)
  133                 {
  134                         SetDlgItemText(hwnd, id_StatusLine, ProtocolLanguage->GetMessage(69));
  135                         MessageBox(GetFocus(), ProtocolLanguage->GetMessage(69),
  136                                            ProtocolLanguage->GetWarning(), MBINFO);
  137                         return FALSE;
  138                 }
  139         }
  140         return ManageDlg(hwnd, id, ChangeTest);
  141 };
  142 
  143 void TProtocolDlg::EnableDlg(HWND hwnd, int id, BOOL Status)
  144 {
  145         if (Status == ENABLE)
  146                 ManageDlg(hwnd, id, Enable);
  147         if (Status == DISABLE)
  148                 ManageDlg(hwnd, id, Disable);
  149 };
  150 
  151 void TProtocolDlg::InitializeManagePrintDlg( TProtocolManagePrintDlg *ManagePrintDlg)
  152 {
  153         ProtocolManagePrintDlg= ManagePrintDlg;
  154 };
  155 
  156 void TProtocolDlg::EnableDialog( BOOL Status)
  157 {
  158         EnableDlg( hwndDlg, ProbeSkizzeDlg, Status );
  159         EnableDlg( hwndDlg, CurrentDlg, Status );
  160         EnableDlgItem( id_Next , Status );
  161         EnableDlgItem( id_Back , Status );
  162         EnableDlgItem( id_Copy , Status );
  163         EnableDlgItem( id_Edit, Status );
  164         if (Status == DISABLE)
  165         {
  166                 EnableDlgItem( IDOK, Status );
  167                 EnableDlgItem( id_ReadOnly, Status );
  168         }
  169         else
  170         {
  171                 EnableDlgItem( IDOK, bOkStatus );
  172                 EnableDlgItem( id_ReadOnly, bReadOnlyStatus );
  173         }
  174         EnableDlgItem( IDCANCEL, Status );
  175         EnableDlgItem( IDPRINT, Status );
  176         EnableDlgItem( id_Tab, Status );
  177         //! neu Kullmann+Reinecker: TheModeless durch ProtoPrintDlg ersetzt
  178         if ( ProtoPrintDlg )
  179                 ProtocolManagePrintDlg->EnableButton( Status );
  180 };
  181 
  182 void TProtocolDlg::EnableOk( BOOL Status)
  183 {
  184         bOkStatus= Status;
  185         EnableDlgItem( IDOK, Status );
  186 };
  187 
  188 void TProtocolDlg::EnableReadOnly( BOOL Status)
  189 {
  190         bReadOnlyStatus= Status;
  191         EnableDlgItem( id_ReadOnly, Status );
  192 };
  193 
  194 BOOL TProtocolDlg::TestChangeDlg( )
  195 {
  196         char lLfdNr[MaxString / 4], lLfdNr2[MaxString / 4];
  197         BOOL bTest;
  198         char buf[MaxString];
  199 
  200         bTest= FALSE;
  201         if (bDebug)
  202                 if (strcmp(Protocol->GetLfdNr(lLfdNr), GetDlgItemText_LfdNr(hwndDlg, lLfdNr2)) != 0)
  203                 {
  204                         sprintf(buf, "currentLfdNr: %s != DlgLfdNr: %s", lLfdNr, lLfdNr2);
  205                         MessageBox(GetFocus(), buf, "Debug Info", MBINFO);
  206                 }
  207         if (!TestDlg(hwndDlg, ProbeSkizzeDlg) || !TestDlg(hwndDlg, CurrentDlg))
  208         {
  209                 if (MessageBox(GetFocus(), ProtocolLanguage->GetMessage(18),
  210                                            ProtocolLanguage->GetQuestion(),
  211                                            MBASK) == IDYES)
  212                 {
  213                         bTest= TRUE;
  214                         if (!TestPflichtDlg(hwndDlg))
  215                                 return bTest;
  216                         if (Protocol->IsProtocolReadOnly())
  217                                 if (!GetPasswort(hwndDlg))
  218                                         return bTest;
  219                         SaveDlg( hwndDlg, ProbeSkizzeDlg);
  220                         SaveDlg( hwndDlg, CurrentDlg);
  221                         Protocol->SavePicFile();
  222                         Protocol->SaveProtocolString();
  223                         LoadMeasurement(hwndDlg);
  224                         SetDlgItemText(hwndDlg, id_StatusLine, ProtocolLanguage->GetMessage(62));
  225                         if ( ProtoPrintDlg )
  226                                 ProtocolManagePrintDlg->SearchNew();
  227                 }
  228         }
  229         return bTest;
  230 };
  231 
  232 BOOL TProtocolDlg::ManageDlgItem(HWND hwnd, int id, int Nr, TAction Action)
  233 {
  234         char buf[MaxParameterString], buf2[MaxParameterString];
  235         char buf3[3*MaxParameterString], buf4[MaxString];
  236         HWND DlgHwnd;
  237 
  238         DlgHwnd= GetDlgItem( hwnd, id);
  239         switch (Action)
  240         {
  241                 case DefaultTest:    // Prueft ob ein Pflichtfeld einen Wert enthaelt
  242                         if ( IsWindowVisible(DlgHwnd) )
  243                                 GetDlgItemText(hwnd, id, buf, MaxParameterString);
  244                         else
  245                                 Protocol->GetProtocolValue(Nr, buf);
  246                         if ( strlen(buf) == 0 )
  247                         {
  248                                 sprintf(buf, ProtocolLanguage->GetMessage(19),
  249                                                 Protocol->GetParameterNamen(Nr, buf2));
  250                                 SetDlgItemText(hwnd, id_StatusLine, buf);
  251                                 MessageBox(GetFocus(), buf, ProtocolLanguage->GetFailure(), MBFAILURE);
  252                                 if ( !IsWindowVisible(DlgHwnd) )
  253                                 {
  254                                         SaveDlg( hwnd, CurrentDlg);
  255                                         ShowDialog( GetDlg(id), SHOW );
  256                                 }
  257                                 SetFocus(DlgHwnd);
  258                                 return FALSE;
  259                         }
  260                         if ((Nr == GetDatumId()) && !Protocol->TestDate(buf))
  261                         {
  262                                 SetDlgItemText(hwnd, id_StatusLine, ProtocolLanguage->GetMessage(58));
  263                                 MessageBox(GetFocus(), ProtocolLanguage->GetMessage(58),
  264                                                    ProtocolLanguage->GetFailure(), MBFAILURE);
  265                                 SetFocus(DlgHwnd);
  266                                 return FALSE;
  267                         }
  268                         break;
  269 
  270                 case ChangeTest:    // Testet ein Feld ob es geaendert wurde
  271                         GetDlgItemText(hwnd, id, buf, MaxParameterString);
  272                         Protocol->GetProtocolValue( Nr, buf2);
  273                         if ( strcmp(buf, buf2) != 0 )
  274                         {
  275                                 sprintf(buf3, ProtocolLanguage->GetMessage(20),
  276                                                 Protocol->GetParameterNamen(Nr, buf4),
  277                                                 Protocol->GetProtocolValue(Nr, buf2), buf);
  278                                 SetDlgItemText(hwnd, id_StatusLine, buf3);
  279                                 MessageBox(GetFocus(), buf3, ProtocolLanguage->GetWarning(), MBINFO);
  280                                 return FALSE;
  281                         }
  282                         break;
  283 
  284                 case Save:    // Speichert ein Feld und testet die zulaessige Parameterlaenge
  285                         GetDlgItemText(hwnd, id, buf, MaxParameterString);
  286                         if (!Protocol->SetProtocolValue(Nr, buf))
  287                         {
  288                                 sprintf(buf3, ProtocolLanguage->GetMessage(21),
  289                                                 Protocol->GetParameterNamen(Nr, buf2), buf,
  290                                                 Protocol->GetParameterMaxLen(Nr));
  291                                 SetDlgItemText(hwnd, id_StatusLine, buf3);
  292                                 MessageBox(GetFocus(), buf3, ProtocolLanguage->GetFailure(), MBFAILURE);
  293                         }
  294                         break;
  295 
  296                 case Refresh:    // Liest ein Feld aus dem Protokolldatensatz und zeigt es an
  297                         EnableDlgItem(hwnd, id, ENABLE);
  298                         Edit_LimitText(GetDlgItem(hwnd, id),
  299                                                    Protocol->GetParameterMaxLen(Nr));
  300                         SetDlgItemText(hwnd, id, Protocol->GetProtocolValue( Nr, buf));
  301                         if ( Protocol->IsParameterReadOnly(Nr) && ((strlen(buf) > 0) ||
  302                                         Protocol->IsProtocolOn()) || Protocol->IsProtocolDelete() )
  303                                 EnableDlgItem(hwnd, id, DISABLE);
  304                         break;
  305 
  306                 case Enable:    // Enabled ein Feld
  307                         if ( !(Protocol->IsParameterReadOnly(Nr) && ((strlen(buf) > 0) ||
  308                                         Protocol->IsProtocolOn()) || Protocol->IsProtocolDelete()) )
  309                                 EnableDlgItem(hwnd, id, ENABLE);
  310                         break;
  311 
  312                 case Disable:    // Disabled ein Feld
  313                         EnableDlgItem(hwnd, id, DISABLE);
  314                         break;
  315         }
  316         return TRUE;
  317 };
  318 
  319 void TProtocolDlg::RefreshPic()
  320 {
  321         char c, t[MaxString];
  322         int x, y;
  323         RECT Rect;
  324 
  325         SelectObject(hDC, hPenWhite);
  326         GetDlgItemRect( hwndDlg, id_Skizze, &Rect );
  327         for (int i= 0; i <= Rect.bottom - Rect.top; i++)
  328         {
  329                 MoveToEx(hDC, 0, i, NULL);
  330                 LineTo(hDC, Rect.right - Rect.left, i);
  331         }
  332         SelectObject(hDC, hPenBlack);
  333 
  334         Protocol->ResetXY();
  335         while (Protocol->GetXY( c, x, y, t ))
  336         {
  337                 switch (c)
  338                 {
  339                         case 'M':
  340                                 MoveToEx(hDC, x, y, NULL);
  341                                 break;
  342                         
  343                         case 'L':
  344                                 LineTo(hDC, x, y);
  345                                 break;
  346                         
  347                         case 'T':
  348                                 TextOut(hDC, x, y, t, strlen(t));
  349                                 break;
  350                         
  351                         default:
  352                                 MessageBox(GetFocus(), ProtocolLanguage->GetMessage(23),
  353                                                    ProtocolLanguage->GetFailure(), MBFAILURE);
  354                                 Protocol->DeletePicFile(Protocol->GetLfdNr(t));
  355                 }
  356         }
  357 };
  358 
  359 
  360 void TProtocolDlg::Dlg_OnInit(HWND hwnd, HWND hwndCtl, LPARAM lParam)
  361 {
  362         HWND hwndSkizze;
  363         RECT Rect;
  364         char buf[MaxString];
  365 
  366         if (!Protocol->Initialize())
  367         {
  368                 DestroyWindow(hwnd);
  369                 return;
  370         }
  371 
  372         if ( GetPrivateProfileInt("Protocol", "Debug", 0, GetCFile()) == 1)
  373                 bDebug= TRUE;
  374         else
  375                 bDebug= FALSE;
  376 
  377         ProtocolDlg= this;
  378 
  379         ProtocolLanguage->InitializeDlgLanguage(hwnd);
  380 
  381         // Retrieve the handle of the edit control.
  382         hwndSkizze= GetDlgItem(hwnd, id_Skizze);
  383         // Subclass the edit control.
  384         wpOrigProc= (WNDPROC) SetWindowLong(hwndSkizze,
  385                                                                                  GWL_WNDPROC, (LONG) SkizzeSubclassProc );
  386 
  387         hwndDlg= hwnd;
  388         bLine= TRUE;
  389         LButtonDown= bEdit= FALSE;
  390         bLfdNrCorrect= TRUE;
  391         hDC= GetDC(GetDlgItem(hwndDlg, id_Skizze));
  392         hPenWhite= CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
  393         hPenBlack= CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
  394         SelectObject(hDC, hPenBlack);
  395 
  396         GetDlgItemRect( hwndDlg, id_EditText, &Rect );
  397         dxText= Rect.right - Rect.left;
  398         dyText= Rect.bottom - Rect.top;
  399         GetDlgItemRect( hwndDlg, id_Skizze, &Rect );
  400         MoveWindow(GetDlgItem( hwndDlg, id_Skizze ), Rect.left, Rect.top,
  401                            Rect.right - Rect.left, Rect.bottom - Rect.top, FALSE);
  402 
  403         hTab= GetDlgItem( hwnd, id_Tab );
  404 
  405         Protocol->InitializeDefaultParameter();
  406         InitializeDlgItems(hwnd);
  407 
  408         if ( Protocol->LoadProtocolString(Protocol->GetLfdNr(buf)) == 1 )
  409         {
  410                 CurrentDlg= DefaultDlg;
  411                 NewMeasurement(hwnd);
  412         }
  413         else
  414         {
  415                 if (CurrentDlg == -1)
  416                         CurrentDlg= Protocol->GetCurrentDlg();
  417                 LoadMeasurement(hwnd);
  418         }
  419         ShowDialog(CurrentDlg, SHOW);
  420         SetFocus(GetDlgItem(hwnd, IDOK));
  421 };
  422 
  423 void TProtocolDlg::Dlg_OnDestroy( HWND hwnd )
  424 {
  425         SetWindowLong(hwnd, GWL_WNDPROC, (LONG) wpOrigProc);
  426 };
  427 
  428 void TProtocolDlg::ShowLfdNr(LPCSTR lLfdNr)
  429 {
  430         bLfdNrCorrect= TRUE;
  431         EnableDialog(ENABLE);
  432         if (Protocol->ReloadProtocolString(lLfdNr) != 0)
  433         {
  434                 NewMeasurement(hwndDlg);
  435         }
  436         else
  437         {
  438                 LoadMeasurement(hwndDlg);
  439         }
  440 };
  441 
  442 BOOL TProtocolDlg::GetPasswort(HWND hwnd)
  443 {
  444         TModalDlg *dlg= 0;
  445         char buf[MaxString];
  446 
  447         GetPrivateProfileString( "Steuerprogramm", "PW", "", buf, MaxString, GetCFile( ) );
  448         strrev(buf);
  449 
  450         dlg= (TProtocolPasswortDlg *)new TProtocolPasswortDlg("ProtocolPasswortDlg", this);
  451         if ( dlg ) dlg->ExecuteDialog(hwnd);
  452         _FREEOBJ(dlg);
  453 
  454         if (strlen(buf) != 0)
  455                 if (strcmp(buf, Passwort) == 0)
  456                         return TRUE;
  457         SetDlgItemText(hwnd, id_StatusLine, ProtocolLanguage->GetMessage(24));
  458         MessageBox(GetFocus(), ProtocolLanguage->GetMessage(24),
  459                            ProtocolLanguage->GetFailure(), MBFAILURE);
  460         return FALSE;
  461 };
  462 
  463 void TProtocolDlg::NewMeasurement( HWND hwnd )
  464 {
  465         bChangeSkizze= FALSE;
  466         if (Protocol->IsEmptyProtocolFile())
  467                 ShowDlgItem(id_Back, HIDE);
  468         else
  469                 ShowDlgItem(id_Back, SHOW);
  470         ShowDlgItem(id_Next, HIDE);
  471         ShowDlgItem(id_Copy, HIDE);
  472         EnableOk(ENABLE);
  473         CheckDlgButton(hwnd, id_ReadOnly, 0);
  474         EnableReadOnly(DISABLE);
  475         SetDlgItemText_LfdNr(hwnd);
  476         Protocol->SetDefaultParameter();
  477         SetParameterStatus();
  478         RefreshDlg(hwnd, ProbeSkizzeDlg);
  479         RefreshPic();
  480         RefreshCombobox();
  481         RefreshDlg(hwnd, CurrentDlg);
  482         SetDlgItemText(hwnd, id_StatusLine, ProtocolLanguage->GetMessage(63));
  483 };
  484 
  485 void TProtocolDlg::LoadMeasurement( HWND hwnd )
  486 {
  487         char buf[MaxString];
  488 
  489         bChangeSkizze= FALSE;
  490         if ( Protocol->IsFirstProtocolString() )
  491                 ShowDlgItem(id_Back, HIDE);
  492         else
  493                 ShowDlgItem(id_Back, SHOW);
  494         if ( Protocol->IsLastProtocolString() )
  495                 SetDlgItemText(hwnd, id_Next, "new");
  496         else
  497                 SetDlgItemText(hwnd, id_Next, "-->");
  498         if (Protocol->IsProtocolOn() && !Protocol->IsProtocolOnBegin())
  499         {
  500                 if (Protocol->IsLastProtocolString())
  501                         ShowDlgItem(id_Next, HIDE);
  502                 else
  503                         ShowDlgItem(id_Next, SHOW);
  504                 ShowDlgItem(id_Copy, HIDE);
  505         }
  506         else
  507         {
  508                 ShowDlgItem(id_Next, SHOW);
  509                 ShowDlgItem(id_Copy, SHOW);
  510         }
  511         if (Protocol->IsMaxLfdNr())
  512         {
  513                 if (Protocol->IsLastProtocolString())
  514                         ShowDlgItem(id_Next, HIDE);
  515                 ShowDlgItem(id_Copy, HIDE);
  516         }
  517         SetDlgItemText_LfdNr(hwnd);
  518         Protocol->LoadPicFile(Protocol->GetLfdNr(buf));
  519         if (!Protocol->IsProtocolReadOnly())
  520                 CheckDlgButton(hwnd, id_ReadOnly, 0);
  521         else
  522                 CheckDlgButton(hwnd, id_ReadOnly, 3);
  523         if (Protocol->IsProtocolOn())
  524         {
  525                 EnableReadOnly(DISABLE);
  526                 if ( Protocol->IsLastProtocolString() && !Protocol->IsProtocolReadOnly() )
  527                 {
  528                         if ( Protocol->IsProtocolOnBegin() )
  529                                 Protocol->SetDefaultParameter();
  530                         EnableOk(ENABLE);
  531                 }
  532                 else
  533                         EnableOk(DISABLE);
  534         }
  535         else
  536                 EnableReadOnly(ENABLE);
  537         SetParameterStatus();
  538         RefreshDlg(hwnd, ProbeSkizzeDlg);
  539         RefreshPic();
  540         RefreshCombobox();
  541         RefreshDlg(hwnd, CurrentDlg);
  542         SetDlgItemText(hwnd, id_StatusLine, "");
  543 };
  544 
  545 void TProtocolDlg::SetParameterStatus( )
  546 {
  547         if (Protocol->IsProtocolOn())
  548                 Protocol->SetOnDefaultParameterReadOnly();
  549         else if (Protocol->IsProtocolDelete())
  550                 Protocol->SetAllParameterReadOnly();
  551         else if (Protocol->IsProtocolReadOnly())
  552                 Protocol->SetDefaultParameterReadOnly();
  553         else
  554                 Protocol->SetAllParameterReadWrite();
  555 };
  556 
  557 BOOL TProtocolDlg::Dlg_OnCommand(HWND hwnd, int id, UINT codeNotify)
  558 {
  559         char buf[MaxString], buf2[MaxString];
  560 
  561         switch (id)
  562         {
  563                 case id_Back:
  564                         bLfdNrCorrect= TRUE;
  565                         if (TestChangeDlg())
  566                                 break;
  567                         Protocol->LoadLastProtocolString();
  568                         LoadMeasurement(hwnd);
  569                         break;
  570                 
  571                 case id_Next:
  572                         bLfdNrCorrect= TRUE;
  573                         if (TestChangeDlg())
  574                                 break;
  575                         if (Protocol->LoadNextProtocolString() == 1)
  576                                 NewMeasurement(hwnd);
  577                         else
  578                                 LoadMeasurement(hwnd);
  579                         break;
  580                 
  581                 case id_Copy:
  582                         bLfdNrCorrect= TRUE;
  583                         if (TestChangeDlg())
  584                                 break;
  585                         Protocol->CopyProtocolString();
  586                         NewMeasurement(hwnd);
  587                         break;
  588                 
  589                 case id_LfdNrBereich:
  590                 case id_RTKNr:
  591                 case id_LfdNr:
  592                         if ( (codeNotify == EN_CHANGE) && IsDlgItemModify() )
  593                         {
  594                                 if (bLfdNrCorrect)
  595                                 {
  596                                         bLfdNrCorrect= FALSE;
  597                                         if (id == id_LfdNr)
  598                                                 if (TestChangeDlg())
  599                                                 {
  600                                                         SetDlgItemText_LfdNr(hwnd);
  601                                                         RefreshDlg(hwnd, ProbeSkizzeDlg);
  602                                                         RefreshPic();
  603                                                         RefreshDlg(hwnd, CurrentDlg);
  604                                                         break;
  605                                                 }
  606                                 }
  607                                 EnableDialog( DISABLE );
  608                                 if ( TestDlgItemText_LfdNr(hwnd, buf) )
  609                                 {
  610                                         bLfdNrCorrect= TRUE;
  611                                         EnableDialog( ENABLE );
  612                                         if ( !Protocol->SearchProtocolString(buf) )
  613                                         {
  614                                                 if (id == id_LfdNr)
  615                                                 {
  616                                                         Protocol->CopyProtocolString(buf);
  617                                                         NewMeasurement(hwnd);
  618                                                 }
  619                                         }
  620                                         else
  621                                         {
  622                                                 Protocol->NewProtocolString();
  623                                                 Protocol->LoadProtocolString(buf);
  624                                                 LoadMeasurement(hwnd);
  625                                         }
  626                                 }
  627                                 else
  628                                 {
  629                                         SetDlgItemText(hwnd, id_StatusLine, ProtocolLanguage->GetMessage(64));
  630                                 }
  631                                 SetFocus(GetDlgItem(hwndDlg, id));
  632                         }
  633                         break;
  634                 
  635                 case id_ReadOnly:
  636                         if (Protocol->IsProtocolOn())
  637                                 break;
  638                         switch (IsDlgButtonChecked(hwnd, id_ReadOnly))
  639                         {
  640                                 case 0:
  641                                         if (Protocol->IsLastProtocolString())
  642                                         {
  643                                                 if (MessageBox(GetFocus(), ProtocolLanguage->GetMessage(26),
  644                                                                            ProtocolLanguage->GetQuestion(), MBASK) == IDNO)
  645                                                         break;
  646                                         }
  647                                         else
  648                                         {
  649                                                 if (MessageBox(GetFocus(), ProtocolLanguage->GetMessage(27),
  650                                                                            ProtocolLanguage->GetQuestion(), MBASK) == IDNO)
  651                                                         break;
  652                                         }
  653                                         CheckDlgButton(hwnd, id_ReadOnly, 1);
  654                                         break;
  655                 
  656                                 case 1:
  657                                         CheckDlgButton(hwnd, id_ReadOnly, 0);
  658                                         break;
  659                         }
  660                         break;
  661                 
  662                 case id_OKEdit:
  663                         GetDlgItemText(hwndDlg, id_EditText, buf, MaxString / 4);
  664                         if (strlen(buf) > 0)
  665                         {
  666                             bChangeSkizze= TRUE;
  667                                 Protocol->SetXY( 'T', xText, yText, buf );
  668                         }
  669                         ShowDlgItem( id_EditText, HIDE );
  670                         ShowDlgItem( id_OKEdit, HIDE );
  671                         ShowDlgItem( id_UnDo, SHOW );
  672                         if (bLine)
  673                         {
  674                                 ShowDlgItem( id_LineButton, HIDE );
  675                                 ShowDlgItem( id_LineText, SHOW );
  676                                 ShowDlgItem( id_PointText, HIDE );
  677                                 ShowDlgItem( id_PointButton, SHOW );
  678                         }
  679                         else
  680                         {
  681                                 ShowDlgItem( id_PointButton, HIDE );
  682                                 ShowDlgItem( id_PointText, SHOW );
  683                                 ShowDlgItem( id_LineText, HIDE );
  684                                 ShowDlgItem( id_LineButton, SHOW );
  685                         }
  686                         ShowDlgItem( id_Loeschen, SHOW );
  687                         ShowDlgItem( id_Cancel, SHOW );
  688                         ShowDlgItem( id_Edit, SHOW );
  689                         RefreshPic();
  690                         break;
  691                 
  692                 case id_Loeschen:
  693                         if (MessageBox(GetFocus(), ProtocolLanguage->GetMessage(25),
  694                                                    ProtocolLanguage->GetQuestion(), MBASK) == IDYES)
  695                         {
  696                                 Protocol->freePic();
  697                                 RefreshPic();
  698                                 EnableDlgItem(id_UnDo, DISABLE);
  699                         }
  700                         break;
  701                 
  702                 case id_UnDo:
  703                         bChangeSkizze= TRUE;
  704                         if (!Protocol->UndoXY())
  705                                 EnableDlgItem(id_UnDo, DISABLE);
  706                         RefreshPic();
  707                         break;
  708                 
  709                 case id_PointButton:
  710                         bLine= FALSE;
  711                         ShowDlgItem( id_PointButton, HIDE );
  712                         ShowDlgItem( id_PointText, SHOW );
  713                         ShowDlgItem( id_LineText, HIDE );
  714                         ShowDlgItem( id_LineButton, SHOW );
  715                         SetDlgItemText(hwnd, id_StatusLine, ProtocolLanguage->GetMessage(65));
  716                         break;
  717                 
  718                 case id_LineButton:
  719                         bLine= TRUE;
  720                         ShowDlgItem( id_LineButton, HIDE );
  721                         ShowDlgItem( id_LineText, SHOW );
  722                         ShowDlgItem( id_PointText, HIDE );
  723                         ShowDlgItem( id_PointButton, SHOW );
  724                         SetDlgItemText(hwnd, id_StatusLine, ProtocolLanguage->GetMessage(66));
  725                         break;
  726                 
  727                 case id_Cancel:
  728                         bEdit= FALSE;
  729                         EnableDlgItem(id_UnDo, ENABLE);
  730                         ShowDlgItem( id_UnDo, HIDE );
  731                         ShowDlgItem( id_LineButton, HIDE );
  732                         ShowDlgItem( id_PointText, HIDE );
  733                         ShowDlgItem( id_PointButton, HIDE );
  734                         ShowDlgItem( id_LineText, HIDE );
  735                         ShowDlgItem( id_Loeschen, HIDE );
  736                         ShowDlgItem( id_Cancel, HIDE );
  737                         SetDlgItemText(hwnd, id_Edit, "Edit");
  738                         Protocol->LoadPicFile(Protocol->GetLfdNr(buf));
  739                         RefreshPic();
  740                         EnableDialog( ENABLE );
  741                         EnableDlgItem_LfdNr( ENABLE );
  742                         SetDlgItemText(hwnd, id_StatusLine, "");
  743                         break;
  744                 
  745                 case id_Edit:
  746                         if (Protocol->IsProtocolDelete())
  747                                 break;
  748                         if (bEdit)
  749                         {
  750                                 bEdit= FALSE;
  751                                 EnableDlgItem(id_UnDo, ENABLE);
  752                                 ShowDlgItem( id_UnDo, HIDE );
  753                                 ShowDlgItem( id_LineButton, HIDE );
  754                                 ShowDlgItem( id_PointText, HIDE );
  755                                 ShowDlgItem( id_PointButton, HIDE );
  756                                 ShowDlgItem( id_LineText, HIDE );
  757                                 ShowDlgItem( id_Loeschen, HIDE );
  758                                 ShowDlgItem( id_Cancel, HIDE );
  759                                 SetDlgItemText(hwnd, id_Edit, "Edit");
  760                                 RefreshPic();
  761                                 EnableDialog( ENABLE );
  762                                 EnableDlgItem_LfdNr( ENABLE );
  763                                 SetDlgItemText(hwnd, id_StatusLine, ProtocolLanguage->GetMessage(67));
  764                         }
  765                         else
  766                         {
  767                                 bEdit= TRUE;
  768                                 SetDlgItemText(hwnd, id_Edit, "Ok");
  769                                 ShowDlgItem( id_UnDo, SHOW );
  770                                 if (bLine)
  771                                 {
  772                                         ShowDlgItem( id_LineButton, HIDE );
  773                                         ShowDlgItem( id_LineText, SHOW );
  774                                         ShowDlgItem( id_PointText, HIDE );
  775                                         ShowDlgItem( id_PointButton, SHOW );
  776                                 }
  777                                 else
  778                                 {
  779                                         ShowDlgItem( id_PointButton, HIDE );
  780                                         ShowDlgItem( id_PointText, SHOW );
  781                                         ShowDlgItem( id_LineText, HIDE );
  782                                         ShowDlgItem( id_LineButton, SHOW );
  783                                 }
  784                                 ShowDlgItem( id_Loeschen, SHOW );
  785                                 ShowDlgItem( id_Cancel, SHOW );
  786                                 RefreshPic();
  787                                 EnableDialog( DISABLE );
  788                                 EnableDlgItem_LfdNr( DISABLE );
  789                                 EnableDlgItem( id_Edit, ENABLE );
  790                                 SetDlgItemText(hwnd, id_StatusLine, ProtocolLanguage->GetMessage(68));
  791                         }
  792                         break;
  793                 
  794                 case id_Help:
  795                         if (bEdit)
  796                                 WinHelp(hwnd, GetHelpFile(), HELP_CONTEXT, Help_ProtocolEditSkizze);
  797                         else
  798                                 WinHelp(hwnd, GetHelpFile(), HELP_CONTEXT, Help_Protocol);
  799                         break;
  800                 
  801                 case IDCANCEL:
  802                         if (TestChangeDlg())
  803                                 break;
  804                         if (Protocol->IsProtocolOn())
  805                         {
  806                                 if (MessageBox(GetFocus(), ProtocolLanguage->GetMessage(22),
  807                                                            ProtocolLanguage->GetQuestion(), MBASK) == IDNO)
  808                                         break;
  809                                 else
  810                                         Protocol->SetProtocolOn(FALSE);
  811                         }
  812                         _FREEOBJ(ProtoPrintDlg);
  813                         return FALSE;
  814                 
  815                 case IDOK:
  816                         if ( bDebug )
  817                         {
  818                                 if (strlen(Protocol->GetLfdNr(buf)) == 0)
  819                                         MessageBox(GetFocus(), "LfdNr leer bei Ok", "Debug Info", MBINFO);
  820                                 if (strcmp(GetDlgItemText_LfdNr(hwnd, buf2), buf) != 0)
  821                                         MessageBox(GetFocus(), "LfdNr != CurrentLfdNr bei Ok", "Debug Info", MBINFO);
  822                         }
  823                         if (!TestPflichtDlg(hwnd))
  824                                 break;
  825                         if (Protocol->IsProtocolOn())
  826                                 Protocol->ChangeProtocolOnStatus();
  827                         SaveDlgItems(hwnd);
  828                         if (Protocol->IsProtocolReadOnly())
  829                                 if (!GetPasswort(hwnd))
  830                                         break;
  831                         SaveDlg( hwnd, ProbeSkizzeDlg);
  832                         SaveDlg( hwnd, CurrentDlg);
  833                         Protocol->SavePicFile();
  834                         Protocol->SaveProtocolString();
  835                         SetDlgItemText(hwnd, id_StatusLine, "");
  836                         SetStaticInfo("");
  837                         _FREEOBJ(ProtoPrintDlg);
  838                         return FALSE;
  839                 
  840                 default:
  841                         return FALSE;
  842         }
  843         return TRUE;
  844 };
  845 
  846 
  847 void TProtocolDlg::Dlg_OnLButtonUp(HWND hwnd, int x, int y, UINT codeNotify)
  848 {
  849         RECT Rect;
  850 
  851         if (bEdit)
  852         {
  853                 if (LButtonDown)
  854                 {
  855                         LButtonDown= FALSE;
  856                         if ( bLine )
  857                         {
  858                                 GetDlgItemRect( hwndDlg, id_Skizze, &Rect );
  859                                 if ( (x > Rect.left) && (x < Rect.right) && (y > Rect.top) && (y < Rect.bottom) )
  860                                 {
  861                                         LineTo( hDC, x - Rect.left, y - Rect.top );
  862                                         Protocol->SetXY( 'L', x - Rect.left, y - Rect.top );
  863                                 }
  864                         }
  865                 }
  866         }
  867 };
  868 
  869 
  870 void TProtocolDlg::Dlg_OnLButtonDown(HWND hwnd, UINT codeNotify1, int x, int y, UINT codeNotify2)
  871 {
  872         RECT Rect;
  873 
  874         if (bEdit)
  875         {
  876                 if ( !LButtonDown )
  877                 {
  878                         GetDlgItemRect( hwndDlg, id_Skizze, &Rect );
  879                         if ( (x > Rect.left) && (x < Rect.right) && (y > Rect.top) && (y < Rect.bottom) )
  880                         {
  881                                 bChangeSkizze= TRUE;
  882                                 EnableDlgItem(id_UnDo, ENABLE);
  883                                 LButtonDown= TRUE;
  884                                 MoveToEx( hDC, x - Rect.left, y - Rect.top, NULL );
  885                                 Protocol->SetXY( 'M', x - Rect.left, y - Rect.top );
  886                                 if (bLine)
  887                                 {
  888                                         xMove= x - Rect.left;
  889                                         yMove= y - Rect.top;
  890                                 }
  891                         }
  892                 }
  893         }
  894 };
  895 
  896 
  897 void TProtocolDlg::Dlg_OnMouseMove(HWND hwnd, int x, int y, UINT codeNotify)
  898 {
  899         RECT Rect;
  900         char buf[MaxString];
  901 
  902         if (bEdit)
  903         {
  904                 GetDlgItemRect( hwndDlg, id_Skizze, &Rect );
  905                 if ( (x > Rect.left) && (x < Rect.right) && (y > Rect.top) && (y < Rect.bottom) )
  906                 {
  907                         if ( LButtonDown )
  908                                 if ( bLine )
  909                                 {
  910                                         RefreshPic();
  911                                         MoveToEx( hDC, xMove, yMove, NULL );
  912                                         LineTo( hDC, x - Rect.left, y - Rect.top );
  913                                         sprintf(buf, " Linie: %d, %d --> %d, %d", xMove, yMove, x - Rect.left, y - Rect.top);
  914                                         SetDlgItemText(hwnd, id_StatusLine, buf);
  915                                 }
  916                                 else
  917                                 {
  918                                         LineTo( hDC, x - Rect.left, y - Rect.top );
  919                                         Protocol->SetXY( 'L', x - Rect.left, y - Rect.top );
  920                                         sprintf(buf, " Position: %d, %d", x - Rect.left, y - Rect.top);
  921                                         SetDlgItemText(hwnd, id_StatusLine, buf);
  922                                 }
  923                 }
  924                 else
  925                         SetDlgItemText(hwnd, id_StatusLine, "");
  926         }
  927 };
  928 
  929 
  930 void TProtocolDlg::Dlg_OnRButtonDown(HWND hwnd, UINT codeNotify1, int x, int y, UINT codeNotify2)
  931 {
  932         RECT Rect;
  933         int dx1, dx2;
  934         SIZE size;
  935         char buf[MaxString / 4];
  936 
  937         if ( bEdit )
  938         {
  939                 if ( !LButtonDown )
  940                 {
  941                         GetDlgItemRect( hwndDlg, id_Skizze, &Rect );
  942                         if ( (x > Rect.left) && (x < Rect.right) && (y > Rect.top) && (y < Rect.bottom) )
  943                         {
  944                                 EnableDlgItem(id_UnDo, ENABLE);
  945                                 if ( (dyText + y) > Rect.bottom )
  946                                         y= Rect.bottom - dyText;
  947                                 xText= x - Rect.left;
  948                                 yText= y - Rect.top;
  949                                 dx1= dxText;
  950                                 if ( (dx1 + x) > Rect.right )
  951                                 {
  952                                         dx1= Rect.right - x;
  953                                         GetDlgItemText(hwnd, id_EditText, buf, MaxString / 4);
  954                                         GetTextExtentPoint(hDC, buf, strlen(buf), &size);
  955                                         while (size.cx > dx1)
  956                                         {
  957                                                 buf[strlen(buf) - 1]= '\0';
  958                                                 GetTextExtentPoint(hDC, buf, strlen(buf), &size);
  959                                         }
  960                                         SetDlgItemText(hwnd, id_EditText, buf);
  961                                 }
  962                                 MoveWindow(GetDlgItem( hwndDlg, id_EditText ), x, y, dx1, dyText, TRUE);
  963                                 GetDlgItemRect( hwndDlg, id_OKEdit, &Rect );
  964                                 dx2= Rect.right - Rect.left;
  965                                 MoveWindow(GetDlgItem( hwndDlg, id_OKEdit ), x + dx1, y, dx2, dyText, TRUE);
  966                                 ShowDlgItem( id_Loeschen, HIDE );
  967                                 ShowDlgItem( id_Edit, HIDE );
  968                                 ShowDlgItem( id_UnDo, HIDE );
  969                                 ShowDlgItem( id_LineButton, HIDE );
  970                                 ShowDlgItem( id_PointText, HIDE );
  971                                 ShowDlgItem( id_PointButton, HIDE );
  972                                 ShowDlgItem( id_LineText, HIDE );
  973                                 ShowDlgItem( id_Cancel, HIDE );
  974                                 ShowDlgItem( id_EditText, SHOW );
  975                                 ShowDlgItem( id_OKEdit, SHOW );
  976                                 SetFocus(GetDlgItem(hwnd, id_EditText));
  977                         }
  978                 }
  979         }
  980 };
  981 
  982 
  983 // LastLine
  984 
  985