/[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 776 by jsorg71, Sat Oct 2 01:30:33 2004 UTC revision 791 by jsorg71, Sat Oct 30 17:02:54 2004 UTC
# Line 1  Line 1 
1  /*  /*
2     rdesktop: A Remote Desktop Protocol client.     rdesktop: A Remote Desktop Protocol client.
3     User interface services - X Window System     User interface services - QT Emb System
4     Copyright (C) Jay Sorg 2004     Copyright (C) Jay Sorg 2004
5    
6     This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
# 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 41  Line 42 
42  #include <qpopupmenu.h>  #include <qpopupmenu.h>
43  #include <stdlib.h>  #include <stdlib.h>
44  #include <stdarg.h> // va_list va_start va_end  #include <stdarg.h> // va_list va_start va_end
45    #include <unistd.h> // gethostname
46    #include <pwd.h> // getpwuid
47    
48  #include "../rdesktop.h"  #include "../rdesktop.h"
49  #include "qtewin.h"  #include "qtewin.h"
# Line 49  Line 52 
52  struct QColorMap  struct QColorMap
53  {  {
54    uint32 RGBColors[256];    uint32 RGBColors[256];
55    int NumColors;    uint32 NumColors;
56  };  };
57    
58  struct bitmap  struct bitmap
59  {  {
60    int w;    int w;
61    int h;    int h;
62    uint8* data;    uint8 * data;
63  };  };
64    
65  uint32 g_flags = 0;  extern int g_tcp_port_rdp;
66  char g_server[64] = "";  extern int g_dsp_fd;
67  char g_domain[16] = "";  
68  char g_password[16] = "";  #ifdef WITH_RDPSND
69  char g_shell[128] = "";  BOOL g_rdpsnd = True;
70  char g_directory[32] = "";  extern int g_dsp_busy;
71    #endif
72  int g_encryption = 1;  int g_encryption = 1;
73  int g_bitmap_cache = 1;  int g_bitmap_cache = 1;
74  int g_bitmap_cache_persist_enable = 0;  int g_bitmap_cache_persist_enable = 0;
# Line 75  int g_bitmap_compression = 1; Line 79  int g_bitmap_compression = 1;
79  int g_rdp5_performanceflags = 0;  int g_rdp5_performanceflags = 0;
80  int g_console_session = 0;  int g_console_session = 0;
81  int g_keylayout = 0x409; /* Defaults to US keyboard layout */  int g_keylayout = 0x409; /* Defaults to US keyboard layout */
   
82  int g_width = 640;  int g_width = 640;
83  int g_height = 480;  int g_height = 480;
84  int g_server_bpp = 8;  int g_server_bpp = 8;
 int g_fullscreen = 0;  
85  char g_hostname[16] = "";  char g_hostname[16] = "";
86  char g_username[100] = "";  char g_username[100] = "";
 int g_global_sock = 0;  
87    
88  int g_deactivated = 0;  static uint32 g_flags = RDP_LOGON_NORMAL;
89  uint32 g_ext_disc_reason = 0;  static char g_server[64] = "";
90    static char g_domain[16] = "";
91    static char g_password[16] = "";
92    static char g_shell[128] = "";
93    static char g_directory[32] = "";
94    static int g_fullscreen = 0;
95    static int g_global_sock = 0;
96    static int g_deactivated = 0;
97    static uint32 g_ext_disc_reason = 0;
98    
99  QSocketNotifier* g_SocketNotifier = 0;  static QSocketNotifier * g_SocketNotifier = 0;
100    static QSocketNotifier * g_SoundNotifier = 0;
101  #ifdef SHARP  #ifdef SHARP
102  QPEApplication* g_App = 0;  static QPEApplication * g_App = 0;
103  #else  #else
104  QApplication* g_App = 0;  static QApplication * g_App = 0;
105  #endif  #endif
106  static QMyMainWindow *g_MW = 0;  static QMyMainWindow * g_MW = 0;
107  static QMyScrollView *g_SV = 0;  static QMyScrollView * g_SV = 0;
108  static struct QColorMap *g_CM = 0;  static struct QColorMap * g_CM = 0;
109  static uint8 *g_BS = 0;  static uint8 * g_BS = 0; /* the screen data */
   
110  static int g_clipx = 0;  static int g_clipx = 0;
111  static int g_clipy = 0;  static int g_clipy = 0;
112  static int g_clipcx = 0;  static int g_clipcx = 0;
113  static int g_clipcy = 0;  static int g_clipcy = 0;
114    
115  //*****************************************************************************  #define BPP ((g_server_bpp + 7) / 8)
116  void CleanString(QString* Item)  #define GETPIXEL8(d, x, y, w) (*(((uint8*)d) + ((y) * (w) + (x))))
117    #define GETPIXEL16(d, x, y, w) (*(((uint16*)d) + ((y) * (w) + (x))))
118    #define GETPIXEL32(d, x, y, w) (*(((uint32*)d) + ((y) * (w) + (x))))
119    #define SETPIXEL8(d, x, y, w, v) *(((uint8*)d) + ((y) * (w) + (x))) = v
120    #define SETPIXEL16(d, x, y, w, v) *(((uint16*)d) + ((y) * (w) + (x))) = v
121    #define SETPIXEL32(d, x, y, w, v) *(((uint32*)d) + ((y) * (w) + (x))) = v
122    
123    /******************************************************************************/
124    void CleanString(QString * Item)
125  {  {
126    int i;    int i;
127    
# Line 117  void CleanString(QString* Item) Line 134  void CleanString(QString* Item)
134    }    }
135  }  }
136    
137  //*****************************************************************************  /******************************************************************************/
138  QMyDialog::QMyDialog(QWidget* parent) : QDialog(parent, "Settings", true)  QMyDialog::QMyDialog(QWidget * parent) : QDialog(parent, "Settings", true)
139  {  {
140    int i, j;    int i, j;
141    char* home;    char * home;
142    char Text[256];    char Text[256];
143    QString Line;    QString Line;
144    QString ItemName;    QString ItemName;
# Line 231  QMyDialog::QMyDialog(QWidget* parent) : Line 248  QMyDialog::QMyDialog(QWidget* parent) :
248    if (home != NULL)    if (home != NULL)
249    {    {
250      sprintf(Text, "%s/rdesktop.ini", home);      sprintf(Text, "%s/rdesktop.ini", home);
251      QFile* File = new QFile(Text);      QFile * File = new QFile(Text);
252      if (File->open(IO_ReadOnly))      if (File->open(IO_ReadOnly))
253      {      {
254        i = -1;        i = -1;
# Line 268  QMyDialog::QMyDialog(QWidget* parent) : Line 285  QMyDialog::QMyDialog(QWidget* parent) :
285    }    }
286  }  }
287    
288  //*****************************************************************************  /******************************************************************************/
289  QMyDialog::~QMyDialog()  QMyDialog::~QMyDialog()
290  {  {
291    QMyConnectionItem* Item;    QMyConnectionItem * Item;
292    int i;    int i;
293    
294    for (i = 0; i < 10; i++)    for (i = 0; i < 10; i++)
# Line 281  QMyDialog::~QMyDialog() Line 298  QMyDialog::~QMyDialog()
298    }    }
299  }  }
300    
301  //*****************************************************************************  /******************************************************************************/
302  void QMyDialog::ComboChanged(int index)  void QMyDialog::ComboChanged(int index)
303  {  {
304    if (index == 0)    if (index == 0)
# Line 301  void QMyDialog::ComboChanged(int index) Line 318  void QMyDialog::ComboChanged(int index)
318    }    }
319  }  }
320    
321  //*****************************************************************************  /******************************************************************************/
322  void QMyDialog::OKClicked()  void QMyDialog::OKClicked()
323  {  {
324    ServerName = ServerNameEdit->text();    ServerName = ServerNameEdit->text();
# Line 313  void QMyDialog::OKClicked() Line 330  void QMyDialog::OKClicked()
330    done(1);    done(1);
331  }  }
332    
333  //*****************************************************************************  /******************************************************************************/
334  void QMyDialog::CancelClicked()  void QMyDialog::CancelClicked()
335  {  {
336    done(0);    done(0);
337  }  }
338    
339  //*****************************************************************************  /******************************************************************************/
340  void QMyDialog::AddClicked()  void QMyDialog::AddClicked()
341  {  {
342    int i;    int i;
343    QMyConnectionItem* Item;    QMyConnectionItem * Item;
344    
345    i = ListBox->count();    i = ListBox->count();
346    if (i < 10)    if (i < 10)
# Line 339  void QMyDialog::AddClicked() Line 356  void QMyDialog::AddClicked()
356    }    }
357  }  }
358    
359  //*****************************************************************************  /******************************************************************************/
360  void QMyDialog::EditClicked()  void QMyDialog::EditClicked()
361  {  {
362    int i;    int i;
363    QMyConnectionItem* Item;    QMyConnectionItem * Item;
364    
365    i = ListBox->currentItem();    i = ListBox->currentItem();
366    if (i >= 0)    if (i >= 0)
# Line 359  void QMyDialog::EditClicked() Line 376  void QMyDialog::EditClicked()
376    }    }
377  }  }
378    
379  //*****************************************************************************  /******************************************************************************/
380  void WriteString(QFile* File, QString* Line)  void WriteString(QFile* File, QString* Line)
381  {  {
382    File->writeBlock((const char*)(*Line), Line->length());    File->writeBlock((const char*)(*Line), Line->length());
383  }  }
384    
385  //*****************************************************************************  /******************************************************************************/
386  void QMyDialog::SaveClicked()  void QMyDialog::SaveClicked()
387  {  {
388    int i, j;    int i, j;
389    QMyConnectionItem* Item;    QMyConnectionItem * Item;
390    QString Line;    QString Line;
391    char* home;    char * home;
392    char Text[256];    char Text[256];
393    QFile* File;    QFile* File;
394    
# Line 423  void QMyDialog::SaveClicked() Line 440  void QMyDialog::SaveClicked()
440    }    }
441  }  }
442    
443  //*****************************************************************************  /******************************************************************************/
444  void QMyDialog::RemoveClicked()  void QMyDialog::RemoveClicked()
445  {  {
446    int i, j, c;    int i, j, c;
447    QMyConnectionItem* Item1;    QMyConnectionItem * Item1;
448    QMyConnectionItem* Item2;    QMyConnectionItem * Item2;
449    
450    i = ListBox->currentItem();    i = ListBox->currentItem();
451    if (i >= 0)    if (i >= 0)
# Line 449  void QMyDialog::RemoveClicked() Line 466  void QMyDialog::RemoveClicked()
466    }    }
467  }  }
468    
469  //*****************************************************************************  /******************************************************************************/
470  void QMyDialog::ListBoxChanged()  void QMyDialog::ListBoxChanged()
471  {  {
472    int i;    int i;
473    QMyConnectionItem* Item;    QMyConnectionItem * Item;
474    char Text[100];    char Text[100];
475    
476    i = ListBox->currentItem();    i = ListBox->currentItem();
# Line 471  void QMyDialog::ListBoxChanged() Line 488  void QMyDialog::ListBoxChanged()
488    }    }
489  }  }
490    
491  //*****************************************************************************  /******************************************************************************/
492  void QMyDialog::ListBoxSelected(int /*index*/)  void QMyDialog::ListBoxSelected(int /*index*/)
493  {  {
494  }  }
495    
496  //*****************************************************************************  /******************************************************************************/
497  void GetScanCode(QKeyEvent* e, int* ScanCode, int* code)  void GetScanCode(QKeyEvent * e, int * ScanCode, int * code)
498  {  {
499    int key;    int key;
500    int mod;    int mod;
# Line 644  void GetScanCode(QKeyEvent* e, int* Scan Line 661  void GetScanCode(QKeyEvent* e, int* Scan
661    
662  }  }
663    
664  //*****************************************************************************  /******************************************************************************/
665  QMyScrollView::QMyScrollView() : QScrollView()  QMyScrollView::QMyScrollView() : QScrollView()
666  {  {
667  }  }
668    
669  //*****************************************************************************  /******************************************************************************/
670  QMyScrollView::~QMyScrollView()  QMyScrollView::~QMyScrollView()
671  {  {
672  }  }
673    
674  //*****************************************************************************  /******************************************************************************/
675  void QMyScrollView::keyPressEvent(QKeyEvent* e)  void QMyScrollView::keyPressEvent(QKeyEvent* e)
676  {  {
677    int ScanCode, code;    int ScanCode, code;
# Line 672  void QMyScrollView::keyPressEvent(QKeyEv Line 689  void QMyScrollView::keyPressEvent(QKeyEv
689    }    }
690  }  }
691    
692  //*****************************************************************************  /******************************************************************************/
693  void QMyScrollView::keyReleaseEvent(QKeyEvent* e)  void QMyScrollView::keyReleaseEvent(QKeyEvent* e)
694  {  {
695    int ScanCode, code;    int ScanCode, code;
# Line 690  void QMyScrollView::keyReleaseEvent(QKey Line 707  void QMyScrollView::keyReleaseEvent(QKey
707    }    }
708  }  }
709    
710  //*****************************************************************************  /******************************************************************************/
711  void QMyScrollView::showEvent(QShowEvent* e)  void QMyScrollView::showEvent(QShowEvent* e)
712  {  {
713    QScrollView::showEvent(e);    QScrollView::showEvent(e);
714  }  }
715    
716  //*****************************************************************************  /******************************************************************************/
717  void QMyScrollView::show()  void QMyScrollView::show()
718  {  {
719    QScrollView::show();    QScrollView::show();
720  }  }
721    
722  //*****************************************************************************  /******************************************************************************/
723  void QMyScrollView::polish()  void QMyScrollView::polish()
724  {  {
725    QScrollView::polish();    QScrollView::polish();
726  }  }
727    
728  //*****************************************************************************  /******************************************************************************/
729  void QMyScrollView::timerEvent(QTimerEvent* e)  void QMyScrollView::timerEvent(QTimerEvent * e)
730  {  {
731    QScrollView::timerEvent(e);    QScrollView::timerEvent(e);
732    killTimer(timer_id);    killTimer(timer_id);
733    QMyDialog* d;    QMyDialog * d;
734    QWidget* Desktop;    QWidget * Desktop;
735    int dw;    int dw;
736    int dh;    int dh;
737    
738    d = new QMyDialog(this);    d = new QMyDialog(this);
739    if (d->exec() == 1) // ok clicked    if (d->exec() == 1) // ok clicked
740    {    {
     g_flags = RDP_LOGON_NORMAL;  
741      g_width = d->Width;      g_width = d->Width;
742      g_height = d->Height;      g_height = d->Height;
743      g_fullscreen = d->FullScreen;      g_fullscreen = d->FullScreen;
# Line 734  void QMyScrollView::timerEvent(QTimerEve Line 750  void QMyScrollView::timerEvent(QTimerEve
750        g_SV->close();        g_SV->close();
751        return;        return;
752      }      }
753      g_BS = (uint8*)xmalloc(g_width * g_height);      g_BS = (uint8*)xmalloc(g_width * g_height * 4);
754      memset(g_BS, 0, g_width * g_height);      memset(g_BS, 0, g_width * g_height * 4);
755      g_clipx = 0;      g_clipx = 0;
756      g_clipy = 0;      g_clipy = 0;
757      g_clipcx = g_width;      g_clipcx = g_width;
# Line 771  void QMyScrollView::timerEvent(QTimerEve Line 787  void QMyScrollView::timerEvent(QTimerEve
787    }    }
788  }  }
789    
790  //*****************************************************************************  /******************************************************************************/
791  QMyMainWindow::QMyMainWindow() : QWidget(g_SV->viewport())  QMyMainWindow::QMyMainWindow() : QWidget(g_SV->viewport())
792  {  {
793    PopupMenu = new QPopupMenu(this);    PopupMenu = new QPopupMenu(this);
# Line 782  QMyMainWindow::QMyMainWindow() : QWidget Line 798  QMyMainWindow::QMyMainWindow() : QWidget
798    connect(PopupMenu, SIGNAL(activated(int)), this, SLOT(MemuClicked(int)));    connect(PopupMenu, SIGNAL(activated(int)), this, SLOT(MemuClicked(int)));
799  }  }
800    
801  //*****************************************************************************  /******************************************************************************/
802  QMyMainWindow::~QMyMainWindow()  QMyMainWindow::~QMyMainWindow()
803  {  {
804    delete PopupMenu;    delete PopupMenu;
805  }  }
806    
807  //*****************************************************************************  /******************************************************************************/
808  void QMyMainWindow::timerEvent(QTimerEvent* e)  void QMyMainWindow::timerEvent(QTimerEvent * e)
809  {  {
810    QWidget::timerEvent(e);    QWidget::timerEvent(e);
811    if (e->timerId() == timer_id)    if (e->timerId() == timer_id)
# Line 809  void QMyMainWindow::timerEvent(QTimerEve Line 825  void QMyMainWindow::timerEvent(QTimerEve
825    killTimer(timer_id);    killTimer(timer_id);
826  }  }
827    
828  //*****************************************************************************  /******************************************************************************/
829  void QMyMainWindow::MemuClicked(int MenuID)  void QMyMainWindow::MemuClicked(int MenuID)
830  {  {
831    QWidget* Desktop;    QWidget * Desktop;
832    int dw;    int dw;
833    int dh;    int dh;
834    
# Line 855  void QMyMainWindow::MemuClicked(int Menu Line 871  void QMyMainWindow::MemuClicked(int Menu
871    }    }
872  }  }
873    
874  //*****************************************************************************  /******************************************************************************/
875  void QMyMainWindow::mouseMoveEvent(QMouseEvent* e)  void QMyMainWindow::mouseMoveEvent(QMouseEvent* e)
876  {  {
877    int x;    int x;
# Line 877  void QMyMainWindow::mouseMoveEvent(QMous Line 893  void QMyMainWindow::mouseMoveEvent(QMous
893    rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_MOVE, e->x(), e->y());    rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_MOVE, e->x(), e->y());
894  }  }
895    
896  //*****************************************************************************  /******************************************************************************/
897  void QMyMainWindow::mousePressEvent(QMouseEvent* e)  void QMyMainWindow::mousePressEvent(QMouseEvent* e)
898  {  {
899    timer_id = startTimer(1000);    timer_id = startTimer(1000);
# Line 891  void QMyMainWindow::mousePressEvent(QMou Line 907  void QMyMainWindow::mousePressEvent(QMou
907      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, e->x(), e->y());
908  }  }
909    
910  //*****************************************************************************  /******************************************************************************/
911  void QMyMainWindow::mouseReleaseEvent(QMouseEvent* e)  void QMyMainWindow::mouseReleaseEvent(QMouseEvent* e)
912  {  {
913    killTimer(timer_id);    killTimer(timer_id);
# Line 904  void QMyMainWindow::mouseReleaseEvent(QM Line 920  void QMyMainWindow::mouseReleaseEvent(QM
920      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON3, e->x(), e->y());      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON3, e->x(), e->y());
921  }  }
922    
923  //*****************************************************************************  /******************************************************************************/
924  void QMyMainWindow::wheelEvent(QWheelEvent* e)  void QMyMainWindow::wheelEvent(QWheelEvent* e)
925  {  {
926    if (e->delta() > 0)    if (e->delta() > 0)
# Line 913  void QMyMainWindow::wheelEvent(QWheelEve Line 929  void QMyMainWindow::wheelEvent(QWheelEve
929      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON5, e->x(), e->y());      rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON5, e->x(), e->y());
930  }  }
931    
932  #define NOT(x) (255-(x))  #define NOT(x) (~x)
933    
934  //*****************************************************************************  /******************************************************************************/
935  uint8 rop(int rop, uint8 src, uint8 dst)  int rop(int rop, int src, int dst)
936  {  {
937    switch (rop)    switch (rop)
938    {    {
# Line 941  uint8 rop(int rop, uint8 src, uint8 dst) Line 957  uint8 rop(int rop, uint8 src, uint8 dst)
957  }  }
958    
959  /*****************************************************************************/  /*****************************************************************************/
960  uint8 get_pixel(int x, int y)  int get_pixel(int x, int y)
961  {  {
962    if (x >= 0 && x < g_width && y >= 0 && y < g_height)    if (x >= 0 && x < g_width && y >= 0 && y < g_height)
963      return g_BS[y * g_width + x];    {
964        if (g_server_bpp == 8)
965          return g_BS[y * g_width + x];
966        else if (g_server_bpp == 16)
967          return *(((uint16*)g_BS) + (y * g_width + x));
968        else if (g_server_bpp == 24)
969          return *(((uint32*)g_BS) + (y * g_width + x));
970        else
971          return 0;
972      }
973    else    else
974      return 0;      return 0;
975  }  }
976    
977  //*****************************************************************************  /******************************************************************************/
978  void set_pixel(int x, int y, uint8 pixel, int op = 0xc)  void set_pixel(int x, int y, int pixel, int op = 0xc)
979  {  {
980      uint32 p;
981    
982    if (x >= g_clipx && x < (g_clipx + g_clipcx) &&    if (x >= g_clipx && x < (g_clipx + g_clipcx) &&
983        y >= g_clipy && y < (g_clipy + g_clipcy))        y >= g_clipy && y < (g_clipy + g_clipcy))
984      {
985      if (x >= 0 && x < g_width && y >= 0 && y < g_height)      if (x >= 0 && x < g_width && y >= 0 && y < g_height)
986        {
987        if (op == 0xc)        if (op == 0xc)
988          g_BS[y * g_width + x] = pixel;        {
989            if (g_server_bpp == 8)
990            {
991              SETPIXEL8(g_BS, x, y, g_width, pixel);
992            }
993            else if (g_server_bpp == 16)
994            {
995              SETPIXEL16(g_BS, x, y, g_width, pixel);
996            }
997            else if (g_server_bpp == 24)
998            {
999              SETPIXEL32(g_BS, x, y, g_width, pixel);
1000            }
1001          }
1002        else        else
1003          g_BS[y * g_width + x] = rop(op, pixel, g_BS[y * g_width + x]);        {
1004            if (g_server_bpp == 8)
1005            {
1006              p = GETPIXEL8(g_BS, x, y, g_width);
1007              p = rop(op, pixel, p);
1008              SETPIXEL8(g_BS, x, y, g_width, p);
1009            }
1010            else if (g_server_bpp == 16)
1011            {
1012              p = GETPIXEL16(g_BS, x, y, g_width);
1013              p = rop(op, pixel, p);
1014              SETPIXEL16(g_BS, x, y, g_width, p);
1015            }
1016            else if (g_server_bpp == 24)
1017            {
1018              p = GETPIXEL32(g_BS, x, y, g_width);
1019              p = rop(op, pixel, p);
1020              SETPIXEL32(g_BS, x, y, g_width, p);
1021            }
1022          }
1023        }
1024      }
1025  }  }
1026    
1027  //******************************************************************************  /******************************************************************************/
1028  // adjust coordinates for cliping rect  // adjust coordinates for cliping rect
1029  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)
1030  {  {
1031    int dx, dy;    int dx, dy;
1032    QRect InRect(*x, *y, *cx, *cy);    QRect InRect(*x, *y, *cx, *cy);
# Line 985  bool WarpCoords(int* x, int* y, int* cx, Line 1048  bool WarpCoords(int* x, int* y, int* cx,
1048    return true;    return true;
1049  }  }
1050    
1051  //*****************************************************************************  /******************************************************************************/
1052  void QMyMainWindow::paintEvent(QPaintEvent* pe)  uint32 color16to32(uint32 colour)
1053  {  {
1054    QImage* Image;    uint32 r, g, b;
1055    QPainter* Painter;    r = ((colour >> 8) & 0xf8) | ((colour >> 13) & 0x7);
1056      g = ((colour >> 3) & 0xfc) | ((colour >> 9) & 0x3);
1057      b = ((colour << 3) & 0xf8) | ((colour >> 2) & 0x7);
1058      return ((r << 16) | (g << 8) | b);
1059    }
1060    
1061    /******************************************************************************/
1062    uint32 color24to32(uint32 colour)
1063    {
1064      uint32 r, g, b;
1065      r = (colour >> 0) & 0xff;
1066      g = (colour >> 8) & 0xff;
1067      b = (colour >> 16) & 0xff;
1068      return ((r << 16) | (g << 8) | b);
1069    }
1070    
1071    /******************************************************************************/
1072    void QMyMainWindow::paintEvent(QPaintEvent * pe)
1073    {
1074      QImage * Image;
1075      QPainter * Painter;
1076    QRect Rect;    QRect Rect;
1077    int i, j, w, h, l, t;    int i, j, w, h, l, t;
1078    uint8* data;    int pixel;
1079      uint8 * data;
1080    
1081      Image = 0;
1082      data = 0;
1083    if (!testWFlags(WRepaintNoErase))    if (!testWFlags(WRepaintNoErase))
1084      setWFlags(WRepaintNoErase);      setWFlags(WRepaintNoErase);
1085    if (g_CM != NULL)    if (g_CM != NULL || g_server_bpp > 8)
1086    {    {
1087      Rect = pe->rect();      Rect = pe->rect();
1088      l = Rect.left();      l = Rect.left();
1089      t = Rect.top();      t = Rect.top();
1090      w = Rect.width();      w = Rect.width();
1091      h = Rect.height();      h = Rect.height();
1092      if (w > 0 && h > 0 && g_CM->NumColors > 0)      if (w > 0 && h > 0)
1093      {      {
1094        w = (w + 3) & ~3;        if (g_server_bpp == 8 && g_CM->NumColors > 0)
1095        data = (uint8*)xmalloc(w * h);        {
1096        for (i = 0; i < h; i++)          w = (w + 3) & ~3;
1097          for (j = 0; j < w; j++)          data = (uint8*)xmalloc(w * h);
1098            data[i * w + j] = get_pixel(l + j, t + i);          for (i = 0; i < h; i++)
1099        Image = new QImage(data, w, h, 8,(QRgb*)g_CM->RGBColors,            for (j = 0; j < w; j++)
1100                           g_CM->NumColors, QImage::IgnoreEndian);              data[i * w + j] = get_pixel(l + j, t + i);
1101        Painter = new QPainter(this);          Image = new QImage(data, w, h, 8,(QRgb*)g_CM->RGBColors,
1102        Painter->drawImage(l, t, *Image, 0, 0, w, h);                             g_CM->NumColors, QImage::IgnoreEndian);
1103          }
1104          else if (g_server_bpp == 16)
1105          {
1106            w = (w + 3) & ~3;
1107            data = (uint8*)xmalloc(w * h * 4);
1108            for (i = 0; i < h; i++)
1109              for (j = 0; j < w; j++)
1110              {
1111                pixel = GETPIXEL16(g_BS, l + j, t + i, g_width);
1112                pixel = color16to32(pixel);
1113                SETPIXEL32(data, j, i, w, pixel);
1114              }
1115            Image = new QImage(data, w, h, 32, NULL,
1116                               0, QImage::IgnoreEndian);
1117          }
1118          else if (g_server_bpp == 24)
1119          {
1120            w = (w + 3) & ~3;
1121            data = (uint8*)xmalloc(w * h * 4);
1122            for (i = 0; i < h; i++)
1123              for (j = 0; j < w; j++)
1124              {
1125                pixel = GETPIXEL32(g_BS, l + j, t + i, g_width);
1126                pixel = color24to32(pixel);
1127                SETPIXEL32(data, j, i, w, pixel);
1128              }
1129            Image = new QImage(data, w, h, 32, NULL,
1130                               0, QImage::IgnoreEndian);
1131          }
1132          if (Image != 0)
1133          {
1134            Painter = new QPainter(this);
1135            Painter->drawImage(l, t, *Image, 0, 0, w, h);
1136            delete Painter;
1137            delete Image;
1138          }
1139        xfree(data);        xfree(data);
       delete Painter;  
       delete Image;  
1140      }      }
1141    }    }
1142  }  }
1143    
1144  //*****************************************************************************  /******************************************************************************/
1145  void QMyMainWindow::closeEvent(QCloseEvent* e)  void QMyMainWindow::closeEvent(QCloseEvent * e)
1146  {  {
1147    e->accept();    e->accept();
1148  }  }
1149    
1150  //*****************************************************************************  /******************************************************************************/
1151  void QMyMainWindow::dataReceived()  void QMyMainWindow::dataReceived()
1152  {  {
1153    if (!rdp_loop(&g_deactivated, &g_ext_disc_reason))    if (!rdp_loop(&g_deactivated, &g_ext_disc_reason))
1154      g_SV->close();      g_SV->close();
1155    #ifdef WITH_RDPSND
1156      if (g_dsp_busy)
1157      {
1158        if (g_SoundNotifier == 0)
1159        {
1160          g_SoundNotifier = new QSocketNotifier(g_dsp_fd, QSocketNotifier::Write,
1161                                                g_MW);
1162          g_MW->connect(g_SoundNotifier, SIGNAL(activated(int)), g_MW,
1163                        SLOT(soundSend()));
1164        }
1165        else
1166        {
1167          if (!g_SoundNotifier->isEnabled())
1168            g_SoundNotifier->setEnabled(true);
1169        }
1170      }
1171    #endif
1172    }
1173    
1174    /******************************************************************************/
1175    void QMyMainWindow::soundSend()
1176    {
1177      g_SoundNotifier->setEnabled(false);
1178    #ifdef WITH_RDPSND
1179      wave_out_play();
1180      if (g_dsp_busy)
1181        g_SoundNotifier->setEnabled(true);
1182    #endif
1183  }  }
1184    
1185  //*****************************************************************************  /******************************************************************************/
1186  void redraw(int x, int y, int cx, int cy)  void redraw(int x, int y, int cx, int cy)
1187  {  {
1188    if (WarpCoords(&x, &y, &cx, &cy, NULL, NULL))    if (WarpCoords(&x, &y, &cx, &cy, NULL, NULL))
# Line 1043  void redraw(int x, int y, int cx, int cy Line 1191  void redraw(int x, int y, int cx, int cy
1191    }    }
1192  }  }
1193    
1194  //*****************************************************************************  /******************************************************************************/
1195  /* Returns 0 after user quit, 1 otherwise */  /* Returns 0 after user quit, 1 otherwise */
1196  int ui_select(int rdp_socket)  int ui_select(int rdp_socket)
1197  {  {
1198    g_global_sock = rdp_socket;    if (g_global_sock == 0)
1199        g_global_sock = rdp_socket;
1200    return 1;    return 1;
1201  }  }
1202    
1203  //*****************************************************************************  /******************************************************************************/
1204  void ui_move_pointer(int /*x*/, int /*y*/)  void ui_move_pointer(int /*x*/, int /*y*/)
1205  {  {
1206  }  }
1207    
1208  /*****************************************************************************/  /******************************************************************************/
1209  void ui_set_null_cursor(void)  void ui_set_null_cursor(void)
1210  {  {
1211  }  }
1212    
1213  //*****************************************************************************  /******************************************************************************/
1214  HBITMAP ui_create_bitmap(int width, int height, uint8 * data)  HBITMAP ui_create_bitmap(int width, int height, uint8 * data)
1215  {  {
1216    struct bitmap* the_bitmap;    struct bitmap * the_bitmap;
1217    uint8* bitmap_data;    uint8 * bitmap_data;
1218    int i, j;    int i, j;
1219      int r, g, b, pixel;
1220    
1221    bitmap_data = (uint8*)xmalloc(width * height);    bitmap_data = (uint8*)xmalloc(width * height * 4);
1222    the_bitmap = (struct bitmap*)xmalloc(sizeof(struct bitmap));    the_bitmap = (struct bitmap*)xmalloc(sizeof(struct bitmap));
1223    the_bitmap->w = width;    the_bitmap->w = width;
1224    the_bitmap->h = height;    the_bitmap->h = height;
1225    the_bitmap->data = bitmap_data;    the_bitmap->data = bitmap_data;
1226    for (i = 0; i < height; i++)    if (g_server_bpp == 8)
1227      for (j = 0; j < width; j++)    {
1228        bitmap_data[i * width + j] = data[i * width + j];      for (i = 0; i < height; i++)
1229          for (j = 0; j < width; j++)
1230            bitmap_data[i * width + j] = data[i * width + j];
1231      }
1232      else if (g_server_bpp == 16)
1233      {
1234        for (i = 0; i < height; i++)
1235          for (j = 0; j < width; j++)
1236            *(((uint16*)bitmap_data) + (i * width + j)) =
1237                         *(((uint16*)data) + (i * width + j));
1238      }
1239      else if (g_server_bpp == 24)
1240      {
1241        for (i = 0; i < height; i++)
1242          for (j = 0; j < width; j++)
1243          {
1244            r = data[(i * width + j) * 3 + 0];
1245            g = data[(i * width + j) * 3 + 1];
1246            b = data[(i * width + j) * 3 + 2];
1247            pixel = (r << 16) | (g << 8) | b;
1248            SETPIXEL32(bitmap_data, j, i, width, pixel);
1249          }
1250      }
1251    return the_bitmap;    return the_bitmap;
1252  }  }
1253    
1254  //*****************************************************************************  /******************************************************************************/
1255  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,
1256                       int height, uint8 * data)                       int height, uint8 * data)
1257  {  {
1258    int i, j;    int i, j;
1259      int r, g, b, pixel;
1260    
1261    for (i = 0; i < cy; i++)    if (g_server_bpp == 8)
1262      for (j = 0; j < cx; j++)    {
1263        if (i < height)      for (i = 0; i < cy; i++)
1264          if (j < width)        for (j = 0; j < cx; j++)
1265            set_pixel(x + j, y + i, data[i * width + j]);          if (i < height)
1266              if (j < width)
1267                set_pixel(x + j, y + i, data[i * width + j]);
1268      }
1269      else if (g_server_bpp == 16)
1270      {
1271        for (i = 0; i < cy; i++)
1272          for (j = 0; j < cx; j++)
1273            if (i < height)
1274              if (j < width)
1275                set_pixel(x + j, y + i, *(((uint16*)data) + (i * width + j)));
1276      }
1277      else if (g_server_bpp == 24)
1278      {
1279        for (i = 0; i < cy; i++)
1280          for (j = 0; j < cx; j++)
1281            if (i < height)
1282              if (j < width)
1283              {
1284                r = data[(i * width + j) * 3 + 0];
1285                g = data[(i * width + j) * 3 + 1];
1286                b = data[(i * width + j) * 3 + 2];
1287                pixel = (r << 16) | (g << 8) | b;
1288                set_pixel(x + j, y + i, pixel);
1289              }
1290      }
1291    redraw(x, y, cx, cy);    redraw(x, y, cx, cy);
1292  }  }
1293    
1294  //*****************************************************************************  /******************************************************************************/
1295  void ui_destroy_bitmap(HBITMAP bmp)  void ui_destroy_bitmap(HBITMAP bmp)
1296  {  {
1297    struct bitmap* the_bitmap;    struct bitmap* the_bitmap;
# Line 1107  void ui_destroy_bitmap(HBITMAP bmp) Line 1305  void ui_destroy_bitmap(HBITMAP bmp)
1305    }    }
1306  }  }
1307    
1308  //*****************************************************************************  /******************************************************************************/
1309  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)
1310  {  {
1311    int start, shift;    int start, shift;
1312    
# Line 1125  bool is_pixel_on(uint8* data, int x, int Line 1323  bool is_pixel_on(uint8* data, int x, int
1323      return false;      return false;
1324  }  }
1325    
1326  //*****************************************************************************  /******************************************************************************/
1327  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)
1328  {  {
1329    if (bpp == 8)    if (bpp == 8)
1330      data[y * width + x] = pixel;      data[y * width + x] = pixel;
1331  }  }
1332    
1333  //*****************************************************************************  /******************************************************************************/
1334  HGLYPH ui_create_glyph(int width, int height, uint8 * data)  HGLYPH ui_create_glyph(int width, int height, uint8 * data)
1335  {  {
1336    int i, j;    int i, j;
# Line 1152  HGLYPH ui_create_glyph(int width, int he Line 1350  HGLYPH ui_create_glyph(int width, int he
1350    return the_glyph;    return the_glyph;
1351  }  }
1352    
1353  //*****************************************************************************  /******************************************************************************/
1354  void ui_destroy_glyph(HGLYPH glyph)  void ui_destroy_glyph(HGLYPH glyph)
1355  {  {
1356    struct bitmap* the_glyph;    struct bitmap* the_glyph;
# Line 1166  void ui_destroy_glyph(HGLYPH glyph) Line 1364  void ui_destroy_glyph(HGLYPH glyph)
1364    }    }
1365  }  }
1366    
1367  //*****************************************************************************  /******************************************************************************/
1368  HCURSOR ui_create_cursor(unsigned int x, unsigned int y,  HCURSOR ui_create_cursor(uint32 x, uint32 y,
1369                           int width, int height, uint8 * andmask,                           int width, int height,
1370                           uint8 * xormask)                           uint8 * andmask, uint8 * xormask)
1371  {  {
1372    return (void*)1;    return (void*)1;
1373  }  }
1374    
1375  //*****************************************************************************  /******************************************************************************/
1376  void ui_set_cursor(HCURSOR /*cursor*/)  void ui_set_cursor(HCURSOR /*cursor*/)
1377  {  {
1378  }  }
1379    
1380  /*****************************************************************************/  /*****************************************************************************/
1381  uint16 ui_get_numlock_state(unsigned int state)  uint16 ui_get_numlock_state(uint32 state)
1382  {  {
1383    return 0;    return 0;
1384  }  }
# Line 1195  unsigned int read_keyboard_state(void) Line 1393  unsigned int read_keyboard_state(void)
1393  void ui_resize_window(void)  void ui_resize_window(void)
1394  {  {
1395  }  }
1396  //*****************************************************************************  
1397    /******************************************************************************/
1398  void ui_destroy_cursor(HCURSOR /*cursor*/)  void ui_destroy_cursor(HCURSOR /*cursor*/)
1399  {  {
1400  }  }
1401    
1402  //*****************************************************************************  /******************************************************************************/
1403  HCOLOURMAP ui_create_colourmap(COLOURMAP * colours)  HCOLOURMAP ui_create_colourmap(COLOURMAP * colours)
1404  {  {
1405    int i;    int i;
# Line 1220  HCOLOURMAP ui_create_colourmap(COLOURMAP Line 1419  HCOLOURMAP ui_create_colourmap(COLOURMAP
1419    return g_CM;    return g_CM;
1420  }  }
1421    
1422  //*****************************************************************************  /******************************************************************************/
1423  void ui_destroy_colourmap(HCOLOURMAP /*map*/)  void ui_set_colourmap(HCOLOURMAP map)
1424  {  {
1425  }  }
1426    
1427  //*****************************************************************************  /******************************************************************************/
1428  void ui_set_colourmap(HCOLOURMAP /*map*/)  void ui_destroy_colourmap(HCOLOURMAP map)
1429  {  {
1430  }  }
1431    
1432  //*****************************************************************************  /******************************************************************************/
1433  void ui_begin_update(void)  void ui_begin_update(void)
1434  {  {
1435  }  }
1436    
1437  //*****************************************************************************  /******************************************************************************/
1438  void ui_end_update(void)  void ui_end_update(void)
1439  {  {
1440  }  }
1441    
1442  //*****************************************************************************  /******************************************************************************/
1443  void ui_set_clip(int x, int y, int cx, int cy)  void ui_set_clip(int x, int y, int cx, int cy)
1444  {  {
1445    g_clipx = x;    g_clipx = x;
# Line 1249  void ui_set_clip(int x, int y, int cx, i Line 1448  void ui_set_clip(int x, int y, int cx, i
1448    g_clipcy = cy;    g_clipcy = cy;
1449  }  }
1450    
1451  //*****************************************************************************  /******************************************************************************/
1452  void ui_reset_clip(void)  void ui_reset_clip(void)
1453  {  {
1454    g_clipx = 0;    g_clipx = 0;
# Line 1258  void ui_reset_clip(void) Line 1457  void ui_reset_clip(void)
1457    g_clipcy = g_height;    g_clipcy = g_height;
1458  }  }
1459    
1460  //*****************************************************************************  /******************************************************************************/
1461  void ui_bell(void)  void ui_bell(void)
1462  {  {
1463    g_App->beep();    g_App->beep();
1464  }  }
1465    
1466  //*****************************************************************************  /******************************************************************************/
1467  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)
1468  {  {
1469    int i, j;    int i, j;
# Line 1275  void ui_destblt(uint8 opcode, int x, int Line 1474  void ui_destblt(uint8 opcode, int x, int
1474    redraw(x, y, cx, cy);    redraw(x, y, cx, cy);
1475  }  }
1476    
1477  //*****************************************************************************  /******************************************************************************/
1478  // does not repaint  // does not repaint
1479  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)
1480  {  {
1481    int i, j;    int i, j;
1482    
1483      if (x + cx > g_width)
1484        cx = g_width - x;
1485      if (y + cy > g_height)
1486        cy = g_height - y;
1487    for (i = 0; i < cy; i++)    for (i = 0; i < cy; i++)
1488      for (j = 0; j < cx; j++)      for (j = 0; j < cx; j++)
1489        set_pixel(x + j, y + i, colour, opcode);        set_pixel(x + j, y + i, colour, opcode);
1490  }  }
1491    
1492  //*****************************************************************************  /******************************************************************************/
1493  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)
1494  {  {
1495    fill_rect(x, y, cx, cy, colour);    fill_rect(x, y, cx, cy, colour);
1496    redraw(x, y, cx, cy);    redraw(x, y, cx, cy);
1497  }  }
1498    
1499  //*****************************************************************************  /******************************************************************************/
1500  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,
1501                 BRUSH * brush, int bgcolour, int fgcolour)                 BRUSH * brush, int bgcolour, int fgcolour)
1502  {  {
# Line 1320  void ui_patblt(uint8 opcode, int x, int Line 1523  void ui_patblt(uint8 opcode, int x, int
1523    redraw(x, y, cx, cy);    redraw(x, y, cx, cy);
1524  }  }
1525    
1526  //*****************************************************************************  /******************************************************************************/
1527  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,
1528                    int srcx, int srcy)                    int srcx, int srcy)
1529  {  {
1530    int i, j;    int i, j;
1531    uint8* temp;    uint8 * temp;
1532    
1533    temp = (uint8*)xmalloc(cx * cy);    temp = (uint8*)xmalloc(cx * cy * (BPP + 1));
1534    for (i = 0; i < cy; i++)    if (g_server_bpp == 8)
1535      for (j = 0; j < cx; j++)    {
1536        temp[i * cx + j] = get_pixel(srcx + j, srcy + i);      for (i = 0; i < cy; i++)
1537    for (i = 0; i < cy; i++)        for (j = 0; j < cx; j++)
1538      for (j = 0; j < cx; j++)          temp[i * cx + j] = get_pixel(srcx + j, srcy + i);
1539        set_pixel(x + j, y + i, temp[i * cx + j], opcode);      for (i = 0; i < cy; i++)
1540          for (j = 0; j < cx; j++)
1541            set_pixel(x + j, y + i, temp[i * cx + j], opcode);
1542      }
1543      else if (g_server_bpp == 16)
1544      {
1545        for (i = 0; i < cy; i++)
1546          for (j = 0; j < cx; j++)
1547            *(((uint16*)temp) + (i * cx + j)) = get_pixel(srcx + j, srcy + i);
1548        for (i = 0; i < cy; i++)
1549          for (j = 0; j < cx; j++)
1550            set_pixel(x + j, y + i, *(((uint16*)temp) + (i * cx + j)), opcode);
1551      }
1552      else if (g_server_bpp == 24)
1553      {
1554        for (i = 0; i < cy; i++)
1555          for (j = 0; j < cx; j++)
1556            *(((uint32*)temp) + (i * cx + j)) = get_pixel(srcx + j, srcy + i);
1557        for (i = 0; i < cy; i++)
1558          for (j = 0; j < cx; j++)
1559            set_pixel(x + j, y + i, *(((uint32*)temp) + (i * cx + j)), opcode);
1560      }
1561    xfree(temp);    xfree(temp);
1562    redraw(x, y, cx, cy);    redraw(x, y, cx, cy);
1563  }  }
1564    
1565  //*****************************************************************************  /******************************************************************************/
1566  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,
1567                 HBITMAP src, int srcx, int srcy)                 HBITMAP src, int srcx, int srcy)
1568  {  {
1569    int i, j;    int i, j;
1570    struct bitmap* the_bitmap;    struct bitmap * the_bitmap;
1571    
1572    the_bitmap = (struct bitmap*)src;    the_bitmap = (struct bitmap*)src;
1573    if (the_bitmap == NULL)    if (the_bitmap == NULL)
1574      return;      return;
1575    for (i = 0; i < cy; i++)    if (g_server_bpp == 8)
1576      for (j = 0; j < cx; j++)    {
1577        if ((i + srcy) < the_bitmap->h && (j + srcx) < the_bitmap->w)      for (i = 0; i < cy; i++)
1578          set_pixel(x + j, y + i,        for (j = 0; j < cx; j++)
1579                    the_bitmap->data[(i + srcy) * the_bitmap->w + (j + srcx)],          if ((i + srcy) < the_bitmap->h && (j + srcx) < the_bitmap->w)
1580                    opcode);            set_pixel(x + j, y + i,
1581                        the_bitmap->data[(i + srcy) * the_bitmap->w + (j + srcx)],
1582                        opcode);
1583      }
1584      else if (g_server_bpp == 16)
1585      {
1586        for (i = 0; i < cy; i++)
1587          for (j = 0; j < cx; j++)
1588            if ((i + srcy) < the_bitmap->h && (j + srcx) < the_bitmap->w)
1589              set_pixel(x + j, y + i,
1590                        *(((uint16*)the_bitmap->data) + ((i + srcy) * the_bitmap->w + (j + srcx))),
1591                        opcode);
1592      }
1593      else if (g_server_bpp == 24)
1594      {
1595        for (i = 0; i < cy; i++)
1596          for (j = 0; j < cx; j++)
1597            if ((i + srcy) < the_bitmap->h && (j + srcx) < the_bitmap->w)
1598              set_pixel(x + j, y + i,
1599                        *(((uint32*)the_bitmap->data) + ((i + srcy) * the_bitmap->w + (j + srcx))),
1600                        opcode);
1601      }
1602    redraw(x, y, cx, cy);    redraw(x, y, cx, cy);
1603  }  }
1604    
1605  //*****************************************************************************  /******************************************************************************/
1606  // not used  // not used
1607  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,
1608                 HBITMAP src, int srcx, int srcy, BRUSH * brush,                 HBITMAP src, int srcx, int srcy, BRUSH * brush,
# Line 1365  void ui_triblt(uint8 opcode, int x, int Line 1610  void ui_triblt(uint8 opcode, int x, int
1610  {  {
1611  }  }
1612    
1613  //*****************************************************************************  /******************************************************************************/
1614  // Bresenham's line drawing algorithm  /* Bresenham's line drawing algorithm */
1615  void ui_line(uint8 opcode, int startx, int starty, int endx,  void ui_line(uint8 opcode, int startx, int starty, int endx,
1616               int endy, PEN * pen)               int endy, PEN * pen)
1617  {  {
# Line 1445  void ui_line(uint8 opcode, int startx, i Line 1690  void ui_line(uint8 opcode, int startx, i
1690    redraw(left, top, (right - left) + 1, (bottom - top) + 1);    redraw(left, top, (right - left) + 1, (bottom - top) + 1);
1691  }  }
1692    
1693  //*****************************************************************************  /******************************************************************************/
1694  void draw_glyph (int x, int y, HGLYPH glyph, int fgcolour)  void draw_glyph (int x, int y, HGLYPH glyph, int fgcolour)
1695  {  {
1696    struct bitmap* the_glyph;    struct bitmap *the_glyph;
1697    int i, j;    int i, j;
1698    
1699    the_glyph = (struct bitmap*)glyph;    the_glyph = (struct bitmap*)glyph;
# Line 1490  void draw_glyph (int x, int y, HGLYPH gl Line 1735  void draw_glyph (int x, int y, HGLYPH gl
1735      }\      }\
1736  }  }
1737    
1738  //*****************************************************************************  /******************************************************************************/
1739  void ui_draw_text(uint8 font, uint8 flags, int mixmode,  void ui_draw_text(uint8 font, uint8 flags, int mixmode,
1740                    int x, int y, int clipx, int clipy,                    int x, int y, int clipx, int clipy,
1741                    int clipcx, int clipcy, int boxx,                    int clipcx, int clipcy, int boxx,
# Line 1561  void ui_draw_text(uint8 font, uint8 flag Line 1806  void ui_draw_text(uint8 font, uint8 flag
1806      redraw(clipx, clipy, clipcx, clipcy);      redraw(clipx, clipy, clipcx, clipcy);
1807  }  }
1808    
1809  //*****************************************************************************  /******************************************************************************/
1810  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)
1811  {  {
1812    uint8* data;    uint8 * data;
1813    int i, j;    int i, j;
1814      int Bpp;
1815    
1816    data = (uint8*)xmalloc(cx * cy);    Bpp = 4;
1817    for (i = 0; i < cy; i++)    switch (g_server_bpp)
1818      for (j = 0; j < cx; j++)    {
1819        data[i * cx + j] = get_pixel(x + j, y + i);      case 8: Bpp = 1; break;
1820    cache_put_desktop(offset, cx, cy, cx, 1, data);      case 15: Bpp = 2; break;
1821        case 16: Bpp = 2; break;
1822      }
1823      data = (uint8*)xmalloc(cx * cy * Bpp);
1824      if (g_server_bpp == 8)
1825      {
1826        for (i = 0; i < cy; i++)
1827          for (j = 0; j < cx; j++)
1828            data[i * cx + j] = get_pixel(x + j, y + i);
1829      }
1830      else if (g_server_bpp == 16)
1831      {
1832        for (i = 0; i < cy; i++)
1833          for (j = 0; j < cx; j++)
1834            *(((uint16*)data) + (i * cx + j)) = get_pixel(x + j, y + i);
1835      }
1836      else if (g_server_bpp == 24)
1837      {
1838        for (i = 0; i < cy; i++)
1839          for (j = 0; j < cx; j++)
1840            *(((uint32*)data) + (i * cx + j)) = get_pixel(x + j, y + i);
1841      }
1842      offset *= Bpp;
1843      cache_put_desktop(offset, cx, cy, cx * Bpp, Bpp, data);
1844    xfree(data);    xfree(data);
1845  }  }
1846    
1847  //*****************************************************************************  /******************************************************************************/
1848  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)
1849  {  {
1850    uint8* data;    uint8* data;
1851    int i, j;    int i, j;
1852      int Bpp;
1853    
1854    data = cache_get_desktop(offset, cx, cy, 1);    Bpp = 4;
1855    for (i = 0; i < cy; i++)    switch (g_server_bpp)
1856      for (j = 0; j < cx; j++)    {
1857        set_pixel(x + j, y + i, data[i * cx + j]);      case 8: Bpp = 1; break;
1858        case 15: Bpp = 2; break;
1859        case 16: Bpp = 2; break;
1860      }
1861      offset *= Bpp;
1862      data = cache_get_desktop(offset, cx, cy, Bpp);
1863      if (g_server_bpp == 8)
1864      {
1865        for (i = 0; i < cy; i++)
1866          for (j = 0; j < cx; j++)
1867            set_pixel(x + j, y + i, data[i * cx + j]);
1868      }
1869      else if (g_server_bpp == 16)
1870      {
1871        for (i = 0; i < cy; i++)
1872          for (j = 0; j < cx; j++)
1873            set_pixel(x + j, y + i, *(((uint16*)data) + (i * cx + j)));
1874      }
1875      else if (g_server_bpp == 24)
1876      {
1877        for (i = 0; i < cy; i++)
1878          for (j = 0; j < cx; j++)
1879            set_pixel(x + j, y + i, *(((uint32*)data) + (i * cx + j)));
1880      }
1881    redraw(x, y, cx, cy);    redraw(x, y, cx, cy);
1882  }  }
1883    
1884  /*****************************************************************************/  /*****************************************************************************/
1885  void* xrealloc(void* in_val, int size)  void* xrealloc(void *in_val, int size)
1886  {  {
1887      if (size < 1)
1888        size = 1;
1889    return realloc(in_val, size);    return realloc(in_val, size);
1890  }  }
1891    
# Line 1601  void* xmalloc(int size) Line 1896  void* xmalloc(int size)
1896  }  }
1897    
1898  /*****************************************************************************/  /*****************************************************************************/
1899  void xfree(void* in_val)  void xfree(void * in_val)
1900  {  {
1901    free(in_val);    if (in_val != NULL)
1902        free(in_val);
1903  }  }
1904    
1905  /*****************************************************************************/  /*****************************************************************************/
1906  void warning(char* format, ...)  void warning(char * format, ...)
1907  {  {
1908    va_list ap;    va_list ap;
1909    
# Line 1618  void warning(char* format, ...) Line 1914  void warning(char* format, ...)
1914  }  }
1915    
1916  /*****************************************************************************/  /*****************************************************************************/
1917  void unimpl(char* format, ...)  void unimpl(char * format, ...)
1918  {  {
1919    va_list ap;    va_list ap;
1920    
# Line 1629  void unimpl(char* format, ...) Line 1925  void unimpl(char* format, ...)
1925  }  }
1926    
1927  /*****************************************************************************/  /*****************************************************************************/
1928  void error(char* format, ...)  void error(char * format, ...)
1929  {  {
1930    va_list ap;    va_list ap;
1931    
# Line 1646  BOOL rd_pstcache_mkdir(void) Line 1942  BOOL rd_pstcache_mkdir(void)
1942  }  }
1943    
1944  /*****************************************************************************/  /*****************************************************************************/
1945  int rd_open_file(char *filename)  int rd_open_file(char * filename)
1946  {  {
1947    return 0;    return 0;
1948  }  }
# Line 1658  void rd_close_file(int fd) Line 1954  void rd_close_file(int fd)
1954  }  }
1955    
1956  /*****************************************************************************/  /*****************************************************************************/
1957  int rd_read_file(int fd, void *ptr, int len)  int rd_read_file(int fd, void * ptr, int len)
1958  {  {
1959    return 0;    return 0;
1960  }  }
1961    
1962  /*****************************************************************************/  /*****************************************************************************/
1963  int rd_write_file(int fd, void* ptr, int len)  int rd_write_file(int fd, void * ptr, int len)
1964  {  {
1965    return 0;    return 0;
1966  }  }
# Line 1682  BOOL rd_lock_file(int fd, int start, int Line 1978  BOOL rd_lock_file(int fd, int start, int
1978  }  }
1979    
1980  /*****************************************************************************/  /*****************************************************************************/
1981  void save_licence(uint8* data, int length)  int load_licence(uint8 ** data)
1982  {  {
1983      return 0;
1984  }  }
1985    
1986  /*****************************************************************************/  /*****************************************************************************/
1987  void generate_random(uint8* random)  void save_licence(uint8 * data, int length)
1988    {
1989    }
1990    
1991    /*****************************************************************************/
1992    void generate_random(uint8 * random)
1993  {  {
1994    QFile File("/dev/random");    QFile File("/dev/random");
1995    File.open(IO_ReadOnly);    File.open(IO_ReadOnly);
# Line 1698  void generate_random(uint8* random) Line 2000  void generate_random(uint8* random)
2000  }  }
2001    
2002  /*****************************************************************************/  /*****************************************************************************/
2003  int load_licence(uint8** data)  /* produce a hex dump */
2004    void hexdump(uint8 * p, uint32 len)
2005    {
2006      uint8 * line = p;
2007      int i, thisline;
2008      uint32 offset = 0;
2009    
2010      while (offset < len)
2011      {
2012        printf("%04x ", offset);
2013        thisline = len - offset;
2014        if (thisline > 16)
2015          thisline = 16;
2016    
2017        for (i = 0; i < thisline; i++)
2018          printf("%02x ", line[i]);
2019    
2020        for (; i < 16; i++)
2021          printf("   ");
2022    
2023        for (i = 0; i < thisline; i++)
2024          printf("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.');
2025    
2026        printf("\n");
2027        offset += thisline;
2028        line += thisline;
2029      }
2030    }
2031    
2032    /*****************************************************************************/
2033    void get_username_and_hostname(void)
2034    {
2035      char fullhostname[64];
2036      char* p;
2037      struct passwd* pw;
2038    
2039      STRNCPY(g_username, "unknown", sizeof(g_username));
2040      STRNCPY(g_hostname, "unknown", sizeof(g_hostname));
2041      pw = getpwuid(getuid());
2042      if (pw != NULL && pw->pw_name != NULL)
2043      {
2044        STRNCPY(g_username, pw->pw_name, sizeof(g_username));
2045      }
2046      if (gethostname(fullhostname, sizeof(fullhostname)) != -1)
2047      {
2048        p = strchr(fullhostname, '.');
2049        if (p != NULL)
2050          *p = 0;
2051        STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));
2052      }
2053    }
2054    
2055    /*****************************************************************************/
2056    void out_params(void)
2057    {
2058      fprintf(stderr, "qterdesktop: A Remote Desktop Protocol client.\n");
2059      fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2004 Matt Chapman.\n");
2060      fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");
2061      fprintf(stderr, "Usage: qterdesktop [options] server\n");
2062      fprintf(stderr, "   -g: desktop geometry (WxH)\n");
2063      fprintf(stderr, "   -4: use RDP version 4\n");
2064      fprintf(stderr, "   -5: use RDP version 5 (default)\n");
2065      fprintf(stderr, "   -t: tcp port)\n");
2066      fprintf(stderr, "   -a: connection colour depth\n");
2067    
2068      fprintf(stderr, "   -u: user name\n");
2069      fprintf(stderr, "   -d: domain\n");
2070      fprintf(stderr, "   -s: shell\n");
2071      fprintf(stderr, "   -c: working directory\n");
2072      fprintf(stderr, "   -p: password (- to prompt)\n");
2073      fprintf(stderr, "   -n: client hostname\n");
2074    
2075      fprintf(stderr, "\n");
2076    }
2077    
2078    /*****************************************************************************/
2079    int parse_parameters(int in_argc, char ** in_argv)
2080    {
2081      int i;
2082      char * p;
2083    
2084      for (i = 1; i < in_argc; i++)
2085      {
2086        strcpy(g_server, in_argv[i]);
2087        if (strcmp(in_argv[i], "-h") == 0)
2088        {
2089          out_params();
2090          return 0;
2091        }
2092        else if (strcmp(in_argv[i], "-g") == 0)
2093        {
2094          g_width = strtol(in_argv[i + 1], &p, 10);
2095          if (g_width <= 0)
2096          {
2097            error("invalid geometry\n");
2098            return 0;
2099          }
2100          if (*p == 'x')
2101            g_height = strtol(p + 1, NULL, 10);
2102          if (g_height <= 0)
2103          {
2104            error("invalid geometry\n");
2105            return 0;
2106          }
2107          g_width = (g_width + 3) & ~3;
2108        }
2109        else if (strcmp(in_argv[i], "-4") == 0)
2110          g_use_rdp5 = 0;
2111        else if (strcmp(in_argv[i], "-5") == 0)
2112          g_use_rdp5 = 1;
2113        else if (strcmp(in_argv[i], "-a") == 0)
2114        {
2115          g_server_bpp = strtol(in_argv[i + 1], &p, 10);
2116          if (g_server_bpp != 8 && g_server_bpp != 15 &&
2117              g_server_bpp != 16 && g_server_bpp != 24)
2118          {
2119            error("invalid bpp\n");
2120            return 0;
2121          }
2122        }
2123        else if (strcmp(in_argv[i], "-t") == 0)
2124          g_tcp_port_rdp = strtol(in_argv[i + 1], &p, 10);
2125    
2126        else if (strcmp(in_argv[i], "-u") == 0)
2127        {
2128          STRNCPY(g_username, in_argv[i + 1], sizeof(g_username));
2129        }
2130        else if (strcmp(in_argv[i], "-d") == 0)
2131        {
2132          STRNCPY(g_domain, in_argv[i + 1], sizeof(g_domain));
2133        }
2134        else if (strcmp(in_argv[i], "-s") == 0)
2135        {
2136          STRNCPY(g_shell, in_argv[i + 1], sizeof(g_shell));
2137        }
2138        else if (strcmp(in_argv[i], "-c") == 0)
2139        {
2140          STRNCPY(g_directory, in_argv[i + 1], sizeof(g_directory));
2141        }
2142        else if (strcmp(in_argv[i], "-p") == 0)
2143        {
2144          STRNCPY(g_password, in_argv[i + 1], sizeof(g_password));
2145          g_flags |= RDP_LOGON_AUTO;
2146        }
2147        else if (strcmp(in_argv[i], "-n") == 0)
2148        {
2149          STRNCPY(g_hostname, in_argv[i + 1], sizeof(g_hostname));
2150        }
2151      }
2152      return 1;
2153    }
2154    
2155    /******************************************************************************/
2156    int param_connect(void)
2157  {  {
2158      QWidget * Desktop;
2159      int dw, dh;
2160    
2161    #ifdef WITH_RDPSND
2162      rdpsnd_init();
2163    #endif
2164      if (rdp_connect(g_server, g_flags, g_domain, g_password, g_shell,
2165                      g_directory))
2166      {
2167        g_BS = (uint8*)xmalloc(g_width * g_height * 4);
2168        memset(g_BS, 0, g_width * g_height * 4);
2169        g_clipx = 0;
2170        g_clipy = 0;
2171        g_clipcx = g_width;
2172        g_clipcy = g_height;
2173        g_CM = (QColorMap*)xmalloc(sizeof(struct QColorMap));
2174        memset(g_CM, 0, sizeof(struct QColorMap));
2175        g_CM->NumColors = 256;
2176        g_MW = new QMyMainWindow();
2177        g_MW->resize(g_width, g_height);
2178        g_MW->show();
2179        g_SV->addChild(g_MW);
2180        g_MW->setMouseTracking(true);
2181        g_SocketNotifier = new QSocketNotifier(g_global_sock,
2182                                               QSocketNotifier::Read,
2183                                               g_MW);
2184        g_MW->connect(g_SocketNotifier, SIGNAL(activated(int)), g_MW,
2185                      SLOT(dataReceived()));
2186        if (g_fullscreen)
2187        {
2188          Desktop = g_App->desktop();
2189          dw = Desktop->width();
2190          dh = Desktop->height();
2191          if (dw == g_width && dh == g_height)
2192            g_MW->resize(g_width - 4, g_height - 4);
2193          g_SV->showFullScreen();
2194        }
2195        g_MW->setCursor((int)10); /* Qt::BlankCursor */
2196        g_App->exec();
2197      }
2198    return 0;    return 0;
2199  }  }
2200    
2201  //*****************************************************************************  /******************************************************************************/
2202  int main(int argc, char** argv)  int main(int argc, char ** argv)
2203  {  {
   g_CM = NULL;  
   g_BS = NULL;  
2204  #ifdef SHARP  #ifdef SHARP
2205    g_App = new QPEApplication(argc, argv);    g_App = new QPEApplication(argc, argv);
2206  #else  #else
# Line 1716  int main(int argc, char** argv) Line 2209  int main(int argc, char** argv)
2209    g_SV = new QMyScrollView();    g_SV = new QMyScrollView();
2210    g_App->setMainWidget(g_SV);    g_App->setMainWidget(g_SV);
2211    g_SV->showMaximized();    g_SV->showMaximized();
2212    g_SV->timer_id = g_SV->startTimer(1000);    if (argc > 1)
2213    g_App->exec();    {
2214        get_username_and_hostname();
2215        if (parse_parameters(argc, argv))
2216          param_connect();
2217      }
2218      else
2219      {
2220        g_SV->timer_id = g_SV->startTimer(1000); /* one sec delay, then dialog */
2221        g_MW->setCursor((int)10); /* Qt::BlankCursor */
2222        g_App->exec();
2223      }
2224    delete g_SV;    delete g_SV;
2225    delete g_App;    delete g_App;
2226    if (g_CM != NULL)    xfree(g_CM);
2227      xfree(g_CM);    xfree(g_BS);
   if (g_BS !=NULL)  
     xfree(g_BS);  
2228    return 0;    return 0;
2229  }  }

Legend:
Removed from v.776  
changed lines
  Added in v.791

  ViewVC Help
Powered by ViewVC 1.1.26