/[rdesktop]/sourceforge.net/trunk/rdesktop/uiports/qtewin.cpp
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/rdesktop/uiports/qtewin.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 780 by jsorg71, Mon Oct 4 03:24:09 2004 UTC revision 796 by jsorg71, Fri Nov 5 03:13:33 2004 UTC
# Line 25  Line 25 
25  #else  #else
26  #include <qapplication.h>  #include <qapplication.h>
27  #endif  #endif
28    #include <qcursor.h>
29  #include <qmainwindow.h>  #include <qmainwindow.h>
30  #include <qwidget.h>  #include <qwidget.h>
31  #include <qpainter.h>  #include <qpainter.h>
# Line 47  Line 48 
48  #include "../rdesktop.h"  #include "../rdesktop.h"
49  #include "qtewin.h"  #include "qtewin.h"
50    
51    #define QT_OPTI
52    
53  /* types */  /* types */
54  struct QColorMap  struct QColorMap
55  {  {
# Line 84  int g_server_bpp = 8; Line 87  int g_server_bpp = 8;
87  char g_hostname[16] = "";  char g_hostname[16] = "";
88  char g_username[100] = "";  char g_username[100] = "";
89    
90    static int g_client_width = 640;
91    static int g_client_height = 480;
92  static uint32 g_flags = RDP_LOGON_NORMAL;  static uint32 g_flags = RDP_LOGON_NORMAL;
93  static char g_server[64] = "";  static char g_server[64] = "";
94  static char g_domain[16] = "";  static char g_domain[16] = "";
# Line 119  static int g_clipcy = 0; Line 124  static int g_clipcy = 0;
124  #define SETPIXEL16(d, x, y, w, v) *(((uint16*)d) + ((y) * (w) + (x))) = v  #define SETPIXEL16(d, x, y, w, v) *(((uint16*)d) + ((y) * (w) + (x))) = v
125  #define SETPIXEL32(d, x, y, w, v) *(((uint32*)d) + ((y) * (w) + (x))) = v  #define SETPIXEL32(d, x, y, w, v) *(((uint32*)d) + ((y) * (w) + (x))) = v
126    
127  //*****************************************************************************  /******************************************************************************/
128  void CleanString(QString * Item)  void CleanString(QString * Item)
129  {  {
130    int i;    int i;
# Line 133  void CleanString(QString * Item) Line 138  void CleanString(QString * Item)
138    }    }
139  }  }
140    
141  //*****************************************************************************  /******************************************************************************/
142  QMyDialog::QMyDialog(QWidget * parent) : QDialog(parent, "Settings", true)  QMyDialog::QMyDialog(QWidget * parent) : QDialog(parent, "Settings", true)
143  {  {
144    int i, j;    int i, j;
# Line 247  QMyDialog::QMyDialog(QWidget * parent) : Line 252  QMyDialog::QMyDialog(QWidget * parent) :
252    if (home != NULL)    if (home != NULL)
253    {    {
254      sprintf(Text, "%s/rdesktop.ini", home);      sprintf(Text, "%s/rdesktop.ini", home);
255      QFile* File = new QFile(Text);      QFile * File = new QFile(Text);
256      if (File->open(IO_ReadOnly))      if (File->open(IO_ReadOnly))
257      {      {
258        i = -1;        i = -1;
# Line 284  QMyDialog::QMyDialog(QWidget * parent) : Line 289  QMyDialog::QMyDialog(QWidget * parent) :
289    }    }
290  }  }
291    
292  //*****************************************************************************  /******************************************************************************/
293  QMyDialog::~QMyDialog()  QMyDialog::~QMyDialog()
294  {  {
295    QMyConnectionItem* Item;    QMyConnectionItem * Item;
296    int i;    int i;
297    
298    for (i = 0; i < 10; i++)    for (i = 0; i < 10; i++)
# Line 297  QMyDialog::~QMyDialog() Line 302  QMyDialog::~QMyDialog()
302    }    }
303  }  }
304    
305  //*****************************************************************************  /******************************************************************************/
306  void QMyDialog::ComboChanged(int index)  void QMyDialog::ComboChanged(int index)
307  {  {
308    if (index == 0)    if (index == 0)
# Line 317  void QMyDialog::ComboChanged(int index) Line 322  void QMyDialog::ComboChanged(int index)
322    }    }
323  }  }
324    
325  //*****************************************************************************  /******************************************************************************/
326  void QMyDialog::OKClicked()  void QMyDialog::OKClicked()
327  {  {
328    ServerName = ServerNameEdit->text();    ServerName = ServerNameEdit->text();
# Line 329  void QMyDialog::OKClicked() Line 334  void QMyDialog::OKClicked()
334    done(1);    done(1);
335  }  }
336    
337  //*****************************************************************************  /******************************************************************************/
338  void QMyDialog::CancelClicked()  void QMyDialog::CancelClicked()
339  {  {
340    done(0);    done(0);
341  }  }
342    
343  //*****************************************************************************  /******************************************************************************/
344  void QMyDialog::AddClicked()  void QMyDialog::AddClicked()
345  {  {
346    int i;    int i;
# Line 355  void QMyDialog::AddClicked() Line 360  void QMyDialog::AddClicked()
360    }    }
361  }  }
362    
363  //*****************************************************************************  /******************************************************************************/
364  void QMyDialog::EditClicked()  void QMyDialog::EditClicked()
365  {  {
366    int i;    int i;
# Line 375  void QMyDialog::EditClicked() Line 380  void QMyDialog::EditClicked()
380    }    }
381  }  }
382    
383  //*****************************************************************************  /******************************************************************************/
384  void WriteString(QFile* File, QString* Line)  void WriteString(QFile* File, QString* Line)
385  {  {
386    File->writeBlock((const char*)(*Line), Line->length());    File->writeBlock((const char*)(*Line), Line->length());
387  }  }
388    
389  //*****************************************************************************  /******************************************************************************/
390  void QMyDialog::SaveClicked()  void QMyDialog::SaveClicked()
391  {  {
392    int i, j;    int i, j;
# Line 439  void QMyDialog::SaveClicked() Line 444  void QMyDialog::SaveClicked()
444    }    }
445  }  }
446    
447  //*****************************************************************************  /******************************************************************************/
448  void QMyDialog::RemoveClicked()  void QMyDialog::RemoveClicked()
449  {  {
450    int i, j, c;    int i, j, c;
# Line 465  void QMyDialog::RemoveClicked() Line 470  void QMyDialog::RemoveClicked()
470    }    }
471  }  }
472    
473  //*****************************************************************************  /******************************************************************************/
474  void QMyDialog::ListBoxChanged()  void QMyDialog::ListBoxChanged()
475  {  {
476    int i;    int i;
# Line 487  void QMyDialog::ListBoxChanged() Line 492  void QMyDialog::ListBoxChanged()
492    }    }
493  }  }
494    
495  //*****************************************************************************  /******************************************************************************/
496  void QMyDialog::ListBoxSelected(int /*index*/)  void QMyDialog::ListBoxSelected(int /*index*/)
497  {  {
498  }  }
499    
500  //*****************************************************************************  /******************************************************************************/
501  void GetScanCode(QKeyEvent * e, int * ScanCode, int * code)  void GetScanCode(QKeyEvent * e, int * ScanCode, int * code)
502  {  {
503    int key;    int key;
# Line 660  void GetScanCode(QKeyEvent * e, int * Sc Line 665  void GetScanCode(QKeyEvent * e, int * Sc
665    
666  }  }
667    
668  //*****************************************************************************  /******************************************************************************/
669  QMyScrollView::QMyScrollView() : QScrollView()  QMyScrollView::QMyScrollView() : QScrollView()
670  {  {
671  }  }
672    
673  //*****************************************************************************  /******************************************************************************/
674  QMyScrollView::~QMyScrollView()  QMyScrollView::~QMyScrollView()
675  {  {
676  }  }
677    
678  //*****************************************************************************  /******************************************************************************/
679  void QMyScrollView::keyPressEvent(QKeyEvent* e)  void QMyScrollView::keyPressEvent(QKeyEvent* e)
680  {  {
681    int ScanCode, code;    int ScanCode, code;
# Line 688  void QMyScrollView::keyPressEvent(QKeyEv Line 693  void QMyScrollView::keyPressEvent(QKeyEv
693    }    }
694  }  }
695    
696  //*****************************************************************************  /******************************************************************************/
697  void QMyScrollView::keyReleaseEvent(QKeyEvent* e)  void QMyScrollView::keyReleaseEvent(QKeyEvent* e)
698  {  {
699    int ScanCode, code;    int ScanCode, code;
# Line 706  void QMyScrollView::keyReleaseEvent(QKey Line 711  void QMyScrollView::keyReleaseEvent(QKey
711    }    }
712  }  }
713    
714  //*****************************************************************************  /******************************************************************************/
715  void QMyScrollView::showEvent(QShowEvent* e)  void QMyScrollView::showEvent(QShowEvent* e)
716  {  {
717    QScrollView::showEvent(e);    QScrollView::showEvent(e);
718  }  }
719    
720  //*****************************************************************************  /******************************************************************************/
721  void QMyScrollView::show()  void QMyScrollView::show()
722  {  {
723    QScrollView::show();    QScrollView::show();
724  }  }
725    
726  //*****************************************************************************  /******************************************************************************/
727  void QMyScrollView::polish()  void QMyScrollView::polish()
728  {  {
729    QScrollView::polish();    QScrollView::polish();
730  }  }
731    
732  //*****************************************************************************  /******************************************************************************/
733  void QMyScrollView::timerEvent(QTimerEvent * e)  void QMyScrollView::timerEvent(QTimerEvent * e)
734  {  {
735    QScrollView::timerEvent(e);    QScrollView::timerEvent(e);
# Line 739  void QMyScrollView::timerEvent(QTimerEve Line 744  void QMyScrollView::timerEvent(QTimerEve
744    {    {
745      g_width = d->Width;      g_width = d->Width;
746      g_height = d->Height;      g_height = d->Height;
747        g_client_width = g_width;
748        g_client_height = g_height;
749      g_fullscreen = d->FullScreen;      g_fullscreen = d->FullScreen;
750      sprintf(g_server, "%s", (const char*)d->ServerIP);      sprintf(g_server, "%s", (const char*)d->ServerIP);
751      sprintf(g_username, "%s", (const char*)d->UserName);      sprintf(g_username, "%s", (const char*)d->UserName);
# Line 759  void QMyScrollView::timerEvent(QTimerEve Line 766  void QMyScrollView::timerEvent(QTimerEve
766      memset(g_CM, 0, sizeof(struct QColorMap));      memset(g_CM, 0, sizeof(struct QColorMap));
767      g_CM->NumColors = 256;      g_CM->NumColors = 256;
768      g_MW = new QMyMainWindow();      g_MW = new QMyMainWindow();
769      g_MW->resize(g_width, g_height);      g_MW->resize(g_client_width, g_client_height);
770      g_MW->show();      g_MW->show();
771      g_SV->addChild(g_MW);      g_SV->addChild(g_MW);
772      g_MW->setMouseTracking(true);      g_MW->setMouseTracking(true);
# Line 773  void QMyScrollView::timerEvent(QTimerEve Line 780  void QMyScrollView::timerEvent(QTimerEve
780        Desktop = g_App->desktop();        Desktop = g_App->desktop();
781        dw = Desktop->width();        dw = Desktop->width();
782        dh = Desktop->height();        dh = Desktop->height();
783        if (dw == g_width && dh == g_height)        if (dw == g_client_width && dh == g_client_height)
784          g_MW->resize(g_width - 4, g_height - 4);          g_MW->resize(g_client_width - 4, g_client_height - 4);
785        g_SV->showFullScreen();        g_SV->showFullScreen();
786      }      }
787      delete d;      delete d;
# Line 786  void QMyScrollView::timerEvent(QTimerEve Line 793  void QMyScrollView::timerEvent(QTimerEve
793    }    }
794  }  }
795    
796  //*****************************************************************************  /******************************************************************************/
797  QMyMainWindow::QMyMainWindow() : QWidget(g_SV->viewport())  QMyMainWindow::QMyMainWindow() : QWidget(g_SV->viewport())
798  {  {
799    PopupMenu = new QPopupMenu(this);    PopupMenu = new QPopupMenu(this);
# Line 797  QMyMainWindow::QMyMainWindow() : QWidget Line 804  QMyMainWindow::QMyMainWindow() : QWidget
804    connect(PopupMenu, SIGNAL(activated(int)), this, SLOT(MemuClicked(int)));    connect(PopupMenu, SIGNAL(activated(int)), this, SLOT(MemuClicked(int)));
805  }  }
806    
807  //*****************************************************************************  /******************************************************************************/
808  QMyMainWindow::~QMyMainWindow()  QMyMainWindow::~QMyMainWindow()
809  {  {
810    delete PopupMenu;    delete PopupMenu;
811  }  }
812    
813  //*****************************************************************************  /******************************************************************************/
814    int rd(double in)
815    {
816      return (int)(in + 0.50);
817    }
818    
819    /******************************************************************************/
820    int c2sx(int cx)
821    {
822      double sx;
823    
824      sx = (double)g_client_width / (double)g_width;
825      return rd(cx / sx);
826    }
827    
828    /******************************************************************************/
829    int c2sy(int cy)
830    {
831      double sy;
832    
833      sy = (double)g_client_height / (double)g_height;
834      return rd(cy / sy);
835    }
836    
837    /******************************************************************************/
838  void QMyMainWindow::timerEvent(QTimerEvent * e)  void QMyMainWindow::timerEvent(QTimerEvent * e)
839  {  {
840    QWidget::timerEvent(e);    QWidget::timerEvent(e);
841    if (e->timerId() == timer_id)    if (e->timerId() == timer_id)
842    {    {
843      // send mouse up      // send mouse up
844      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1, mx, my);      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1,
845                       rd(c2sx(mx)), rd(c2sy(my)));
846      // if in fullscreen, take it out or the menu won't work      // if in fullscreen, take it out or the menu won't work
847      if (g_fullscreen)      if (g_fullscreen)
848      {      {
# Line 824  void QMyMainWindow::timerEvent(QTimerEve Line 856  void QMyMainWindow::timerEvent(QTimerEve
856    killTimer(timer_id);    killTimer(timer_id);
857  }  }
858    
859  //*****************************************************************************  /******************************************************************************/
860  void QMyMainWindow::MemuClicked(int MenuID)  void QMyMainWindow::MemuClicked(int MenuID)
861  {  {
862    QWidget * Desktop;    QWidget * Desktop;
# Line 833  void QMyMainWindow::MemuClicked(int Menu Line 865  void QMyMainWindow::MemuClicked(int Menu
865    
866    if (MenuID == 1) // right click    if (MenuID == 1) // right click
867    {    {
868      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON2, mx, my);      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON2,
869      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON2, mx, my);                     rd(c2sx(mx)), rd(c2sy(my)));
870        rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON2,
871                       rd(c2sx(mx)), rd(c2sy(my)));
872    }    }
873    else if (MenuID == 2) // toggle full screen    else if (MenuID == 2) // toggle full screen
874    {    {
# Line 844  void QMyMainWindow::MemuClicked(int Menu Line 878  void QMyMainWindow::MemuClicked(int Menu
878        Desktop = g_App->desktop();        Desktop = g_App->desktop();
879        dw = Desktop->width();        dw = Desktop->width();
880        dh = Desktop->height();        dh = Desktop->height();
881        if (dw == g_width && dh == g_height)        if (dw == g_client_width && dh == g_client_height)
882          g_MW->resize(g_width - 4, g_height - 4);          g_MW->resize(g_client_width - 4, g_client_height - 4);
883        g_SV->showFullScreen();        g_SV->showFullScreen();
884      }      }
885      else      else
886      {      {
887        g_SV->showNormal();        g_SV->showNormal();
888        g_SV->showMaximized();        g_SV->showMaximized();
889        g_MW->resize(g_width, g_height);        g_MW->resize(g_client_width, g_client_height);
890      }      }
891    }    }
892    else if (MenuID == 3) // reset keyboard    else if (MenuID == 3) // reset keyboard
# Line 863  void QMyMainWindow::MemuClicked(int Menu Line 897  void QMyMainWindow::MemuClicked(int Menu
897    }    }
898    else if (MenuID == 4) // double click    else if (MenuID == 4) // double click
899    {    {
900      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON1, mx, my);      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON1,
901      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1, mx, my);                     rd(c2sx(mx)), rd(c2sy(my)));
902      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON1, mx, my);      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1,
903      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1, mx, my);                     rd(c2sx(mx)), rd(c2sy(my)));
904        rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON1,
905                       rd(c2sx(mx)), rd(c2sy(my)));
906        rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1,
907                       rd(c2sx(mx)), rd(c2sy(my)));
908    }    }
909  }  }
910    
911  //*****************************************************************************  /******************************************************************************/
912  void QMyMainWindow::mouseMoveEvent(QMouseEvent* e)  void QMyMainWindow::mouseMoveEvent(QMouseEvent* e)
913  {  {
914    int x;    int x, y;
   int y;  
915    
916    x = e->x();    x = e->x();
917    y = e->y();    y = e->y();
   
918    if (timer_id)    if (timer_id)
919    {    {
920      x = x - mx;      x = x - mx;
# Line 889  void QMyMainWindow::mouseMoveEvent(QMous Line 925  void QMyMainWindow::mouseMoveEvent(QMous
925        timer_id = 0;        timer_id = 0;
926      }      }
927    }    }
928    rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_MOVE, e->x(), e->y());    rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_MOVE, c2sx(e->x()),
929                     c2sy(e->y()));
930  }  }
931    
932  //*****************************************************************************  /******************************************************************************/
933  void QMyMainWindow::mousePressEvent(QMouseEvent* e)  void QMyMainWindow::mousePressEvent(QMouseEvent* e)
934  {  {
935    timer_id = startTimer(1000);    timer_id = startTimer(1000);
936    mx = e->x();    mx = e->x();
937    my = e->y();    my = e->y();
938    if (e->button() == LeftButton)    if (e->button() == LeftButton)
939      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON1, e->x(), e->y());      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON1,
940                       c2sx(e->x()), c2sy(e->y()));
941    else if (e->button() == RightButton)    else if (e->button() == RightButton)
942      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON2, e->x(), e->y());      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON2,
943                       c2sx(e->x()), c2sy(e->y()));
944    else if (e->button() == MidButton)    else if (e->button() == MidButton)
945      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON3, e->x(), e->y());      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON3,
946                       c2sx(e->x()), c2sy(e->y()));
947  }  }
948    
949  //*****************************************************************************  /******************************************************************************/
950  void QMyMainWindow::mouseReleaseEvent(QMouseEvent* e)  void QMyMainWindow::mouseReleaseEvent(QMouseEvent* e)
951  {  {
952    killTimer(timer_id);    killTimer(timer_id);
953    timer_id = 0;    timer_id = 0;
954    if (e->button() == LeftButton)    if (e->button() == LeftButton)
955      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1, e->x(), e->y());      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1, c2sx(e->x()),
956                       c2sy(e->y()));
957    else if (e->button() == RightButton)    else if (e->button() == RightButton)
958      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON2, e->x(), e->y());      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON2, c2sx(e->x()),
959                       c2sy(e->y()));
960    else if (e->button() == MidButton)    else if (e->button() == MidButton)
961      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON3, e->x(), e->y());      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON3, c2sx(e->x()),
962                       c2sy(e->y()));
963  }  }
964    
965  //*****************************************************************************  /******************************************************************************/
966  void QMyMainWindow::wheelEvent(QWheelEvent* e)  void QMyMainWindow::wheelEvent(QWheelEvent* e)
967  {  {
968    if (e->delta() > 0)    if (e->delta() > 0)
969      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON4, e->x(), e->y());      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON4, c2sx(e->x()),
970                       c2sy(e->y()));
971    else if (e->delta() < 0)    else if (e->delta() < 0)
972      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON5, e->x(), e->y());      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON5, c2sx(e->x()),
973                       c2sy(e->y()));
974  }  }
975    
976  #define NOT(x) (~x)  #define NOT(x) (~x)
977    
978  //*****************************************************************************  /******************************************************************************/
979  int rop(int rop, int src, int dst)  int rop(int rop, int src, int dst)
980  {  {
981    switch (rop)    switch (rop)
# Line 961  int get_pixel(int x, int y) Line 1006  int get_pixel(int x, int y)
1006    if (x >= 0 && x < g_width && y >= 0 && y < g_height)    if (x >= 0 && x < g_width && y >= 0 && y < g_height)
1007    {    {
1008      if (g_server_bpp == 8)      if (g_server_bpp == 8)
1009        return g_BS[y * g_width + x];        return GETPIXEL8(g_BS, x, y, g_width);
1010      else if (g_server_bpp == 16)      else if (g_server_bpp == 16)
1011        return *(((uint16*)g_BS) + (y * g_width + x));        return GETPIXEL16(g_BS, x, y, g_width);
1012        else if (g_server_bpp == 24)
1013          return GETPIXEL32(g_BS, x, y, g_width);
1014      else      else
1015        return 0;        return 0;
1016    }    }
# Line 971  int get_pixel(int x, int y) Line 1018  int get_pixel(int x, int y)
1018      return 0;      return 0;
1019  }  }
1020    
1021  //*****************************************************************************  /******************************************************************************/
1022  void set_pixel(int x, int y, int pixel, int op = 0xc)  void set_pixel(int x, int y, int pixel, int op = 0xc)
1023  {  {
1024    uint32 p;    int p;
1025    
1026    if (x >= g_clipx && x < (g_clipx + g_clipcx) &&    if (x >= g_clipx && x < (g_clipx + g_clipcx) &&
1027        y >= g_clipy && y < (g_clipy + g_clipcy))        y >= g_clipy && y < (g_clipy + g_clipcy))
# Line 991  void set_pixel(int x, int y, int pixel, Line 1038  void set_pixel(int x, int y, int pixel,
1038          {          {
1039            SETPIXEL16(g_BS, x, y, g_width, pixel);            SETPIXEL16(g_BS, x, y, g_width, pixel);
1040          }          }
1041            else if (g_server_bpp == 24)
1042            {
1043              SETPIXEL32(g_BS, x, y, g_width, pixel);
1044            }
1045        }        }
1046        else        else
1047        {        {
# Line 1006  void set_pixel(int x, int y, int pixel, Line 1057  void set_pixel(int x, int y, int pixel,
1057            p = rop(op, pixel, p);            p = rop(op, pixel, p);
1058            SETPIXEL16(g_BS, x, y, g_width, p);            SETPIXEL16(g_BS, x, y, g_width, p);
1059          }          }
1060            else if (g_server_bpp == 24)
1061            {
1062              p = GETPIXEL32(g_BS, x, y, g_width);
1063              p = rop(op, pixel, p);
1064              SETPIXEL32(g_BS, x, y, g_width, p);
1065            }
1066        }        }
1067      }      }
1068    }    }
1069  }  }
1070    
1071  //******************************************************************************  /******************************************************************************/
1072  // adjust coordinates for cliping rect  // adjust coordinates for cliping rect
1073  bool WarpCoords(int * x, int * y, int * cx, int * cy, int * srcx, int * srcy)  bool WarpCoords(int * x, int * y, int * cx, int * cy, int * srcx, int * srcy)
1074  {  {
# Line 1035  bool WarpCoords(int * x, int * y, int * Line 1092  bool WarpCoords(int * x, int * y, int *
1092    return true;    return true;
1093  }  }
1094    
1095  //*****************************************************************************  /******************************************************************************/
 uint32 color16to32(uint32 colour)  
 {  
   uint32 r, g, b;  
   r = ((colour >> 8) & 0xf8) | ((colour >> 13) & 0x7);  
   g = ((colour >> 3) & 0xfc) | ((colour >> 9) & 0x3);  
   b = ((colour << 3) & 0xf8) | ((colour >> 2) & 0x7);  
   return ((r << 16) | (g << 8) | b);  
 }  
   
 //*****************************************************************************  
1096  void QMyMainWindow::paintEvent(QPaintEvent * pe)  void QMyMainWindow::paintEvent(QPaintEvent * pe)
1097  {  {
1098    QImage * Image;    QImage * Image;
1099    QPainter * Painter;    QPainter * Painter;
1100    QRect Rect;    QRect Rect;
1101    int i, j, w, h, l, t;    int i, j, w, h, l, t, pixel, r, g, b;
1102    uint8 * data;    uint8 * data;
1103      double sx, sy;
1104    
1105    Image = 0;    Image = 0;
1106    data = 0;    data = 0;
# Line 1060  void QMyMainWindow::paintEvent(QPaintEve Line 1108  void QMyMainWindow::paintEvent(QPaintEve
1108      setWFlags(WRepaintNoErase);      setWFlags(WRepaintNoErase);
1109    if (g_CM != NULL || g_server_bpp > 8)    if (g_CM != NULL || g_server_bpp > 8)
1110    {    {
1111        sx = (double)g_client_width / (double)g_width;
1112        sy = (double)g_client_height / (double)g_height;
1113      Rect = pe->rect();      Rect = pe->rect();
1114      l = Rect.left();      l = rd(Rect.left() / sx);
1115      t = Rect.top();      t = rd(Rect.top() / sy);
1116      w = Rect.width();      w = rd(Rect.width() / sx);
1117      h = Rect.height();      h = rd(Rect.height() / sy);
1118      if (w > 0 && h > 0)      if (w > 0 && h > 0)
1119      {      {
1120        if (g_server_bpp == 8 && g_CM->NumColors > 0)        if (g_server_bpp == 8 && g_CM->NumColors > 0)
# Line 1073  void QMyMainWindow::paintEvent(QPaintEve Line 1123  void QMyMainWindow::paintEvent(QPaintEve
1123          data = (uint8*)xmalloc(w * h);          data = (uint8*)xmalloc(w * h);
1124          for (i = 0; i < h; i++)          for (i = 0; i < h; i++)
1125            for (j = 0; j < w; j++)            for (j = 0; j < w; j++)
1126              data[i * w + j] = get_pixel(l + j, t + i);              data[i * w + j] = GETPIXEL8(g_BS, l + j, t + i, g_width);
1127          Image = new QImage(data, w, h, 8,(QRgb*)g_CM->RGBColors,          Image = new QImage(data, w, h, 8,(QRgb*)g_CM->RGBColors,
1128                             g_CM->NumColors, QImage::IgnoreEndian);                             g_CM->NumColors, QImage::IgnoreEndian);
1129        }        }
# Line 1083  void QMyMainWindow::paintEvent(QPaintEve Line 1133  void QMyMainWindow::paintEvent(QPaintEve
1133          data = (uint8*)xmalloc(w * h * 4);          data = (uint8*)xmalloc(w * h * 4);
1134          for (i = 0; i < h; i++)          for (i = 0; i < h; i++)
1135            for (j = 0; j < w; j++)            for (j = 0; j < w; j++)
1136              *(((uint32*)data) + (i * w + j)) = color16to32(get_pixel(l + j, t + i));            {
1137                pixel = GETPIXEL16(g_BS, l + j, t + i, g_width);
1138                r = ((pixel >> 8) & 0xf8) | ((pixel >> 13) & 0x7);
1139                g = ((pixel >> 3) & 0xfc) | ((pixel >> 9) & 0x3);
1140                b = ((pixel << 3) & 0xf8) | ((pixel >> 2) & 0x7);
1141                pixel = ((r << 16) | (g << 8) | b);
1142                SETPIXEL32(data, j, i, w, pixel);
1143              }
1144            Image = new QImage(data, w, h, 32, NULL,
1145                               0, QImage::IgnoreEndian);
1146          }
1147          else if (g_server_bpp == 24)
1148          {
1149            w = (w + 3) & ~3;
1150            data = (uint8*)xmalloc(w * h * 4);
1151            for (i = 0; i < h; i++)
1152              for (j = 0; j < w; j++)
1153              {
1154                pixel = GETPIXEL32(g_BS, l + j, t + i, g_width);
1155                r = (pixel >> 0) & 0xff;
1156                g = (pixel >> 8) & 0xff;
1157                b = (pixel >> 16) & 0xff;
1158                pixel = ((r << 16) | (g << 8) | b);
1159                SETPIXEL32(data, j, i, w, pixel);
1160              }
1161          Image = new QImage(data, w, h, 32, NULL,          Image = new QImage(data, w, h, 32, NULL,
1162                             0, QImage::IgnoreEndian);                             0, QImage::IgnoreEndian);
1163        }        }
1164        if (Image != 0)        if (Image != 0)
1165        {        {
1166          Painter = new QPainter(this);          Painter = new QPainter(this);
1167            Painter->scale(sx, sy);
1168          Painter->drawImage(l, t, *Image, 0, 0, w, h);          Painter->drawImage(l, t, *Image, 0, 0, w, h);
1169          delete Painter;          delete Painter;
1170          delete Image;          delete Image;
# Line 1099  void QMyMainWindow::paintEvent(QPaintEve Line 1174  void QMyMainWindow::paintEvent(QPaintEve
1174    }    }
1175  }  }
1176    
1177  //*****************************************************************************  /******************************************************************************/
1178  void QMyMainWindow::closeEvent(QCloseEvent * e)  void QMyMainWindow::closeEvent(QCloseEvent * e)
1179  {  {
1180    e->accept();    e->accept();
1181  }  }
1182    
1183  //*****************************************************************************  /******************************************************************************/
1184  void QMyMainWindow::dataReceived()  void QMyMainWindow::dataReceived()
1185  {  {
1186    if (!rdp_loop(&g_deactivated, &g_ext_disc_reason))    if (!rdp_loop(&g_deactivated, &g_ext_disc_reason))
# Line 1129  void QMyMainWindow::dataReceived() Line 1204  void QMyMainWindow::dataReceived()
1204  #endif  #endif
1205  }  }
1206    
1207  //*****************************************************************************  /******************************************************************************/
1208  void QMyMainWindow::soundSend()  void QMyMainWindow::soundSend()
1209  {  {
1210    g_SoundNotifier->setEnabled(false);    g_SoundNotifier->setEnabled(false);
# Line 1140  void QMyMainWindow::soundSend() Line 1215  void QMyMainWindow::soundSend()
1215  #endif  #endif
1216  }  }
1217    
1218  //*****************************************************************************  /******************************************************************************/
1219  void redraw(int x, int y, int cx, int cy)  void redraw(int x, int y, int cx, int cy)
1220  {  {
1221      double sx, sy;
1222    
1223    if (WarpCoords(&x, &y, &cx, &cy, NULL, NULL))    if (WarpCoords(&x, &y, &cx, &cy, NULL, NULL))
1224    {    {
1225        sx = (double)g_client_width / (double)g_width;
1226        sy = (double)g_client_height / (double)g_height;
1227        x = rd(x * sx);
1228        y = rd(y * sy);
1229        cx = rd(cx * sx);
1230        cy = rd(cy * sy);
1231      g_MW->update(x, y, cx, cy);      g_MW->update(x, y, cx, cy);
1232    }    }
1233  }  }
1234    
1235  //*****************************************************************************  /******************************************************************************/
1236  /* Returns 0 after user quit, 1 otherwise */  /* Returns 0 after user quit, 1 otherwise */
1237  int ui_select(int rdp_socket)  int ui_select(int rdp_socket)
1238  {  {
# Line 1158  int ui_select(int rdp_socket) Line 1241  int ui_select(int rdp_socket)
1241    return 1;    return 1;
1242  }  }
1243    
1244  //*****************************************************************************  /******************************************************************************/
1245  void ui_move_pointer(int /*x*/, int /*y*/)  void ui_move_pointer(int /*x*/, int /*y*/)
1246  {  {
1247  }  }
1248    
1249  /*****************************************************************************/  /******************************************************************************/
1250  void ui_set_null_cursor(void)  void ui_set_null_cursor(void)
1251  {  {
1252  }  }
1253    
1254  //*****************************************************************************  /******************************************************************************/
1255  HBITMAP ui_create_bitmap(int width, int height, uint8 * data)  HBITMAP ui_create_bitmap(int width, int height, uint8 * data)
1256  {  {
1257    struct bitmap * the_bitmap;    struct bitmap * the_bitmap;
1258    uint8 * bitmap_data;    uint8 * bitmap_data;
1259    int i, j;    int i, j;
1260      int r, g, b, pixel;
1261    
1262    bitmap_data = (uint8*)xmalloc(width * height * BPP);    bitmap_data = (uint8*)xmalloc(width * height * 4);
1263    the_bitmap = (struct bitmap*)xmalloc(sizeof(struct bitmap));    the_bitmap = (struct bitmap*)xmalloc(sizeof(struct bitmap));
1264    the_bitmap->w = width;    the_bitmap->w = width;
1265    the_bitmap->h = height;    the_bitmap->h = height;
# Line 1190  HBITMAP ui_create_bitmap(int width, int Line 1274  HBITMAP ui_create_bitmap(int width, int
1274    {    {
1275      for (i = 0; i < height; i++)      for (i = 0; i < height; i++)
1276        for (j = 0; j < width; j++)        for (j = 0; j < width; j++)
1277          *(((uint16*)bitmap_data) + (i * width + j)) = *(((uint16*)data) + (i * width + j));          *(((uint16*)bitmap_data) + (i * width + j)) =
1278                         *(((uint16*)data) + (i * width + j));
1279      }
1280      else if (g_server_bpp == 24)
1281      {
1282        for (i = 0; i < height; i++)
1283          for (j = 0; j < width; j++)
1284          {
1285            r = data[(i * width + j) * 3 + 0];
1286            g = data[(i * width + j) * 3 + 1];
1287            b = data[(i * width + j) * 3 + 2];
1288            pixel = (r << 16) | (g << 8) | b;
1289            SETPIXEL32(bitmap_data, j, i, width, pixel);
1290          }
1291    }    }
1292    return the_bitmap;    return the_bitmap;
1293  }  }
1294    
1295  //*****************************************************************************  /******************************************************************************/
1296  void ui_paint_bitmap(int x, int y, int cx, int cy, int width,  void ui_paint_bitmap(int x, int y, int cx, int cy, int width,
1297                       int height, uint8 * data)                       int height, uint8 * data)
1298  {  {
1299    int i, j;    int i, j;
1300      int r, g, b, pixel;
1301    
1302    if (g_server_bpp == 8)    if (g_server_bpp == 8)
1303    {    {
# Line 1217  void ui_paint_bitmap(int x, int y, int c Line 1315  void ui_paint_bitmap(int x, int y, int c
1315            if (j < width)            if (j < width)
1316              set_pixel(x + j, y + i, *(((uint16*)data) + (i * width + j)));              set_pixel(x + j, y + i, *(((uint16*)data) + (i * width + j)));
1317    }    }
1318      else if (g_server_bpp == 24)
1319      {
1320        for (i = 0; i < cy; i++)
1321          for (j = 0; j < cx; j++)
1322            if (i < height)
1323              if (j < width)
1324              {
1325                r = data[(i * width + j) * 3 + 0];
1326                g = data[(i * width + j) * 3 + 1];
1327                b = data[(i * width + j) * 3 + 2];
1328                pixel = (r << 16) | (g << 8) | b;
1329                set_pixel(x + j, y + i, pixel);
1330              }
1331      }
1332    redraw(x, y, cx, cy);    redraw(x, y, cx, cy);
1333  }  }
1334    
1335  //*****************************************************************************  /******************************************************************************/
1336  void ui_destroy_bitmap(HBITMAP bmp)  void ui_destroy_bitmap(HBITMAP bmp)
1337  {  {
1338    struct bitmap* the_bitmap;    struct bitmap* the_bitmap;
# Line 1234  void ui_destroy_bitmap(HBITMAP bmp) Line 1346  void ui_destroy_bitmap(HBITMAP bmp)
1346    }    }
1347  }  }
1348    
1349  //*****************************************************************************  /******************************************************************************/
1350  bool is_pixel_on(uint8* data, int x, int y, int width, int bpp)  bool is_pixel_on(uint8 * data, int x, int y, int width, int bpp)
1351  {  {
1352    int start, shift;    int start, shift;
1353    
# Line 1252  bool is_pixel_on(uint8* data, int x, int Line 1364  bool is_pixel_on(uint8* data, int x, int
1364      return false;      return false;
1365  }  }
1366    
1367  //*****************************************************************************  /******************************************************************************/
1368  void set_pixel_on(uint8* data, int x, int y, int width, int bpp, uint8 pixel)  void set_pixel_on(uint8 * data, int x, int y, int width, int bpp, uint8 pixel)
1369  {  {
1370    if (bpp == 8)    if (bpp == 8)
1371      data[y * width + x] = pixel;      data[y * width + x] = pixel;
1372  }  }
1373    
1374  //*****************************************************************************  /******************************************************************************/
1375  HGLYPH ui_create_glyph(int width, int height, uint8 * data)  HGLYPH ui_create_glyph(int width, int height, uint8 * data)
1376  {  {
1377    int i, j;    int i, j;
# Line 1279  HGLYPH ui_create_glyph(int width, int he Line 1391  HGLYPH ui_create_glyph(int width, int he
1391    return the_glyph;    return the_glyph;
1392  }  }
1393    
1394  //*****************************************************************************  /******************************************************************************/
1395  void ui_destroy_glyph(HGLYPH glyph)  void ui_destroy_glyph(HGLYPH glyph)
1396  {  {
1397    struct bitmap* the_glyph;    struct bitmap* the_glyph;
# Line 1293  void ui_destroy_glyph(HGLYPH glyph) Line 1405  void ui_destroy_glyph(HGLYPH glyph)
1405    }    }
1406  }  }
1407    
1408  //*****************************************************************************  /******************************************************************************/
1409  HCURSOR ui_create_cursor(uint32 x, uint32 y,  HCURSOR ui_create_cursor(uint32 x, uint32 y,
1410                           int width, int height,                           int width, int height,
1411                           uint8 * andmask, uint8 * xormask)                           uint8 * andmask, uint8 * xormask)
# Line 1301  HCURSOR ui_create_cursor(uint32 x, uint3 Line 1413  HCURSOR ui_create_cursor(uint32 x, uint3
1413    return (void*)1;    return (void*)1;
1414  }  }
1415    
1416  //*****************************************************************************  /******************************************************************************/
1417  void ui_set_cursor(HCURSOR /*cursor*/)  void ui_set_cursor(HCURSOR /*cursor*/)
1418  {  {
1419  }  }
# Line 1322  unsigned int read_keyboard_state(void) Line 1434  unsigned int read_keyboard_state(void)
1434  void ui_resize_window(void)  void ui_resize_window(void)
1435  {  {
1436  }  }
1437  //*****************************************************************************  
1438    /******************************************************************************/
1439  void ui_destroy_cursor(HCURSOR /*cursor*/)  void ui_destroy_cursor(HCURSOR /*cursor*/)
1440  {  {
1441  }  }
1442    
1443  //*****************************************************************************  /******************************************************************************/
1444  HCOLOURMAP ui_create_colourmap(COLOURMAP * colours)  HCOLOURMAP ui_create_colourmap(COLOURMAP * colours)
1445  {  {
1446    int i;    int i;
# Line 1347  HCOLOURMAP ui_create_colourmap(COLOURMAP Line 1460  HCOLOURMAP ui_create_colourmap(COLOURMAP
1460    return g_CM;    return g_CM;
1461  }  }
1462    
1463  //*****************************************************************************  /******************************************************************************/
1464  void ui_set_colourmap(HCOLOURMAP map)  void ui_set_colourmap(HCOLOURMAP map)
1465  {  {
1466  }  }
1467    
1468  //*****************************************************************************  /******************************************************************************/
1469  void ui_destroy_colourmap(HCOLOURMAP map)  void ui_destroy_colourmap(HCOLOURMAP map)
1470  {  {
1471  }  }
1472    
1473  //*****************************************************************************  /******************************************************************************/
1474  void ui_begin_update(void)  void ui_begin_update(void)
1475  {  {
1476  }  }
1477    
1478  //*****************************************************************************  /******************************************************************************/
1479  void ui_end_update(void)  void ui_end_update(void)
1480  {  {
1481  }  }
1482    
1483  //*****************************************************************************  /******************************************************************************/
1484  void ui_set_clip(int x, int y, int cx, int cy)  void ui_set_clip(int x, int y, int cx, int cy)
1485  {  {
1486    g_clipx = x;    g_clipx = x;
# Line 1376  void ui_set_clip(int x, int y, int cx, i Line 1489  void ui_set_clip(int x, int y, int cx, i
1489    g_clipcy = cy;    g_clipcy = cy;
1490  }  }
1491    
1492  //*****************************************************************************  /******************************************************************************/
1493  void ui_reset_clip(void)  void ui_reset_clip(void)
1494  {  {
1495    g_clipx = 0;    g_clipx = 0;
# Line 1385  void ui_reset_clip(void) Line 1498  void ui_reset_clip(void)
1498    g_clipcy = g_height;    g_clipcy = g_height;
1499  }  }
1500    
1501  //*****************************************************************************  /******************************************************************************/
1502  void ui_bell(void)  void ui_bell(void)
1503  {  {
1504    g_App->beep();    g_App->beep();
1505  }  }
1506    
1507  //*****************************************************************************  /******************************************************************************/
1508  void ui_destblt(uint8 opcode, int x, int y, int cx, int cy)  void ui_destblt(uint8 opcode, int x, int y, int cx, int cy)
1509  {  {
1510    int i, j;    int i, j;
1511    
1512    for (i = 0; i < cy; i++)  
1513      for (j = 0; j < cx; j++)    if (opcode == 0x0) /* black */
1514        set_pixel(x + j, y + i, get_pixel(x + j, y + i), opcode);    {
1515        for (i = 0; i < cy; i++)
1516          for (j = 0; j < cx; j++)
1517            set_pixel(x + j, y + i, 0, 0xc);
1518      }
1519      else if (opcode == 0xf) /* white */
1520      {
1521        for (i = 0; i < cy; i++)
1522          for (j = 0; j < cx; j++)
1523            set_pixel(x + j, y + i, 0xffffff, 0xc);
1524      }
1525      else
1526      {
1527        for (i = 0; i < cy; i++)
1528          for (j = 0; j < cx; j++)
1529            set_pixel(x + j, y + i, get_pixel(x + j, y + i), opcode);
1530      }
1531    redraw(x, y, cx, cy);    redraw(x, y, cx, cy);
1532  }  }
1533    
1534  //*****************************************************************************  /******************************************************************************/
1535  // does not repaint  // does not repaint
1536  void fill_rect(int x, int y, int cx, int cy, int colour, int opcode = 0xc)  void fill_rect(int x, int y, int cx, int cy, int colour, int opcode = 0xc)
1537  {  {
# Line 1412  void fill_rect(int x, int y, int cx, int Line 1541  void fill_rect(int x, int y, int cx, int
1541      cx = g_width - x;      cx = g_width - x;
1542    if (y + cy > g_height)    if (y + cy > g_height)
1543      cy = g_height - y;      cy = g_height - y;
1544    for (i = 0; i < cy; i++)  #ifdef QT_OPTI
1545      for (j = 0; j < cx; j++)    if (opcode == 0xc) /* optimize */
1546        set_pixel(x + j, y + i, colour, opcode);    {
1547        if (WarpCoords(&x, &y, &cx, &cy, 0, 0))
1548        {
1549          if (g_server_bpp == 8)
1550          {
1551            for (i = 0; i < cy; i++)
1552              for (j = 0; j < cx; j++)
1553                SETPIXEL8(g_BS, x + j, y + i, g_width, colour);
1554          }
1555          else if (g_server_bpp == 16)
1556          {
1557            for (i = 0; i < cy; i++)
1558              for (j = 0; j < cx; j++)
1559                SETPIXEL16(g_BS, x + j, y + i, g_width, colour);
1560          }
1561          else if (g_server_bpp == 24)
1562          {
1563            for (i = 0; i < cy; i++)
1564              for (j = 0; j < cx; j++)
1565                SETPIXEL32(g_BS, x + j, y + i, g_width, colour);
1566          }
1567        }
1568      }
1569      else
1570    #endif
1571      {
1572        for (i = 0; i < cy; i++)
1573          for (j = 0; j < cx; j++)
1574            set_pixel(x + j, y + i, colour, opcode);
1575      }
1576  }  }
1577    
1578  //*****************************************************************************  /******************************************************************************/
1579  void ui_rect(int x, int y, int cx, int cy, int colour)  void ui_rect(int x, int y, int cx, int cy, int colour)
1580  {  {
1581    fill_rect(x, y, cx, cy, colour);    fill_rect(x, y, cx, cy, colour);
1582    redraw(x, y, cx, cy);    redraw(x, y, cx, cy);
1583  }  }
1584    
1585  //*****************************************************************************  /******************************************************************************/
1586  void ui_patblt(uint8 opcode, int x, int y, int cx, int cy,  void ui_patblt(uint8 opcode, int x, int y, int cx, int cy,
1587                 BRUSH * brush, int bgcolour, int fgcolour)                 BRUSH * brush, int bgcolour, int fgcolour)
1588  {  {
# Line 1451  void ui_patblt(uint8 opcode, int x, int Line 1609  void ui_patblt(uint8 opcode, int x, int
1609    redraw(x, y, cx, cy);    redraw(x, y, cx, cy);
1610  }  }
1611    
1612  //*****************************************************************************  /******************************************************************************/
1613  void ui_screenblt(uint8 opcode, int x, int y, int cx, int cy,  void ui_screenblt(uint8 opcode, int x, int y, int cx, int cy,
1614                    int srcx, int srcy)                    int srcx, int srcy)
1615  {  {
1616    int i, j;    int i, j, pixel;
1617    uint8* temp;    uint8 * temp;
1618    
1619    temp = (uint8*)xmalloc(cx * cy * BPP);    temp = (uint8*)xmalloc(cx * cy * 4);
1620    if (g_server_bpp == 8)  #ifdef QT_OPTI
1621      if (opcode == 0xc)
1622    {    {
1623      for (i = 0; i < cy; i++)      if (WarpCoords(&x, &y, &cx, &cy, &srcx, &srcy))
1624        for (j = 0; j < cx; j++)      {
1625          temp[i * cx + j] = get_pixel(srcx + j, srcy + i);        if (g_server_bpp == 8)
1626      for (i = 0; i < cy; i++)        {
1627        for (j = 0; j < cx; j++)          for (i = 0; i < cy; i++)
1628          set_pixel(x + j, y + i, temp[i * cx + j], opcode);            for (j = 0; j < cx; j++)
1629              {
1630                pixel = GETPIXEL8(g_BS, srcx + j, srcy + i, g_width);
1631                SETPIXEL8(temp, j, i, cx, pixel);
1632              }
1633            for (i = 0; i < cy; i++)
1634              for (j = 0; j < cx; j++)
1635              {
1636                pixel = GETPIXEL8(temp, j, i, cx);
1637                SETPIXEL8(g_BS, x + j, y + i, g_width, pixel);
1638              }
1639          }
1640          else if (g_server_bpp == 16)
1641          {
1642            for (i = 0; i < cy; i++)
1643              for (j = 0; j < cx; j++)
1644              {
1645                pixel = GETPIXEL16(g_BS, srcx + j, srcy + i, g_width);
1646                SETPIXEL16(temp, j, i, cx, pixel);
1647              }
1648            for (i = 0; i < cy; i++)
1649              for (j = 0; j < cx; j++)
1650              {
1651                pixel = GETPIXEL16(temp, j, i, cx);
1652                SETPIXEL16(g_BS, x + j, y + i, g_width, pixel);
1653              }
1654          }
1655          else if (g_server_bpp == 24)
1656          {
1657            for (i = 0; i < cy; i++)
1658              for (j = 0; j < cx; j++)
1659              {
1660                pixel = GETPIXEL32(g_BS, srcx + j, srcy + i, g_width);
1661                SETPIXEL32(temp, j, i, cx, pixel);
1662              }
1663            for (i = 0; i < cy; i++)
1664              for (j = 0; j < cx; j++)
1665              {
1666                pixel = GETPIXEL32(temp, j, i, cx);
1667                SETPIXEL32(g_BS, x + j, y + i, g_width, pixel);
1668              }
1669          }
1670        }
1671    }    }
1672    else if (g_server_bpp == 16)    else
1673    #endif
1674    {    {
1675      for (i = 0; i < cy; i++)      if (g_server_bpp == 8)
1676        for (j = 0; j < cx; j++)      {
1677          *(((uint16*)temp) + (i * cx + j)) = get_pixel(srcx + j, srcy + i);        for (i = 0; i < cy; i++)
1678      for (i = 0; i < cy; i++)          for (j = 0; j < cx; j++)
1679        for (j = 0; j < cx; j++)            temp[i * cx + j] = get_pixel(srcx + j, srcy + i);
1680          set_pixel(x + j, y + i, *(((uint16*)temp) + (i * cx + j)), opcode);        for (i = 0; i < cy; i++)
1681            for (j = 0; j < cx; j++)
1682              set_pixel(x + j, y + i, temp[i * cx + j], opcode);
1683        }
1684        else if (g_server_bpp == 16)
1685        {
1686          for (i = 0; i < cy; i++)
1687            for (j = 0; j < cx; j++)
1688            {
1689              pixel = get_pixel(srcx + j, srcy + i);
1690              SETPIXEL16(temp, j, i, cx, pixel);
1691            }
1692          for (i = 0; i < cy; i++)
1693            for (j = 0; j < cx; j++)
1694            {
1695              pixel = GETPIXEL16(temp, j, i, cx);
1696              set_pixel(x + j, y + i, pixel, opcode);
1697            }
1698        }
1699        else if (g_server_bpp == 24)
1700        {
1701          for (i = 0; i < cy; i++)
1702            for (j = 0; j < cx; j++)
1703              *(((uint32*)temp) + (i * cx + j)) = get_pixel(srcx + j, srcy + i);
1704          for (i = 0; i < cy; i++)
1705            for (j = 0; j < cx; j++)
1706              set_pixel(x + j, y + i, *(((uint32*)temp) + (i * cx + j)), opcode);
1707        }
1708    }    }
1709    xfree(temp);    xfree(temp);
1710    redraw(x, y, cx, cy);    redraw(x, y, cx, cy);
1711  }  }
1712    
1713  //*****************************************************************************  /******************************************************************************/
1714  void ui_memblt(uint8 opcode, int x, int y, int cx, int cy,  void ui_memblt(uint8 opcode, int x, int y, int cx, int cy,
1715                 HBITMAP src, int srcx, int srcy)                 HBITMAP src, int srcx, int srcy)
1716  {  {
1717    int i, j;    int i, j, p;
1718    struct bitmap* the_bitmap;    struct bitmap * the_bitmap;
1719    
1720    the_bitmap = (struct bitmap*)src;    the_bitmap = (struct bitmap*)src;
1721    if (the_bitmap == NULL)    if (the_bitmap == NULL)
1722      return;      return;
1723    if (g_server_bpp == 8)  #ifdef QT_OPTI
1724      if (opcode == 0xc) /* optimize */
1725    {    {
1726      for (i = 0; i < cy; i++)      if (WarpCoords(&x, &y, &cx, &cy, &srcx, &srcy))
1727        for (j = 0; j < cx; j++)      {
1728          if ((i + srcy) < the_bitmap->h && (j + srcx) < the_bitmap->w)        if (g_server_bpp == 8)
1729            set_pixel(x + j, y + i,        {
1730                      the_bitmap->data[(i + srcy) * the_bitmap->w + (j + srcx)],          for (i = 0; i < cy; i++)
1731                      opcode);            for (j = 0; j < cx; j++)
1732              {
1733                p = GETPIXEL8(the_bitmap->data, srcx + j, srcy + i, the_bitmap->w);
1734                SETPIXEL8(g_BS, x + j, y + i, g_width, p);
1735              }
1736          }
1737          else if (g_server_bpp == 16)
1738          {
1739            for (i = 0; i < cy; i++)
1740              for (j = 0; j < cx; j++)
1741              {
1742                p = GETPIXEL16(the_bitmap->data, srcx + j, srcy + i, the_bitmap->w);
1743                SETPIXEL16(g_BS, x + j, y + i, g_width, p);
1744              }
1745          }
1746          else if (g_server_bpp == 24)
1747          {
1748            for (i = 0; i < cy; i++)
1749              for (j = 0; j < cx; j++)
1750              {
1751                p = GETPIXEL32(the_bitmap->data, srcx + j, srcy + i, the_bitmap->w);
1752                SETPIXEL32(g_BS, x + j, y + i, g_width, p);
1753              }
1754          }
1755        }
1756    }    }
1757    else if (g_server_bpp == 16)    else
1758    #endif
1759    {    {
1760      for (i = 0; i < cy; i++)      if (g_server_bpp == 8)
1761        for (j = 0; j < cx; j++)      {
1762          if ((i + srcy) < the_bitmap->h && (j + srcx) < the_bitmap->w)        for (i = 0; i < cy; i++)
1763            set_pixel(x + j, y + i,          for (j = 0; j < cx; j++)
1764                      *(((uint16*)the_bitmap->data) + ((i + srcy) * the_bitmap->w + (j + srcx))),            if ((i + srcy) < the_bitmap->h && (j + srcx) < the_bitmap->w)
1765                      opcode);              set_pixel(x + j, y + i,
1766                          the_bitmap->data[(i + srcy) * the_bitmap->w + (j + srcx)],
1767                          opcode);
1768        }
1769        else if (g_server_bpp == 16)
1770        {
1771          for (i = 0; i < cy; i++)
1772            for (j = 0; j < cx; j++)
1773              if ((i + srcy) < the_bitmap->h && (j + srcx) < the_bitmap->w)
1774                set_pixel(x + j, y + i,
1775                          *(((uint16*)the_bitmap->data) + ((i + srcy) * the_bitmap->w + (j + srcx))),
1776                          opcode);
1777        }
1778        else if (g_server_bpp == 24)
1779        {
1780          for (i = 0; i < cy; i++)
1781            for (j = 0; j < cx; j++)
1782              if ((i + srcy) < the_bitmap->h && (j + srcx) < the_bitmap->w)
1783                set_pixel(x + j, y + i,
1784                          *(((uint32*)the_bitmap->data) + ((i + srcy) * the_bitmap->w + (j + srcx))),
1785                          opcode);
1786        }
1787    }    }
1788    redraw(x, y, cx, cy);    redraw(x, y, cx, cy);
1789  }  }
1790    
1791  //*****************************************************************************  /******************************************************************************/
1792  // not used  // not used
1793  void ui_triblt(uint8 opcode, int x, int y, int cx, int cy,  void ui_triblt(uint8 opcode, int x, int y, int cx, int cy,
1794                 HBITMAP src, int srcx, int srcy, BRUSH * brush,                 HBITMAP src, int srcx, int srcy, BRUSH * brush,
# Line 1520  void ui_triblt(uint8 opcode, int x, int Line 1796  void ui_triblt(uint8 opcode, int x, int
1796  {  {
1797  }  }
1798    
1799  //*****************************************************************************  /******************************************************************************/
1800  // Bresenham's line drawing algorithm  /* Bresenham's line drawing algorithm */
1801  void ui_line(uint8 opcode, int startx, int starty, int endx,  void ui_line(uint8 opcode, int startx, int starty, int endx,
1802               int endy, PEN * pen)               int endy, PEN * pen)
1803  {  {
# Line 1600  void ui_line(uint8 opcode, int startx, i Line 1876  void ui_line(uint8 opcode, int startx, i
1876    redraw(left, top, (right - left) + 1, (bottom - top) + 1);    redraw(left, top, (right - left) + 1, (bottom - top) + 1);
1877  }  }
1878    
1879  //*****************************************************************************  /******************************************************************************/
1880  void draw_glyph (int x, int y, HGLYPH glyph, int fgcolour)  void draw_glyph (int x, int y, HGLYPH glyph, int fgcolour)
1881  {  {
1882    struct bitmap *the_glyph;    struct bitmap *the_glyph;
# Line 1645  void draw_glyph (int x, int y, HGLYPH gl Line 1921  void draw_glyph (int x, int y, HGLYPH gl
1921      }\      }\
1922  }  }
1923    
1924  //*****************************************************************************  /******************************************************************************/
1925  void ui_draw_text(uint8 font, uint8 flags, int mixmode,  void ui_draw_text(uint8 font, uint8 flags, int mixmode,
1926                    int x, int y, int clipx, int clipy,                    int x, int y, int clipx, int clipy,
1927                    int clipcx, int clipcy, int boxx,                    int clipcx, int clipcy, int boxx,
1928                    int boxy, int boxcx, int boxcy, int bgcolour,                    int boxy, int boxcx, int boxcy, int bgcolour,
1929                    int fgcolour, uint8 * text, uint8 length)                    int fgcolour, uint8 * text, uint8 length)
1930  {  {
1931    FONTGLYPH *glyph;    FONTGLYPH * glyph;
1932    int i, j, xyoffset;    int i, j, xyoffset;
1933    DATABLOB *entry;    DATABLOB * entry;
1934    
1935      if (boxx + boxcx > g_width)
1936        boxcx = g_width - boxx;
1937      if (boxy + boxcy > g_height)
1938        boxcy = g_height - boxy;
1939    
1940    if (boxcx > 1)    if (boxcx > 1)
1941      fill_rect(boxx, boxy, boxcx, boxcy, bgcolour);      fill_rect(boxx, boxy, boxcx, boxcy, bgcolour);
# Line 1716  void ui_draw_text(uint8 font, uint8 flag Line 1997  void ui_draw_text(uint8 font, uint8 flag
1997      redraw(clipx, clipy, clipcx, clipcy);      redraw(clipx, clipy, clipcx, clipcy);
1998  }  }
1999    
2000  //*****************************************************************************  /******************************************************************************/
2001  void ui_desktop_save(uint32 offset, int x, int y, int cx, int cy)  void ui_desktop_save(uint32 offset, int x, int y, int cx, int cy)
2002  {  {
2003    uint8* data;    uint8 * data;
2004    int i, j;    int i, j, Bpp, pixel;
2005    
2006    data = (uint8*)xmalloc(cx * cy * BPP);    Bpp = 4;
2007      switch (g_server_bpp)
2008      {
2009        case 8: Bpp = 1; break;
2010        case 15: Bpp = 2; break;
2011        case 16: Bpp = 2; break;
2012      }
2013      data = (uint8*)xmalloc(cx * cy * Bpp);
2014    if (g_server_bpp == 8)    if (g_server_bpp == 8)
2015    {    {
2016      for (i = 0; i < cy; i++)      for (i = 0; i < cy; i++)
2017        for (j = 0; j < cx; j++)        for (j = 0; j < cx; j++)
2018          data[i * cx + j] = get_pixel(x + j, y + i);        {
2019            pixel = get_pixel(x + j, y + i);
2020            SETPIXEL8(data, j, i, cx, pixel);
2021          }
2022    }    }
2023    else if (g_server_bpp == 16)    else if (g_server_bpp == 16)
2024    {    {
2025      for (i = 0; i < cy; i++)      for (i = 0; i < cy; i++)
2026        for (j = 0; j < cx; j++)        for (j = 0; j < cx; j++)
2027          *(((uint16*)data) + (i * cx + j)) = get_pixel(x + j, y + i);        {
2028            pixel = get_pixel(x + j, y + i);
2029            SETPIXEL16(data, j, i, cx, pixel);
2030          }
2031    }    }
2032    offset *= BPP;    else if (g_server_bpp == 24)
2033    cache_put_desktop(offset, cx, cy, cx * BPP, BPP, data);    {
2034        for (i = 0; i < cy; i++)
2035          for (j = 0; j < cx; j++)
2036            *(((uint32*)data) + (i * cx + j)) = get_pixel(x + j, y + i);
2037      }
2038      offset *= Bpp;
2039      cache_put_desktop(offset, cx, cy, cx * Bpp, Bpp, data);
2040    xfree(data);    xfree(data);
2041  }  }
2042    
2043  //*****************************************************************************  /******************************************************************************/
2044  void ui_desktop_restore(uint32 offset, int x, int y, int cx, int cy)  void ui_desktop_restore(uint32 offset, int x, int y, int cx, int cy)
2045  {  {
2046    uint8* data;    uint8 * data;
2047    int i, j;    int i, j;
2048      int Bpp;
2049    
2050    offset *= BPP;    Bpp = 4;
2051    data = cache_get_desktop(offset, cx, cy, BPP);    switch (g_server_bpp)
2052      {
2053        case 8: Bpp = 1; break;
2054        case 15: Bpp = 2; break;
2055        case 16: Bpp = 2; break;
2056      }
2057      offset *= Bpp;
2058      data = cache_get_desktop(offset, cx, cy, Bpp);
2059    if (g_server_bpp == 8)    if (g_server_bpp == 8)
2060    {    {
2061      for (i = 0; i < cy; i++)      for (i = 0; i < cy; i++)
# Line 1760  void ui_desktop_restore(uint32 offset, i Line 2068  void ui_desktop_restore(uint32 offset, i
2068        for (j = 0; j < cx; j++)        for (j = 0; j < cx; j++)
2069          set_pixel(x + j, y + i, *(((uint16*)data) + (i * cx + j)));          set_pixel(x + j, y + i, *(((uint16*)data) + (i * cx + j)));
2070    }    }
2071      else if (g_server_bpp == 24)
2072      {
2073        for (i = 0; i < cy; i++)
2074          for (j = 0; j < cx; j++)
2075            set_pixel(x + j, y + i, *(((uint32*)data) + (i * cx + j)));
2076      }
2077    redraw(x, y, cx, cy);    redraw(x, y, cx, cy);
2078  }  }
2079    
2080  /*****************************************************************************/  /*****************************************************************************/
2081  void* xrealloc(void *in_val, int size)  void* xrealloc(void * in_val, int size)
2082  {  {
2083    if (size < 1)    if (size < 1)
2084      size = 1;      size = 1;
# Line 1915  void hexdump(uint8 * p, uint32 len) Line 2229  void hexdump(uint8 * p, uint32 len)
2229  void get_username_and_hostname(void)  void get_username_and_hostname(void)
2230  {  {
2231    char fullhostname[64];    char fullhostname[64];
2232    char* p;    char * p;
2233    struct passwd* pw;    struct passwd * pw;
2234    
2235    STRNCPY(g_username, "unknown", sizeof(g_username));    STRNCPY(g_username, "unknown", sizeof(g_username));
2236    STRNCPY(g_hostname, "unknown", sizeof(g_hostname));    STRNCPY(g_hostname, "unknown", sizeof(g_hostname));
# Line 1953  void out_params(void) Line 2267  void out_params(void)
2267    fprintf(stderr, "   -c: working directory\n");    fprintf(stderr, "   -c: working directory\n");
2268    fprintf(stderr, "   -p: password (- to prompt)\n");    fprintf(stderr, "   -p: password (- to prompt)\n");
2269    fprintf(stderr, "   -n: client hostname\n");    fprintf(stderr, "   -n: client hostname\n");
2270      fprintf(stderr, "   -f: full screen\n");
2271    
2272    fprintf(stderr, "\n");    fprintf(stderr, "\n");
2273  }  }
# Line 1974  int parse_parameters(int in_argc, char * Line 2289  int parse_parameters(int in_argc, char *
2289      else if (strcmp(in_argv[i], "-g") == 0)      else if (strcmp(in_argv[i], "-g") == 0)
2290      {      {
2291        g_width = strtol(in_argv[i + 1], &p, 10);        g_width = strtol(in_argv[i + 1], &p, 10);
       if (g_width <= 0)  
       {  
         error("invalid geometry\n");  
         return 0;  
       }  
2292        if (*p == 'x')        if (*p == 'x')
2293          g_height = strtol(p + 1, NULL, 10);          g_height = strtol(p + 1, &p, 10);
2294        if (g_height <= 0)        if (*p == '-')
2295            g_client_width = strtol(p + 1, &p, 10);
2296          else
2297        {        {
2298          error("invalid geometry\n");          g_client_width = g_width;
2299          return 0;          g_client_height = g_height;
2300        }        }
2301          if (*p == 'x')
2302            g_client_height = strtol(p + 1, NULL, 10);
2303        g_width = (g_width + 3) & ~3;        g_width = (g_width + 3) & ~3;
2304          g_height = (g_height + 3) & ~3;
2305          g_client_width = (g_client_width + 3) & ~3;
2306          g_client_height = (g_client_height + 3) & ~3;
2307          //printf("%d %d %d %d\n", g_width, g_height, g_client_width, g_client_height);
2308      }      }
2309      else if (strcmp(in_argv[i], "-4") == 0)      else if (strcmp(in_argv[i], "-4") == 0)
2310        g_use_rdp5 = 0;        g_use_rdp5 = 0;
# Line 1995  int parse_parameters(int in_argc, char * Line 2313  int parse_parameters(int in_argc, char *
2313      else if (strcmp(in_argv[i], "-a") == 0)      else if (strcmp(in_argv[i], "-a") == 0)
2314      {      {
2315        g_server_bpp = strtol(in_argv[i + 1], &p, 10);        g_server_bpp = strtol(in_argv[i + 1], &p, 10);
2316        if (g_server_bpp != 8 && g_server_bpp != 15 &&        if (g_server_bpp != 8 &&
2317            g_server_bpp != 16 && g_server_bpp != 24)            g_server_bpp != 16 && g_server_bpp != 24)
2318        {        {
2319          error("invalid bpp\n");          error("invalid bpp\n");
# Line 2030  int parse_parameters(int in_argc, char * Line 2348  int parse_parameters(int in_argc, char *
2348      {      {
2349        STRNCPY(g_hostname, in_argv[i + 1], sizeof(g_hostname));        STRNCPY(g_hostname, in_argv[i + 1], sizeof(g_hostname));
2350      }      }
2351        else if (strcmp(in_argv[i], "-f") == 0)
2352        {
2353          g_fullscreen = 1;
2354        }
2355    }    }
2356    return 1;    return 1;
2357  }  }
2358    
2359  //*****************************************************************************  /******************************************************************************/
2360  int param_connect(void)  int param_connect(void)
2361  {  {
2362    QWidget * Desktop;    QWidget * Desktop;
# Line 2056  int param_connect(void) Line 2378  int param_connect(void)
2378      memset(g_CM, 0, sizeof(struct QColorMap));      memset(g_CM, 0, sizeof(struct QColorMap));
2379      g_CM->NumColors = 256;      g_CM->NumColors = 256;
2380      g_MW = new QMyMainWindow();      g_MW = new QMyMainWindow();
2381      g_MW->resize(g_width, g_height);      g_MW->resize(g_client_width, g_client_height);
2382      g_MW->show();      g_MW->show();
2383      g_SV->addChild(g_MW);      g_SV->addChild(g_MW);
2384      g_MW->setMouseTracking(true);      g_MW->setMouseTracking(true);
# Line 2070  int param_connect(void) Line 2392  int param_connect(void)
2392        Desktop = g_App->desktop();        Desktop = g_App->desktop();
2393        dw = Desktop->width();        dw = Desktop->width();
2394        dh = Desktop->height();        dh = Desktop->height();
2395        if (dw == g_width && dh == g_height)        if (dw == g_client_width && dh == g_client_height)
2396          g_MW->resize(g_width - 4, g_height - 4);          g_MW->resize(g_client_width - 4, g_client_height - 4);
2397        g_SV->showFullScreen();        g_SV->showFullScreen();
2398      }      }
2399      g_MW->setCursor(BlankCursor);      g_MW->setCursor((int)10); /* Qt::BlankCursor */
2400      g_App->exec();      g_App->exec();
2401    }    }
2402    return 0;    return 0;
2403  }  }
2404    
2405  //*****************************************************************************  /******************************************************************************/
2406  int main(int argc, char ** argv)  int main(int argc, char ** argv)
2407  {  {
2408  #ifdef SHARP  #ifdef SHARP
2409    g_App = new QPEApplication(argc, argv);    g_App = new QPEApplication(argc, argv);
2410  #else  #else
2411    g_App = new QApplication(argc, argv, QApplication::GuiServer);    //g_App = new QApplication(argc, argv, QApplication::GuiServer);
2412      g_App = new QApplication(argc, argv);
2413  #endif  #endif
2414    g_SV = new QMyScrollView();    g_SV = new QMyScrollView();
2415    g_App->setMainWidget(g_SV);    g_App->setMainWidget(g_SV);
# Line 2100  int main(int argc, char ** argv) Line 2423  int main(int argc, char ** argv)
2423    else    else
2424    {    {
2425      g_SV->timer_id = g_SV->startTimer(1000); /* one sec delay, then dialog */      g_SV->timer_id = g_SV->startTimer(1000); /* one sec delay, then dialog */
2426      g_MW->setCursor(BlankCursor);      g_MW->setCursor((int)10); /* Qt::BlankCursor */
2427      g_App->exec();      g_App->exec();
2428    }    }
2429    delete g_SV;    delete g_SV;

Legend:
Removed from v.780  
changed lines
  Added in v.796

  ViewVC Help
Powered by ViewVC 1.1.26