00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <windows.h>
00026
00027
00028 #ifndef WS_EX_LAYERED
00029 #define WS_EX_LAYERED 0x00080000
00030 #define LWA_ALPHA 0x00000002
00031 #endif // ndef WS_EX_LAYERED
00032
00033 #ifndef MSG_WAITALL
00034 #define MSG_WAITALL 0x100
00035 #endif
00036
00037 #include <stdlib.h>
00038 #include <string.h>
00039 #include <time.h>
00040
00041 #include "Bases.h"
00042 #include "NetCommon.h"
00043 #include "Memory.h"
00044 #include "debug.h"
00045 #include "Net.h"
00046 #include "Gui.h"
00047 #include "Common.h"
00048 #include "Endian.h"
00049
00050
00051 typedef DWORD (WINAPI *PSLWA)(HWND, DWORD, BYTE, DWORD);
00052
00053
00054 struct glw_Window
00055 {
00056 HWND window;
00057 u32 fgrgb;
00058 u32 bgrgb;
00059 COLORREF fgcol;
00060 COLORREF bgcol;
00061 HBRUSH fgbrush;
00062 HBRUSH bgbrush;
00063 HPEN pen;
00064 LOGBRUSH logbrush;
00065 HDC hdcMem;
00066 HBITMAP hbmMem;
00067 HBITMAP hbmOld;
00068 RECT wrect;
00069 u32 flags;
00070 u32 userdata;
00071 int minwidth;
00072 int maxwidth;
00073 int minheight;
00074 int maxheight;
00075 int done;
00076 struct glw_Connection *conn;
00077 int state;
00078 int paint;
00079 int user_state;
00080 };
00081
00082
00083 struct glw_Connection
00084 {
00085 struct glw_ConnUser cuser;
00086 SOCKET sd;
00087
00088 int window_count;
00089 struct glw_Window *win;
00090 struct glw_SockMsg sockmsg;
00091 u32 completed;
00092 u8 *write_buffer;
00093 struct glw_Event curr_event;
00094 int level;
00095 int mx,my;
00096 List_t *windowlist;
00097 int byteorder;
00098 SOCKET sterm;
00099 int termbyteorder;
00100 };
00101
00102
00103 struct glw_FontFace
00104 {
00105 char *face;
00106 char *win_name;
00107 };
00108
00109 struct glw_Font
00110 {
00111 Node_t *node;
00112 struct glw_Connection *conn;
00113 struct glw_FontFace *face;
00114 int size;
00115 u32 style;
00116 HFONT handle;
00117 int counter;
00118 };
00119
00120
00121 struct glw_Dir
00122 {
00123 HANDLE hdir;
00124 char *filename;
00125 };
00126
00127
00128 #define NWHT_NOWHERE 0x0000
00129 #define NWHT_LEFT 0x0001
00130 #define NWHT_RIGHT 0x0002
00131 #define NWHT_TOP 0x0003
00132 #define NWHT_TOPLEFT 0x0004
00133 #define NWHT_TOPRIGHT 0x0005
00134 #define NWHT_BOTTOM 0x0006
00135 #define NWHT_BOTTOMLEFT 0x0007
00136 #define NWHT_BOTTOMRIGHT 0x0008
00137
00138 #ifndef ANTIALIASED_QUALITY
00139 #define ANTIALIASED_QUALITY 4
00140 #endif
00141
00142 #define GLW_FONTNAME_SIZE 64
00143
00144
00145 struct glw_InternalBMI
00146 {
00147 BITMAPINFOHEADER bmiHeader;
00148 RGBQUAD bmiColors[3];
00149 };
00150
00151
00152 static u32 (*call_vector[GLW_FUNC_DONE-GLW_FUNCBASE+1])(tag *);
00153
00154
00155 static int quit=0;
00156 static int buffsizeX,buffsizeY;
00157 static List_t *windowlist;
00158 static WNDCLASSEX WindowClass;
00159 static int sCommandShow;
00160 static List_t *fontfacelist;
00161 static List_t *fontlist;
00162 static int wv;
00163 static HINSTANCE sInstance;
00164 static HMODULE user32_DLL;
00165
00166
00167 static HDC workDC=NULL;
00168
00169
00170 u32 glw_GetConnection(u32 window)
00171 {
00172 struct glw_Window *win=(struct glw_Window *)window;
00173 return((u32)win->conn);
00174 }
00175
00176 static void glw_UnloadFontFaces(List_t *faces)
00177 {
00178 Node_t *node;
00179 struct glw_FontFace *face;
00180
00181 debug_Begin();
00182
00183 while(NULL!=(node=list_GetNodeHead(faces)))
00184 {
00185 list_RemoveNode(faces,node);
00186 if(NULL!=(face=(struct glw_FontFace *)list_GetNodeData(node)))
00187 {
00188 if(NULL!=face->face) mem_free(face->face);
00189 if(NULL!=face->win_name) mem_free(face->win_name);
00190 mem_free(face);
00191 }
00192 list_SetNodeData(node,NULL);
00193 list_DeleteNode(node);
00194 }
00195 list_DeleteList(faces);
00196
00197 debug_End();
00198
00199 }
00200
00201
00202 static int glw_LoadFontFaces(List_t *faces)
00203 {
00204 int ret=-1;
00205 FILE *f;
00206 char str[GLW_FONTNAME_SIZE];
00207 struct glw_FontFace *face;
00208 Node_t *node;
00209 char *eq;
00210
00211 debug_Begin();
00212
00213 if(faces!=NULL)
00214 {
00215 if(NULL!=(f=fopen("files/Fonts.list","r")))
00216 {
00217 while(NULL!=(fgets(str,GLW_FONTNAME_SIZE,f)))
00218 {
00219 str[strlen(str)-1]='\0';
00220 if(NULL!=(eq=strchr(str,'=')))
00221 {
00222 *eq++='\0';
00223 ret=-1;
00224 if(NULL!=(node=list_CreateNode()))
00225 {
00226 if(NULL!=(face=mem_malloc(sizeof(struct glw_FontFace))))
00227 {
00228 if(NULL!=(face->face=mem_malloc(strlen(str)+1)))
00229 {
00230 strcpy(face->face,str);
00231 if(NULL!=(face->win_name=mem_malloc(strlen(eq)+1)))
00232 {
00233 strcpy(face->win_name,eq);
00234 list_SetNodeData(node,face);
00235 list_InsertNodeTail(faces,node);
00236 ret=0;
00237 }
00238 }
00239 }
00240 }
00241 }
00242 }
00243 fclose(f);
00244 }
00245 }
00246
00247 debug_End();
00248
00249 return(ret);
00250 }
00251
00252
00253 static struct glw_FontFace *glw_GetFaceWinName(List_t *fflist, char *name)
00254 {
00255 Node_t *node;
00256 struct glw_FontFace *face=NULL;
00257
00258 debug_Begin();
00259
00260 for(node=list_GetNodeHead(fflist);node!=NULL;node=list_GetNodeNext(fflist,node))
00261 {
00262 if(NULL!=(face=list_GetNodeData(node)))
00263 {
00264 if(strcmp(face->face,name)==0) break;
00265 }
00266 }
00267
00268 debug_End();
00269
00270 return(face);
00271 }
00272
00273
00274 static int glw_WindowTransparent(struct glw_Window *win, int percent)
00275 {
00276 static PSLWA pSetLayeredWindowAttributes=NULL;
00277 int ret=-1;
00278
00279 debug_Begin();
00280
00281 if(NULL==pSetLayeredWindowAttributes) pSetLayeredWindowAttributes=(PSLWA)GetProcAddress(user32_DLL,"SetLayeredWindowAttributes");
00282 if(pSetLayeredWindowAttributes!=NULL)
00283 {
00284 SetWindowLong(win->window,GWL_EXSTYLE,GetWindowLong(win->window,GWL_EXSTYLE)|WS_EX_LAYERED);
00285 pSetLayeredWindowAttributes(win->window,0,(255*percent)/100,LWA_ALPHA);
00286 ret=0;
00287 }
00288
00289 debug_End();
00290
00291 return(ret);
00292 }
00293
00294
00295 static void glw_CreateBuffer(struct glw_Window *win, HDC referenceDC, int sizeX, int sizeY)
00296 {
00297 debug_Begin();
00298
00299 if((win->flags&GLWF_SMART_REFRESH)!=0)
00300 {
00301 win->hdcMem=CreateCompatibleDC(referenceDC);
00302 win->hbmMem=CreateCompatibleBitmap(referenceDC,sizeX,sizeY);
00303 win->hbmOld=SelectObject(win->hdcMem, win->hbmMem);
00304 }
00305 else win->hdcMem=GetDC(win->window);
00306 win->fgcol=0x00000000;
00307 win->bgcol=0x00ffffff;
00308 win->fgbrush=CreateSolidBrush(win->fgcol);
00309 win->bgbrush=CreateSolidBrush(win->bgcol);
00310 win->logbrush.lbStyle=BS_SOLID;
00311 win->logbrush.lbColor=win->fgcol;
00312 win->pen=ExtCreatePen(PS_COSMETIC|PS_SOLID,1,&win->logbrush,0,NULL);
00313
00314 debug_End();
00315
00316 }
00317
00318
00322 u32 glw_ClearWindow(u32 firsttag, ...)
00323 {
00324 return(glw_ClearWindowTL((tag *)&firsttag));
00325 }
00326 u32 glw_ClearWindowTL(tag *taglist)
00327 {
00328 struct glw_Window *win;
00329
00330 RECT rc;
00331
00332 debug_Begin();
00333
00334 win=(struct glw_Window *)tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
00335
00336 if(win!=NULL&&win->bgrgb!=GLW_TRANSPARENT)
00337 {
00338 rc.left=rc.top=0;
00339 rc.bottom=buffsizeY;
00340 rc.right=buffsizeX;
00341 FillRect(win->hdcMem,&rc,win->bgbrush);
00342 }
00343
00344 debug_End();
00345
00346 return(0L);
00347 }
00348
00349
00350 static void glw_DeleteBuffer(struct glw_Window *win)
00351 {
00352 debug_Begin();
00353
00354 DeleteObject(win->fgbrush);
00355 DeleteObject(win->bgbrush);
00356 DeleteObject(win->pen);
00357 if((win->flags&GLWF_SMART_REFRESH)!=0)
00358 {
00359 SelectObject(win->hdcMem, win->hbmOld);
00360 DeleteObject(win->hbmMem);
00361 DeleteDC(win->hdcMem);
00362 }
00363
00364 debug_End();
00365
00366 }
00367
00368
00369 static Node_t *glw_GetNode(HWND win)
00370 {
00371 Node_t *node;
00372 Node_t *ret=NULL;
00373 struct glw_Window *w;
00374
00375 debug_Begin();
00376
00377 for(node=list_GetNodeHead(windowlist);node!=NULL;node=list_GetNodeNext(windowlist,node))
00378 {
00379 w=(struct glw_Window *)list_GetNodeData(node);
00380 if(w->window==win) { ret=node; break; }
00381 }
00382
00383 debug_End();
00384
00385 return(ret);
00386 }
00387
00388
00389 static Node_t *glw_GetNode2(struct glw_Connection *conn, HWND win)
00390 {
00391 Node_t *node;
00392 Node_t *ret=NULL;
00393 struct glw_Window *w;
00394
00395 debug_Begin();
00396
00397 for(node=list_GetNodeHead(conn->windowlist);node!=NULL;node=list_GetNodeNext(conn->windowlist,node))
00398 {
00399 w=(struct glw_Window *)list_GetNodeData(node);
00400 if(w->window==win) { ret=node; break; }
00401 }
00402
00403 debug_End();
00404
00405 return(ret);
00406 }
00407
00408
00409 static struct glw_Window *glw_GetGlwWindow(HWND w)
00410 {
00411 struct glw_Window *win=NULL;
00412 Node_t *node;
00413
00414 debug_Begin();
00415
00416 if((node=glw_GetNode(w))!=NULL)
00417 {
00418 win=(struct glw_Window *)list_GetNodeData(node);
00419 }
00420
00421 debug_End();
00422
00423 return(win);
00424 }
00425
00426
00427 static int glw_FillEvent(struct glw_Event *ev, struct glw_Window *win)
00428 {
00429 int ret=-1;
00430 SYSTEMTIME stime;
00431
00432 debug_Begin();
00433
00434 if(ev!=NULL)
00435 {
00436 GetSystemTime(&stime);
00437 ev->window=(u32)win;
00438 ev->second=(u32)time(NULL);
00439 ev->millis=stime.wMilliseconds;
00440 ret=0;
00441 }
00442
00443 debug_End();
00444
00445 return(ret);
00446 }
00447
00448
00449 static void glw_CopyBck(struct glw_Window *win, RECT *rct)
00450 {
00451 RECT rc;
00452 RECT *myrect=&rc;
00453 HDC hDC;
00454 Rect_t grct;
00456
00457 debug_Begin();
00458
00459 if(rct==NULL)
00460 {
00461 rc.left=rc.top=0;
00462 rc.right=win->wrect.right-win->wrect.left;
00463 rc.bottom=win->wrect.bottom-win->wrect.top;
00464 }
00465 else myrect=rct;
00466 if((win->flags&GLWF_SMART_REFRESH)==0)
00467 {
00468 glw_FillEvent(&win->conn->curr_event,win);
00469 grct.left=myrect->left;
00470 grct.top=myrect->top;
00471 grct.width=myrect->right-myrect->left;
00472 grct.height=myrect->bottom-myrect->top;
00473 win->conn->curr_event.event=GLWEV_DAMAGE;
00474 win->conn->curr_event.data=(u32)&grct;
00475 win->done|=gui_Event((u32)win->conn,&win->conn->curr_event);
00476 }
00477 else
00478 {
00480 hDC=GetDC(win->window);
00481 BitBlt(hDC,myrect->left,myrect->top,myrect->right-myrect->left,myrect->bottom-myrect->top,win->hdcMem,myrect->left,myrect->top,SRCCOPY);
00482 ReleaseDC(win->window,hDC);
00484 }
00485
00486 debug_End();
00487
00488 }
00489
00490
00491 static void glw_CopyBckIndirect(HWND hwnd,RECT *rct)
00492 {
00493 struct glw_Window *win;
00494 Node_t *node;
00495
00496 debug_Begin();
00497
00498 if((node=glw_GetNode(hwnd))!=NULL)
00499 {
00500 if(NULL!=(win=(struct glw_Window *)list_GetNodeData(node))) glw_CopyBck(win,rct);
00501 }
00502
00503 debug_End();
00504
00505 }
00506
00507
00508 static int glw_ReadMessage(struct glw_Connection *conn)
00509 {
00510 char header[GLW_HEADER_LENGTH];
00511 int rcv=0,r=0,ret=0;
00512 SYSTEMTIME stime;
00513
00514 if(conn->completed==0)
00515 {
00516
00517 while(rcv<GLW_HEADER_LENGTH)
00518 {
00519 if((r=recv(conn->sd,header+rcv,GLW_HEADER_LENGTH-rcv,0))<=0)
00520 {
00521 if(WSAGetLastError()==WSAEWOULDBLOCK)
00522 {
00523 fd_set fdread;
00524 FD_ZERO(&fdread);
00525 FD_SET(conn->sd,&fdread);
00526 if((r=select(0,&fdread,NULL,NULL,NULL))==SOCKET_ERROR) break;
00527 }
00528 else
00529 {
00530 debug_Error("socket error: %d",WSAGetLastError());
00531 conn->cuser.quit=1;
00532 break;
00533 }
00534 if((r=recv(conn->sd,header+rcv,GLW_HEADER_LENGTH-rcv,0))<=0)
00535 {
00536 debug_Error("socket error (2): %d",WSAGetLastError());
00537 conn->cuser.quit=1;
00538 break;
00539 }
00540 }
00541 rcv+=r;
00542 }
00543 if(header[0]=='?')
00544 {
00545 conn->sockmsg.type=(int)header[1];
00546 conn->sockmsg.length=ntohl(*((u32 *)&header[2]));
00547 conn->sockmsg.id=ntohl(*((u32 *)&header[6]));
00548 conn->sockmsg.body=mem_malloc(conn->sockmsg.length-GLW_HEADER_LENGTH);
00549 conn->completed=GLW_HEADER_LENGTH;
00550
00551 if(conn->sockmsg.body==NULL)
00552 {
00553
00555
00556 }
00557 else
00558 {
00559
00560 debug_Error("unknown message (%p) -> header=%02x type=%d",conn,(unsigned char)header[0],header[1]);
00562 }
00563 }
00564 else
00565 {
00566
00567 r=recv( conn->sd,conn->sockmsg.body+conn->completed-GLW_HEADER_LENGTH,
00568 conn->sockmsg.length-conn->completed,0);
00569 if(r>0)
00570 {
00571 conn->completed+=r;
00572 if(conn->completed>=conn->sockmsg.length)
00573 {
00574 conn->completed=0;
00575 conn->curr_event.event=GLWEV_SOCKET;
00576 conn->curr_event.data=(u32)&conn->sockmsg;
00577 conn->curr_event.second=(u32)time(NULL);
00578 GetSystemTime(&stime);
00579 conn->curr_event.millis=stime.wMilliseconds;
00580 }
00581 }
00582 }
00583 return(ret);
00584 }
00585
00586
00587 LRESULT CALLBACK glw_StdWindowProc(HWND Window, UINT MessageType, WPARAM FirstParameter, LPARAM SecondParameter)
00588 {
00589 PAINTSTRUCT ps;
00590 POINTS pnts;
00591 LRESULT ret=1L;
00592 struct glw_Window *win;
00593 struct glw_Connection *conn=NULL;
00594
00595 debug_Begin();
00596
00597 win=glw_GetGlwWindow(Window);
00598 if(win!=NULL)
00599 {
00600 conn=win->conn;
00601 if(win->user_state==GLWWS_OPENING||win->user_state==GLWWS_SKINNING) win=NULL;
00602 }
00603 if(conn!=NULL)
00604 {
00605 glw_FillEvent(&conn->curr_event,win);
00606 conn->curr_event.mousex=conn->mx;
00607 conn->curr_event.mousey=conn->my;
00608 }
00609 switch(MessageType)
00610 {
00611 case WM_ENTERSIZEMOVE:
00612 {
00613 if(win!=NULL)
00614 {
00615 win->state=1;
00616 }
00617 ret=0;
00618 break;
00619 }
00620 case WM_EXITSIZEMOVE:
00621 {
00622 if(win!=NULL)
00623 {
00624 if(win->state==2)
00625 {
00626
00627 win->conn->curr_event.event=GLWEV_WINDOW;
00628 win->conn->curr_event.data=GLWEVD_SIZEEND;
00629 win->done|=gui_Event((u32)win->conn,&win->conn->curr_event);
00630 }
00631 else if(win->state==3)
00632 {
00633
00634 win->conn->curr_event.event=GLWEV_WINDOW;
00635 win->conn->curr_event.data=GLWEVD_MOVEEND;
00636 win->done|=gui_Event((u32)win->conn,&win->conn->curr_event);
00637 }
00638 win->state=0;
00639 }
00640 ret=0;
00641 break;
00642 }
00643 case WM_QUIT:
00644 {
00645 if(conn!=NULL)
00646 {
00647 conn->curr_event.event=GLWEV_SYSTEM;
00648 conn->curr_event.data=GLWEVD_QUIT;
00649 }
00650 ret=0;
00651 break;
00652 }
00653 case WM_CLOSE:
00654 {
00655 DestroyWindow(Window);
00656 ret=0;
00657 break;
00658 }
00659 case WM_DESTROY:
00660 {
00661 ret=0;
00662 break;
00663 }
00664 case WM_ACTIVATE:
00665 {
00666 if(win!=NULL)
00667 {
00668 win->conn->curr_event.event=GLWEV_ACTIVATION;
00669 if(FirstParameter==WA_INACTIVE)
00670 {
00671 win->conn->curr_event.data=GLWEVD_INACTIVATE;
00672 }
00673 else
00674 {
00675 win->conn->curr_event.data=GLWEVD_ACTIVATE;
00676 }
00677 win->done|=gui_Event((u32)win->conn,&win->conn->curr_event);
00678 }
00679 ret=0;
00680 break;
00681 }
00682 case WM_MOUSEMOVE:
00683 {
00684 pnts=MAKEPOINTS(SecondParameter);
00685 if(conn!=NULL)
00686 {
00687 conn->mx=conn->curr_event.mousex=pnts.x;
00688 conn->my=conn->curr_event.mousey=pnts.y;
00689 conn->curr_event.event=GLWEV_MOUSEMOVE;
00690 conn->curr_event.data=GLWEVD_ABSOLUTE;
00691 }
00692 DefWindowProc(Window, MessageType, FirstParameter, SecondParameter);
00693 ret=0;
00694 break;
00695 }
00696 case WM_LBUTTONDOWN:
00697 {
00698 if(win!=NULL)
00699 {
00700 pnts=MAKEPOINTS(SecondParameter);
00701 win->conn->mx=win->conn->curr_event.mousex=pnts.x;
00702 win->conn->my=win->conn->curr_event.mousey=pnts.y;
00703 win->conn->curr_event.event=GLWEV_MOUSEBUTTONS;
00704 win->conn->curr_event.data=GLWEVD_LEFTDOWN;
00705 }
00706 ret=0;
00707 break;
00708 }
00709 case WM_LBUTTONUP:
00710 {
00711 if(win!=NULL)
00712 {
00713 pnts=MAKEPOINTS(SecondParameter);
00714 win->conn->mx=win->conn->curr_event.mousex=pnts.x;
00715 win->conn->my=win->conn->curr_event.mousey=pnts.y;
00716 win->conn->curr_event.event=GLWEV_MOUSEBUTTONS;
00717 win->conn->curr_event.data=GLWEVD_LEFTUP;
00718 }
00719 ret=0;
00720 break;
00721 }
00722 case WM_RBUTTONUP:
00723 {
00724 if(win!=NULL)
00725 {
00726 pnts=MAKEPOINTS(SecondParameter);
00727 win->conn->mx=win->conn->curr_event.mousex=pnts.x;
00728 win->conn->my=win->conn->curr_event.mousey=pnts.y;
00729 win->conn->curr_event.event=GLWEV_MOUSEBUTTONS;
00730 win->conn->curr_event.data=GLWEVD_RIGHTUP;
00731 }
00732 ret=0;
00733 break;
00734 }
00735 case WM_RBUTTONDOWN:
00736 {
00737 if(win!=NULL)
00738 {
00739 pnts=MAKEPOINTS(SecondParameter);
00740 win->conn->mx=win->conn->curr_event.mousex=pnts.x;
00741 win->conn->my=win->conn->curr_event.mousey=pnts.y;
00742 win->conn->curr_event.event=GLWEV_MOUSEBUTTONS;
00743 win->conn->curr_event.data=GLWEVD_RIGHTDOWN;
00744 }
00745 ret=0;
00746 break;
00747 }
00748 case WM_MBUTTONUP:
00749 {
00750 if(win!=NULL)
00751 {
00752 pnts=MAKEPOINTS(SecondParameter);
00753 win->conn->mx=win->conn->curr_event.mousex=pnts.x;
00754 win->conn->my=win->conn->curr_event.mousey=pnts.y;
00755 win->conn->curr_event.event=GLWEV_MOUSEBUTTONS;
00756 win->conn->curr_event.data=GLWEVD_MIDDLEUP;
00757 }
00758 ret=0;
00759 break;
00760 }
00761 case WM_MBUTTONDOWN:
00762 {
00763 if(win!=NULL)
00764 {
00765 pnts=MAKEPOINTS(SecondParameter);
00766 win->conn->mx=win->conn->curr_event.mousex=pnts.x;
00767 win->conn->my=win->conn->curr_event.mousey=pnts.y;
00768 win->conn->curr_event.event=GLWEV_MOUSEBUTTONS;
00769 win->conn->curr_event.data=GLWEVD_MIDDLEDOWN;
00770 }
00771 ret=0;
00772 break;
00773 }
00774 case WM_KEYDOWN:
00775 {
00776 if(win!=NULL)
00777 {
00778 win->conn->curr_event.event=GLWEV_KEYDOWN;
00779 win->conn->curr_event.data=FirstParameter;
00780 }
00781 ret=0;
00782 break;
00783 }
00784 case WM_KEYUP:
00785 {
00786 if(win!=NULL)
00787 {
00788 win->conn->curr_event.event=GLWEV_KEYUP;
00789 win->conn->curr_event.data=FirstParameter;
00790 }
00791 ret=0;
00792 break;
00793 }
00794 case WM_DISPLAYCHANGE:
00795 {
00796 HDC hDC;
00797 HWND dw;
00798 RECT rct;
00799 int oldX,oldY;
00800
00801 if(win!=NULL)
00802 {
00803 oldX=buffsizeX;
00804 oldY=buffsizeY;
00805 dw=GetDesktopWindow();
00806 GetClientRect(dw,&rct);
00807 buffsizeX=rct.right;
00808 buffsizeY=rct.bottom;
00809 hDC=GetDC(dw);
00810 glw_DeleteBuffer(win);
00811 glw_CreateBuffer(win,hDC,buffsizeX,buffsizeY);
00812 ReleaseDC(dw,hDC);
00813 if((win->wrect.right-win->wrect.left)>buffsizeX||(win->wrect.bottom-win->wrect.top)>buffsizeY)
00814 {
00815 int w=min((win->wrect.right-win->wrect.left),buffsizeX);
00816 int h=min((win->wrect.bottom-win->wrect.top),buffsizeY);
00817 MoveWindow(Window,win->wrect.left,win->wrect.top,w,h,FALSE);
00818 win->wrect.right=win->wrect.left+w;
00819 win->wrect.bottom=win->wrect.top+h;
00820 }
00821 win->conn->curr_event.event=GLWEV_WINDOW;
00822 win->conn->curr_event.data=GLWEVD_REPAINT;
00823 }
00824 ret=0;
00825 break;
00826 }
00827 case WM_GETMINMAXINFO:
00828 {
00829 MINMAXINFO *sp=(MINMAXINFO *)SecondParameter;
00830 struct glw_Window *win;
00831 win=(struct glw_Window *)list_GetNodeData(glw_GetNode(Window));
00832 if(win!=NULL)
00833 {
00834 sp->ptMaxSize.x=buffsizeX;
00835 sp->ptMaxSize.y=buffsizeY;
00836 sp->ptMaxTrackSize.x=buffsizeX;
00837 sp->ptMaxTrackSize.y=buffsizeY;
00838 sp->ptMinTrackSize.x=win->minwidth;
00839 sp->ptMinTrackSize.y=win->minheight;
00840 }
00841 ret=0;
00842 break;
00843 }
00844 case WM_SIZING:
00845 {
00846 ret=0;
00847 break;
00848 }
00849 case WM_NCCALCSIZE:
00850 {
00851 if(win!=NULL)
00852 {
00853 memcpy(&win->wrect,(RECT *)SecondParameter,sizeof(RECT));
00854 if(win->state==1)
00855 {
00856
00857 win->state=2;
00858 win->conn->curr_event.event=GLWEV_WINDOW;
00859 win->conn->curr_event.data=GLWEVD_SIZEBEGIN;
00860 win->done|=gui_Event((u32)win->conn,&win->conn->curr_event);
00861 }
00862 win->conn->curr_event.event=GLWEV_WINDOW;
00863 win->conn->curr_event.data=GLWEVD_SIZING;
00864 win->done|=gui_Event((u32)win->conn,&win->conn->curr_event);
00865 }
00866 ret=0;
00867 break;
00868 }
00869 case WM_MOVING:
00870 {
00871 if(win!=NULL)
00872 {
00873 memcpy(&win->wrect,(RECT *)SecondParameter,sizeof(RECT));
00874 if(win->state==1)
00875 {
00876
00877 win->state=3;
00878 win->conn->curr_event.event=GLWEV_WINDOW;
00879 win->conn->curr_event.data=GLWEVD_MOVEBEGIN;
00880 win->done|=gui_Event((u32)win->conn,&win->conn->curr_event);
00881 }
00882 win->conn->curr_event.event=GLWEV_WINDOW;
00883 win->conn->curr_event.data=GLWEVD_MOVING;
00884 win->done|=gui_Event((u32)win->conn,&win->conn->curr_event);
00885 }
00886 ret=0;
00887 break;
00888 }
00889 case WM_TIMER:
00890 {
00891 if(win!=NULL)
00892 {
00893 win->conn->curr_event.event=GLWEV_TIMER;
00894 win->conn->curr_event.data=FirstParameter;
00895 }
00896 ret=0;
00897 break;
00898 }
00899 case WM_PAINT:
00900 {
00901 if(win!=NULL)
00902 {
00903 BeginPaint(Window,&ps);
00904 if(win->paint>0)
00905 {
00906 glw_CopyBckIndirect(Window,&ps.rcPaint);
00907 }
00908 else win->paint=1;
00909 EndPaint(Window,&ps);
00910 }
00911 ret=0;
00912 break;
00913 }
00914 case WM_NCPAINT:
00915 {
00916 ret=0;
00917 break;
00918 }
00919 case WM_SYSCOMMAND:
00920 {
00921 DefWindowProc(Window, MessageType, FirstParameter, SecondParameter);
00922 ret=0;
00923 break;
00924 }
00925 case WM_APP:
00926 {
00927 if(conn!=NULL) glw_ReadMessage(conn);
00928 ret=0;
00929 break;
00930 }
00931 }
00932
00933 debug_End();
00934
00935 return(ret);
00936 }
00937
00938
00939
00940
00944 u32 glw_htonl2(u32 firsttag, ...)
00945 {
00946 return(glw_htonl2TL((tag *)&firsttag));
00947 }
00948 u32 glw_htonl2TL(tag *taglist)
00949 {
00950 u32 value;
00951 u32 ret;
00952
00953 debug_Begin();
00954
00955 value=(u32 )tag_GetTagData(taglist,TAG_GLW_VALUE,0L);
00956 ret=htonl(value);
00957
00958 debug_End();
00959
00960 return((u32)ret);
00961 }
00962
00963
00967 u32 glw_ntohl2(u32 firsttag, ...)
00968 {
00969 return(glw_ntohl2TL((tag *)&firsttag));
00970 }
00971 u32 glw_ntohl2TL(tag *taglist)
00972 {
00973 u32 value;
00974 u32 ret;
00975
00976 debug_Begin();
00977
00978 value=(u32 )tag_GetTagData(taglist,TAG_GLW_VALUE,0L);
00979 ret=ntohl(value);
00980
00981 debug_End();
00982
00983 return((u32)ret);
00984 }
00985
00986 u32 glw_htonl(u32 value)
00987 {
00988 return(htonl(value));
00989 }
00990
00991 u32 glw_ntohl(u32 value)
00992 {
00993 return(ntohl(value));
00994 }
00995
00996
00997 int glw_Recv(u32 connection, u8 *buff, int bufflen)
00998 {
00999 struct glw_Connection *conn=(struct glw_Connection *)connection;
01000 int ret=0;
01001
01002 debug_Begin();
01003
01004 if(conn!=NULL&&buff!=NULL&&bufflen>0)
01005 {
01006 ret=recv(conn->sd,buff,bufflen,0);
01007 }
01008
01009 debug_End();
01010
01011 return(ret);
01012 }
01013
01014
01015 int glw_Send(u32 connection, u8 *buff, int bufflen)
01016 {
01017 struct glw_Connection *conn=(struct glw_Connection *)connection;
01018 int ret=0;
01019
01020 debug_Begin();
01021
01022 if(conn!=NULL&&buff!=NULL&&bufflen>0)
01023 {
01024 ret=send(conn->sd,buff,bufflen,0);
01025 }
01026
01027 debug_End();
01028
01029 return(ret);
01030 }
01031
01032
01033 int glw_SendMsg(u32 connection, u8 type, u32 id, u8 *buff, int bufflen)
01034 {
01035 struct glw_Connection *conn=(struct glw_Connection *)connection;
01036 u8 header[GLW_HEADER_LENGTH];
01037 int mlen;
01038
01039 debug_Begin();
01040
01041 mlen=bufflen+GLW_HEADER_LENGTH;
01042 header[0]='?';
01043 header[1]=type;
01044 *((u32 *)&header[2])=htonl(mlen);
01045 *((u32 *)&header[6])=htonl(id);
01046 if(mlen<NET_WRITE_BUFFER_SIZE)
01047 {
01048 memcpy(conn->write_buffer,header,GLW_HEADER_LENGTH);
01049 if(bufflen>0) memcpy(conn->write_buffer+GLW_HEADER_LENGTH,buff,bufflen);
01050 send(conn->sd,conn->write_buffer,mlen,0);
01051 }
01052 else
01053 {
01054 send(conn->sd,header,GLW_HEADER_LENGTH,0);
01055 if(bufflen>0&&buff!=NULL) send(conn->sd,buff,bufflen,0);
01056 }
01057
01058 debug_End();
01059
01060 return(0);
01061 }
01062
01063
01064 #define SOCK_CLOSE_BUFSIZE 256
01065
01066 static DWORD WINAPI glw_Thread(void *sock)
01067 {
01068 struct glw_Connection *conn;
01069 int NewBytes;
01070 char ReadBuffer[SOCK_CLOSE_BUFSIZE];
01071 Node_t *node;
01072
01073 printf("server start (socket=%d)\n",(int)sock);
01074
01075 mem_trace_checkpoint();
01076
01077 if(NULL!=(conn=mem_calloc(1,sizeof(struct glw_Connection))))
01078 {
01079 if(NULL!=(conn->windowlist=list_CreateList()))
01080 {
01081 conn->sd=(SOCKET)sock;
01082 conn->cuser.quit=0;
01083 conn->win=NULL;
01084 conn->window_count=0;
01085 conn->termbyteorder=0;
01086 if(NULL!=(conn->write_buffer=mem_malloc(NET_WRITE_BUFFER_SIZE)))
01087 {
01088 if(NULL!=(conn->cuser.appname=net_CheckClient((u32)conn,&conn->byteorder)))
01089 {
01090
01091 debug_Message("ByteOrder: %d",conn->byteorder);
01092 net_Server((u32)conn);
01093 }
01094 if(shutdown(conn->sd,SD_SEND)!=SOCKET_ERROR)
01095 {
01096 while(1)
01097 {
01098 NewBytes=recv(conn->sd,ReadBuffer,SOCK_CLOSE_BUFSIZE,0);
01099 if(NewBytes==0||NewBytes==SOCKET_ERROR) break;
01100 }
01101 closesocket(conn->sd);
01102 }
01103 }
01104 while(NULL!=(node=list_GetNodeHead(conn->windowlist))) glw_CloseWindow(TAG_GLW_WINDOW,(u32)list_GetNodeData(node),TAG_DONE);
01105 list_DeleteList(conn->windowlist);
01106 if(conn->cuser.appname!=NULL) mem_free(conn->cuser.appname);
01107 mem_free(conn->write_buffer);
01108 mem_free(conn);
01109 }
01110 }
01111
01112 mem_trace_report();
01113
01114 printf("server end\n");
01115
01116 return(0);
01117 }
01118
01119
01120 static void glw_Server(int port)
01121 {
01122 char address[]="0.0.0.0";
01123 WSADATA wsaData;
01124 u_long InterfaceAddr;
01125 SOCKET ret=INVALID_SOCKET,sd,clisd;
01126 struct sockaddr_in Interface,Remote;
01127 int AddrSize=sizeof(Remote);
01128 HANDLE thandle=INVALID_HANDLE_VALUE;
01129
01130 debug_Begin();
01131
01132 quit=0;
01133 InterfaceAddr=inet_addr(address);
01134 if(WSAStartup(MAKEWORD(1,1),&wsaData)==0)
01135 {
01136 printf("Establishing the listener...\n");
01137 if(InterfaceAddr!=INADDR_NONE)
01138 {
01139 sd=socket(AF_INET,SOCK_STREAM,0);
01140 if(sd!=INVALID_SOCKET)
01141 {
01142 Interface.sin_family=AF_INET;
01143 Interface.sin_addr.s_addr=InterfaceAddr;
01144 Interface.sin_port=htons(port);
01145 if(bind(sd,(struct sockaddr *)&Interface,sizeof(struct sockaddr_in))!=SOCKET_ERROR)
01146 {
01147 listen(sd,SOMAXCONN);
01148 ret=sd;
01149 }
01150 }
01151 }
01152 if(ret!=INVALID_SOCKET)
01153 {
01154 sd=ret;
01155 printf("Waiting for connections...\n");
01156 while(quit==0)
01157 {
01158 clisd=accept(sd,(struct sockaddr *)&Remote,&AddrSize);
01159 if(clisd!=INVALID_SOCKET)
01160 {
01161 printf("Accepted (on socket %d) %lx connection from %s:%d .\n",clisd,Remote.sin_addr.s_addr,inet_ntoa(Remote.sin_addr),ntohs(Remote.sin_port));
01162 thandle=CreateThread(0,0,glw_Thread,(void *)clisd,0,NULL);
01163 quit=1;
01164 }
01165 }
01166
01167 if(INVALID_HANDLE_VALUE!=thandle) WaitForSingleObject(thandle,-1);
01168 }
01169 WSACleanup();
01170 }
01171
01172 debug_End();
01173 }
01174
01175
01176
01177 int WINAPI WinMain(HINSTANCE Instance, HINSTANCE PreviousInstance, LPSTR CommandLine, int CommandShow)
01178 {
01179 RECT rct3vv;
01180 Node_t *node;
01181 OSVERSIONINFO ovi;
01182
01183 debug_Begin();
01184
01185
01186
01187
01188
01189
01190
01191
01192 call_vector[GLW_STARTMOUSETRACKING-GLW_FUNCBASE]=glw_StartMouseTrackingTL;
01193 call_vector[GLW_STOPMOUSETRACKING-GLW_FUNCBASE]=glw_StopMouseTrackingTL;
01194 call_vector[GLW_DRAGWINDOW-GLW_FUNCBASE]=glw_DragWindowTL;
01195 call_vector[GLW_RESIZEWINDOW-GLW_FUNCBASE]=glw_ResizeWindowTL;
01196 call_vector[GLW_SETCOLOR-GLW_FUNCBASE]=glw_SetColorTL;
01197 call_vector[GLW_SETBACKGROUND-GLW_FUNCBASE]=glw_SetBackgroundTL;
01198 call_vector[GLW_DRAWLINE-GLW_FUNCBASE]=glw_DrawLineTL;
01199 call_vector[GLW_DRAWRECT-GLW_FUNCBASE]=glw_DrawRectTL;
01200 call_vector[GLW_DRAWFILLEDRECT-GLW_FUNCBASE]=glw_DrawFilledRectTL;
01201 call_vector[GLW_DRAWPIXEL-GLW_FUNCBASE]=glw_DrawPixelTL;
01202 call_vector[GLW_OPENFONT-GLW_FUNCBASE]=glw_OpenFontTL;
01203 call_vector[GLW_CLOSEFONT-GLW_FUNCBASE]=glw_CloseFontTL;
01204 call_vector[GLW_DRAWTEXT-GLW_FUNCBASE]=glw_DrawTextTL;
01205 call_vector[GLW_GETFONTSIZE-GLW_FUNCBASE]=glw_GetFontSizeTL;
01206 call_vector[GLW_GETTEXTLENGTH-GLW_FUNCBASE]=glw_GetTextLengthTL;
01207 call_vector[GLW_PUTIMAGE-GLW_FUNCBASE]=glw_PutImageTL;
01208 call_vector[GLW_GETSCREENDIMENSIONS-GLW_FUNCBASE]=glw_GetScreenDimensionsTL;
01209 call_vector[GLW_TIMERSTART-GLW_FUNCBASE]=glw_TimerStartTL;
01210 call_vector[GLW_TIMERCANCEL-GLW_FUNCBASE]=glw_TimerCancelTL;
01211 call_vector[GLW_GETTIME-GLW_FUNCBASE]=glw_GetTimeTL;
01212 call_vector[GLW_HTONL2-GLW_FUNCBASE]=glw_htonl2TL;
01213 call_vector[GLW_NTOHL2-GLW_FUNCBASE]=glw_ntohl2TL;
01214 call_vector[GLW_SETWINDOWDIMENSIONS-GLW_FUNCBASE]=glw_SetWindowDimensionsTL;
01215 call_vector[GLW_GETWINDOWDIMENSIONS-GLW_FUNCBASE]=glw_GetWindowDimensionsTL;
01216 call_vector[GLW_SETPOINTER-GLW_FUNCBASE]=glw_SetPointerTL;
01217 call_vector[GLW_SETWINDOWTRANSPARENCY-GLW_FUNCBASE]=glw_SetWindowTransparencyTL;
01218 call_vector[GLW_SLEEP-GLW_FUNCBASE]=glw_SleepTL;
01219 bases_modules.glw_Call=glw_Call;
01220 bases_modules.glw_CallTL=glw_CallTL;
01221
01222
01223
01224 ovi.dwOSVersionInfoSize=sizeof(ovi);
01225 GetVersionEx(&ovi);
01226
01227
01228
01229
01230
01231
01232 if(ovi.dwPlatformId==VER_PLATFORM_WIN32_NT&&ovi.dwMajorVersion>=5) wv=4;
01233 else if(ovi.dwPlatformId==VER_PLATFORM_WIN32_NT&&ovi.dwMajorVersion>=4) wv=3;
01234 else if(ovi.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS&&ovi.dwMajorVersion>=4) wv=2;
01235 else if(ovi.dwPlatformId==VER_PLATFORM_WIN32_WINDOWS&&ovi.dwMajorVersion>=3) wv=1;
01236 else wv=0;
01237 sInstance=Instance;
01238 sCommandShow=CommandShow;
01239 user32_DLL=LoadLibrary("user32");
01240 if(NULL!=(windowlist=list_CreateList()))
01241 {
01242 if(NULL!=(fontfacelist=list_CreateList()))
01243 {
01244 if(0==(glw_LoadFontFaces(fontfacelist)))
01245 {
01246 if(NULL!=(fontlist=list_CreateList()))
01247 {
01248 WindowClass.cbSize = sizeof(WNDCLASSEX);
01249 WindowClass.style = 0;
01250 WindowClass.lpfnWndProc = glw_StdWindowProc;
01251 WindowClass.cbClsExtra = 0;
01252 WindowClass.cbWndExtra = 0;
01253 WindowClass.hInstance = sInstance;
01254 WindowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
01255 WindowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
01256 WindowClass.hbrBackground = GetStockObject(WHITE_BRUSH);
01257 WindowClass.lpszMenuName = NULL;
01258 WindowClass.lpszClassName = "glw_StdWindowClass";
01259 WindowClass.hIconSm = NULL;
01260 if(RegisterClassEx(&WindowClass)!=0)
01261 {
01262 GetClientRect(GetDesktopWindow(),&rct3vv);
01263 buffsizeX=rct3vv.right;
01264 buffsizeY=rct3vv.bottom;
01265 workDC=CreateCompatibleDC(NULL);
01266
01267 gui_Init();
01268 debug_Message("Server is up and running.");
01269 glw_Server(net_GetPort());
01270 gui_CleanUp();
01271
01272 while(NULL!=(node=list_GetNodeHead(windowlist))) glw_CloseWindow(TAG_GLW_WINDOW,(u32)list_GetNodeData(node),TAG_DONE);
01273 }
01274 while(NULL!=(node=list_GetNodeHead(fontlist))) glw_CloseFont(TAG_GLW_FONT,(u32)list_GetNodeData(node),TAG_DONE);
01275 list_DeleteList(fontlist);
01276 if(NULL!=workDC) DeleteDC(workDC);
01277 }
01278 glw_UnloadFontFaces(fontfacelist);
01279 fontfacelist=NULL;
01280 }
01281 }
01282 list_DeleteList(windowlist);
01283 }
01284 FreeLibrary(user32_DLL);
01285
01286 mem_trace_report();
01287
01288 debug_End();
01289
01290 return(0L);
01291 }
01292
01293
01294
01295
01296
01303 u32 glw_OpenWindow(u32 firsttag, ...)
01304 {
01305 return(glw_OpenWindowTL((tag *)&firsttag));
01306 }
01307 u32 glw_OpenWindowTL(tag *taglist)
01308 {
01309 struct glw_Connection *conn;
01310 Rect_t *rect;
01311 u32 flags;
01312 u32 userdata;
01313
01314 HWND dw;
01315 HDC hDC;
01316 struct glw_Window *win=NULL;
01317 Node_t *node,*node2;
01318
01319 debug_Begin();
01320
01321 conn=(struct glw_Connection *)tag_GetTagData(taglist,TAG_GLW_CONN,0L);
01322 rect=(Rect_t *)tag_GetTagData(taglist,TAG_GLW_RECT,0L);
01323 flags=(u32)tag_GetTagData(taglist,TAG_GLW_FLAGS,0L);
01324 userdata=(u32)tag_GetTagData(taglist,TAG_GLW_USERDATA,0L);
01325
01326 if(NULL!=(node=list_CreateNode()))
01327 {
01328 if(NULL!=(node2=list_CreateNode()))
01329 {
01330 if(NULL!=(win=mem_malloc(sizeof(struct glw_Window))))
01331 {
01332 win->user_state=GLWWS_OPENING;
01333 win->conn=conn;
01334 win->flags=flags;
01335 win->userdata=userdata;
01336 list_SetNodeData(node,win);
01337 list_SetNodeData(node2,win);
01338 list_InsertNodeTail(windowlist,node);
01339 list_InsertNodeTail(conn->windowlist,node2);
01340 debug_Message("open %dx%d window",rect->width,rect->height);
01341 if((dw=CreateWindowEx(
01342 (((flags&~GLWF_MAYBE_SMALL)!=0)?WS_EX_OVERLAPPEDWINDOW:WS_EX_TOOLWINDOW),
01343 "glw_StdWindowClass",
01344 NULL,
01345 WS_OVERLAPPED|WS_VISIBLE,
01346 rect->left, rect->top, rect->width, rect->height,
01347 NULL,
01348 NULL,
01349 sInstance,
01350 NULL))!=NULL)
01351 {
01352 if(conn->window_count==0)
01353 {
01354 WSAAsyncSelect(conn->sd,dw,WM_APP,FD_READ);
01355 conn->win=win;
01356 }
01357 win->window=dw;
01358 ShowWindow(win->window,sCommandShow);
01359 dw=GetDesktopWindow();
01360 hDC=GetDC(dw);
01361 glw_CreateBuffer(win,hDC,buffsizeX,buffsizeY);
01362 ReleaseDC(dw,hDC);
01363 GetWindowRect(win->window,&win->wrect);
01364 glw_ClearWindow(TAG_GLW_WINDOW,(u32)win,TAG_DONE);
01365 SetCursor(LoadCursor(NULL,IDC_ARROW));
01366 conn->window_count++;
01367 win->minwidth=0;
01368 win->minheight=0;
01369 win->done=0;
01370
01371 }
01372 }
01373 }
01374 }
01375
01376 debug_End();
01377
01378 return((u32)win);
01379 }
01380
01381
01386 u32 glw_SetWindowState(u32 firsttag, ...)
01387 {
01388 return(glw_SetWindowStateTL((tag *)&firsttag));
01389 }
01390 u32 glw_SetWindowStateTL(tag *taglist)
01391 {
01392 struct glw_Window *win;
01393 int state;
01394
01395 int ret=0;
01396
01397 debug_Begin();
01398
01399 win=(struct glw_Window *)tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
01400 state=(int)tag_GetTagData(taglist,TAG_GLW_STATE,0L);
01401
01402 if(win!=NULL)
01403 {
01404 ret=win->user_state;
01405 win->user_state=state;
01406 }
01407
01408 debug_End();
01409
01410 return((u32)ret);
01411 }
01412
01413
01417 u32 glw_CloseWindow(u32 firsttag, ...)
01418 {
01419 return(glw_CloseWindowTL((tag *)&firsttag));
01420 }
01421 u32 glw_CloseWindowTL(tag *taglist)
01422 {
01423 struct glw_Window *win;
01424 Node_t *node;
01425
01426 debug_Begin();
01427
01428 win=(struct glw_Window *)tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
01429
01430 if(win!=NULL)
01431 {
01432 node=glw_GetNode(win->window);
01433 list_SetNodeData(node,NULL);
01434 list_RemoveNode(windowlist,node);
01435 list_DeleteNode(node);
01436
01437 node=glw_GetNode2(win->conn,win->window);
01438 list_SetNodeData(node,NULL);
01439 list_RemoveNode(win->conn->windowlist,node);
01440 list_DeleteNode(node);
01441
01442 SetWindowRgn(win->window,NULL,FALSE);
01443 DestroyWindow(win->window);
01444 glw_DeleteBuffer(win);
01445 win->conn->window_count--;
01446 if(win->conn->win==win)
01447 {
01448 WSAAsyncSelect(win->conn->sd,win->window,0,0);
01449 if(NULL!=(node=list_GetNodeHead(win->conn->windowlist)))
01450 {
01451 struct glw_Window *w2;
01452 if(NULL!=(w2=list_GetNodeData(node)))
01453 {
01454 win->conn->win=w2;
01455 WSAAsyncSelect(win->conn->sd,w2->window,WM_APP,FD_READ);
01456 }
01457 }
01458 }
01459 mem_free(win);
01460 }
01461
01462 debug_End();
01463
01464 return(0L);
01465 }
01466
01467
01471 u32 glw_GetWindowUserdata(u32 firsttag, ...)
01472 {
01473 return(glw_GetWindowUserdataTL((tag *)&firsttag));
01474 }
01475 u32 glw_GetWindowUserdataTL(tag *taglist)
01476 {
01477 struct glw_Window *win;
01478
01479 u32 ret;
01480
01481 debug_Begin();
01482
01483 win=(struct glw_Window *)tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
01484
01485 ret=(win==NULL?0L:win->userdata);
01486
01487 debug_End();
01488
01489 return(ret);
01490 }
01491
01492
01500 u32 glw_SetWindowLimits(u32 firsttag, ...)
01501 {
01502 return(glw_SetWindowLimitsTL((tag *)&firsttag));
01503 }
01504 u32 glw_SetWindowLimitsTL(tag *taglist)
01505 {
01506 struct glw_Window *win;
01507 int minwidth;
01508 int minheight;
01509 int maxwidth;
01510 int maxheight;
01511
01512 debug_Begin();
01513
01514 win=(struct glw_Window *)tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
01515 minwidth=(int)tag_GetTagData(taglist,TAG_GLW_MINWIDTH,0L);
01516 minheight=(int)tag_GetTagData(taglist,TAG_GLW_MINHEIGHT,0L);
01517 maxwidth=(int)tag_GetTagData(taglist,TAG_GLW_MAXWIDTH,0L);
01518 maxheight=(int)tag_GetTagData(taglist,TAG_GLW_MAXHEIGHT,0L);
01519
01520 if(win!=NULL)
01521 {
01522 win->minwidth=minwidth;
01523 win->minheight=minheight;
01524 win->maxwidth=maxwidth;
01525 win->maxheight=maxheight;
01526 }
01527
01528 debug_End();
01529
01530 return(0L);
01531 }
01532
01533
01538 u32 glw_SetWindowTransparency(u32 firsttag, ...)
01539 {
01540 return(glw_SetWindowTransparencyTL((tag *)&firsttag));
01541 }
01542 u32 glw_SetWindowTransparencyTL(tag *taglist)
01543 {
01544 u32 window;
01545 int percent;
01546
01547 u32 ret=~0L;
01548 struct glw_Window *win;
01549
01550 debug_Begin();
01551
01552 window=(u32 )tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
01553 percent=(int)tag_GetTagData(taglist,TAG_GLW_PERCENT,0L);
01554
01555 win=(struct glw_Window *)window;
01556 if(win!=NULL&&percent>=0&&percent<=100)
01557 {
01558 if(0==glw_WindowTransparent(win,percent)) ret=0L;
01559 }
01560
01561 debug_End();
01562
01563 return(ret);
01564 }
01565
01566
01571 u32 glw_SetWindowDimensions(u32 firsttag, ...)
01572 {
01573 return(glw_SetWindowDimensionsTL((tag *)&firsttag));
01574 }
01575 u32 glw_SetWindowDimensionsTL(tag *taglist)
01576 {
01577 u32 window;
01578 Rect_t *rect;
01579
01580 u32 ret=~0L;
01581 struct glw_Window *win;
01582
01583 debug_Begin();
01584
01585 window=(u32 )tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
01586 rect=(Rect_t *)tag_GetTagData(taglist,TAG_GLW_RECT,0L);
01587
01588 win=(struct glw_Window *)window;
01589 if(win!=NULL)
01590 {
01591 GetWindowRect(win->window,&win->wrect);
01592 win->wrect.right=win->wrect.left+rect->width;
01593 win->wrect.bottom=win->wrect.top+rect->height;
01594
01595 debug_Message("%ld,%ld (%ldx%ld)",win->wrect.left,win->wrect.top,win->wrect.right-win->wrect.left,win->wrect.bottom-win->wrect.top);
01596 MoveWindow(win->window,win->wrect.left,win->wrect.top,win->wrect.right-win->wrect.left+0,win->wrect.bottom-win->wrect.top+0,FALSE);
01597 debug_Message("after");
01598 ret=0L;
01599 }
01600
01601 debug_End();
01602
01603 return(ret);
01604 }
01605
01606
01611 u32 glw_GetWindowDimensions(u32 firsttag, ...)
01612 {
01613 return(glw_GetWindowDimensionsTL((tag *)&firsttag));
01614 }
01615 u32 glw_GetWindowDimensionsTL(tag *taglist)
01616 {
01617 u32 window;
01618 Rect_t *rect;
01619
01620 struct glw_Window *win;
01621
01622 debug_Begin();
01623
01624 window=(u32 )tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
01625 rect=(Rect_t *)tag_GetTagData(taglist,TAG_GLW_RECT,0L);
01626
01627 win=(struct glw_Window *)window;
01628 if(win!=NULL)
01629 {
01630
01631 rect->left=win->wrect.left;
01632 rect->top=win->wrect.top;
01633 rect->width=win->wrect.right-win->wrect.left;
01634 rect->height=win->wrect.bottom-win->wrect.top;
01635 }
01636
01637 debug_End();
01638
01639 return(0L);
01640 }
01641
01642
01647 u32 glw_SetPointer(u32 firsttag, ...)
01648 {
01649 return(glw_SetPointerTL((tag *)&firsttag));
01650 }
01651 #define CRSR_MAX 4
01652 u32 glw_SetPointerTL(tag *taglist)
01653 {
01654
01655 int pnt;
01656
01657 static LPCTSTR cursors[]=
01658 {
01659 IDC_ARROW,
01660 IDC_SIZENESW,
01661 IDC_SIZENS,
01662 IDC_SIZENWSE,
01663 IDC_SIZEWE
01664 };
01665
01666 debug_Begin();
01667
01668
01669 pnt=(int)tag_GetTagData(taglist,TAG_GLW_POINTER,0L);
01670
01671 if(pnt>CRSR_MAX||pnt<0) pnt=0;
01672
01673
01674
01675
01676
01677
01678
01679
01680
01681 SetCursor(LoadCursor(NULL,cursors[pnt]));
01682
01683 debug_End();
01684
01685 return(0L);
01686 }
01687
01688
01692 u32 glw_RefreshWindow(u32 firsttag, ...)
01693 {
01694 return(glw_RefreshWindowTL((tag *)&firsttag));
01695 }
01696 u32 glw_RefreshWindowTL(tag *taglist)
01697 {
01698 struct glw_Window *win;
01699
01700 debug_Begin();
01701
01702 win=(struct glw_Window *)tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
01703
01704 if(win!=NULL&&(win->flags&GLWF_SMART_REFRESH)!=0) glw_CopyBck(win,NULL);
01705
01706 debug_End();
01707
01708 return(0L);
01709 }
01710
01711
01716 u32 glw_RefreshWindowPartial(u32 firsttag, ...)
01717 {
01718 return(glw_RefreshWindowPartialTL((tag *)&firsttag));
01719 }
01720 u32 glw_RefreshWindowPartialTL(tag *taglist)
01721 {
01722 struct glw_Window *win;
01723 Rect_t *rect;
01724
01725 RECT rct;
01726
01727 debug_Begin();
01728
01729 win=(struct glw_Window *)tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
01730 rect=(Rect_t *)tag_GetTagData(taglist,TAG_GLW_RECT,0L);
01731
01732 if(rect!=NULL&&win!=NULL&&(win->flags&GLWF_SMART_REFRESH)!=0)
01733 {
01734 rct.left=rect->left;
01735 rct.top=rect->top;
01736 rct.right=rect->left+rect->width;
01737 rct.bottom=rect->top+rect->height;
01738 glw_CopyBck(win,&rct);
01739 }
01740
01741 debug_End();
01742
01743 return(0L);
01744 }
01745
01746
01750 u32 glw_StartMouseTracking(u32 firsttag, ...)
01751 {
01752 return(glw_StartMouseTrackingTL((tag *)&firsttag));
01753 }
01754 u32 glw_StartMouseTrackingTL(tag *taglist)
01755 {
01756 u32 window;
01757
01758 struct glw_Window *win;
01759
01760 debug_Begin();
01761
01762 window=(u32 )tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
01763
01764 win=(struct glw_Window *)window;
01765
01766 if(win!=NULL) SetCapture(win->window);
01767
01768 debug_End();
01769
01770 return(0L);
01771 }
01772
01773
01777 u32 glw_StopMouseTracking(u32 firsttag, ...)
01778 {
01779 return(glw_StopMouseTrackingTL((tag *)&firsttag));
01780 }
01781 u32 glw_StopMouseTrackingTL(tag *taglist)
01782 {
01783 struct glw_Window *win;
01784
01785 u32 ret=~0L;
01786
01787 debug_Begin();
01788
01789 win=(struct glw_Window *)tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
01790
01791
01792 debug_Begin();
01793
01794 if(win!=NULL)
01795 {
01796 ReleaseCapture();
01797 ret=0L;
01798 }
01799
01800 debug_End();
01801
01802 return(ret);
01803 }
01804
01805
01809 u32 glw_DragWindow(u32 firsttag, ...)
01810 {
01811 return(glw_DragWindowTL((tag *)&firsttag));
01812 }
01813 u32 glw_DragWindowTL(tag *taglist)
01814 {
01815 u32 window;
01816
01817 struct glw_Window *win;
01818
01819
01820 debug_Begin();
01821
01822 window=(u32 )tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
01823
01824 win=(struct glw_Window *)window;
01825
01826 if(window!=0L) SendMessage(win->window,WM_SYSCOMMAND,SC_MOVE|0x0002,0);
01827
01828 debug_End();
01829
01830 return((u32)0);
01831 }
01832
01833
01838 u32 glw_ResizeWindow(u32 firsttag, ...)
01839 {
01840 return(glw_ResizeWindowTL((tag *)&firsttag));
01841 }
01842 u32 glw_ResizeWindowTL(tag *taglist)
01843 {
01844 u32 window;
01845 int type;
01846
01847 struct glw_Window *win;
01848
01849
01850 debug_Begin();
01851
01852 window=(u32 )tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
01853 type=(int )tag_GetTagData(taglist,TAG_GLW_TYPE,0L);
01854
01855 win=(struct glw_Window *)window;
01856
01857 if(window!=0L) SendMessage(win->window,WM_SYSCOMMAND,SC_SIZE|type,0);
01858
01859 debug_End();
01860
01861 return((u32)0);
01862 }
01863
01864
01865
01870 u32 glw_SetColor(u32 firsttag, ...)
01871 {
01872 return(glw_SetColorTL((tag *)&firsttag));
01873 }
01874 u32 glw_SetColorTL(tag *taglist)
01875 {
01876 u32 window;
01877 u32 rgb;
01878
01879 struct glw_Window *win;
01880 u32 ret;
01881
01882
01883 debug_Begin();
01884
01885 window=(u32 )tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
01886 rgb=(u32 )tag_GetTagData(taglist,TAG_GLW_RGB,0L);
01887
01888 win=(struct glw_Window *)window;
01889
01890 ret=win->fgrgb;
01891 win->fgrgb=rgb;
01892 if(rgb!=GLW_TRANSPARENT)
01893 {
01894 win->fgcol=RGB(rgb>>16,(rgb>>8)&0xff,rgb&0xff);
01895 DeleteObject(win->fgbrush);
01896 win->fgbrush=CreateSolidBrush(win->fgcol);
01897 DeleteObject(win->pen);
01898 win->logbrush.lbColor=win->fgcol;
01899 win->pen=ExtCreatePen(PS_COSMETIC|PS_SOLID,1,&win->logbrush,0,NULL);
01900 }
01901
01902 debug_End();
01903
01904 return((u32)ret);
01905 }
01906
01907
01912 u32 glw_SetBackground(u32 firsttag, ...)
01913 {
01914 return(glw_SetBackgroundTL((tag *)&firsttag));
01915 }
01916 u32 glw_SetBackgroundTL(tag *taglist)
01917 {
01918 u32 window;
01919 u32 rgb;
01920
01921 struct glw_Window *win;
01922 u32 ret;
01923
01924
01925 debug_Begin();
01926
01927 window=(u32 )tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
01928 rgb=(u32 )tag_GetTagData(taglist,TAG_GLW_RGB,0L);
01929
01930 win=(struct glw_Window *)window;
01931
01932 ret=win->bgrgb;
01933 win->bgrgb=rgb;
01934 if(rgb!=GLW_TRANSPARENT)
01935 {
01936 win->bgcol=RGB(rgb>>16,(rgb>>8)&0xff,rgb&0xff);
01937 DeleteObject(win->bgbrush);
01938 win->bgbrush=CreateSolidBrush(win->bgcol);
01939 }
01940
01941 debug_End();
01942
01943 return((u32)ret);
01944 }
01945
01946
01954 u32 glw_DrawLine(u32 firsttag, ...)
01955 {
01956 return(glw_DrawLineTL((tag *)&firsttag));
01957 }
01958 u32 glw_DrawLineTL(tag *taglist)
01959 {
01960 u32 window;
01961 int x1;
01962 int y1;
01963 int x2;
01964 int y2;
01965
01966 struct glw_Window *win;
01968 HPEN hbpOld;
01969
01970
01971 debug_Begin();
01972
01973 window=(u32 )tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
01974 x1=(int )tag_GetTagData(taglist,TAG_GLW_X1,0L);
01975 y1=(int )tag_GetTagData(taglist,TAG_GLW_Y1,0L);
01976 x2=(int )tag_GetTagData(taglist,TAG_GLW_X2,0L);
01977 y2=(int )tag_GetTagData(taglist,TAG_GLW_Y2,0L);
01978
01979 win=(struct glw_Window *)window;
01980
01981 if(win->fgrgb!=GLW_TRANSPARENT)
01982 {
01984 hbpOld=SelectObject(win->hdcMem,win->pen);
01985 MoveToEx(win->hdcMem,x1,y1,NULL);
01986 LineTo(win->hdcMem,x2,y2);
01987 SelectObject(win->hdcMem,hbpOld);
01989 }
01990
01991 debug_End();
01992
01993 return((u32)0);
01994 }
01995
01996
02004 u32 glw_DrawRect(u32 firsttag, ...)
02005 {
02006 return(glw_DrawRectTL((tag *)&firsttag));
02007 }
02008 u32 glw_DrawRectTL(tag *taglist)
02009 {
02010 u32 window;
02011 int left;
02012 int top;
02013 int width;
02014 int height;
02015
02016 struct glw_Window *win;
02018 HPEN hbpOld;
02019
02020
02021 debug_Begin();
02022
02023 window=(u32 )tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
02024 left=(int )tag_GetTagData(taglist,TAG_GLW_LEFT,0L);
02025 top=(int )tag_GetTagData(taglist,TAG_GLW_TOP,0L);
02026 width=(int )tag_GetTagData(taglist,TAG_GLW_WIDTH,0L);
02027 height=(int )tag_GetTagData(taglist,TAG_GLW_HEIGHT,0L);
02028
02029 win=(struct glw_Window *)window;
02030
02031 if(win->fgrgb!=GLW_TRANSPARENT)
02032 {
02034 hbpOld=SelectObject(win->hdcMem,win->pen);
02035 MoveToEx(win->hdcMem,left,top,NULL);
02036 LineTo(win->hdcMem,left+width,top);
02037 LineTo(win->hdcMem,left+width,top+height);
02038 LineTo(win->hdcMem,left,top+height);
02039 LineTo(win->hdcMem,left,top);
02041 SelectObject(win->hdcMem,hbpOld);
02042 }
02043
02044 debug_End();
02045
02046 return((u32)0);
02047 }
02048
02049
02057 u32 glw_DrawFilledRect(u32 firsttag, ...)
02058 {
02059 return(glw_DrawFilledRectTL((tag *)&firsttag));
02060 }
02061 u32 glw_DrawFilledRectTL(tag *taglist)
02062 {
02063 u32 window;
02064 int left;
02065 int top;
02066 int width;
02067 int height;
02068
02069 struct glw_Window *win;
02071 RECT rc;
02072
02073
02074 debug_Begin();
02075
02076 window=(u32 )tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
02077 left=(int )tag_GetTagData(taglist,TAG_GLW_LEFT,0L);
02078 top=(int )tag_GetTagData(taglist,TAG_GLW_TOP,0L);
02079 width=(int )tag_GetTagData(taglist,TAG_GLW_WIDTH,0L);
02080 height=(int )tag_GetTagData(taglist,TAG_GLW_HEIGHT,0L);
02081
02082 win=(struct glw_Window *)window;
02083
02084 if(win->fgrgb!=GLW_TRANSPARENT)
02085 {
02086 rc.left=left;
02087 rc.top=top;
02088 rc.bottom=top+height;
02089 rc.right=left+width;
02091 FillRect(win->hdcMem,&rc,win->fgbrush);
02093 }
02094
02095 debug_End();
02096
02097 return((u32)0);
02098 }
02099
02100
02106 u32 glw_DrawPixel(u32 firsttag, ...)
02107 {
02108 return(glw_DrawPixelTL((tag *)&firsttag));
02109 }
02110 u32 glw_DrawPixelTL(tag *taglist)
02111 {
02112 u32 window;
02113 int x;
02114 int y;
02115
02116 struct glw_Window *win;
02118
02119
02120 debug_Begin();
02121
02122 window=(u32 )tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
02123 x=(int )tag_GetTagData(taglist,TAG_GLW_X,0L);
02124 y=(int )tag_GetTagData(taglist,TAG_GLW_Y,0L);
02125
02126 win=(struct glw_Window *)window;
02127
02128 if(win->fgrgb!=GLW_TRANSPARENT)
02129 {
02131 SetPixel(win->hdcMem,x,y,win->fgcol);
02133 }
02134
02135 debug_End();
02136
02137 return((u32)0);
02138 }
02139
02140
02141
02142
02143 int glw_MainLoop(u32 connection, u32 userdata, u32 mask)
02144 {
02145 struct glw_Connection *conn=(struct glw_Connection *)connection;
02146 struct glw_Window *win=NULL;
02147 MSG Message;
02148 int r=1;
02149
02150 debug_Begin();
02151
02152 if(conn->cuser.quit==0)
02153 {
02154 conn->level++;
02155 conn->curr_event.userdata=userdata;
02156 conn->curr_event.event=GLWEV_SOCKET;
02157 conn->curr_event.data=0;
02158 if(0==(gui_Event((u32)conn,&conn->curr_event)))
02159 {
02160 while(r!=0)
02161 {
02162 conn->curr_event.mask=mask;
02163 conn->curr_event.userdata=userdata;
02164 if(conn->window_count>0)
02165 {
02166 win=NULL;
02167 conn->curr_event.event=GLWEV_NOEVENT;
02168 conn->curr_event.data=0;
02169 while(conn->curr_event.event==GLWEV_NOEVENT)
02170 {
02171 r=GetMessage(&Message,NULL,0,0);
02172 win=glw_GetGlwWindow(Message.hwnd);
02173 glw_FillEvent(&conn->curr_event,win);
02174 TranslateMessage(&Message);
02175 DispatchMessage(&Message);
02176 }
02177 if(win!=NULL)
02178 {
02179 win->done|=gui_Event((u32)conn,&win->conn->curr_event);
02180
02181 if(win->done!=0)
02182 {
02183 break;
02184 }
02185 }
02186 if(conn->completed<0) break;
02187 }
02188 else
02189 {
02190 conn->curr_event.event=GLWEV_NOEVENT;
02191 conn->curr_event.window=0L;
02192 conn->curr_event.mousex=conn->curr_event.mousey=0;
02193 glw_ReadMessage(conn);
02194 if(conn->curr_event.event!=GLWEV_NOEVENT)
02195 {
02196 if(0!=gui_Event((u32)conn,&conn->curr_event)) break;
02197 }
02198 if(conn->completed<0) break;
02199 }
02200 }
02201 }
02202 if(win!=NULL) win->done=0;
02203 conn->level--;
02204 }
02205 debug_End();
02206
02207 return(0);
02208 }
02209
02210
02211
02218 u32 glw_OpenFont(u32 firsttag, ...)
02219 {
02220 return(glw_OpenFontTL((tag *)&firsttag));
02221 }
02222 u32 glw_OpenFontTL(tag *taglist)
02223 {
02224 struct glw_Connection *conn;
02225 char *face;
02226 int size;
02227 u32 style;
02228
02229 struct glw_FontFace *fface;
02230 struct glw_Font *font=NULL;
02231 Node_t *node;
02232
02233 debug_Begin();
02234
02235 conn=(struct glw_Connection *)tag_GetTagData(taglist,TAG_GLW_CONN,0L);
02236 face=(char *)tag_GetTagData(taglist,TAG_GLW_FACE,0L);
02237 size=(int )tag_GetTagData(taglist,TAG_GLW_SIZE,0L);
02238 style=(u32 )tag_GetTagData(taglist,TAG_GLW_STYLE,0L);
02239
02240 if(conn!=NULL)
02241 {
02242 if(NULL!=(fface=glw_GetFaceWinName(fontfacelist,face)))
02243 {
02244
02245 for(node=list_GetNodeHead(fontlist);node!=NULL;node=list_GetNodeNext(fontlist,node))
02246 {
02247 if(NULL!=(font=(struct glw_Font *)list_GetNodeData(node)))
02248 {
02249 if(font->conn==conn&&font->face==fface&&(font->size==size||font->size==0)&&font->style==style) break;
02250 font=NULL;
02251 }
02252 }
02253 if(font==NULL)
02254 {
02255 if(NULL!=(font=mem_malloc(sizeof(struct glw_Font)))&&NULL!=(node=list_CreateNode()))
02256 {
02257 font->conn=conn;
02258 font->face=fface;
02259 font->size=size;
02260 font->style=style;
02261 font->counter=1;
02262 font->node=node;
02263 font->handle=CreateFont(size,0,0,0,((style&GLWFS_BOLD)==0?400:700),
02264 ((style&GLWFS_ITALIC)==0?FALSE:TRUE),
02265 ((style&GLWFS_UNDERLINE)==0?FALSE:TRUE),FALSE,
02266 DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
02267 ANTIALIASED_QUALITY,DEFAULT_PITCH|FF_DONTCARE,(LPCTSTR)fface->win_name);
02268 if(font->handle!=NULL)
02269 {
02270 list_SetNodeData(node,font);
02271 list_InsertNodeTail(fontlist,node);
02272 }
02273 else
02274 {
02275 glw_CloseFont(TAG_GLW_FONT,(u32)font,TAG_DONE);
02276 font=NULL;
02277 list_DeleteNode(node);
02278 }
02279 }
02280 }
02281 else
02282 {
02283 font->counter++;
02284 }
02285 }
02286 }
02287
02288 debug_End();
02289
02290 return((u32)(u32)font);
02291 }
02292
02293
02297 u32 glw_CloseFont(u32 firsttag, ...)
02298 {
02299 return(glw_CloseFontTL((tag *)&firsttag));
02300 }
02301 u32 glw_CloseFontTL(tag *taglist)
02302 {
02303 u32 font;
02304
02305 struct glw_Font *fnt;
02306
02307 debug_Begin();
02308
02309 font=(u32 )tag_GetTagData(taglist,TAG_GLW_FONT,0L);
02310 fnt=(struct glw_Font *)font;
02311
02312 if(fnt!=NULL)
02313 {
02314 if(--fnt->counter<=0)
02315 {
02316 if(fnt->handle!=NULL)
02317 {
02318 DeleteObject(fnt->handle);
02319 fnt->handle=NULL;
02320 list_RemoveNode(fontlist,fnt->node);
02321 list_SetNodeData(fnt->node,NULL);
02322 list_DeleteNode(fnt->node);
02323 }
02324 mem_free(fnt);
02325 }
02326 }
02327
02328 debug_End();
02329
02330 return(0L);
02331 }
02332
02333
02341 u32 glw_DrawText(u32 firsttag, ...)
02342 {
02343 return(glw_DrawTextTL((tag *)&firsttag));
02344 }
02345 u32 glw_DrawTextTL(tag *taglist)
02346 {
02347 u32 window;
02348 Rect_t *cliprect;
02349 u32 font;
02350 char *text;
02351 u32 flags;
02352
02353 struct glw_Window *win;
02354 struct glw_Font *fnt;
02355 RECT rct;
02357 HFONT oldfont;
02358 int left,top;
02359 u32 alignH=TA_LEFT;
02360
02361
02362 debug_Begin();
02363
02364 window=(u32 )tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
02365 cliprect=(Rect_t *)tag_GetTagData(taglist,TAG_GLW_CLIPRECT,0L);
02366 font=(u32 )tag_GetTagData(taglist,TAG_GLW_FONT,0L);
02367 text=(char *)tag_GetTagData(taglist,TAG_GLW_TEXT,0L);
02368 flags=(u32 )tag_GetTagData(taglist,TAG_GLW_FLAGS,0L);
02369
02370 win=(struct glw_Window *)window;
02371 fnt=(struct glw_Font *)font;
02372
02373 if(win->fgrgb!=GLW_TRANSPARENT&&fnt!=NULL)
02374 {
02375 rct.left=cliprect->left;
02376 rct.top=cliprect->top;
02377 rct.right=cliprect->left+cliprect->width-1;
02378 rct.bottom=cliprect->top+cliprect->height-1;
02380 oldfont=SelectObject(win->hdcMem,fnt->handle);
02381 SetTextColor(win->hdcMem,win->fgcol);
02382 left=cliprect->left;
02383 top=cliprect->top;
02384 if((flags&GLWFA_ALIGN_RIGHT)!=0)
02385 {
02386 left=cliprect->left+cliprect->width;
02387 alignH=TA_RIGHT;
02388 }
02389 if((flags&GLWFA_ALIGN_CENTER)!=0)
02390 {
02391 left+=cliprect->width>>1;
02392 alignH=TA_CENTER;
02393 }
02394 if((flags&GLWFA_VALIGN_BOTTOM)!=0)
02395 {
02396 top+=cliprect->height-fnt->size;
02397 }
02398 if((flags&GLWFA_VALIGN_CENTER)!=0)
02399 {
02400 top+=(cliprect->height-fnt->size)>>1;
02401 }
02402 SetTextAlign(win->hdcMem,alignH|TA_TOP);
02403
02404 SetBkMode(win->hdcMem,TRANSPARENT);
02405
02406 ExtTextOut(win->hdcMem,left,top,ETO_CLIPPED,&rct,text,strlen(text),NULL);
02407 SelectObject(win->hdcMem,oldfont);
02409 }
02410
02411 debug_End();
02412
02413 return((u32)0);
02414 };
02415
02416
02420 u32 glw_GetFontSize(u32 firsttag, ...)
02421 {
02422 return(glw_GetFontSizeTL((tag *)&firsttag));
02423 }
02424 u32 glw_GetFontSizeTL(tag *taglist)
02425 {
02426 u32 font;
02427
02428 int ret=-1;
02429 struct glw_Font *fnt;
02430
02431
02432 debug_Begin();
02433
02434 font=(u32 )tag_GetTagData(taglist,TAG_GLW_FONT,0L);
02435
02436 fnt=(struct glw_Font *)font;
02437
02438 if(fnt!=NULL) ret=fnt->size;
02439
02440 debug_End();
02441
02442 return((u32)ret);
02443 }
02444
02445
02450 u32 glw_GetTextLength(u32 firsttag, ...)
02451 {
02452 return(glw_GetTextLengthTL((tag *)&firsttag));
02453 }
02454 u32 glw_GetTextLengthTL(tag *taglist)
02455 {
02456 u32 font;
02457 char *text;
02458
02459 int ret=0;
02460 struct glw_Font *fnt;
02461 HFONT oldfont;
02462 SIZE size;
02463
02464 debug_Begin();
02465
02466 font=(u32 )tag_GetTagData(taglist,TAG_GLW_FONT,0L);
02467 text=(char *)tag_GetTagData(taglist,TAG_GLW_TEXT,0L);
02468
02469 fnt=(struct glw_Font *)font;
02470
02471 if(text!=NULL&&fnt!=NULL&&workDC!=NULL)
02472 {
02473 oldfont=SelectObject(workDC,fnt->handle);
02474 GetTextExtentPoint32(workDC,text,strlen(text),&size);
02475 SelectObject(workDC,oldfont);
02476 ret=size.cx;
02477 }
02478
02479 debug_End();
02480
02481 return((u32)ret);
02482 }
02483
02484
02485
02495 u32 glw_PutImage(u32 firsttag, ...)
02496 {
02497 return(glw_PutImageTL((tag *)&firsttag));
02498 }
02499 u32 glw_PutImageTL(tag *taglist)
02500 {
02501 u32 window;
02502 Vector_t *pixels;
02503 Rect_t *cliprect;
02504 int left;
02505 int top;
02506 int width;
02507 int height;
02508
02509 struct glw_Window *win;
02511 struct glw_InternalBMI bmi;
02512 int ret,fr=0;
02513 u8 *buf=NULL;
02514
02515
02516 debug_Begin();
02517
02518 window=(u32 )tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
02519 pixels=(Vector_t *)tag_GetTagData(taglist,TAG_GLW_PIXELS,0L);
02520 cliprect=(Rect_t *)tag_GetTagData(taglist,TAG_GLW_CLIPRECT,0L);
02521 left=(int )tag_GetTagData(taglist,TAG_GLW_LEFT,0L);
02522 top=(int )tag_GetTagData(taglist,TAG_GLW_TOP,0L);
02523 width=(int )tag_GetTagData(taglist,TAG_GLW_WIDTH,0L);
02524 height=(int )tag_GetTagData(taglist,TAG_GLW_HEIGHT,0L);
02525
02526 win=(struct glw_Window *)window;
02527
02528 memset(&bmi,0,sizeof(struct glw_InternalBMI));
02529
02531 bmi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
02532 bmi.bmiHeader.biWidth=width;
02533 bmi.bmiHeader.biHeight=-height;
02534 bmi.bmiHeader.biPlanes=1;
02535 bmi.bmiHeader.biBitCount=32;
02536 bmi.bmiHeader.biXPelsPerMeter=1;
02537 bmi.bmiHeader.biYPelsPerMeter=1;
02538 if(wv>=3)
02539 {
02540 bmi.bmiHeader.biCompression=BI_BITFIELDS;
02541 bmi.bmiColors[0].rgbGreen=0xff;
02542 bmi.bmiColors[1].rgbRed=0xff;
02543 bmi.bmiColors[2].rgbReserved=0xff;
02544 buf=pixels->data;
02545 }
02546 else
02547 {
02548 int mx,j;
02549 u32 px;
02550 u8 *pxb;
02551 u32 *npx;
02552
02553 bmi.bmiHeader.biCompression=BI_RGB;
02554 if(NULL!=(buf=mem_malloc(width*height*4)))
02555 {
02556 fr=1;
02557 mx=width*height;
02558 for(j=0,pxb=pixels->data,npx=(u32 *)buf;j<mx;j++,pxb+=4)
02559 {
02560 px=pxb[0]<<24|pxb[1]<<16|pxb[2]<<8|pxb[3];
02561 *npx++=px;
02562 }
02563 } else buf=pixels->data;
02564 }
02565 ret=-!SetDIBitsToDevice(win->hdcMem,left,top,cliprect->width,cliprect->height,0,0,0,height,buf,(BITMAPINFO *)&bmi,DIB_RGB_COLORS);
02566
02568
02569 if(fr!=0) mem_free(buf);
02570
02571 debug_End();
02572
02573 return((u32)0);
02574 };
02575
02576
02577
02582 u32 glw_GetScreenDimensions(u32 firsttag, ...)
02583 {
02584 return(glw_GetScreenDimensionsTL((tag *)&firsttag));
02585 }
02586 u32 glw_GetScreenDimensionsTL(tag *taglist)
02587 {
02588 u32 window;
02589 Rect_t *rect;
02590
02591
02592 debug_Begin();
02593
02594 window=(u32 )tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
02595 rect=(Rect_t *)tag_GetTagData(taglist,TAG_GLW_RECT,0L);
02596
02597 rect->left=0;
02598 rect->top=0;
02599 rect->width=buffsizeX;
02600 rect->height=buffsizeY;
02601
02602 debug_End();
02603
02604 return((u32)0);
02605 }
02606
02607
02611 u32 glw_Sleep(u32 firsttag, ...)
02612 {
02613 return(glw_SleepTL((tag *)&firsttag));
02614 }
02615 u32 glw_SleepTL(tag *taglist)
02616 {
02617 u32 millisec;
02618
02619 debug_Begin();
02620
02621 millisec=(u32 )tag_GetTagData(taglist,TAG_GLW_MILLISEC,0L);
02622
02623 Sleep((DWORD)millisec);
02624
02625 debug_End();
02626
02627 return(0L);
02628 }
02629
02630
02636 u32 glw_TimerStart(u32 firsttag, ...)
02637 {
02638 return(glw_TimerStartTL((tag *)&firsttag));
02639 }
02640 u32 glw_TimerStartTL(tag *taglist)
02641 {
02642 u32 window;
02643 u32 millisec;
02644 u32 userdata;
02645
02646 struct glw_Window *win;
02647 u32 id;
02648
02649 debug_Begin();
02650
02651 window=(u32 )tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
02652 millisec=(u32 )tag_GetTagData(taglist,TAG_GLW_MILLISEC,0L);
02653 userdata=(u32 )tag_GetTagData(taglist,TAG_GLW_USERDATA,0L);
02654
02655 win=(struct glw_Window *)window;
02656
02657 id=SetTimer(win->window,userdata,(UINT)millisec,NULL);
02658
02659 debug_End();
02660
02661 return((u32)id);
02662 }
02663
02664
02669 u32 glw_TimerCancel(u32 firsttag, ...)
02670 {
02671 return(glw_TimerCancelTL((tag *)&firsttag));
02672 }
02673 u32 glw_TimerCancelTL(tag *taglist)
02674 {
02675 u32 window;
02676 u32 id;
02677
02678 struct glw_Window *win;
02679
02680 debug_Begin();
02681
02682 window=(u32 )tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
02683 id=(u32 )tag_GetTagData(taglist,TAG_GLW_ID,0L);
02684
02685 win=(struct glw_Window *)window;
02686
02687 KillTimer(win->window,id);
02688
02689 debug_End();
02690 return(0L);
02691 }
02692
02693
02697 u32 glw_GetTime(u32 firsttag, ...)
02698 {
02699 return(glw_GetTimeTL((tag *)&firsttag));
02700 }
02701 u32 glw_GetTimeTL(tag *taglist)
02702 {
02703 struct glw_Time *tm;
02704
02705 SYSTEMTIME st;
02706 u32 ret=0L;
02707
02708
02709 debug_Begin();
02710
02711 tm=(struct glw_Time *)tag_GetTagData(taglist,TAG_GLW_TM,0L);
02712
02713 ret=(u32)time(NULL);
02714 if(tm!=NULL)
02715 {
02716 GetSystemTime(&st);
02717 tm->secs=ret;
02718 tm->millis=(u32)st.wMilliseconds;
02719 }
02720
02721 debug_End();
02722
02723 return((u32)ret);
02724 }
02725
02726
02727
02728 u32 glw_Call(int function, u32 firsttag, ...)
02729 {
02730 return(glw_CallTL(function,(tag *)&firsttag));
02731 }
02732 u32 glw_CallTL(int function, tag *taglist)
02733 {
02734 u32 ret=~0L;
02735
02736 debug_Begin();
02737
02738 if(function>=GLW_FUNCBASE&&function<GLW_FUNC_DONE)
02739 {
02740 ret=call_vector[function-GLW_FUNCBASE](taglist);
02741 }
02742 else debug_Warning("%s(): Function code out of range! code=0x%04x",__FUNCTION__,function);
02743
02744 debug_End();
02745
02746 return(ret);
02747 }
02748
02749
02750 static char *glw_ConvPath(char *name)
02751 {
02752 char *name2=NULL;
02753 int i,j;
02754
02755 debug_Begin();
02756
02757 if(NULL!=(name2=mem_malloc(strlen(name)*2+2)))
02758 {
02759 for(i=j=0;name[i]!='\0';i++)
02760 {
02761 if(name[i]!='/') name2[j++]=name[i];
02762 else name2[j++]='\\';
02763 }
02764 name2[j]='\0';
02765 }
02766
02767 debug_End();
02768
02769 return(name2);
02770 }
02771
02772
02773 u32 glw_OpenModule(char *name)
02774 {
02775 u32 ret=0L;
02776 HMODULE hmod;
02777 int (*module_Init)(u32,bases_Modules_t *);
02778 char *name2;
02779
02780 debug_Begin();
02781
02782 if(NULL!=(name2=glw_ConvPath(name)))
02783 {
02784 debug_Message("Module request: '%s' -> '%s'",name,name2);
02785 hmod=LoadLibraryEx(name2,NULL,0L);
02786 if(hmod!=NULL)
02787 {
02788 module_Init=(int (*)(u32,bases_Modules_t *))GetProcAddress(hmod,"module_Init");
02789 ret=(u32)hmod;
02790 module_Init(ret,&bases_modules);
02791 }
02792 else debug_Warning("Cannot load module '%s'!",name);
02793 mem_free(name2);
02794 }
02795 if(ret==0L) debug_Error("cannot load module '%s'",name);
02796
02797 debug_End();
02798
02799 return(ret);
02800 }
02801 void glw_CloseModule(u32 handle)
02802 {
02803 if(handle!=0L)
02804 {
02805 FreeLibrary((HMODULE)handle);
02806 }
02807 }
02808
02809
02810
02811
02812
02813 glw_Dir_t *glw_DirOpen(char *path)
02814 {
02815 glw_Dir_t *dir=NULL;
02816 char *path2;
02817 char *path3;
02818 WIN32_FIND_DATA FindFileData;
02819
02820 debug_Begin();
02821
02822 FindFileData.cFileName[0]='\0';
02823 if(NULL!=(path2=glw_ConvPath(path)))
02824 {
02825 if(NULL!=(path3=mem_malloc(strlen(path2)+3)))
02826 {
02827 strcpy(path3,path2);
02828 strcat(path3,"\\*");
02829 if(NULL!=(dir=mem_malloc(sizeof(struct glw_Dir))))
02830 {
02831 dir->filename=NULL;
02832 if(INVALID_HANDLE_VALUE!=(dir->hdir=FindFirstFile(path3,&FindFileData)))
02833 {
02834 dir->filename=common_strdup(FindFileData.cFileName);
02835 }
02836 }
02837 mem_free(path3);
02838 }
02839 mem_free(path2);
02840 }
02841
02842 debug_End();
02843
02844 return(dir);
02845 }
02846
02847 void glw_DirClose(glw_Dir_t *dir)
02848 {
02849 debug_Begin();
02850
02851 if(dir!=NULL)
02852 {
02853 if(dir->filename!=NULL) mem_free(dir->filename);
02854 if(dir->hdir!=INVALID_HANDLE_VALUE) FindClose(dir->hdir);
02855 mem_free(dir);
02856 }
02857
02858 debug_End();
02859 }
02860
02861 char *glw_DirNext(glw_Dir_t *dir)
02862 {
02863 char *ret=NULL;
02864 WIN32_FIND_DATA FindFileData;
02865
02866 debug_Begin();
02867
02868 FindFileData.cFileName[0]='\0';
02869 if(dir!=NULL)
02870 {
02871 if(dir->filename!=NULL)
02872 {
02873 ret=dir->filename;
02874 dir->filename=NULL;
02875 }
02876 else
02877 {
02878 FindNextFile(dir->hdir,&FindFileData);
02879 if(FindFileData.cFileName[0]!='\0') ret=common_strdup(FindFileData.cFileName);
02880 else ret=NULL;
02881 }
02882 }
02883
02884 debug_End();
02885
02886 return(ret);
02887 }
02888
02889
02890
02891
02892
02900 u32 glw_SetWindowShape(u32 firsttag, ...)
02901 {
02902 return(glw_SetWindowShapeTL((tag *)&firsttag));
02903 }
02904 u32 glw_SetWindowShapeTL(tag *taglist)
02905 {
02906 struct glw_Window *win;
02907 Vector_t *vector;
02908 int width;
02909 int height;
02910 int bytewidth;
02911
02912 u32 ret=~0L;
02913 int x,y,addr,bit;
02914 HRGN hRgn;
02915 HRGN hTmpRgn;
02916 int state;
02917 int prevx=-1;
02918
02919 debug_Begin();
02920
02921 win=(struct glw_Window *)tag_GetTagData(taglist,TAG_GLW_WINDOW,0L);
02922 vector=(Vector_t *)tag_GetTagData(taglist,TAG_GLW_VECTOR,0L);
02923 width=(int)tag_GetTagData(taglist,TAG_GLW_WIDTH,0L);
02924 height=(int)tag_GetTagData(taglist,TAG_GLW_HEIGHT,0L);
02925 bytewidth=(int)tag_GetTagData(taglist,TAG_GLW_BYTEWIDTH,0L);
02926
02927 if(win!=NULL)
02928 {
02929 ret=0L;
02930 state=win->user_state;
02931 win->user_state=GLWWS_SKINNING;
02932 if(vector!=NULL&&vector->data!=NULL&&vector->size>0&&width>0&&height>0&&bytewidth>0)
02933 {
02934 if(vector->size==height*bytewidth)
02935 {
02936 if((hRgn=CreateRectRgn(0,0,width,height)))
02937 {
02938
02939 for(y=0;y<height;y++)
02940 {
02941 for(x=0;x<width;x++)
02942 {
02943 addr=y*bytewidth+(x/8);
02944 bit=1<<(7-(x%8));
02945 if(((vector->data[addr]&bit)&0xff)==0)
02946 {
02947 if(prevx<0) prevx=x;
02948 }
02949 else if(prevx>=0)
02950 {
02951 if((hTmpRgn=CreateRectRgn(prevx,y,x,y+1)))
02952 {
02953 CombineRgn(hRgn,hRgn,hTmpRgn,RGN_XOR);
02954 DeleteObject(hTmpRgn);
02955 }
02956 prevx=-1;
02957 }
02958 }
02959 if(prevx>=0)
02960 {
02961 if((hTmpRgn=CreateRectRgn(prevx,y,x,y+1)))
02962 {
02963 CombineRgn(hRgn,hRgn,hTmpRgn,RGN_XOR);
02964 DeleteObject(hTmpRgn);
02965 }
02966 prevx=-1;
02967 }
02968 }
02969
02970 SetWindowRgn(win->window,hRgn,FALSE);
02971 }
02972 }
02973 else debug_Error("Vector size doesn't match");
02974 }
02975 else
02976 {
02977
02978 SetWindowRgn(win->window,NULL,FALSE);
02979 }
02980 win->user_state=state;
02981 }
02982
02983 debug_End();
02984
02985 return(ret);
02986 }
02987
02988
02989 int glw_GetTerminalByteOrder(u32 connection)
02990 {
02991 struct glw_Connection *conn=(struct glw_Connection *)connection;
02992 int ret=-1;
02993
02994 debug_Begin();
02995
02996 if(conn!=NULL) ret=conn->termbyteorder;
02997
02998 debug_End();
02999
03000 return(ret);
03001 }
03002
03003
03004 int glw_ReadTerm(u32 connection, u8 *buff, int len)
03005 {
03006 int ret=-1;
03007 struct glw_Connection *conn=(struct glw_Connection *)connection;
03008 int r;
03009
03010 debug_Begin();
03011
03012 if(conn!=NULL)
03013 {
03014 ret=0;
03015 if((r=recv(conn->sterm,buff,len,MSG_WAITALL))!=len)
03016 {
03017 ret=-1;
03018 debug_Error("Socket error: (r=%d) %d",r,WSAGetLastError());
03019 conn->cuser.quit=1;
03020 }
03021 }
03022
03023 debug_End();
03024
03025 return(ret);
03026 }
03027
03028
03029 int glw_SendTerm(u32 connection, u8 *buff, int len)
03030 {
03031 int ret=-1;
03032 struct glw_Connection *conn=(struct glw_Connection *)connection;
03033
03034 debug_Begin();
03035
03036 if(conn!=NULL&&buff!=NULL&&len>0)
03037 {
03038 ret=send(conn->sterm,buff,len,0);
03039 }
03040
03041 debug_End();
03042
03043 return(ret);
03044 }
03045
03046
03047
03048
03049