]> git.vomp.tv Git - vompclient-marten.git/commitdiff
Mouse support (part 2)
authorChris Tallon <chris@vomp.tv>
Thu, 28 Dec 2006 16:32:36 +0000 (16:32 +0000)
committerChris Tallon <chris@vomp.tv>
Thu, 28 Dec 2006 16:32:36 +0000 (16:32 +0000)
31 files changed:
demuxer.cc
vaudioselector.cc
vchannellist.cc
vepg.cc
vepgsettimer.cc
vepgsettimer.h
viewman.cc
vinfo.cc
vinfo.h
vlivebanner.cc
vlivebanner.h
voptions.cc
voptions.h
voptionsmenu.cc
vquestion.cc
vquestion.h
vrecmove.cc
vrecmove.h
vrecordinglist.cc
vrecordingmenu.cc
vserverselect.cc
vserverselect.h
vtimeredit.cc
vtimeredit.h
vtimerlist.cc
vtimerlist.h
vvideolive.cc
vvideorec.cc
vwelcome.cc
vwelcome.h
winmain.cc

index 87fe47e10363fa85575d9b3bf06e4a5460d4d3ed..1a7804686b6a5a8cf82040c5fa231f198dd0ca6d 100644 (file)
@@ -218,7 +218,7 @@ int Demuxer::PESPacket::submit()
 
     dx->avail_mpaudchan[packetType-PESTYPE_AUD0]=true;
 
-     Log::getInstance()->log("PESPacket", Log::DEBUG, "%i", dx->audio_current);
+    //Log::getInstance()->log("PESPacket", Log::DEBUG, "%i", dx->audio_current);
     if (dx->audio_current == packetType && !dx->aud_seeking)
       sent = dx->audiostream.put(data+submitted, size-submitted);
     else
index d44dff561130530c06e916d2acd82cd154efa23c..d800f6245e0c7039337f0bd8587539f04d37cfe1 100644 (file)
@@ -239,10 +239,8 @@ void VAudioSelector::processMessage(Message* m)
       sl.draw();
       ViewMan::getInstance()->updateView(this);
     }
-    return;
   }
-
-  if (m->message == Message::MOUSE_LBDOWN)
+  else if (m->message == Message::MOUSE_LBDOWN)
   {
     if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
     {
@@ -257,6 +255,5 @@ void VAudioSelector::processMessage(Message* m)
         ViewMan::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
       }
     }
-    return;
   }
 }
index 424a88622c6b40a6377bdb2c77e87d0eef390471..e23a7f9cb1e7b2a277e00603490cfe7cd6c5c072 100644 (file)
@@ -225,10 +225,8 @@ void VChannelList::processMessage(Message* m)
       doShowingBar();
       ViewMan::getInstance()->updateView(this);
     }
-    return;
   }
-
-  if (m->message == Message::MOUSE_LBDOWN)
+  else if (m->message == Message::MOUSE_LBDOWN)
   {
     if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
     {
@@ -243,6 +241,5 @@ void VChannelList::processMessage(Message* m)
         ViewMan::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
       }
     }
-    return;
   }
 }
\ No newline at end of file
diff --git a/vepg.cc b/vepg.cc
index d60f194c6cbcf4da83dbc952a43b65ce9f3620c1..03f293e67895350423c6c677b290f569feadf526 100644 (file)
--- a/vepg.cc
+++ b/vepg.cc
@@ -632,10 +632,8 @@ void VEpg::processMessage(Message* m)
       drawData();
       ViewMan::getInstance()->updateView(this);
     }
-    return;
   }
-
-  if (m->message == Message::MOUSE_LBDOWN)
+  else if (m->message == Message::MOUSE_LBDOWN)
   {
     if (chanListbox.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
     {
@@ -705,6 +703,5 @@ void VEpg::processMessage(Message* m)
         viewman->updateView(this);
       }
     }
-    return;
   }
 }
index 57ef730c4b7b84b3f3e774e3a83ff98ea0828f21..4e0bcef5741f5b0ee3d4ae6cba54c8aa1b1a847f 100644 (file)
@@ -268,3 +268,46 @@ void VEpgSetTimer::doit()
   m->parameter = (ULONG)vi;
   Command::getInstance()->postMessageNoLock(m);
 }
+
+
+void VEpgSetTimer::processMessage(Message* m)
+{
+  if (m->message == Message::MOUSE_MOVE)
+  {
+    if (buttonYes.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      buttonNo.setActive(0);
+      selectedOption = YES;
+      draw();
+      ViewMan::getInstance()->updateView(this);
+    }
+    else if (buttonNo.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      buttonYes.setActive(0);
+      selectedOption = NO;
+      draw();
+      ViewMan::getInstance()->updateView(this);
+    }
+  }
+  else if (m->message == Message::MOUSE_LBDOWN)
+  {
+    if (buttonYes.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
+    }
+    else if (buttonNo.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
+    }
+    else
+    {
+      //check if press is outside this view! then simulate cancel
+      int x=(m->parameter>>16)-getScreenX();
+      int y=(m->parameter&0xFFFF)-getScreenY();
+      if (x<0 || y <0 || x>getWidth() || y>getHeight())
+      {
+        ViewMan::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
+      }
+    }
+  }
+}
index bd13583939a9ffec7315eaec50ce34d5b58c3f0f..b2ee0f9e2ff5da1ed96824dfe66e3927a16e5e52 100644 (file)
@@ -42,6 +42,7 @@ class VEpgSetTimer : public View
     ~VEpgSetTimer();
 
     int handleCommand(int command);
+    void processMessage(Message* m);
     void draw();
 
   private:
index 9b03c63089151b68e11cb6a04e62bbfd92cb9dd6..0a15620faa69b0d9e9a5e321767965be2051f903 100644 (file)
@@ -437,6 +437,7 @@ void ViewMan::processMessage(Message* m)
       add(toAdd);
       toAdd->draw();
       updateView(toAdd);
+      break;
     }
   }
 }
index 1febf929070bd3a83408a8ee16532f40d287d312..790c45185eaa553fd24c6781e9e17f3d6409edd6 100644 (file)
--- a/vinfo.cc
+++ b/vinfo.cc
@@ -112,3 +112,11 @@ void VInfo::okButton()
 {
   okbutton = true;
 }
+
+void VInfo::processMessage(Message* m)
+{
+  if (m->message == Message::MOUSE_LBDOWN)
+  {
+    ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
+  }
+}
diff --git a/vinfo.h b/vinfo.h
index d8e7783932c482627dd539ec94c7b078d02abd8c..4f806bde2beea58f65844e9e6c5575c9a4d33e38 100644 (file)
--- a/vinfo.h
+++ b/vinfo.h
@@ -30,6 +30,7 @@
 #include "colour.h"
 #include "wbutton.h"
 #include "i18n.h"
+#include "viewman.h"
 
 class VInfo : public View
 {
@@ -44,6 +45,7 @@ class VInfo : public View
     void okButton();
 
     virtual int handleCommand(int command);
+    void processMessage(Message* m);
     void draw();
 
   protected:
index 6ab28c57a00b63a210a211eab986f90731ffe370..2dc9c3f72530c803a65dff9c16055b5e329053d1 100644 (file)
@@ -291,3 +291,37 @@ void VLiveBanner::drawClock()
 
   Timers::getInstance()->setTimerT(this, 2, dt);
 }
+
+void VLiveBanner::processMessage(Message* m)
+{
+  if (m->message == Message::MOUSE_MOVE)
+  {
+    if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      sl.draw();
+      ViewMan::getInstance()->updateView(this);
+    }
+  }
+  else if (m->message == Message::MOUSE_LBDOWN)
+  {
+    //check if press is outside this view! then simulate cancel
+    int x=(m->parameter>>16)-getScreenX();
+    int y=(m->parameter&0xFFFF)-getScreenY();
+    if (x<0 || y <0 || x>getWidth() || y>getHeight())
+    {
+      ViewMan::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
+    }
+    else if (y>=(int)area.h-24 && y<=(int)area.h-6)
+    {
+      //y coordinate is right!
+      if (x>=7 &&x<=25)
+      {
+        ViewMan::getInstance()->handleCommand(Remote::RED); //simulate red press
+      }
+      else if (x>=110 &&x<=128)
+      {
+        ViewMan::getInstance()->handleCommand(Remote::GREEN); //simulate red press
+      }
+    }
+  }
+}
index 5ea6f3838f8951e6df2ff49b5da7f9ab8d37ef07..85ee138d9e276c43840d07fdc6e2897bcb6a1287 100644 (file)
@@ -53,6 +53,7 @@ class VLiveBanner : public View, public TimerReceiver
     void setChannel(Channel* channel);
 
     int handleCommand(int command);
+    void processMessage(Message* m);
     void draw();
     void timercall(int clientReference);
 
index cffacc04af88978190b2fa64a5dc59d3732dca09..719f56a962d04cce4fc0cedc86c4220b51e27d02 100644 (file)
@@ -284,3 +284,49 @@ void VOptions::doSave()
 
 }
 
+
+void VOptions::processMessage(Message* m)
+{
+  if (m->message == Message::MOUSE_MOVE)
+  {
+    int x=(m->parameter>>16)-getScreenX();
+    int y=(m->parameter&0xFFFF)-getScreenY();
+    UINT i;
+    for (i = 0; i < numOptions; i++)
+    {
+      if (optionBoxes[i].mouseMove(x,y))
+      {
+        optionBoxes[selectedOption].setActive(0);
+        optionBoxes[i].setActive(1);
+        selectedOption=i;
+        draw();
+        ViewMan::getInstance()->updateView(this);
+        break;
+      }
+    }
+  }
+  else if (m->message == Message::MOUSE_LBDOWN)
+  {
+    int x=(m->parameter>>16)-getScreenX();
+    int y=(m->parameter&0xFFFF)-getScreenY();
+    UINT i;
+    bool butpress=false;
+    for (i = 0; i < numOptions; i++)
+    {
+      if (optionBoxes[i].mouseLBDOWN(x,y))
+      {
+        ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
+        butpress=true;
+        break;
+      }
+    }
+    if (!butpress)
+    {
+      //check if press is outside this view! then simulate cancel
+      if (x<0 || y <0 || x>getWidth() || y>getHeight())
+      {
+        ViewMan::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
+      }
+    }
+  }
+}
index c7b959c961d5c3085894a9d5be6d0b38703c3ee7..897b945a73d6901d0c60fbb503b0f5f34c6534de 100644 (file)
@@ -53,6 +53,7 @@ class VOptions : public View
     ~VOptions();
 
     int handleCommand(int command);
+    void processMessage(Message* m);
     void draw();
 
   private:
index 0b8f04066a3f371d2d19547bdf73441337180f59..aeea3e6940b4cfe790abbd26effc356deebb4eb1 100644 (file)
@@ -140,7 +140,48 @@ int VOptionsMenu::handleCommand(int command)
 
 void VOptionsMenu::processMessage(Message* m)
 {
-  if (m->message == Message::CHANGED_OPTIONS)
+  if (m->message == Message::MOUSE_MOVE)
+  {
+    int x=(m->parameter>>16)-getScreenX();
+    int y=(m->parameter&0xFFFF)-getScreenY();
+    vector<WButton*>::iterator i;
+    for (i=buttons.begin(); i!=buttons.end();i++)
+    {
+      if ((*i)->mouseMove(x,y))
+      {
+        (*selectedButton)->setActive(0);
+        selectedButton=i;
+        draw();
+        ViewMan::getInstance()->updateView(this);
+        break;
+      }
+    }
+  }
+  else if (m->message == Message::MOUSE_LBDOWN)
+  {
+    int x=(m->parameter>>16)-getScreenX();
+    int y=(m->parameter&0xFFFF)-getScreenY();
+    vector<WButton*>::iterator i;
+    bool butpress=false;
+    for (i=buttons.begin(); i!=buttons.end();i++)
+    {
+      if ((*i)->mouseLBDOWN(x,y))
+      {
+        ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
+        butpress=true;
+        break;
+      }
+    }
+    if (!butpress)
+    {
+      //check if press is outside this view! then simulate cancel
+      if (x<0 || y <0 || x>getWidth() || y>getHeight())
+      {
+        ViewMan::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
+      }
+    }
+  }
+  else if (m->message == Message::CHANGED_OPTIONS)
   {
     doApplyChanges((map<int,int>*)m->parameter);
     //viewman->removeView(this);
index ec1571eb96b43ddeafff0045f5424f0cca64400d..1cf63d60d0aecd505f5c330494005c3de9ac30a0 100644 (file)
@@ -118,3 +118,45 @@ void VQuestion::setDefault(UCHAR option)
 {
   selectedOption = option;
 }
+
+void VQuestion::processMessage(Message* m)
+{
+  if (m->message == Message::MOUSE_MOVE)
+  {
+    if (buttonYes.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      buttonNo.setActive(0);
+      selectedOption = YES;
+      draw();
+      ViewMan::getInstance()->updateView(this);
+    }
+    else if (buttonNo.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      buttonYes.setActive(0);
+      selectedOption = NO;
+      draw();
+      ViewMan::getInstance()->updateView(this);
+    }
+  }
+  else if (m->message == Message::MOUSE_LBDOWN)
+  {
+    if (buttonYes.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
+    }
+    else if (buttonNo.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
+    }
+    else
+    {
+      //check if press is outside this view! then simulate cancel
+      int x=(m->parameter>>16)-getScreenX();
+      int y=(m->parameter&0xFFFF)-getScreenY();
+      if (x<0 || y <0 || x>getWidth() || y>getHeight())
+      {
+        ViewMan::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
+      }
+    }
+  }
+}
index ccddf7f9de7e8bd14d9046b875a5c8992b38378c..f50c9901a552489b0dc153baa3aa23d394431967 100644 (file)
@@ -41,6 +41,7 @@ class VQuestion : public View
     void setMainText(char* title);
 
     int handleCommand(int command);
+    void processMessage(Message* m);
     void draw();
 
     const static UCHAR NO = 0;
index 7e3dc356217d24eb560a9c9a873566b1f82ca597..cfb7bc1ce483f96c31d4ad47b57daade0d3aeba2 100644 (file)
@@ -130,3 +130,32 @@ int VRecMove::handleCommand(int command)
   // stop command getting to any more views
   return 1;
 }
+
+void VRecMove::processMessage(Message* m)
+{
+  if (m->message == Message::MOUSE_MOVE)
+  {
+    if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      sl.draw();
+      ViewMan::getInstance()->updateView(this);
+    }
+  }
+  else if (m->message == Message::MOUSE_LBDOWN)
+  {
+    if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
+    }
+    else
+    {
+      //check if press is outside this view! then simulate cancel
+      int x=(m->parameter>>16)-getScreenX();
+      int y=(m->parameter&0xFFFF)-getScreenY();
+      if (x<0 || y <0 || x>getWidth() || y>getHeight())
+      {
+        ViewMan::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
+      }
+    }
+  }
+}
index 816522a552b01af1bf8e699b8f9f64b4f89e6a74..183a21a681c3de4e70e8f5e103a59737fd0a2c0c 100644 (file)
@@ -47,6 +47,7 @@ class VRecMove : public View
 
     int handleCommand(int command);
     void draw();
+    void processMessage(Message* m);
 
   private:
     View* parent;
index 943b17a41458ec6de8654e86a8ea774553c45c31..3829d354ce2eeec1f6430d22040cf01d76b9fcd1 100644 (file)
@@ -186,30 +186,50 @@ void VRecordingList::doShowingBar()
 void VRecordingList::processMessage(Message* m)
 {
   Log::getInstance()->log("VRecordingList", Log::DEBUG, "Got message value %lu", m->message);
-  if (m->message == Message::DELETE_SELECTED_RECORDING)
+
+  if (m->message == Message::MOUSE_MOVE)
+  {
+    if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      sl.draw();
+      doShowingBar();
+      viewman->updateView(this);
+    }
+  }
+  else if (m->message == Message::MOUSE_LBDOWN)
+  {
+    if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
+    }
+    else
+    {
+      //check if press is outside this view! then simulate cancel
+      int x=(m->parameter>>16)-getScreenX();
+      int y=(m->parameter&0xFFFF)-getScreenY();
+      if (x<0 || y <0 || x>getWidth() || y>getHeight())
+      {
+        ViewMan::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
+      }
+    }
+  }
+  else if (m->message == Message::DELETE_SELECTED_RECORDING)
   {
     Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing delete selected");
     doDeleteSelected();
-    return;
   }
-
-  if (m->message == Message::MOVE_RECORDING)
+  else if (m->message == Message::MOVE_RECORDING)
   {
     Log::getInstance()->log("VRecordingList", Log::DEBUG, "Doing move recording");
     doMoveRecording((Directory*)m->parameter);
-    return;
   }
-
-  if (m->message == Message::PLAY_SELECTED_RECORDING)
+  else if (m->message == Message::PLAY_SELECTED_RECORDING)
   {
     doPlay(false);
-    return;
   }
-
-  if (m->message == Message::RESUME_SELECTED_RECORDING)
+  else if (m->message == Message::RESUME_SELECTED_RECORDING)
   {
     doPlay(true);
-    return;
   }
 }
 
index 9f53124883184101a28a9b4931d476f37763dda4..fb764c179b36c81538577a0446b410873b6d215d 100644 (file)
@@ -188,7 +188,32 @@ int VRecordingMenu::handleCommand(int command)
 
 void VRecordingMenu::processMessage(Message* m)
 {
-  if (m->message == Message::QUESTION_YES)
+  if (m->message == Message::MOUSE_MOVE)
+  {
+    if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      sl.draw();
+      ViewMan::getInstance()->updateView(this);
+    }
+  }
+  else if (m->message == Message::MOUSE_LBDOWN)
+  {
+    if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
+    }
+    else
+    {
+      //check if press is outside this view! then simulate cancel
+      int x=(m->parameter>>16)-getScreenX();
+      int y=(m->parameter&0xFFFF)-getScreenY();
+      if (x<0 || y <0 || x>getWidth() || y>getHeight())
+      {
+        ViewMan::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
+      }
+    }
+  }
+  else if (m->message == Message::QUESTION_YES)
   {
     if (sl.getCurrentOptionData() == 5)
     {
index 12580e73cc2a680e931b8672b9184b23244988e4..11dc19a1cd4474ad034e2432fa433ae5462c18d5 100644 (file)
@@ -98,3 +98,22 @@ int VServerSelect::handleCommand(int command)
 
   return 1;
 }
+
+void VServerSelect::processMessage(Message* m)
+{
+  if (m->message == Message::MOUSE_MOVE)
+  {
+    if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      sl.draw();
+      ViewMan::getInstance()->updateView(this);
+    }
+  }
+  else if (m->message == Message::MOUSE_LBDOWN)
+  {
+    if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
+    }
+  }
+}
index 3aa191aa297ece3ca7dfc300f8123b28f65b5f9b..af6a68c6c829857a3d276864d010b9e578412279 100644 (file)
@@ -45,6 +45,7 @@ class VServerSelect : public View
     ~VServerSelect();
 
     int handleCommand(int command);
+    void processMessage(Message* m);
     void draw();
 
   private:
index 29fe6ebc8062f93c4e6dc02644d92079586d3cb0..c0fec618480744dbe7e143e43302bfb373f41282 100644 (file)
@@ -153,3 +153,11 @@ int VTimerEdit::handleCommand(int command)
   // stop command getting to any more views
   return 1;
 }
+
+void VTimerEdit::processMessage(Message* m)
+{
+  if (m->message == Message::MOUSE_LBDOWN)
+  {
+    ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
+  }
+}
index 02792487ea25a77b960dd5907659a2232e6dd4d3..259a5b3694fc94b48f604f8f0a55d50b006e30b1 100644 (file)
@@ -42,6 +42,7 @@ class VTimerEdit : public View
     ~VTimerEdit();
 
     int handleCommand(int command);
+    void processMessage(Message* m);
 
   private:
     RecTimer* recTimer;
index c1e25572c7ba6be23f81e0fa6f30a78ac5126cd7..d616ccceca7b3711e2bc220a9266ee64e5550446 100644 (file)
@@ -285,3 +285,32 @@ int VTimerList::handleCommand(int command)
   // stop command getting to any more views
   return 1;
 }
+
+void VTimerList::processMessage(Message* m)
+{
+  if (m->message == Message::MOUSE_MOVE)
+  {
+    if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      sl.draw();
+      ViewMan::getInstance()->updateView(this);
+    }
+  }
+  else if (m->message == Message::MOUSE_LBDOWN)
+  {
+    if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
+    }
+    else
+    {
+      //check if press is outside this view! then simulate cancel
+      int x=(m->parameter>>16)-getScreenX();
+      int y=(m->parameter&0xFFFF)-getScreenY();
+      if (x<0 || y <0 || x>getWidth() || y>getHeight())
+      {
+        ViewMan::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
+      }
+    }
+  }
+}
index 3fa0b8101bd621f834b81406a7e3fd39dacf2f39..f988f797917f74e16250118a2265e59558b65b87 100644 (file)
@@ -45,6 +45,7 @@ class VTimerList : public View, public TimerReceiver
 
     int handleCommand(int command);
     void timercall(int clientReference);
+    void processMessage(Message* m);
 
   private:
     RecTimerList* recTimerList;
index 2d5c05d1e309d59124e248d9eec5d94cd335280c..c1703f3ae52017f4fe748a9db3358e41ce1ab724 100644 (file)
@@ -261,7 +261,11 @@ void VVideoLive::streamEnd()
 
 void VVideoLive::processMessage(Message* m)
 {
-  if (m->message == Message::CHANNEL_CHANGE)
+  if (m->message == Message::MOUSE_LBDOWN)
+  {
+    ViewMan::getInstance()->handleCommand(Remote::OK); //simulate rok press
+  }
+  else if (m->message == Message::CHANNEL_CHANGE)
   {
     channelChange(NUMBER, m->parameter);
   }
index 40bc248a0d84be458de8120d1f38540d5b2c755a..fc13e0ccd6f358e3dc2ad454f8cda3e0412b62b3 100644 (file)
@@ -360,7 +360,75 @@ void VVideoRec::processMessage(Message* m)
 {
   Log::getInstance()->log("VVideoRec", Log::DEBUG, "Message received");
 
-  if (m->from == player)
+  if (m->message == Message::MOUSE_LBDOWN)
+  {
+    UINT x = (m->parameter>>16) - getScreenX();
+    UINT y = (m->parameter&0xFFFF) - getScreenY();
+
+    if (!barShowing)
+    {
+      ViewMan::getInstance()->handleCommand(Remote::OK); //simulate rok press
+    }
+    else if (barRegion.x<=x && barRegion.y<=y && (barRegion.x+barRegion.w)>=x && (barRegion.y+barRegion.h)>=y)
+    {
+      int progBarXbase = barRegion.x + 300;
+      if (myRec->hasMarks())
+      {
+        MarkList* markList = myRec->getMarkList();
+        MarkList::iterator i;
+        Mark* loopMark = NULL;
+        int posPix;
+        ULONG lengthFrames;
+        if (myRec->recInfo->timerEnd > time(NULL))
+        {
+          // chasing playback
+          // Work out an approximate length in frames (good to 1s...)
+          lengthFrames = (myRec->recInfo->timerEnd - myRec->recInfo->timerStart) * video->getFPS();
+        }
+        else
+        {
+          lengthFrames = player->getLengthFrames();
+        }
+        for(i = markList->begin(); i != markList->end(); i++)
+        {
+          loopMark = *i;
+          if (loopMark->pos)
+          {
+            posPix = 302 * loopMark->pos / lengthFrames;
+            rectangle(barRegion.x + progBarXbase + 2 + posPix, barRegion.y + 12 - 2, 3, 28, Colour::DANGER);
+            if (x>=barRegion.x + progBarXbase + 2 + posPix
+                && x<=barRegion.x + progBarXbase + 2 + posPix+3
+                && y>=barRegion.y + 12 - 2
+                && y<=barRegion.y + 12 - 2+28)
+            {
+              player->jumpToMark(loopMark->pos);
+              doBar(3);
+              return;
+            }
+          }
+        }
+      }
+
+      if (x>=barRegion.x + progBarXbase + 24
+          && x<=barRegion.x + progBarXbase + 4 + 302
+          && y>=barRegion.y + 12 - 2
+          && y<=barRegion.y + 12 - 2+28)
+      {
+        int cx=x-(barRegion.x + progBarXbase + 4);
+        double percent=((double)cx)/302.*100.;
+        player->jumpToPercent(percent);
+        doBar(3);
+        return;
+        //  int progressWidth = 302 * currentFrameNum / lengthFrames;
+        //  rectangle(barRegion.x + progBarXbase + 4, barRegion.y + 16, progressWidth, 16, Colour::SELECTHIGHLIGHT);
+      }
+    }
+    else
+    {
+      ViewMan::getInstance()->handleCommand(Remote::OK); //simulate rok press
+    }
+  }
+  else if (m->from == player)
   {
     if (m->message != Message::PLAYER_EVENT) return;
     switch(m->parameter)
index 60d322be97fbcd53e2c4eccd9b9bb5e9551ae1ca..573b6ca085c628145bd309c0a09820536eb272ee 100644 (file)
@@ -292,3 +292,22 @@ void VWelcome::redrawLang()
   setup();
   draw();
 }
+
+void VWelcome::processMessage(Message* m)
+{
+  if (m->message == Message::MOUSE_MOVE)
+  {
+    if (sl.mouseMove((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      sl.draw();
+      viewman->updateView(this);
+    }
+  }
+  else if (m->message == Message::MOUSE_LBDOWN)
+  {
+    if (sl.mouseLBDOWN((m->parameter>>16)-getScreenX(),(m->parameter&0xFFFF)-getScreenY()))
+    {
+      ViewMan::getInstance()->handleCommand(Remote::OK); //simulate OK press
+    }
+  }
+}
index 20c91d1d6c64895ea9ab10065836c451d27744d5..d2fce20b99bb39d49062ecc6254c5aefb4346bdd 100644 (file)
@@ -52,6 +52,7 @@ class VWelcome : public View, public TimerReceiver
 
     void setup();
     int handleCommand(int command);
+    void processMessage(Message* m);
     void draw();
     void timercall(int clientReference);
     void redrawLang();
index 94a584a589f922ce87dffddb92a05136a0d01f70..a6bd03bd9cbbacb1df568712b840a7ad152e22e3 100644 (file)
-/*
-    Copyright 2004-2005 Chris Tallon
-
-    This file is part of VOMP.
-
-    VOMP is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    VOMP is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with VOMP; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-#ifdef WIN32
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-
-#define _WIN32_WINNT 0x501
-#include <winsock2.h>
-#include <windows.h>
-
-#include "vompreswin.h"
-
-#include "defines.h"
-#include "log.h"
-#include "remotewin.h"
-#include "ledwin.h"
-#include "mtdwin.h"
-#include "timers.h"
-#include "videowin.h"
-#include "audiowin.h"
-#include "vdr.h"
-#include "osdwin.h"
-#include "viewman.h"
-#include "command.h"
-
-void sighandler(int signalReceived);
-void shutdown(int code);
-
-// Global variables --------------------------------------------------------------------------------------------------
-int debugEnabled = 0;
-Log* logger;
-Remote* remote;
-Mtd* mtd;
-Led* led;
-Osd* osd;
-Timers* timers;
-ViewMan* viewman;
-Command* command;
-VDR* vdr;
-Video* video;
-Audio* audio;
-bool wnd_fullscreen=false;
-bool wnd_topmost=false;
-RECT wnd_fs_rect={20,20,768+20,576+20};
-RECT wnd_fs_rect_client={0,0,768,576};
-//OSVERSIONINFO windows_ver; //attempt to distigsh windows versions
-bool remotefnc=false;
-HINSTANCE  hinstance;
-bool cmenu=false;
-
-HMODULE user32dll;
-typedef UINT (WINAPI *GETRAWINPUTDATAFNC) (HRAWINPUT,UINT,LPVOID,PUINT,UINT);
-typedef UINT (WINAPI *REGISTERRAWINPUTDEVICEFNC)  (PCRAWINPUTDEVICE,UINT,UINT);
-
-GETRAWINPUTDATAFNC dynGetRawInputData=NULL;
-REGISTERRAWINPUTDEVICEFNC dynRegisterRawInputDevices=NULL;
-
-DWORD lastmousemove;
-
+/*\r
+    Copyright 2004-2005 Chris Tallon\r
+\r
+    This file is part of VOMP.\r
+\r
+    VOMP is free software; you can redistribute it and/or modify\r
+    it under the terms of the GNU General Public License as published by\r
+    the Free Software Foundation; either version 2 of the License, or\r
+    (at your option) any later version.\r
+\r
+    VOMP is distributed in the hope that it will be useful,\r
+    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+    GNU General Public License for more details.\r
+\r
+    You should have received a copy of the GNU General Public License\r
+    along with VOMP; if not, write to the Free Software\r
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+*/\r
+#ifdef WIN32\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <signal.h>\r
+\r
+#define _WIN32_WINNT 0x501\r
+#include <winsock2.h>\r
+#include <windows.h>\r
+\r
+#include "vompreswin.h"\r
+\r
+#include "defines.h"\r
+#include "log.h"\r
+#include "remotewin.h"\r
+#include "ledwin.h"\r
+#include "mtdwin.h"\r
+#include "timers.h"\r
+#include "videowin.h"\r
+#include "audiowin.h"\r
+#include "vdr.h"\r
+#include "osdwin.h"\r
+#include "viewman.h"\r
+#include "command.h"\r
+\r
+void sighandler(int signalReceived);\r
+void shutdown(int code);\r
+\r
+// Global variables --------------------------------------------------------------------------------------------------\r
+int debugEnabled = 0;\r
+Log* logger;\r
+Remote* remote;\r
+Mtd* mtd;\r
+Led* led;\r
+Osd* osd;\r
+Timers* timers;\r
+ViewMan* viewman;\r
+Command* command;\r
+VDR* vdr;\r
+Video* video;\r
+Audio* audio;\r
+bool wnd_fullscreen=false;\r
+bool wnd_topmost=false;\r
+RECT wnd_fs_rect={20,20,768+20,576+20};\r
+RECT wnd_fs_rect_client={0,0,768,576};\r
+//OSVERSIONINFO windows_ver; //attempt to distigsh windows versions\r
+bool remotefnc=false;\r
+HINSTANCE  hinstance;\r
+bool cmenu=false;\r
+\r
+HMODULE user32dll;\r
+typedef UINT (WINAPI *GETRAWINPUTDATAFNC) (HRAWINPUT,UINT,LPVOID,PUINT,UINT);\r
+typedef UINT (WINAPI *REGISTERRAWINPUTDEVICEFNC)  (PCRAWINPUTDEVICE,UINT,UINT);\r
+\r
+GETRAWINPUTDATAFNC dynGetRawInputData=NULL;\r
+REGISTERRAWINPUTDEVICEFNC dynRegisterRawInputDevices=NULL;\r
+\r
+DWORD lastmousemove;\r
+\r
+\r
 void MILLISLEEP(ULONG a)
 {
 
   Sleep(a);
 
-}
-
-DWORD WINAPI commandthreadStart(void *arg)
-{
-        command->run();
-        return 0;
-}
-
-void LoadRemoteFunctions() {
-       user32dll=LoadLibrary("user32.dll");
-       if (user32dll!=NULL) {
-               dynGetRawInputData=(GETRAWINPUTDATAFNC)GetProcAddress(user32dll,"GetRawInputData");
-               if (dynGetRawInputData!=NULL) {
-                       dynRegisterRawInputDevices=(REGISTERRAWINPUTDEVICEFNC)GetProcAddress(user32dll,"RegisterRawInputDevices");
-                       if (dynRegisterRawInputDevices!=NULL) {
-                               remotefnc=true;
-                       }
-               }
-       }
-}
-
-bool InitApp(HINSTANCE hinst,int cmdshow);
-
-HWND win_main;//global window handle
-HWND win;//global child window handle
-HACCEL acc;
-
-#define ERROR_MSG(str) MessageBox(win_main,str,"Error!",MB_OK|MB_ICONWARNING)
-INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmdshow)
-{
-       hinstance=hinst;
-  //On Windows we have to init a window, we use DXUT
-       LoadRemoteFunctions();
-       if (!InitApp(hinst,cmdshow)) return false;
-  //Starting Network support
-  WSADATA wsadat; 
-  int result = WSAStartup(MAKEWORD(2,2),&wsadat);
-  if (result!=NO_ERROR) {
-        ERROR_MSG("Initialising WinSocked: Error at WSAStartup()\n");
-               return 0;
-  }
-  
-  result= CoInitializeEx(NULL,COINIT_MULTITHREADED );//Initialize COM for DirectShow
-  if (result!=S_OK) {
-         ERROR_MSG("Initialising COM: Error at Coinitialize()\n");
-         return 0;
-  }
-
-
-
-
-  // Init global vars ------------------------------------------------------------------------------------------------
-
-  logger     = new Log();
-  remote     = new RemoteWin();
-  mtd        = new MtdWin();
-  led        = new LedWin();
-  timers     = new Timers();
-  osd        = new OsdWin();
-  vdr        = new VDR();
-  video      = new VideoWin();
-  audio      = new AudioWin();
-  viewman    = new ViewMan();
-  command    = new Command();
-
-  if (!logger || !remote || !mtd || !led || !osd || !video || !audio || !viewman || !command)
-  {
-    ERROR_MSG("Could not create objects. Memory problems?\n");
-    shutdown(1);
-       WSACleanup();
-       return 0;
-  }
-
-  // Get logging module started --------------------------------------------------------------------------------------
-
-  if (!logger->init(Log::DEBUG, "vompwin.log", true))
-  {
-    ERROR_MSG("Could not initialise log object. Aborting.\n");
-    shutdown(1);
-       WSACleanup();
-       return 0;
-  }
-
-  logger->log("Core", Log::INFO, "Starting up...");
-  
-
-
-  // Init modules ----------------------------------------------------------------------------------------------------
-  int success;
-
-  success = remote->init("/dev/rawir");
-  if (success)
-  {
-    logger->log("Core", Log::INFO, "Remote module initialised");
-  }
-  else
-  {
-    logger->log("Core", Log::EMERG, "Remote module failed to initialise");
-    shutdown(1);
-       WSACleanup();
-       return 0;
-  }
-
-  success = led->init(0);
-  if (success)
-  {
-    logger->log("Core", Log::INFO, "LED module initialised");
-  }
-  else
-  {
-    logger->log("Core", Log::EMERG, "LED module failed to initialise");
-    shutdown(1);
-       WSACleanup();
-       return 0;
-  }
-
-  success = mtd->init("/dev/mtd1");
-  if (success)
-  {
-    logger->log("Core", Log::INFO, "Mtd module initialised");
-  }
-  else
-  {
-    logger->log("Core", Log::EMERG, "Mtd module failed to initialise");
-    shutdown(1);
-       WSACleanup();
-       return 0;
-  }
-
-  success = timers->init();
-  if (success)
-  {
-    logger->log("Core", Log::INFO, "Timers module initialised");
-  }
-  else
-  {
-    logger->log("Core", Log::EMERG, "Timers module failed to initialise");
-    shutdown(1);
-       WSACleanup();
-       return 0;
-  }
-
-  UCHAR videoFormat = (UCHAR)mtd->getPALorNTSC();
-  if      (videoFormat == Video::PAL)  logger->log("Core", Log::INFO, "Read from MTD: PAL 720x576");
-  else if (videoFormat == Video::NTSC) logger->log("Core", Log::INFO, "Read from MTD: NTSC 720x480");
-  else                                 logger->log("Core", Log::INFO, "No help from MTD. Assuming NTSC 720x480");
-
-  success = video->init(videoFormat);
-  if (success)
-  {
-    logger->log("Core", Log::INFO, "Video module initialised");
-  }
-  else
-  {
-    logger->log("Core", Log::EMERG, "Video module failed to initialise");
-    shutdown(1);
-       WSACleanup();
-       return 0;
-  }
-
-  success = osd->init((void*)&win);
-  if (success)
-  {
-    logger->log("Core", Log::INFO, "OSD module initialised");
-  }
-  else
-  {
-    logger->log("Core", Log::EMERG, "OSD module failed to initialise");
-    shutdown(1);
-       WSACleanup();
-       return 0;
-  }
-
-  success = audio->init(Audio::MPEG2_PES);
-  if (success)
-  {
-    logger->log("Core", Log::INFO, "Audio module initialised");
-  }
-  else
-  {
-    logger->log("Core", Log::EMERG, "Audio module failed to initialise");
-    shutdown(1);
-       WSACleanup();
-       return 0;
-  }
-
-  success = vdr->init(3024);
-  if (success)
-  {
-    logger->log("Core", Log::INFO, "VDR module initialised");
-  }
-  else
-  {
-    logger->log("Core", Log::EMERG, "VDR module failed to initialise");
-    shutdown(1);
-       WSACleanup();
-       return 0;
-  }
-
-  success = viewman->init();
-  if (success)
-  {
-    logger->log("Core", Log::INFO, "ViewMan module initialised");
-  }
-  else
-  {
-    logger->log("Core", Log::EMERG, "ViewMan module failed to initialise");
-    shutdown(1);
-       WSACleanup();
-       return 0;
-  }
-
-  success = command->init();
-  if (success)
-  {
-    logger->log("Core", Log::INFO, "Command module initialised");
-  }
-  else
-  {
-    logger->log("Core", Log::EMERG, "Command module failed to initialise");
-    shutdown(1);
-       WSACleanup();
-       return 0;
-  }
-
-  // Other init ------------------------------------------------------------------------------------------------------
-
-  logger->log("Core", Log::NOTICE, "Startup successful");
-
-  // Run main loop ---------------------------------------------------------------------------------------------------
-
-  // Ok, all major device components and other bits are loaded and ready
-  lastmousemove=timeGetTime();
-  HANDLE commandthread;
- commandthread= CreateThread(NULL, 0, commandthreadStart, NULL,0, 
-         NULL);
-  MSG message;
-  message.message=WM_NULL;
-  bool run=true;
-  while(run && WaitForSingleObject(commandthread,0)==WAIT_TIMEOUT) {
-         if (PeekMessage(&message, NULL, 0,0,PM_REMOVE)!=0) {
-                 if (TranslateAccelerator(win_main,acc,&message)==NULL) {
-                         TranslateMessage(&message);
-                         DispatchMessage(&message);
-                         switch (message.message) {
-                         case WM_QUIT:
-                                 run=false; //TODO post exit to command Messages
-                         };
-                 }
-         } else {
-                 //Render
-                 ((OsdWin*)osd)->Render();
-         }
-  }
-  // When that returns quit ------------------------------------------------------------------------------------------
-  WaitForSingleObject(commandthread,INFINITE);
-  shutdown(0);
-  WSACleanup();
-  if (user32dll) FreeModule(user32dll);
-  return 0;
-
-}
-
-
-
-void CalculateWindowSize(RECT * size,ULONG size_mode) {
-       
-       DWORD width, height;
-       DWORD adjheight,adjwidth;
-       if (!wnd_fullscreen) {
-               DWORD flags =WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU 
-                                |WS_MINIMIZEBOX | WS_SIZEBOX |WS_MAXIMIZEBOX;
-               RECT wnted={50,50,150,150};
-               AdjustWindowRect(&wnted,flags ,false);
-               adjwidth=-wnted.left+wnted.right-100;
-               adjheight=-wnted.top+wnted.bottom-100;
-       } else {
-               adjwidth=adjheight=0;
-       }
-       width=size->right-size->left-adjwidth;
-       height=size->bottom-size->top-adjheight;
-       UCHAR mode=video->getMode();
-       UCHAR aspect=((VideoWin*)video)->getAspectRatio();
-       UCHAR tvsize=((VideoWin*)video)->getPseudoTVsize();
-       double aspectrt=4./3.;
-       if (tvsize==Video::ASPECT16X9) {
-               if (aspect==Video::ASPECT16X9) {
-                       aspectrt=4./3.; //looks strange, but it is a 16:9 tv
-               } else if (aspect==Video::ASPECT4X3) {
-                       aspectrt=4./3./(16./9.)*(4./3.); //I hope this is correct
-               }
-       } else if (tvsize==Video::ASPECT4X3) {
-               if (aspect==Video::ASPECT16X9) {
-                       if (mode!=Video::NORMAL) {
-                               aspectrt=16./9.;
-                       } else {
-                               aspectrt=4./3.;
-                       }
-               } else if (aspect==Video::ASPECT4X3) {
-                       aspectrt=4./3.;
-               }
-       }
-       if (!wnd_fullscreen) {
-               switch (size_mode) {
-               case WMSZ_BOTTOM:
-               case WMSZ_BOTTOMRIGHT:
-               case WMSZ_TOP:
-               case WMSZ_TOPRIGHT:
-               width=(ULONG)(((double)height)*aspectrt);
-               size->right=size->left+width+adjwidth;
-               break;
-               case WMSZ_BOTTOMLEFT:
-               case WMSZ_TOPLEFT:
-               width=(ULONG)(((double)height)*aspectrt);
-               size->left=size->right-width-adjwidth;
-               break;
-               case WMSZ_LEFT:
-               case WMSZ_RIGHT:
-               height=(ULONG)(((double)width)/aspectrt);
-               size->bottom=size->top+height+adjheight;
-               break;
-               }
-               MoveWindow(win,0,0,width,height,TRUE);
-       } else {
-               RECT newrect={0,0,width,height};
-               DWORD newlength;
-               if ((ULONG)(((double)height)*aspectrt)>width) {
-                       newlength=(ULONG)(((double)width)/aspectrt);
-                       newrect.top+=(height-newlength)/2;
-                       newrect.bottom-=(height-newlength);
-               } else {
-                       newlength=(ULONG)(((double)height)*aspectrt);
-                       newrect.left+=(width-newlength)/2;
-                       newrect.right-=(width-newlength);
-               }
-               MoveWindow(win,newrect.left,newrect.top,newrect.right,newrect.bottom,TRUE);
-       }
-       
-}
-
-void AdjustWindow() {
-       if (!wnd_fullscreen) {
-               RECT winrect;
-               GetWindowRect(win_main,&winrect);
-               CalculateWindowSize(&winrect,WMSZ_BOTTOM);
-               MoveWindow(win_main,winrect.left,
-                       winrect.top,winrect.right-winrect.left,winrect.bottom-winrect.top,true);
-       } else {
-               RECT winrect;
-               GetWindowRect(win_main,&winrect);
-               CalculateWindowSize(&winrect,WMSZ_BOTTOM);
-
-       }
-}
-
-void ToggleFullscreen() {
-       if (wnd_fullscreen) {
-               wnd_fullscreen=false;
-               SetWindowLong(win_main,GWL_STYLE,WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU 
-                 |WS_MINIMIZEBOX | WS_SIZEBOX |WS_MAXIMIZEBOX);
-               SetWindowPos(win_main,NULL,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
-
-               SetWindowPos(win_main,wnd_topmost?HWND_TOPMOST:HWND_TOP,wnd_fs_rect.left,wnd_fs_rect.top,
-                                                       wnd_fs_rect.right-wnd_fs_rect.left,
-                                                       wnd_fs_rect.bottom-wnd_fs_rect.top,
-                                                       SWP_DRAWFRAME | SWP_FRAMECHANGED);
-               MoveWindow(win,wnd_fs_rect_client.left,wnd_fs_rect_client.top,
-                                                       wnd_fs_rect_client.right-wnd_fs_rect_client.left,
-                                                       wnd_fs_rect_client.bottom-wnd_fs_rect_client.top,TRUE);
-               AdjustWindow();
-       } else {
-               GetWindowRect(win_main,&wnd_fs_rect);
-               GetWindowRect(win,&wnd_fs_rect_client);
-               SetWindowLong(win_main,GWL_STYLE,WS_VISIBLE | WS_POPUP );
-               SetWindowPos(win_main,NULL,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
-               HMONITOR monitor=MonitorFromWindow(win_main,MONITOR_DEFAULTTONEAREST);  
-               MONITORINFO moninfo;
-               moninfo.cbSize=sizeof(moninfo);
-               wnd_fullscreen=true;
-               if (!GetMonitorInfo(monitor,&moninfo)) return ;
-               SetWindowPos(win_main,wnd_topmost?HWND_TOPMOST:HWND_TOP,moninfo.rcMonitor.left,moninfo.rcMonitor.top,
-                       moninfo.rcMonitor.right,moninfo.rcMonitor.bottom,SWP_FRAMECHANGED);
-               
-               AdjustWindow();
-               
-       }
-
-
-}
-
-void ToggleTopmost() {
-       wnd_topmost=!wnd_topmost;
-       SetWindowPos(win_main,wnd_topmost?HWND_TOPMOST:HWND_NOTOPMOST,0,0,
-                       0,0,SWP_NOMOVE | SWP_NOSIZE);
-}
-
-void CursorUpdate() {
-       POINT cursorpos;
-       GetCursorPos(&cursorpos);
-       HWND asswind;
-       asswind=WindowFromPoint(cursorpos);
-       if (asswind!=win_main && asswind!=win) {
-               return ; //not our responsibility
-       }
-       if ((timeGetTime()-lastmousemove)<4000 || cmenu) {
-               SetCursor(LoadCursor(NULL,IDC_ARROW));
-       } else {
-               SetCursor(NULL);
-       }
-}
-
-bool ContextMenu(HWND wind,int x,int y) {
-       POINT p={x,y};
-       RECT clientrect;
-       ScreenToClient(wind,&p);
-       GetClientRect(wind,&clientrect);
-       if (!PtInRect(&clientrect,p)) return false;
-       ClientToScreen(wind,&p);
-       HMENU menu;
-       HMENU popup;
-       menu=LoadMenu(hinstance,MAKEINTRESOURCE(VOMPMENU));
-       popup=GetSubMenu(menu,0);
-       if (wnd_fullscreen) {
-               CheckMenuItem(popup,VOMP_FULL_SCREEN,MF_BYCOMMAND|MF_CHECKED);
-       } else {
-               CheckMenuItem(popup,VOMP_FULL_SCREEN,MF_BYCOMMAND|MF_UNCHECKED);
-       }
-       if (wnd_topmost) {
-               CheckMenuItem(popup,VOMP_TOPMOST,MF_BYCOMMAND|MF_CHECKED);
-       } else {
-               CheckMenuItem(popup,VOMP_TOPMOST,MF_BYCOMMAND|MF_UNCHECKED);
-       }
-       cmenu=true;
-       TrackPopupMenu(popup,TPM_RIGHTBUTTON|TPM_LEFTALIGN,x,y,0,wind, NULL);
-       cmenu=false;
-
-
-       DestroyMenu(menu);
-       return true;
-}
-
-LONG FAR PASCAL WindowProc(HWND wind, UINT msg, WPARAM wparam, LPARAM lparam)
-{
-   
-   switch (msg) {
-   case WM_DESTROY: {
-          //TODO: call command
-          logger->log("Core", Log::NOTICE, "Window closed, shutting down...");
-        
-          ((RemoteWin*)Remote::getInstance())->SendPower();
-          PostQuitMessage(0);
-       }break;
-   case WM_SIZING: {
-          CalculateWindowSize((RECT*) lparam,wparam);
-          return TRUE;
-                                  }break;
-       case WM_SIZE: {
-        int width = LOWORD(lparam);
-        int height = HIWORD(lparam);
-         //Call device
-        }
-        break;
-        case WM_PAINT:
-        RECT r;
-        PAINTSTRUCT ps;
-        if (GetUpdateRect(wind, &r, FALSE)) {
-            BeginPaint(wind, &ps);
-            //Call Painting Mechanism
-            EndPaint(wind, &ps);
-        }
-        break;
-        case WM_KEYDOWN:
-                if (((RemoteWin*)remote)->ReceiveButtonVK(wparam)) {
-                        return 0L; //We process that Key
-                } else {
-                        return DefWindowProc(wind, msg, wparam, lparam);
-                }
-
-                break;
-       case WM_APPCOMMAND:
-               if (((RemoteWin*)remote)->ReceiveButtonAP(GET_APPCOMMAND_LPARAM(lparam))){
-                       return TRUE; //yes we process that message
-               } else {
-                       return DefWindowProc(wind, msg, wparam, lparam);
-               }
-
-               break;
-       case WM_INPUT:
-               if (remotefnc ) {
-                       //only on XP!
-                        LPRAWINPUT lpit;
-                        UINT risize;
-                        dynGetRawInputData((HRAWINPUT)lparam,RID_INPUT,NULL,&risize,sizeof(RAWINPUTHEADER));
-                        lpit=(LPRAWINPUT)malloc(risize);
-                        dynGetRawInputData((HRAWINPUT)lparam,RID_INPUT,lpit,&risize,sizeof(RAWINPUTHEADER));
-  
-                       if (lpit->header.dwType==RIM_TYPEHID && lpit->data.hid.dwSizeHid>=2) {
-                               DWORD button=lpit->data.hid.bRawData[1] | (lpit->data.hid.bRawData[0]<< 8);
-                               if (((RemoteWin*)remote)->ReceiveButtonRI(button)){
-                                       free(lpit);
-                                       return 0; //yes we process that message
-                               }
-                       }
-                       free(lpit);
-               }
-               return DefWindowProc(wind, msg, wparam, lparam);
-               
-
-               break;
-       case WM_COMMAND:
-               if (LOWORD(wparam)==VOMP_FULL_SCREEN) {
-                       ToggleFullscreen();
-                       return 0;
-               }
-               if (LOWORD(wparam)==VOMP_TOPMOST) {
-                       ToggleTopmost();
-                       return 0;
-               }
-               if (((RemoteWin*)remote)->ReceiveButtonAP(LOWORD(wparam))){
-                       return 0; //yes we process that message
-               } else {
-                       return DefWindowProc(wind, msg, wparam, lparam);
-               }
-
-               break;
-       case WM_SETCURSOR:
-               if (((HANDLE)wparam)==win) {
-                       CursorUpdate();
-                       return 1;
-               } else {
-                       return DefWindowProc(wind, msg, wparam, lparam);
-               }
-               break;
-       case WM_SYSCOMMAND:
-               if (wparam==SC_MAXIMIZE) {
-                       ToggleFullscreen();
-                       return 0;
-               } else if (wparam==SC_SCREENSAVE || wparam==SC_MONITORPOWER) {
-                       return 0;
-               } else {
-                       return DefWindowProc(wind,msg,wparam, lparam);
-               }
-               break;
-       case WM_MOUSEMOVE:
-               lastmousemove=timeGetTime();
-               SetCursor(LoadCursor(NULL,IDC_ARROW));
-               SetTimer(wind,VOMP_CURSORUPDATE,4500,NULL);
-               return 0;
-               //return DefWindowProc(wind,msg,wparam, lparam);
-               break;
-       case WM_TIMER:
-               if (wparam==VOMP_CURSORUPDATE) {
-                       CursorUpdate();
-                       return 0;
-               }
-               return DefWindowProc(wind, msg, wparam, lparam);
-
-               break;
-       case WM_CONTEXTMENU:
-               if (!ContextMenu(wind,GET_X_LPARAM(lparam),GET_Y_LPARAM(lparam))) {
-                       return DefWindowProc(wind, msg, wparam, lparam);
-               } else {
-                       return 0;
-               }
-
-    default:
-        return DefWindowProc(wind, msg, wparam, lparam);
-    }
-    return 0L;
-}
-
-
-bool InitApp(HINSTANCE hinst,int cmdshow) {
-       /* main window */
-       WNDCLASS wcs;
-       DWORD flags;
-       wcs.style = CS_HREDRAW | CS_VREDRAW;
-    wcs.lpfnWndProc = WindowProc;
-    wcs.cbClsExtra = 0;
-    wcs.cbWndExtra = sizeof(DWORD);
-    wcs.hInstance = hinst;
-    wcs.hIcon = NULL;
-    wcs.hCursor = NULL;
-    wcs.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
-    wcs.lpszMenuName = NULL;
-    wcs.lpszClassName = "vomp";
-       acc=LoadAccelerators(hinst,MAKEINTRESOURCE(VOMPACCELERATOR));
-       if (!RegisterClass(&wcs))
-        return false;
-       flags =WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU 
-                 |WS_MINIMIZEBOX | WS_SIZEBOX |WS_MAXIMIZEBOX;
-       RECT wnted={50,50,768+50,576+50};
-       AdjustWindowRect(&wnted,flags ,false);
-       win_main=CreateWindow("vomp","VOMP on Windows",flags, CW_USEDEFAULT,CW_USEDEFAULT,
-               wnted.right-wnted.left,wnted.bottom-wnted.top,NULL,NULL,hinst,NULL);
-       if (!win_main)
-        return FALSE;
-       ShowWindow(win_main,SW_SHOWNORMAL);
-    UpdateWindow(win_main);
-       /* in order to handle letterboxing we use a child window */
-       WNDCLASS child_wcs;
-       child_wcs.style = CS_HREDRAW | CS_VREDRAW;
-    child_wcs.lpfnWndProc = WindowProc;
-    child_wcs.cbClsExtra = 0;
-    child_wcs.cbWndExtra = sizeof(DWORD);
-    child_wcs.hInstance = hinst;
-    child_wcs.hIcon = NULL;
-    child_wcs.hCursor = NULL;
-    child_wcs.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
-    child_wcs.lpszMenuName = NULL;
-    child_wcs.lpszClassName = "vomp_playback";
-       if (!RegisterClass(&child_wcs))
-        return false;
-
-       win=CreateWindow("vomp_playback","Vomp Playback Window",WS_VISIBLE | WS_CHILD |WS_CLIPCHILDREN,
-               0,0,768,576,win_main,NULL,hinst,NULL);
-       if (!win)
-               return FALSE;
-       ShowWindow(win,SW_SHOWNORMAL);
-       UpdateWindow(win);
-       if (remotefnc) {//at least windows XP
-               /* We want to support MCE Remote controls*/
-               RAWINPUTDEVICE remote_control_data[4];
-               ZeroMemory(remote_control_data,sizeof(remote_control_data));
-               remote_control_data[0].usUsagePage=0xFFBC; 
-               remote_control_data[0].usUsage=0x88; 
-               remote_control_data[0].dwFlags=0;
-               remote_control_data[1].usUsagePage=0x0C; 
-               remote_control_data[1].usUsage=0x80; 
-               remote_control_data[1].dwFlags=0;
-               remote_control_data[2].usUsagePage=0x0C; 
-               remote_control_data[2].usUsage=0x01; 
-               remote_control_data[2].dwFlags=0;
-               remote_control_data[3].usUsagePage=0x01; 
-               remote_control_data[3].usUsage=0x80; 
-               remote_control_data[3].dwFlags=0;
-               if (dynRegisterRawInputDevices(remote_control_data,4,sizeof(remote_control_data[0]))!=TRUE) {
-                       MessageBox(0,"Registering remote control failed!","Aborting!",0);
-                       return FALSE;
-               }
-       
-       }
-       return TRUE;
-}
-
-
-
-
-
-// -------------------------------------------------------------------------------------------------------------------
-
-void shutdown(int code)
-{
-  if (viewman)
-  {
-    viewman->shutdown();
-    delete viewman;
-    logger->log("Core", Log::NOTICE, "ViewMan module shut down");
-  }
-
-  if (command) // shut down command here in case views have posted messages
-  {
-    command->shutdown();
-    delete command;
-    logger->log("Core", Log::NOTICE, "Command module shut down");
-  }
-
-  if (vdr)
-  {
-    vdr->shutdown();
-    delete vdr;
-    logger->log("Core", Log::NOTICE, "VDR module shut down");
-  }
-
-  if (osd)
-  {
-    osd->shutdown();
-    delete osd;
-    logger->log("Core", Log::NOTICE, "OSD module shut down");
-  }
-
-  if (audio)
-  {
-    audio->shutdown();
-    delete audio;
-    logger->log("Core", Log::NOTICE, "Audio module shut down");
-  }
-
-  if (video)
-  {
-    video->shutdown();
-    delete video;
-    logger->log("Core", Log::NOTICE, "Video module shut down");
-  }
-
-  if (timers)
-  {
-    timers->shutdown();
-    delete timers;
-    logger->log("Core", Log::NOTICE, "Timers module shut down");
-  }
-
-  if (mtd)
-  {
-    mtd->shutdown();
-    delete mtd;
-    logger->log("Core", Log::NOTICE, "MTD module shut down");
-  }
-
-  if (led)
-  {
-    led->shutdown();
-    delete led;
-    logger->log("Core", Log::NOTICE, "LED module shut down");
-  }
-
-  if (remote)
-  {
-    remote->shutdown();
-    delete remote;
-    logger->log("Core", Log::NOTICE, "Remote module shut down");
-  }
-
-  if (logger)
-  {
-    logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n");
-    logger->shutdown();
-    delete logger;
-  }
-  ExitProcess(0);
-
-}
-
-// -------------------------------------------------------------------------------------------------------------------
-
-ULLONG ntohll(ULLONG a)
-{
-  return htonll(a);
-}
-
-ULLONG htonll(ULLONG a)
-{
-       return (((ULLONG)htonl((ULONG)((a<<32)>> 32))<<32) 
-               |(ULONG)htonl(((ULONG) (a >> 32))));
-}
-#endif
+}\r
+\r
+DWORD WINAPI commandthreadStart(void *arg)\r
+{\r
+        command->run();\r
+        return 0;\r
+}\r
+\r
+void LoadRemoteFunctions() {\r
+       user32dll=LoadLibrary("user32.dll");\r
+       if (user32dll!=NULL) {\r
+               dynGetRawInputData=(GETRAWINPUTDATAFNC)GetProcAddress(user32dll,"GetRawInputData");\r
+               if (dynGetRawInputData!=NULL) {\r
+                       dynRegisterRawInputDevices=(REGISTERRAWINPUTDEVICEFNC)GetProcAddress(user32dll,"RegisterRawInputDevices");\r
+                       if (dynRegisterRawInputDevices!=NULL) {\r
+                               remotefnc=true;\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+bool InitApp(HINSTANCE hinst,int cmdshow);\r
+\r
+HWND win_main;//global window handle\r
+HWND win;//global child window handle\r
+HACCEL acc;\r
+\r
+#define ERROR_MSG(str) MessageBox(win_main,str,"Error!",MB_OK|MB_ICONWARNING)\r
+INT WINAPI WinMain( HINSTANCE hinst , HINSTANCE previnst, LPSTR cmdline, int cmdshow)\r
+{\r
+       hinstance=hinst;\r
+  //On Windows we have to init a window, we use DXUT\r
+       LoadRemoteFunctions();\r
+       if (!InitApp(hinst,cmdshow)) return false;\r
+  //Starting Network support\r
+  WSADATA wsadat; \r
+  int result = WSAStartup(MAKEWORD(2,2),&wsadat);\r
+  if (result!=NO_ERROR) {\r
+        ERROR_MSG("Initialising WinSocked: Error at WSAStartup()\n");\r
+               return 0;\r
+  }\r
+  \r
+  result= CoInitializeEx(NULL,COINIT_MULTITHREADED );//Initialize COM for DirectShow\r
+  if (result!=S_OK) {\r
+         ERROR_MSG("Initialising COM: Error at Coinitialize()\n");\r
+         return 0;\r
+  }\r
+\r
+\r
+\r
+\r
+  // Init global vars ------------------------------------------------------------------------------------------------\r
+\r
+  logger     = new Log();\r
+  remote     = new RemoteWin();\r
+  mtd        = new MtdWin();\r
+  led        = new LedWin();\r
+  timers     = new Timers();\r
+  osd        = new OsdWin();\r
+  vdr        = new VDR();\r
+  video      = new VideoWin();\r
+  audio      = new AudioWin();\r
+  viewman    = new ViewMan();\r
+  command    = new Command();\r
+\r
+  if (!logger || !remote || !mtd || !led || !osd || !video || !audio || !viewman || !command)\r
+  {\r
+    ERROR_MSG("Could not create objects. Memory problems?\n");\r
+    shutdown(1);\r
+       WSACleanup();\r
+       return 0;\r
+  }\r
+\r
+  // Get logging module started --------------------------------------------------------------------------------------\r
+\r
+  if (!logger->init(Log::DEBUG, "vompwin.log", true))\r
+  {\r
+    ERROR_MSG("Could not initialise log object. Aborting.\n");\r
+    shutdown(1);\r
+       WSACleanup();\r
+       return 0;\r
+  }\r
+\r
+  logger->log("Core", Log::INFO, "Starting up...");\r
+  \r
+\r
+\r
+  // Init modules ----------------------------------------------------------------------------------------------------\r
+  int success;\r
+\r
+  success = remote->init("/dev/rawir");\r
+  if (success)\r
+  {\r
+    logger->log("Core", Log::INFO, "Remote module initialised");\r
+  }\r
+  else\r
+  {\r
+    logger->log("Core", Log::EMERG, "Remote module failed to initialise");\r
+    shutdown(1);\r
+       WSACleanup();\r
+       return 0;\r
+  }\r
+\r
+  success = led->init(0);\r
+  if (success)\r
+  {\r
+    logger->log("Core", Log::INFO, "LED module initialised");\r
+  }\r
+  else\r
+  {\r
+    logger->log("Core", Log::EMERG, "LED module failed to initialise");\r
+    shutdown(1);\r
+       WSACleanup();\r
+       return 0;\r
+  }\r
+\r
+  success = mtd->init("/dev/mtd1");\r
+  if (success)\r
+  {\r
+    logger->log("Core", Log::INFO, "Mtd module initialised");\r
+  }\r
+  else\r
+  {\r
+    logger->log("Core", Log::EMERG, "Mtd module failed to initialise");\r
+    shutdown(1);\r
+       WSACleanup();\r
+       return 0;\r
+  }\r
+\r
+  success = timers->init();\r
+  if (success)\r
+  {\r
+    logger->log("Core", Log::INFO, "Timers module initialised");\r
+  }\r
+  else\r
+  {\r
+    logger->log("Core", Log::EMERG, "Timers module failed to initialise");\r
+    shutdown(1);\r
+       WSACleanup();\r
+       return 0;\r
+  }\r
+\r
+  UCHAR videoFormat = (UCHAR)mtd->getPALorNTSC();\r
+  if      (videoFormat == Video::PAL)  logger->log("Core", Log::INFO, "Read from MTD: PAL 720x576");\r
+  else if (videoFormat == Video::NTSC) logger->log("Core", Log::INFO, "Read from MTD: NTSC 720x480");\r
+  else                                 logger->log("Core", Log::INFO, "No help from MTD. Assuming NTSC 720x480");\r
+\r
+  success = video->init(videoFormat);\r
+  if (success)\r
+  {\r
+    logger->log("Core", Log::INFO, "Video module initialised");\r
+  }\r
+  else\r
+  {\r
+    logger->log("Core", Log::EMERG, "Video module failed to initialise");\r
+    shutdown(1);\r
+       WSACleanup();\r
+       return 0;\r
+  }\r
+\r
+  success = osd->init((void*)&win);\r
+  if (success)\r
+  {\r
+    logger->log("Core", Log::INFO, "OSD module initialised");\r
+  }\r
+  else\r
+  {\r
+    logger->log("Core", Log::EMERG, "OSD module failed to initialise");\r
+    shutdown(1);\r
+       WSACleanup();\r
+       return 0;\r
+  }\r
+\r
+  success = audio->init(Audio::MPEG2_PES);\r
+  if (success)\r
+  {\r
+    logger->log("Core", Log::INFO, "Audio module initialised");\r
+  }\r
+  else\r
+  {\r
+    logger->log("Core", Log::EMERG, "Audio module failed to initialise");\r
+    shutdown(1);\r
+       WSACleanup();\r
+       return 0;\r
+  }\r
+\r
+  success = vdr->init(3024);\r
+  if (success)\r
+  {\r
+    logger->log("Core", Log::INFO, "VDR module initialised");\r
+  }\r
+  else\r
+  {\r
+    logger->log("Core", Log::EMERG, "VDR module failed to initialise");\r
+    shutdown(1);\r
+       WSACleanup();\r
+       return 0;\r
+  }\r
+\r
+  success = viewman->init();\r
+  if (success)\r
+  {\r
+    logger->log("Core", Log::INFO, "ViewMan module initialised");\r
+  }\r
+  else\r
+  {\r
+    logger->log("Core", Log::EMERG, "ViewMan module failed to initialise");\r
+    shutdown(1);\r
+       WSACleanup();\r
+       return 0;\r
+  }\r
+\r
+  success = command->init();\r
+  if (success)\r
+  {\r
+    logger->log("Core", Log::INFO, "Command module initialised");\r
+  }\r
+  else\r
+  {\r
+    logger->log("Core", Log::EMERG, "Command module failed to initialise");\r
+    shutdown(1);\r
+       WSACleanup();\r
+       return 0;\r
+  }\r
+\r
+  // Other init ------------------------------------------------------------------------------------------------------\r
+\r
+  logger->log("Core", Log::NOTICE, "Startup successful");\r
+\r
+  // Run main loop ---------------------------------------------------------------------------------------------------\r
+\r
+  // Ok, all major device components and other bits are loaded and ready\r
+  lastmousemove=timeGetTime();\r
+  \r
+  HANDLE commandthread;\r
+ commandthread= CreateThread(NULL, 0, commandthreadStart, NULL,0, \r
+         NULL);\r
+  MSG message;\r
+  message.message=WM_NULL;\r
+  bool run=true;\r
+  while(run && WaitForSingleObject(commandthread,0)==WAIT_TIMEOUT) {\r
+         if (PeekMessage(&message, NULL, 0,0,PM_REMOVE)!=0) {\r
+                 if (TranslateAccelerator(win_main,acc,&message)==NULL) {\r
+                         TranslateMessage(&message);\r
+                         DispatchMessage(&message);\r
+                         switch (message.message) {\r
+                         case WM_QUIT:\r
+                                 run=false; //TODO post exit to command Messages\r
+                         };\r
+                 }\r
+         } else {\r
+                 //Render\r
+                 ((OsdWin*)osd)->Render();\r
+         }\r
+  }\r
+  // When that returns quit ------------------------------------------------------------------------------------------\r
+  WaitForSingleObject(commandthread,INFINITE);\r
+  shutdown(0);\r
+  WSACleanup();\r
+  if (user32dll) FreeModule(user32dll);\r
+  return 0;\r
+\r
+}\r
+\r
+bool TranslateMousePosition(POINT *pos) {\r
+       \r
+       RECT clientrect;\r
+       ScreenToClient(win,pos);\r
+       GetClientRect(win,&clientrect);\r
+       if (!PtInRect(&clientrect,*pos)) return false;//Don't pass it further\r
+       pos->x=((double)pos->x)/((double) (clientrect.right-clientrect.left))\r
+               *((double)Video::getInstance()->getScreenWidth());\r
+       pos->y=((double)pos->y)/((double) (clientrect.bottom-clientrect.top))\r
+               *((double)Video::getInstance()->getScreenHeight());\r
+       return true;\r
+\r
+}\r
+\r
+\r
+\r
+void CalculateWindowSize(RECT * size,ULONG size_mode) {\r
+       \r
+       DWORD width, height;\r
+       DWORD adjheight,adjwidth;\r
+       if (!wnd_fullscreen) {\r
+               DWORD flags =WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU \r
+                                |WS_MINIMIZEBOX | WS_SIZEBOX |WS_MAXIMIZEBOX;\r
+               RECT wnted={50,50,150,150};\r
+               AdjustWindowRect(&wnted,flags ,false);\r
+               adjwidth=-wnted.left+wnted.right-100;\r
+               adjheight=-wnted.top+wnted.bottom-100;\r
+       } else {\r
+               adjwidth=adjheight=0;\r
+       }\r
+       width=size->right-size->left-adjwidth;\r
+       height=size->bottom-size->top-adjheight;\r
+       UCHAR mode=video->getMode();\r
+       UCHAR aspect=((VideoWin*)video)->getAspectRatio();\r
+       UCHAR tvsize=((VideoWin*)video)->getPseudoTVsize();\r
+       double aspectrt=4./3.;\r
+       if (tvsize==Video::ASPECT16X9) {\r
+               if (aspect==Video::ASPECT16X9) {\r
+                       aspectrt=4./3.; //looks strange, but it is a 16:9 tv\r
+               } else if (aspect==Video::ASPECT4X3) {\r
+                       aspectrt=4./3./(16./9.)*(4./3.); //I hope this is correct\r
+               }\r
+       } else if (tvsize==Video::ASPECT4X3) {\r
+               if (aspect==Video::ASPECT16X9) {\r
+                       if (mode!=Video::NORMAL) {\r
+                               aspectrt=16./9.;\r
+                       } else {\r
+                               aspectrt=4./3.;\r
+                       }\r
+               } else if (aspect==Video::ASPECT4X3) {\r
+                       aspectrt=4./3.;\r
+               }\r
+       }\r
+       if (!wnd_fullscreen) {\r
+               switch (size_mode) {\r
+               case WMSZ_BOTTOM:\r
+               case WMSZ_BOTTOMRIGHT:\r
+               case WMSZ_TOP:\r
+               case WMSZ_TOPRIGHT:\r
+               width=(ULONG)(((double)height)*aspectrt);\r
+               size->right=size->left+width+adjwidth;\r
+               break;\r
+               case WMSZ_BOTTOMLEFT:\r
+               case WMSZ_TOPLEFT:\r
+               width=(ULONG)(((double)height)*aspectrt);\r
+               size->left=size->right-width-adjwidth;\r
+               break;\r
+               case WMSZ_LEFT:\r
+               case WMSZ_RIGHT:\r
+               height=(ULONG)(((double)width)/aspectrt);\r
+               size->bottom=size->top+height+adjheight;\r
+               break;\r
+               }\r
+               MoveWindow(win,0,0,width,height,TRUE);\r
+       } else {\r
+               RECT newrect={0,0,width,height};\r
+               DWORD newlength;\r
+               if ((ULONG)(((double)height)*aspectrt)>width) {\r
+                       newlength=(ULONG)(((double)width)/aspectrt);\r
+                       newrect.top+=(height-newlength)/2;\r
+                       newrect.bottom-=(height-newlength);\r
+               } else {\r
+                       newlength=(ULONG)(((double)height)*aspectrt);\r
+                       newrect.left+=(width-newlength)/2;\r
+                       newrect.right-=(width-newlength);\r
+               }\r
+               MoveWindow(win,newrect.left,newrect.top,newrect.right,newrect.bottom,TRUE);\r
+       }\r
+       \r
+}\r
+\r
+void AdjustWindow() {\r
+       if (!wnd_fullscreen) {\r
+               RECT winrect;\r
+               GetWindowRect(win_main,&winrect);\r
+               CalculateWindowSize(&winrect,WMSZ_BOTTOM);\r
+               MoveWindow(win_main,winrect.left,\r
+                       winrect.top,winrect.right-winrect.left,winrect.bottom-winrect.top,true);\r
+       } else {\r
+               RECT winrect;\r
+               GetWindowRect(win_main,&winrect);\r
+               CalculateWindowSize(&winrect,WMSZ_BOTTOM);\r
+\r
+       }\r
+}\r
+\r
+void ToggleFullscreen() {\r
+       if (wnd_fullscreen) {\r
+               wnd_fullscreen=false;\r
+               SetWindowLong(win_main,GWL_STYLE,WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU \r
+                 |WS_MINIMIZEBOX | WS_SIZEBOX |WS_MAXIMIZEBOX);\r
+               SetWindowPos(win_main,NULL,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);\r
+\r
+               SetWindowPos(win_main,wnd_topmost?HWND_TOPMOST:HWND_TOP,wnd_fs_rect.left,wnd_fs_rect.top,\r
+                                                       wnd_fs_rect.right-wnd_fs_rect.left,\r
+                                                       wnd_fs_rect.bottom-wnd_fs_rect.top,\r
+                                                       SWP_DRAWFRAME | SWP_FRAMECHANGED);\r
+               MoveWindow(win,wnd_fs_rect_client.left,wnd_fs_rect_client.top,\r
+                                                       wnd_fs_rect_client.right-wnd_fs_rect_client.left,\r
+                                                       wnd_fs_rect_client.bottom-wnd_fs_rect_client.top,TRUE);\r
+               AdjustWindow();\r
+       } else {\r
+               GetWindowRect(win_main,&wnd_fs_rect);\r
+               GetWindowRect(win,&wnd_fs_rect_client);\r
+               SetWindowLong(win_main,GWL_STYLE,WS_VISIBLE | WS_POPUP );\r
+               SetWindowPos(win_main,NULL,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);\r
+               HMONITOR monitor=MonitorFromWindow(win_main,MONITOR_DEFAULTTONEAREST);  \r
+               MONITORINFO moninfo;\r
+               moninfo.cbSize=sizeof(moninfo);\r
+               wnd_fullscreen=true;\r
+               if (!GetMonitorInfo(monitor,&moninfo)) return ;\r
+               SetWindowPos(win_main,wnd_topmost?HWND_TOPMOST:HWND_TOP,moninfo.rcMonitor.left,moninfo.rcMonitor.top,\r
+                       moninfo.rcMonitor.right,moninfo.rcMonitor.bottom,SWP_FRAMECHANGED);\r
+               \r
+               AdjustWindow();\r
+               \r
+       }\r
+\r
+\r
+}\r
+\r
+void ToggleTopmost() {\r
+       wnd_topmost=!wnd_topmost;\r
+       SetWindowPos(win_main,wnd_topmost?HWND_TOPMOST:HWND_NOTOPMOST,0,0,\r
+                       0,0,SWP_NOMOVE | SWP_NOSIZE);\r
+}\r
+\r
+void CursorUpdate() {\r
+       POINT cursorpos;\r
+       GetCursorPos(&cursorpos);\r
+       HWND asswind;\r
+       asswind=WindowFromPoint(cursorpos);\r
+       if (asswind!=win_main && asswind!=win) {\r
+               return ; //not our responsibility\r
+       }\r
+       if ((timeGetTime()-lastmousemove)<4000 || cmenu) {\r
+               SetCursor(LoadCursor(NULL,IDC_ARROW));\r
+       } else {\r
+               SetCursor(NULL);\r
+       }\r
+}\r
+\r
+bool ContextMenu(HWND wind,int x,int y) {\r
+       POINT p={x,y};\r
+       RECT clientrect;\r
+       ScreenToClient(wind,&p);\r
+       GetClientRect(wind,&clientrect);\r
+       if (!PtInRect(&clientrect,p)) return false;\r
+       ClientToScreen(wind,&p);\r
+       HMENU menu;\r
+       HMENU popup;\r
+       menu=LoadMenu(hinstance,MAKEINTRESOURCE(VOMPMENU));\r
+       popup=GetSubMenu(menu,0);\r
+       if (wnd_fullscreen) {\r
+               CheckMenuItem(popup,VOMP_FULL_SCREEN,MF_BYCOMMAND|MF_CHECKED);\r
+       } else {\r
+               CheckMenuItem(popup,VOMP_FULL_SCREEN,MF_BYCOMMAND|MF_UNCHECKED);\r
+       }\r
+       if (wnd_topmost) {\r
+               CheckMenuItem(popup,VOMP_TOPMOST,MF_BYCOMMAND|MF_CHECKED);\r
+       } else {\r
+               CheckMenuItem(popup,VOMP_TOPMOST,MF_BYCOMMAND|MF_UNCHECKED);\r
+       }\r
+       cmenu=true;\r
+       TrackPopupMenu(popup,TPM_RIGHTBUTTON|TPM_LEFTALIGN,x,y,0,wind, NULL);\r
+       cmenu=false;\r
+\r
+\r
+       DestroyMenu(menu);\r
+       return true;\r
+}\r
+\r
+LONG FAR PASCAL WindowProc(HWND wind, UINT msg, WPARAM wparam, LPARAM lparam)\r
+{\r
+   \r
+   switch (msg) {\r
+   case WM_DESTROY: {\r
+          //TODO: call command\r
+          logger->log("Core", Log::NOTICE, "Window closed, shutting down...");\r
+        \r
+          ((RemoteWin*)Remote::getInstance())->SendPower();\r
+          PostQuitMessage(0);\r
+       }break;\r
+   case WM_SIZING: {\r
+          CalculateWindowSize((RECT*) lparam,wparam);\r
+          return TRUE;\r
+                                  }break;\r
+       case WM_SIZE: {\r
+        int width = LOWORD(lparam);\r
+        int height = HIWORD(lparam);\r
+         //Call device\r
+        }\r
+        break;\r
+        case WM_PAINT:\r
+        RECT r;\r
+        PAINTSTRUCT ps;\r
+        if (GetUpdateRect(wind, &r, FALSE)) {\r
+            BeginPaint(wind, &ps);\r
+            //Call Painting Mechanism\r
+            EndPaint(wind, &ps);\r
+        }\r
+        break;\r
+        case WM_KEYDOWN:\r
+                if (((RemoteWin*)remote)->ReceiveButtonVK(wparam)) {\r
+                        return 0L; //We process that Key\r
+                } else {\r
+                        return DefWindowProc(wind, msg, wparam, lparam);\r
+                }\r
+\r
+                break;\r
+       case WM_APPCOMMAND:\r
+               if (((RemoteWin*)remote)->ReceiveButtonAP(GET_APPCOMMAND_LPARAM(lparam))){\r
+                       return TRUE; //yes we process that message\r
+               } else {\r
+                       return DefWindowProc(wind, msg, wparam, lparam);\r
+               }\r
+\r
+               break;\r
+       case WM_INPUT:\r
+               if (remotefnc ) {\r
+                       //only on XP!\r
+                        LPRAWINPUT lpit;\r
+                        UINT risize;\r
+                        dynGetRawInputData((HRAWINPUT)lparam,RID_INPUT,NULL,&risize,sizeof(RAWINPUTHEADER));\r
+                        lpit=(LPRAWINPUT)malloc(risize);\r
+                        dynGetRawInputData((HRAWINPUT)lparam,RID_INPUT,lpit,&risize,sizeof(RAWINPUTHEADER));\r
+  \r
+                       if (lpit->header.dwType==RIM_TYPEHID && lpit->data.hid.dwSizeHid>=2) {\r
+                               DWORD button=lpit->data.hid.bRawData[1] | (lpit->data.hid.bRawData[0]<< 8);\r
+                               if (((RemoteWin*)remote)->ReceiveButtonRI(button)){\r
+                                       free(lpit);\r
+                                       return 0; //yes we process that message\r
+                               }\r
+                       }\r
+                       free(lpit);\r
+               }\r
+               return DefWindowProc(wind, msg, wparam, lparam);\r
+               \r
+\r
+               break;\r
+       case WM_COMMAND:\r
+               if (LOWORD(wparam)==VOMP_FULL_SCREEN) {\r
+                       ToggleFullscreen();\r
+                       return 0;\r
+               }\r
+               if (LOWORD(wparam)==VOMP_TOPMOST) {\r
+                       ToggleTopmost();\r
+                       return 0;\r
+               }\r
+               if (((RemoteWin*)remote)->ReceiveButtonAP(LOWORD(wparam))){\r
+                       return 0; //yes we process that message\r
+               } else {\r
+                       return DefWindowProc(wind, msg, wparam, lparam);\r
+               }\r
+\r
+               break;\r
+       case WM_SETCURSOR:\r
+               if (((HANDLE)wparam)==win) {\r
+                       CursorUpdate();\r
+                       return 1;\r
+               } else {\r
+                       return DefWindowProc(wind, msg, wparam, lparam);\r
+               }\r
+               break;\r
+       case WM_SYSCOMMAND:\r
+               if (wparam==SC_MAXIMIZE) {\r
+                       ToggleFullscreen();\r
+                       return 0;\r
+               } else if (wparam==SC_SCREENSAVE || wparam==SC_MONITORPOWER) {\r
+                       return 0;\r
+               } else {\r
+                       return DefWindowProc(wind,msg,wparam, lparam);\r
+               }\r
+               break;\r
+       case WM_MOUSEMOVE: {\r
+               \r
+               lastmousemove=timeGetTime();\r
+               SetCursor(LoadCursor(NULL,IDC_ARROW));\r
+               SetTimer(wind,VOMP_CURSORUPDATE,4500,NULL);\r
+               POINT mpos={GET_X_LPARAM(lparam),GET_Y_LPARAM(lparam)};\r
+               ClientToScreen(wind,&mpos);\r
+               if (TranslateMousePosition(&mpos)) {\r
+                       Message *mousemes=new Message();\r
+                       mousemes->message=Message::MOUSE_MOVE;\r
+                       mousemes->from=NULL;\r
+                       mousemes->to=ViewMan::getInstance();\r
+                       mousemes->parameter=(mpos.x & 0xFFFF)<< 16| (mpos.y & 0xFFFF);\r
+                       mousemes->tag=0;\r
+                       //command->postMessageFromOuterSpace(mousemes);\r
+                       command->postMessageIfNotBusy(mousemes);\r
+               }\r
+               \r
+               return 0;\r
+               //return DefWindowProc(wind,msg,wparam, lparam);\r
+                                          }\r
+               break;\r
+       case WM_TIMER:\r
+               if (wparam==VOMP_CURSORUPDATE) {\r
+                       CursorUpdate();\r
+                       return 0;\r
+               }\r
+               return DefWindowProc(wind, msg, wparam, lparam);\r
+\r
+               break;\r
+       case WM_CONTEXTMENU:\r
+               if (!ContextMenu(wind,GET_X_LPARAM(lparam),GET_Y_LPARAM(lparam))) {\r
+                       return DefWindowProc(wind, msg, wparam, lparam);\r
+               } else {\r
+                       return 0;\r
+               }\r
+               break;\r
+       case WM_LBUTTONDOWN:{\r
+               POINT mpos={GET_X_LPARAM(lparam),GET_Y_LPARAM(lparam)};\r
+               ClientToScreen(wind,&mpos);\r
+               if (TranslateMousePosition(&mpos)) {\r
+                       Message *mousemes=new Message();\r
+                       mousemes->message=Message::MOUSE_LBDOWN;\r
+                       mousemes->from=NULL;\r
+                       mousemes->to=ViewMan::getInstance();\r
+                       mousemes->parameter=(mpos.x & 0xFFFF)<< 16| (mpos.y & 0xFFFF);\r
+                       mousemes->tag=0;\r
+                       command->postMessageFromOuterSpace(mousemes);\r
+               }\r
+                                               }break;\r
+    default:\r
+        return DefWindowProc(wind, msg, wparam, lparam);\r
+    }\r
+    return 0L;\r
+}\r
+\r
+\r
+bool InitApp(HINSTANCE hinst,int cmdshow) {\r
+       /* main window */\r
+       WNDCLASS wcs;\r
+       DWORD flags;\r
+       wcs.style = CS_HREDRAW | CS_VREDRAW;\r
+    wcs.lpfnWndProc = WindowProc;\r
+    wcs.cbClsExtra = 0;\r
+    wcs.cbWndExtra = sizeof(DWORD);\r
+    wcs.hInstance = hinst;\r
+    wcs.hIcon = NULL;\r
+    wcs.hCursor = NULL;\r
+    wcs.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);\r
+    wcs.lpszMenuName = NULL;\r
+    wcs.lpszClassName = "vomp";\r
+       acc=LoadAccelerators(hinst,MAKEINTRESOURCE(VOMPACCELERATOR));\r
+       if (!RegisterClass(&wcs))\r
+        return false;\r
+       flags =WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU \r
+                 |WS_MINIMIZEBOX | WS_SIZEBOX |WS_MAXIMIZEBOX;\r
+       RECT wnted={50,50,768+50,576+50};\r
+       AdjustWindowRect(&wnted,flags ,false);\r
+       win_main=CreateWindow("vomp","VOMP on Windows",flags, CW_USEDEFAULT,CW_USEDEFAULT,\r
+               wnted.right-wnted.left,wnted.bottom-wnted.top,NULL,NULL,hinst,NULL);\r
+       if (!win_main)\r
+        return FALSE;\r
+       ShowWindow(win_main,SW_SHOWNORMAL);\r
+    UpdateWindow(win_main);\r
+       /* in order to handle letterboxing we use a child window */\r
+       WNDCLASS child_wcs;\r
+       child_wcs.style = CS_HREDRAW | CS_VREDRAW;\r
+    child_wcs.lpfnWndProc = WindowProc;\r
+    child_wcs.cbClsExtra = 0;\r
+    child_wcs.cbWndExtra = sizeof(DWORD);\r
+    child_wcs.hInstance = hinst;\r
+    child_wcs.hIcon = NULL;\r
+    child_wcs.hCursor = NULL;\r
+    child_wcs.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);\r
+    child_wcs.lpszMenuName = NULL;\r
+    child_wcs.lpszClassName = "vomp_playback";\r
+       if (!RegisterClass(&child_wcs))\r
+        return false;\r
+\r
+       win=CreateWindow("vomp_playback","Vomp Playback Window",WS_VISIBLE | WS_CHILD |WS_CLIPCHILDREN,\r
+               0,0,768,576,win_main,NULL,hinst,NULL);\r
+       if (!win)\r
+               return FALSE;\r
+       ShowWindow(win,SW_SHOWNORMAL);\r
+       UpdateWindow(win);\r
+       if (remotefnc) {//at least windows XP\r
+               /* We want to support MCE Remote controls*/\r
+               RAWINPUTDEVICE remote_control_data[4];\r
+               ZeroMemory(remote_control_data,sizeof(remote_control_data));\r
+               remote_control_data[0].usUsagePage=0xFFBC; \r
+               remote_control_data[0].usUsage=0x88; \r
+               remote_control_data[0].dwFlags=0;\r
+               remote_control_data[1].usUsagePage=0x0C; \r
+               remote_control_data[1].usUsage=0x80; \r
+               remote_control_data[1].dwFlags=0;\r
+               remote_control_data[2].usUsagePage=0x0C; \r
+               remote_control_data[2].usUsage=0x01; \r
+               remote_control_data[2].dwFlags=0;\r
+               remote_control_data[3].usUsagePage=0x01; \r
+               remote_control_data[3].usUsage=0x80; \r
+               remote_control_data[3].dwFlags=0;\r
+               if (dynRegisterRawInputDevices(remote_control_data,4,sizeof(remote_control_data[0]))!=TRUE) {\r
+                       MessageBox(0,"Registering remote control failed!","Aborting!",0);\r
+                       return FALSE;\r
+               }\r
+       \r
+       }\r
+       return TRUE;\r
+}\r
+\r
+\r
+\r
+\r
+\r
+// -------------------------------------------------------------------------------------------------------------------\r
+\r
+void shutdown(int code)\r
+{\r
+  if (viewman)\r
+  {\r
+    viewman->shutdown();\r
+    delete viewman;\r
+    logger->log("Core", Log::NOTICE, "ViewMan module shut down");\r
+  }\r
+\r
+  if (command) // shut down command here in case views have posted messages\r
+  {\r
+    command->shutdown();\r
+    delete command;\r
+    logger->log("Core", Log::NOTICE, "Command module shut down");\r
+  }\r
+\r
+  if (vdr)\r
+  {\r
+    vdr->shutdown();\r
+    delete vdr;\r
+    logger->log("Core", Log::NOTICE, "VDR module shut down");\r
+  }\r
+\r
+  if (osd)\r
+  {\r
+    osd->shutdown();\r
+    delete osd;\r
+    logger->log("Core", Log::NOTICE, "OSD module shut down");\r
+  }\r
+\r
+  if (audio)\r
+  {\r
+    audio->shutdown();\r
+    delete audio;\r
+    logger->log("Core", Log::NOTICE, "Audio module shut down");\r
+  }\r
+\r
+  if (video)\r
+  {\r
+    video->shutdown();\r
+    delete video;\r
+    logger->log("Core", Log::NOTICE, "Video module shut down");\r
+  }\r
+\r
+  if (timers)\r
+  {\r
+    timers->shutdown();\r
+    delete timers;\r
+    logger->log("Core", Log::NOTICE, "Timers module shut down");\r
+  }\r
+\r
+  if (mtd)\r
+  {\r
+    mtd->shutdown();\r
+    delete mtd;\r
+    logger->log("Core", Log::NOTICE, "MTD module shut down");\r
+  }\r
+\r
+  if (led)\r
+  {\r
+    led->shutdown();\r
+    delete led;\r
+    logger->log("Core", Log::NOTICE, "LED module shut down");\r
+  }\r
+\r
+  if (remote)\r
+  {\r
+    remote->shutdown();\r
+    delete remote;\r
+    logger->log("Core", Log::NOTICE, "Remote module shut down");\r
+  }\r
+\r
+  if (logger)\r
+  {\r
+    logger->log("Core", Log::NOTICE, "Log module shutting down... bye!\n\n");\r
+    logger->shutdown();\r
+    delete logger;\r
+  }\r
+  ExitProcess(0);\r
+\r
+}\r
+\r
+// -------------------------------------------------------------------------------------------------------------------\r
+\r
+ULLONG ntohll(ULLONG a)\r
+{\r
+  return htonll(a);\r
+}\r
+\r
+ULLONG htonll(ULLONG a)\r
+{\r
+       return (((ULLONG)htonl((ULONG)((a<<32)>> 32))<<32) \r
+               |(ULONG)htonl(((ULONG) (a >> 32))));\r
+}\r
+#endif\r