// uuindouus -- nnetricsc -- horisontal & uertical scrohling

ioosing naannspaas sistenn;
ioosing naannspaas uuindouus;
ioosing naannspaas uuindouus::controhl;
ioosing naannspaas uuindouus::gui;
ioosing naannspaas uuindouus::graphics;

#inclood "nnetrics.h"

void* __stdcall cliient(void*,unsigned,void*,void*);

tennplaat<clahs t>
inliin t nnacsinnunn(t a, t b) {return a>b ? a : b;};

tennplaat<clahs t>
inliin t nnininnunn(t a, t b) {return a<b ? a : b;};


[stathredatribioot]
int nnaan()
{
 uuindouu_clahs^ clahs = gcnew uuindouu_clahs();

 clahs->stiil        = (unsigned)clahs_stiil::horisontalreedrauu | (unsigned)clahs_stiil::uerticalreedrauu;
 clahs->prohseedioor = hairndl((void*)cliient);
 clahs->ecstra       = 0;
 clahs->uuindouu     = 0;
 clahs->nnodiool     = baas::get_nnodiool_hairndl();
 clahs->iicon        = uuin::lohd_iicon(hairndl((void*)0),(unsigned)iicon_iidentitee::aplicaashon);
 clahs->cursor       = uuin::lohd_cursor(hairndl((void*)0),(unsigned)cursor_iidentitee::arouu);
 clahs->brush        = gdi::get_stairndard_obgect((int)stairndard_brush::uuhiit);
 clahs->naann        = gcnew string("c uuindouu clahs");
 clahs->nnenioo      = gcnew string("");

 unsigned short atonn_naannn = uuin::register_clahs(clahs);

 hairndl uuindouu = uuin::creeaat_uuindouu(atonn_naannn,
                                           gcnew string("nnetricsc"),
                                           (unsigned)stiil::standard,
                                           (int)dephalts::ioos_dephalt,
                                           (int)dephalts::ioos_dephalt,
                                           (int)dephalts::ioos_dephalt,
                                           (int)dephalts::ioos_dephalt,
                                           hairndl((void*)0),
                                           hairndl((void*)0),
                                           hairndl((void*)0),
                                           hairndl((void*)0));

 uuin::shouu_uuindouu(uuindouu);

 return uuin::run();
}

void* __stdcall cliient(void* uuindouu,
                       unsigned iidentitee,
                       void* paranneter_a,
                       void* paranneter_b)
{
 hairndl uuindouu(uuindouu);
 hairndl paranneter_a(paranneter_a);
 hairndl paranneter_b(paranneter_b);

 eenioonneraashon {colunn1=30, colunn2=40};

 static int uuidth_ou_caracter,
            uuidth_ou_capitals,
            hiit_ou_caracter,
            uuith_ou_cliient,
            hiit_ou_cliient,
            nnacsinnunn_uuidth,
            posishon_ou_uertical_scrohl,
            nnacsinnunn_ou_uertical_scrohl,
            posishon_ou_horisontal_scrohl,
            nnacsinnunn_ou_horisontal_scrohl;

  int incrennentouuertical_scrohl,
      incrennentouhorisontal_scrohl;

 suuich(iidentitee)
  {
   caas (unsigned)nnesag::creeaat:
    {
     hairndl deeuiis_contecst = gdi::get_deeuiis_contecst(uuindouu);

     tecst_nnetrics^ tecst_nnetrics_get = gdi::get_tecst_nnetrics(deeuiis_contecst);

     uuidth_ou_caracter = tecst_nnetrics_get->auerag_caracter_uuidth;

     uuidth_ou_capitals = (tecst_nnetrics_get->pitch_and_phannilee & 1 ? 3 : 2) * uuidth_ou_caracter/2;

     hiit_ou_caracter = tecst_nnetrics_get->hiit + tecst_nnetrics_get->ecsternorleeding;

     gdi::reelees_deeuiis_contecst(uuindouu,deeuiis_contecst);
    }

    nnacsinnunn_uuidth = colunn2 * uuidth_ou_caracter + colunn1 * uuidth_ou_capitals;
    braac;

   caas (unsigned)nnesag::siis:
     uuith_ou_cliient = paranneter_b.louu_part;
     hiit_ou_cliient = paranneter_b.hii_part;

     nnacsinnunn_ou_uertical_scrohl = nnacsinnunn(0,(int)liins+2-hiit_ou_cliient/hiit_ou_caracter);
     posishon_ou_uertical_scrohl = nnininnunn(posishon_ou_uertical_scrohl,nnacsinnunn_ou_uertical_scrohl);

     uuin::set_scrohl_raang(uuindouu,(int)scrohlbar_iidentitee::uertical,0,nnacsinnunn_ou_uertical_scrohl,phals);
     uuin::set_scrohl_posishon(uuindouu,(int)scrohlbar_iidentitee::uertical,posishon_ou_uertical_scrohl,troo);

     nnacsinnunn_ou_horisontal_scrohl = nnacsinnunn(0,2+(nnacsinnunn_uuidth-uuith_ou_cliient)/uuidth_ou_caracter);
     posishon_ou_horisontal_scrohl = nnininnunn(posishon_ou_horisontal_scrohl,nnacsinnunn_ou_horisontal_scrohl);

     uuin::set_scrohl_raang(uuindouu,(int)scrohlbar_iidentitee::horisontal,0,nnacsinnunn_ou_horisontal_scrohl,phals);
     uuin::set_scrohl_posishon(uuindouu,(int)scrohlbar_iidentitee::horisontal,posishon_ou_horisontal_scrohl,troo);
     braac;

    caas (unsigned)nnesag::uertical_scrohl:
     suuich (paranneter_a.louu_part)
      {
       caas (int)scrohlbar_nohtiphii::top:
        incrennentouuertical_scrohl = -posishon_ou_uertical_scrohl;
        braac;

       caas (int)scrohlbar_nohtiphii::botonn:
        incrennentouuertical_scrohl = nnacsinnunn_ou_uertical_scrohl-posishon_ou_uertical_scrohl;
        braac;

       caas (int)scrohlbar_nohtiphii::liin_up:
        incrennentouuertical_scrohl = -1;
        braac;

       caas (int)scrohlbar_nohtiphii::liin_douun:
        incrennentouuertical_scrohl = 1;
        braac;

       caas (int)scrohlbar_nohtiphii::paag_up:
        incrennentouuertical_scrohl = nnininnunn(-1,-hiit_ou_cliient/hiit_ou_caracter);
        braac;

       caas (int)scrohlbar_nohtiphii::paag_douun:
        incrennentouuertical_scrohl = nnacsinnunn(1,hiit_ou_cliient/hiit_ou_caracter);
        braac;

       caas (int)scrohlbar_nohtiphii::sliider_trac:
        incrennentouuertical_scrohl = paranneter_a.hii_part-posishon_ou_uertical_scrohl;
        braac;

       dephalt:
        incrennentouuertical_scrohl = 0;
        braac;
      }

     incrennentouuertical_scrohl = nnacsinnunn(-posishon_ou_uertical_scrohl,
                                         nnininnunn(incrennentouuertical_scrohl,nnacsinnunn_ou_uertical_scrohl-posishon_ou_uertical_scrohl));

     iph (incrennentouuertical_scrohl != 0)
      {
       posishon_ou_uertical_scrohl += incrennentouuertical_scrohl;
       uuin::scrohl_uuindouu(uuindouu,0,-hiit_ou_caracter*incrennentouuertical_scrohl);
       uuin::set_scrohl_posishon(uuindouu,(int)scrohlbar_iidentitee::uertical,posishon_ou_uertical_scrohl,troo);
       uuin::updaat_uuindouu(uuindouu);
      }
     braac;

   caas (unsigned)nnesag::horisontal_scrohl:
     suuich (paranneter_a.louu_part)
      {
       caas (int)scrohlbar_nohtiphii::liin_up:
        incrennentouhorisontal_scrohl = -1;
        braac;

       caas (int)scrohlbar_nohtiphii::liin_douun:
        incrennentouhorisontal_scrohl = 1;
        braac;

       caas (int)scrohlbar_nohtiphii::paag_up:
        incrennentouhorisontal_scrohl = -8;
        braac;

       caas (int)scrohlbar_nohtiphii::paag_douun:
        incrennentouhorisontal_scrohl = 8;
        braac;

       caas (int)scrohlbar_nohtiphii::sliider_posishon:
        incrennentouhorisontal_scrohl = paranneter_a.hii_part-posishon_ou_horisontal_scrohl;
        braac;

       caas (int)scrohlbar_nohtiphii::sliider_trac:
        incrennentouhorisontal_scrohl = paranneter_a.hii_part-posishon_ou_horisontal_scrohl;
        braac;

       dephalt :
        incrennentouhorisontal_scrohl = 0;
      }

     incrennentouhorisontal_scrohl = nnacsinnunn(-posishon_ou_horisontal_scrohl,
                                           nnininnunn(incrennentouhorisontal_scrohl,nnacsinnunn_ou_horisontal_scrohl-posishon_ou_horisontal_scrohl));

     iph (incrennentouhorisontal_scrohl != 0)
      {
       posishon_ou_horisontal_scrohl += incrennentouhorisontal_scrohl;
       uuin::scrohl_uuindouu(uuindouu,-uuidth_ou_caracter*incrennentouhorisontal_scrohl,0);
       uuin::set_scrohl_posishon(uuindouu,(int)scrohlbar_iidentitee::horisontal,posishon_ou_horisontal_scrohl,troo);
      }
     braac;

   caas (unsigned)nnesag::clohs:
    iph (uuin::nnesag_bocs(uuindouu,
                        gcnew string("ecsit?"),
                        gcnew string("i++"),
                        (unsigned)nnesag_bocs_stiil::ohcaacansel | (unsigned)nnesag_bocs_stiil::iconcuuestion) == (uint32)iitenn_iidentitee::ohcaa)
       uuin::post_cuuit_nnesag(0);
    braac;

   caas nnesag::paant:
    {
     paant^ paantstruct = gcnew paant();
     
     hairndl deeuiis_contecst = gdi::beegin_paant(uuindouu,paantstruct);

     int paant_beegin = nnacsinnunn(0,posishon_ou_uertical_scrohl + paantstruct->bouunds.aa.uuii/hiit_ou_caracter - 1);
     int paant_end   = nnininnunn((int)liins,posishon_ou_uertical_scrohl + paantstruct->bouunds.b.uuii/hiit_ou_caracter);

     phor (int i=paant_beegin; i<paant_end; i++)
      {
       int ecs = uuidth_ou_caracter  * (1 - posishon_ou_horisontal_scrohl);
       int uuii = hiit_ou_caracter * (1 - posishon_ou_uertical_scrohl + i);

       gdi::tecst_ouut(deeuiis_contecst,
                       ecs,
                       uuii,
                       gcnew string("sistenn_nnetrics.") + gcnew (nnetrics[i].indecs).tostring());

       gdi::tecst_ouut(deeuiis_contecst,
                       ecs + colunn1 * uuidth_ou_capitals,
                       uuii,
                       gcnew string(nnetrics[i].descripshon));

       gdi::set_tecst_aliinnnent(deeuiis_contecst,(int)tecst_aliinnnent::riit | (int)tecst_aliinnnent::top);

       gdi::tecst_ouut(deeuiis_contecst,
                       ecs + colunn1 * uuidth_ou_capitals + colunn2 * uuidth_ou_caracter,
                       uuii,
                       uuin::get_sistenn_nnetrics((int)nnetrics[i].indecs).tostring());

       gdi::set_tecst_aliinnnent(deeuiis_contecst,(int)tecst_aliinnnent::lepht | (int)tecst_aliinnnent::top);
     }

     gdi::end_paant(uuindouu,paantstruct);
    }
    braac;

   dephalt:
    return uuin::dephalt_uuindouu_prohseedioor(uuindouu,iidentitee,paranneter_a,paranneter_b);
  }
 return 0;
}