aboutsummaryrefslogtreecommitdiffstats
path: root/rfbplayer/rfbplayer.h
blob: e1c0b3d5c8b0d70d4ce11a8c0aa3400260e6423b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/* Copyright (C) 2004 TightVNC Team.  All Rights Reserved.
 *    
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this software; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
 * USA.
 */

// -=- RfbPlayer.h

#include <commdlg.h>
#include <windows.h>
#include <shellapi.h>

#include <rfb_win32/DIBSectionBuffer.h>

#include <rfbplayer/resource.h>
#include <rfbplayer/ToolBar.h>
#include <rfbplayer/rfbSessionReader.h>
#include <rfbplayer/GotoPosDialog.h>
#include <rfbplayer/ChoosePixelFormatDialog.h>
#include <rfbplayer/OptionsDialog.h>
#include <rfbplayer/InfoDialog.h>
#include <rfbplayer/SessionInfoDialog.h>

using namespace rfb;
using namespace rfb::win32;

class RfbPlayer : public RfbProto {
  public:
    RfbPlayer(char *fileName, PlayerOptions *options);
    ~RfbPlayer();

    // -=- Window Message handling

    LRESULT processMainMessage(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam);
    LRESULT processFrameMessage(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam);

    // -=- Window interface

    HWND getMainHandle() const {return mainHwnd;}
    HWND getFrameHandle() const {return frameHwnd;}
    void createToolBar(HWND parentHwnd);
    void disableTBandMenuItems();
    void enableTBandMenuItems();
    void setFrameSize(int width, int height);
    void setVisible(bool visible);
    void setTitle(const char *title);
    void calculateScrollBars();
    void close(const char* reason=0);
    void updatePos(long pos);
    void init();

    // -=- Coordinate conversions

    inline Point bufferToClient(const Point& p) {
      Point pos = p;
      if (client_size.width() > buffer->width())
        pos.x += (client_size.width() - buffer->width()) / 2;
      else if (client_size.width() < buffer->width())
        pos.x -= scrolloffset.x;
      if (client_size.height() > buffer->height())
        pos.y += (client_size.height() - buffer->height()) / 2;
      else if (client_size.height() < buffer->height())
        pos.y -= scrolloffset.y;
      return pos;
    }
    inline Rect bufferToClient(const Rect& r) {
      return Rect(bufferToClient(r.tl), bufferToClient(r.br));
    }

    inline Point clientToBuffer(const Point& p) {
      Point pos = p;
      if (client_size.width() > buffer->width())
        pos.x -= (client_size.width() - buffer->width()) / 2;
      else if (client_size.width() < buffer->width())
        pos.x += scrolloffset.x;
      if (client_size.height() > buffer->height())
        pos.y -= (client_size.height() - buffer->height()) / 2;
      else if (client_size.height() < buffer->height())
        pos.y += scrolloffset.y;
      return pos;
    }
    inline Rect clientToBuffer(const Rect& r) {
      return Rect(clientToBuffer(r.tl), clientToBuffer(r.br));
    }

    bool setViewportOffset(const Point& tl);

    // -=- RfbProto interface overrides

    virtual void processMsg();
    virtual void serverInit();
    virtual void frameBufferUpdateEnd();
    virtual void setColourMapEntries(int first, int count, U16* rgbs);
    virtual void serverCutText(const char* str, int len);
    virtual void bell();

    virtual void beginRect(const Rect& r, unsigned int encoding);
    virtual void endRect(const Rect& r, unsigned int encoding);
    virtual void fillRect(const Rect& r, Pixel pix);
    virtual void imageRect(const Rect& r, void* pixels);
    virtual void copyRect(const Rect& r, int srcX, int srcY);

    // -=- Player functions

    // calculateSessionTime() calculates the full session time in sec
    long calculateSessionTime(char *fileName);

    // closeSessionFile() closes the session file and blanks the frame buffer
    void closeSessionFile();

    // openSessionFile() opens the new session file and starts play it
    void openSessionFile(char *fileName);

    // skipHandshaking() - is implemented to skip the initial handshaking when
    // perform backward seeking OR replaying.
    void skipHandshaking();

    void blankBuffer();
    void rewind();
    void setPaused(bool paused);
    void stopPlayback();
    long getTimeOffset();
    bool isSeekMode();
    bool isSeeking();
    bool isPaused();
    long getSeekOffset();
    void setPos(long pos);
    void setSpeed(double speed);
    double getSpeed();

  protected:
    bool seekMode;
    bool stopped;
    long lastPos;
    bool sliderDraging;
    long sliderStepMs;
    char fullSessionTime[20];
    int time_pos_m;
    int time_pos_s;
    char *fileName;
    
    // rfbReader is a class which used to reading the rfb data from the file
    rfbSessionReader *rfbReader;

    // Returns true if part of the supplied rect is visible, false otherwise
    bool invalidateBufferRect(const Rect& crect);

    bool waitWhilePaused();

    // rewindFlag is a flag wich disable the update of the frame buffer window 
    // while the rewind is performing.
    bool rewindFlag;
    
    // Local window state
    HWND mainHwnd;
    HWND frameHwnd;
    HWND timeStatic;
    HWND speedEdit;
    HWND posTrackBar;
    HWND speedUpDown;
    HMENU hMenu;
    Rect window_size;
    Rect client_size;
    Point scrolloffset;
    Point maxscrolloffset;
    char *cutText;
    win32::DIBSectionBuffer* buffer;
    ToolBar tb;

    // The player's parameters
    PlayerOptions options;
    PixelFormatList supportedPF;
    long imageDataStartTime;
    long sessionTimeMs;
    int currentEncoding;
};

// -=- sessionTerminateThread class

// It is a special thread class, wich is allow the rfbSessionReader class
// terminate itself.

class sessionTerminateThread : public rfb::Thread {
public:
  sessionTerminateThread(RfbPlayer *_player) : player(_player) {
    setDeleteAfterRun();
  }
  virtual void run() {
    player->closeSessionFile();
  }
protected:
  RfbPlayer *player;
};