Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

Glw.c

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

Generated on Tue Jan 7 12:11:20 2003 for THEGUI by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002