| 1 |
import tango.sys.win32.Types; |
|---|
| 2 |
import tango.stdc.stringz; |
|---|
| 3 |
|
|---|
| 4 |
struct SUMATRA_CREATE_PARAMS |
|---|
| 5 |
{ |
|---|
| 6 |
HWND pHandle; //parent. NULL means windowless mode |
|---|
| 7 |
int bSelection; //allow selection |
|---|
| 8 |
|
|---|
| 9 |
extern(Windows): |
|---|
| 10 |
int function(WindowInfo*) cbPageChanged; //notify our DLL when page is changed instead of doing the normal logic |
|---|
| 11 |
int function(WindowInfo*,int,void*) cbHandleLink; //1: goto (int*), 2: url (char*) |
|---|
| 12 |
void function(WindowInfo*,int) cbRepaint; //the display needs to be repainted |
|---|
| 13 |
void function(WindowInfo*,int,int,int,int,uint) cbSetScrollbarsSize; //this is for windowless mode |
|---|
| 14 |
void function(WindowInfo*,int) cbSetCursor; //1: arrow, 2: hand (pointer), 3: drag |
|---|
| 15 |
} |
|---|
| 16 |
|
|---|
| 17 |
enum DisplayMode { |
|---|
| 18 |
DM_FIRST = 1, |
|---|
| 19 |
DM_SINGLE_PAGE = DM_FIRST, |
|---|
| 20 |
DM_FACING, |
|---|
| 21 |
DM_CONTINUOUS, |
|---|
| 22 |
DM_CONTINUOUS_FACING, |
|---|
| 23 |
DM_LAST = DM_CONTINUOUS_FACING |
|---|
| 24 |
}; |
|---|
| 25 |
|
|---|
| 26 |
alias DisplayMode.DM_FIRST DM_FIRST; |
|---|
| 27 |
alias DisplayMode.DM_SINGLE_PAGE DM_SINGLE_PAGE; |
|---|
| 28 |
alias DisplayMode.DM_FACING DM_FACING; |
|---|
| 29 |
alias DisplayMode.DM_CONTINUOUS DM_CONTINUOUS; |
|---|
| 30 |
alias DisplayMode.DM_CONTINUOUS_FACING DM_CONTINUOUS_FACING; |
|---|
| 31 |
alias DisplayMode.DM_LAST DM_LAST; |
|---|
| 32 |
|
|---|
| 33 |
const ZOOM_FIT_PAGE = -1; |
|---|
| 34 |
const ZOOM_FIT_WIDTH = -2; |
|---|
| 35 |
const ZOOM_MAX = 6401.0; /* max zoom in % */ |
|---|
| 36 |
const ZOOM_MIN = 8.0; /* min zoom in % */ |
|---|
| 37 |
|
|---|
| 38 |
class Sumatra |
|---|
| 39 |
{ |
|---|
| 40 |
this(HWND parent=null) |
|---|
| 41 |
{ |
|---|
| 42 |
mHandle=Sumatra_Init(&SUMATRA_CREATE_PARAMS(parent,0,&cbPageChanged,&cbHandleLink,&cbRepaint,&cbSetScrollbarsSize,&cbSetCursor)); |
|---|
| 43 |
mSumatras[mHandle]=this; |
|---|
| 44 |
mSumatras.rehash; |
|---|
| 45 |
} |
|---|
| 46 |
~this(){Sumatra_Exit();} |
|---|
| 47 |
|
|---|
| 48 |
void loadFile(char[] pdfFile){if(mFile !is null) close; mFile=pdfFile.dup;return Sumatra_LoadPDF(mHandle,toStringz(pdfFile),0);} |
|---|
| 49 |
void loadBuffer(void[] buffer){if(mFile !is null) close; mFile="\0"; return Sumatra_LoadPDF(mHandle,cast(char*)buffer.ptr,buffer.length);} |
|---|
| 50 |
void print(){return Sumatra_Print(mHandle);} |
|---|
| 51 |
void print(char[] pdfFile, int showOptionWindow){return Sumatra_PrintPDF(mHandle,toStringz(pdfFile),showOptionWindow);} |
|---|
| 52 |
void displayMode(int displayMode){return Sumatra_SetDisplayMode(mHandle,displayMode);} |
|---|
| 53 |
int displayMode(){return Sumatra_GetDisplayMode(mHandle);} |
|---|
| 54 |
int nextPage(){return Sumatra_GoToNextPage(mHandle);} |
|---|
| 55 |
int prevPage(){return Sumatra_GoToPreviousPage(mHandle);} |
|---|
| 56 |
int firstPage(){return Sumatra_GoToFirstPage(mHandle);} |
|---|
| 57 |
int lastPage(){return Sumatra_GoToLastPage(mHandle);} |
|---|
| 58 |
int pages(){return Sumatra_GetNumberOfPages(mHandle);} |
|---|
| 59 |
int page(int pageNumber){return Sumatra_GoToThisPage(mHandle,pageNumber);} |
|---|
| 60 |
int page(){return Sumatra_GetCurrentPage(mHandle);} |
|---|
| 61 |
int zoomIn(){return Sumatra_ZoomIn(mHandle);} |
|---|
| 62 |
int zoomOut(){return Sumatra_ZoomOut(mHandle);} |
|---|
| 63 |
int zoom(int zoomValue){return Sumatra_SetZoom(mHandle,zoomValue);} |
|---|
| 64 |
int zoom(){return Sumatra_GetCurrentZoom(mHandle);} |
|---|
| 65 |
void resize(int w,int h){return Sumatra_Resize(mHandle,w,h);} |
|---|
| 66 |
void close(){mFile=null;return Sumatra_ClosePdf(mHandle);} |
|---|
| 67 |
void printDialog(){return Sumatra_ShowPrintDialog(mHandle);} |
|---|
| 68 |
|
|---|
| 69 |
HWND hwndCanvas(){return Sumatra_GetHwndCanvas(mHandle);} |
|---|
| 70 |
void render(HDC hdc,int x,int y,int w,int h) {Sumatra_Render(mHandle,hdc,x,y,w,h);} |
|---|
| 71 |
void scrollX(int type,int pos){Sumatra_ScrollX(mHandle,type,pos);} |
|---|
| 72 |
void scrollY(int type,int pos){Sumatra_ScrollY(mHandle,type,pos);} |
|---|
| 73 |
void mouseMove(int x,int y,uint flags){Sumatra_MouseMove(mHandle,x,y,flags);} |
|---|
| 74 |
void mouseDown(int x,int y,uint flags){Sumatra_MouseLeftDown(mHandle,x,y,flags);} |
|---|
| 75 |
void mouseUp(int x,int y,uint flags){Sumatra_MouseLeftUp(mHandle,x,y,flags);} |
|---|
| 76 |
WindowInfo* handle(){return mHandle;} |
|---|
| 77 |
|
|---|
| 78 |
void delegate(bool now) onRepaint; |
|---|
| 79 |
void delegate(int type) onSetCursor; |
|---|
| 80 |
int delegate() onPageChanged; |
|---|
| 81 |
void delegate(int type,int pos,int min,int max,uint page) onSetScrollbarSize; |
|---|
| 82 |
void delegate(double x,double y) onSetTotalDrawAreaSize; |
|---|
| 83 |
int delegate(int type,void* data) onHandleLink; |
|---|
| 84 |
|
|---|
| 85 |
protected: |
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
extern(Windows) static void cbRepaint(WindowInfo* win,int now) |
|---|
| 89 |
{ |
|---|
| 90 |
auto su=win in mSumatras; |
|---|
| 91 |
if(su && (*su).onRepaint) (*su).onRepaint(now!=0); |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
extern(Windows) static int cbPageChanged(WindowInfo* win) |
|---|
| 95 |
{ |
|---|
| 96 |
auto su=win in mSumatras; |
|---|
| 97 |
if(su && (*su).onPageChanged) return (*su).onPageChanged(); |
|---|
| 98 |
return 0; |
|---|
| 99 |
} |
|---|
| 100 |
|
|---|
| 101 |
extern(Windows) static void cbSetScrollbarsSize(WindowInfo* win,int type,int pos,int min,int max,uint page) |
|---|
| 102 |
{ |
|---|
| 103 |
auto su=win in mSumatras; |
|---|
| 104 |
if(su && (*su).onSetScrollbarSize) (*su).onSetScrollbarSize(type,pos,min,max,page); |
|---|
| 105 |
} |
|---|
| 106 |
|
|---|
| 107 |
extern(Windows) static void cbSetCursor(WindowInfo* win,int type) |
|---|
| 108 |
{ |
|---|
| 109 |
auto su=win in mSumatras; |
|---|
| 110 |
if(su && (*su).onSetCursor) (*su).onSetCursor(type); |
|---|
| 111 |
} |
|---|
| 112 |
|
|---|
| 113 |
extern(Windows) static int cbHandleLink(WindowInfo* win,int type,void* data) |
|---|
| 114 |
{ |
|---|
| 115 |
auto su=win in mSumatras; |
|---|
| 116 |
if(su && (*su).onHandleLink) return (*su).onHandleLink(type,data); |
|---|
| 117 |
else return 0; |
|---|
| 118 |
} |
|---|
| 119 |
|
|---|
| 120 |
char[] mFile; |
|---|
| 121 |
WindowInfo* mHandle; |
|---|
| 122 |
static Sumatra[WindowInfo*] mSumatras; |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|
| 125 |
extern(C): |
|---|
| 126 |
|
|---|
| 127 |
alias void WindowInfo; |
|---|
| 128 |
|
|---|
| 129 |
alias void function(WindowInfo* pdfWin, char *pdfFile, int size) Sumatra_LoadPDF_t; |
|---|
| 130 |
Sumatra_LoadPDF_t Sumatra_LoadPDF; |
|---|
| 131 |
alias void function(WindowInfo* pdfWin) Sumatra_Print_t; |
|---|
| 132 |
Sumatra_Print_t Sumatra_Print; |
|---|
| 133 |
alias void function(WindowInfo* pdfWin, char *pdfFile, int showOptionWindow) Sumatra_PrintPDF_t; |
|---|
| 134 |
Sumatra_PrintPDF_t Sumatra_PrintPDF; |
|---|
| 135 |
alias void function(WindowInfo* pdfWin, int displayMode) Sumatra_SetDisplayMode_t; |
|---|
| 136 |
Sumatra_SetDisplayMode_t Sumatra_SetDisplayMode; |
|---|
| 137 |
alias int function(WindowInfo* pdfWin) Sumatra_GetDisplayMode_t; |
|---|
| 138 |
Sumatra_GetDisplayMode_t Sumatra_GetDisplayMode; |
|---|
| 139 |
alias int function(WindowInfo* pdfWin) Sumatra_GoToNextPage_t; |
|---|
| 140 |
Sumatra_GoToNextPage_t Sumatra_GoToNextPage; |
|---|
| 141 |
alias int function(WindowInfo* pdfWin) Sumatra_GoToPreviousPage_t; |
|---|
| 142 |
Sumatra_GoToPreviousPage_t Sumatra_GoToPreviousPage; |
|---|
| 143 |
alias int function(WindowInfo* pdfWin) Sumatra_GoToFirstPage_t; |
|---|
| 144 |
Sumatra_GoToFirstPage_t Sumatra_GoToFirstPage; |
|---|
| 145 |
alias int function(WindowInfo* pdfWin) Sumatra_GoToLastPage_t; |
|---|
| 146 |
Sumatra_GoToLastPage_t Sumatra_GoToLastPage; |
|---|
| 147 |
alias int function(WindowInfo* pdfWin, int pageNumber) Sumatra_GoToThisPage_t; |
|---|
| 148 |
Sumatra_GoToThisPage_t Sumatra_GoToThisPage; |
|---|
| 149 |
alias int function(WindowInfo* pdfWin) Sumatra_GetNumberOfPages_t; |
|---|
| 150 |
Sumatra_GetNumberOfPages_t Sumatra_GetNumberOfPages; |
|---|
| 151 |
alias int function(WindowInfo* pdfWin) Sumatra_GetCurrentPage_t; |
|---|
| 152 |
Sumatra_GetCurrentPage_t Sumatra_GetCurrentPage; |
|---|
| 153 |
alias int function(WindowInfo* pdfWin) Sumatra_ZoomIn_t; |
|---|
| 154 |
Sumatra_ZoomIn_t Sumatra_ZoomIn; |
|---|
| 155 |
alias int function(WindowInfo* pdfWin) Sumatra_ZoomOut_t; |
|---|
| 156 |
Sumatra_ZoomOut_t Sumatra_ZoomOut; |
|---|
| 157 |
alias int function(WindowInfo* pdfWin, int zoomValue) Sumatra_SetZoom_t; |
|---|
| 158 |
Sumatra_SetZoom_t Sumatra_SetZoom; |
|---|
| 159 |
alias int function(WindowInfo* pdfWin) Sumatra_GetCurrentZoom_t; |
|---|
| 160 |
Sumatra_GetCurrentZoom_t Sumatra_GetCurrentZoom; |
|---|
| 161 |
alias void function(WindowInfo* pdfWin,int,int) Sumatra_Resize_t; |
|---|
| 162 |
Sumatra_Resize_t Sumatra_Resize; |
|---|
| 163 |
alias void function(WindowInfo* pdfWin) Sumatra_ClosePdf_t; |
|---|
| 164 |
Sumatra_ClosePdf_t Sumatra_ClosePdf; |
|---|
| 165 |
alias void function(WindowInfo* pdfWin) Sumatra_ShowPrintDialog_t; |
|---|
| 166 |
Sumatra_ShowPrintDialog_t Sumatra_ShowPrintDialog; |
|---|
| 167 |
alias WindowInfo* function(SUMATRA_CREATE_PARAMS*) Sumatra_Init_t; |
|---|
| 168 |
Sumatra_Init_t Sumatra_Init; |
|---|
| 169 |
alias void function() Sumatra_Exit_t; |
|---|
| 170 |
Sumatra_Exit_t Sumatra_Exit; |
|---|
| 171 |
alias HWND function(WindowInfo* pdfWin) Sumatra_GetHwndCanvas_t; |
|---|
| 172 |
Sumatra_GetHwndCanvas_t Sumatra_GetHwndCanvas; |
|---|
| 173 |
alias void function(WindowInfo *win, HDC hdc,int x,int y,int w,int h) Sumatra_Render_t; |
|---|
| 174 |
Sumatra_Render_t Sumatra_Render; |
|---|
| 175 |
alias void function(WindowInfo *win,int type,int pos) Sumatra_ScrollX_t; |
|---|
| 176 |
Sumatra_ScrollX_t Sumatra_ScrollX; |
|---|
| 177 |
alias void function(WindowInfo *win,int type,int pos) Sumatra_ScrollY_t; |
|---|
| 178 |
Sumatra_ScrollY_t Sumatra_ScrollY; |
|---|
| 179 |
alias void function(WindowInfo *win,int x,int y,uint flags) Sumatra_MouseMove_t; |
|---|
| 180 |
Sumatra_MouseMove_t Sumatra_MouseMove; |
|---|
| 181 |
alias void function(WindowInfo *win,int x,int y,uint flags) Sumatra_MouseLeftDown_t; |
|---|
| 182 |
Sumatra_MouseLeftDown_t Sumatra_MouseLeftDown; |
|---|
| 183 |
alias void function(WindowInfo *win,int x,int y,uint flags) Sumatra_MouseLeftUp_t; |
|---|
| 184 |
Sumatra_MouseLeftUp_t Sumatra_MouseLeftUp; |
|---|
| 185 |
|
|---|
| 186 |
import tango.sys.SharedLib; |
|---|
| 187 |
|
|---|
| 188 |
void loadSumatra(char[] name=null) |
|---|
| 189 |
{ |
|---|
| 190 |
static SharedLib dll; |
|---|
| 191 |
dll=SharedLib.load(name?name:"sumatrapdf.dll"); |
|---|
| 192 |
Sumatra_LoadPDF=cast(Sumatra_LoadPDF_t)dll.getSymbol("Sumatra_LoadPDF\0"); |
|---|
| 193 |
Sumatra_Print=cast(Sumatra_Print_t)dll.getSymbol("Sumatra_Print\0"); |
|---|
| 194 |
Sumatra_PrintPDF=cast(Sumatra_PrintPDF_t)dll.getSymbol("Sumatra_PrintPDF\0"); |
|---|
| 195 |
Sumatra_SetDisplayMode=cast(Sumatra_SetDisplayMode_t)dll.getSymbol("Sumatra_SetDisplayMode\0"); |
|---|
| 196 |
Sumatra_GetDisplayMode=cast(Sumatra_GetDisplayMode_t)dll.getSymbol("Sumatra_GetDisplayMode\0"); |
|---|
| 197 |
Sumatra_GoToNextPage=cast(Sumatra_GoToNextPage_t)dll.getSymbol("Sumatra_GoToNextPage\0"); |
|---|
| 198 |
Sumatra_GoToPreviousPage=cast(Sumatra_GoToPreviousPage_t)dll.getSymbol("Sumatra_GoToPreviousPage\0"); |
|---|
| 199 |
Sumatra_GoToFirstPage=cast(Sumatra_GoToFirstPage_t)dll.getSymbol("Sumatra_GoToFirstPage\0"); |
|---|
| 200 |
Sumatra_GoToLastPage=cast(Sumatra_GoToLastPage_t)dll.getSymbol("Sumatra_GoToLastPage\0"); |
|---|
| 201 |
Sumatra_GoToThisPage=cast(Sumatra_GoToThisPage_t)dll.getSymbol("Sumatra_GoToThisPage\0"); |
|---|
| 202 |
Sumatra_GetNumberOfPages=cast(Sumatra_GetNumberOfPages_t)dll.getSymbol("Sumatra_GetNumberOfPages\0"); |
|---|
| 203 |
Sumatra_GetCurrentPage=cast(Sumatra_GetCurrentPage_t)dll.getSymbol("Sumatra_GetCurrentPage\0"); |
|---|
| 204 |
Sumatra_ZoomIn=cast(Sumatra_ZoomIn_t)dll.getSymbol("Sumatra_ZoomIn\0"); |
|---|
| 205 |
Sumatra_ZoomOut=cast(Sumatra_ZoomOut_t)dll.getSymbol("Sumatra_ZoomOut\0"); |
|---|
| 206 |
Sumatra_SetZoom=cast(Sumatra_SetZoom_t)dll.getSymbol("Sumatra_SetZoom\0"); |
|---|
| 207 |
Sumatra_GetCurrentZoom=cast(Sumatra_GetCurrentZoom_t)dll.getSymbol("Sumatra_GetCurrentZoom\0"); |
|---|
| 208 |
Sumatra_Resize=cast(Sumatra_Resize_t)dll.getSymbol("Sumatra_Resize\0"); |
|---|
| 209 |
Sumatra_ClosePdf=cast(Sumatra_ClosePdf_t)dll.getSymbol("Sumatra_ClosePdf\0"); |
|---|
| 210 |
Sumatra_ShowPrintDialog=cast(Sumatra_ShowPrintDialog_t)dll.getSymbol("Sumatra_ShowPrintDialog\0"); |
|---|
| 211 |
Sumatra_Init=cast(Sumatra_Init_t)dll.getSymbol("Sumatra_Init\0"); |
|---|
| 212 |
Sumatra_Exit=cast(Sumatra_Exit_t)dll.getSymbol("Sumatra_Exit\0"); |
|---|
| 213 |
Sumatra_GetHwndCanvas=cast(Sumatra_GetHwndCanvas_t)dll.getSymbol("Sumatra_GetHwndCanvas\0"); |
|---|
| 214 |
Sumatra_Render=cast(Sumatra_Render_t)dll.getSymbol("Sumatra_Render\0"); |
|---|
| 215 |
Sumatra_ScrollX=cast(Sumatra_ScrollX_t)dll.getSymbol("Sumatra_ScrollX\0"); |
|---|
| 216 |
Sumatra_ScrollY=cast(Sumatra_ScrollY_t)dll.getSymbol("Sumatra_ScrollY\0"); |
|---|
| 217 |
Sumatra_MouseMove=cast(Sumatra_MouseMove_t)dll.getSymbol("Sumatra_MouseMove\0"); |
|---|
| 218 |
Sumatra_MouseLeftDown=cast(Sumatra_MouseLeftDown_t)dll.getSymbol("Sumatra_MouseLeftDown\0"); |
|---|
| 219 |
Sumatra_MouseLeftUp=cast(Sumatra_MouseLeftUp_t)dll.getSymbol("Sumatra_MouseLeftUp\0"); |
|---|
| 220 |
} |
|---|