/[gpgoe]/trunk/src/OEMisc.c
ViewVC logotype

Diff of /trunk/src/OEMisc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 15 by twoaday, Fri Apr 7 10:46:41 2006 UTC revision 16 by twoaday, Tue Apr 11 06:56:23 2006 UTC
# Line 30  Line 30 
30  #include "GPGOE.h"  #include "GPGOE.h"
31    
32    
33    /* Convert the string from the native code page  to UTF8. */
34  char*  char*
35  native_to_utf8 (const char *string)  native_to_utf8 (const char *string)
36  {  {
# Line 165  set_clip_text (HWND hwnd, const char *te Line 166  set_clip_text (HWND hwnd, const char *te
166      SetClipboardData (CF_TEXT, clipmem);      SetClipboardData (CF_TEXT, clipmem);
167      GlobalUnlock (clipmem);      GlobalUnlock (clipmem);
168      CloseClipboard ();      CloseClipboard ();
169      GlobalFree (clipmem);      GlobalFree (clipmem);  
170            
171      return 0;      return 0;
172  }  }
# Line 213  show_error (HWND hwnd, const char *capti Line 214  show_error (HWND hwnd, const char *capti
214      va_end (ptr);      va_end (ptr);
215      MessageBox (hwnd, buffer, caption, type);      MessageBox (hwnd, buffer, caption, type);
216  }  }
217    
218    
219    /* Prepend '> ' to line line in the buffer @inp
220       and store the result in @r_outp. */
221    void
222    quote_msg_text (const char *inp, char **r_outp)
223    {
224        size_t i, n=0;
225        char *p;
226        char *outp;
227    
228        for (i=0; i < strlen (inp); i++) {
229            if (inp[i] == '\r')
230                n += 4;
231        }
232        outp = xcalloc (1, strlen (inp) + 1 + n + 1);
233        p = strtok ((char *)inp, "\r");
234        while (p != NULL) {
235            if (*p == '\n')
236                p++;
237            strcat (outp, "> ");
238            strcat (outp, p);
239            strcat (outp, "\r\n");
240            p = strtok (NULL, "\r");
241        }
242        *r_outp = outp;
243    }
244    
245    
246    /* Center the window @hwndChild over the parent window @parent. */
247    void
248    center_window (HWND hwndChild, HWND parent)
249    {    
250        HWND hwndParent;
251        RECT rChild, rParent;
252        HDC hdc;
253        int wChild, hChild, wParent, hParent;
254        int wScreen, hScreen, xNew, yNew;
255        int flags = SWP_NOSIZE | SWP_NOZORDER;
256    
257        hwndParent = parent;
258        if (hwndParent == NULL)
259            hwndParent = GetDesktopWindow ();
260        GetWindowRect (hwndChild, &rChild);    
261        wChild = rChild.right - rChild.left;    
262        hChild = rChild.bottom - rChild.top;
263    
264        GetWindowRect (hwndParent, &rParent);    
265        wParent = rParent.right - rParent.left;    
266        hParent = rParent.bottom - rParent.top;      
267        
268        hdc = GetDC (hwndChild);    
269        wScreen = GetDeviceCaps (hdc, HORZRES);    
270        hScreen = GetDeviceCaps (hdc, VERTRES);    
271        ReleaseDC (hwndChild, hdc);      
272        xNew = rParent.left + ((wParent - wChild) /2);    
273        if (xNew < 0)
274            xNew = 0;
275        else if ((xNew+wChild) > wScreen)
276            xNew = wScreen - wChild;
277        yNew = rParent.top  + ((hParent - hChild) /2);
278        if (yNew < 0)
279            yNew = 0;
280        else if ((yNew+hChild) > hScreen)
281            yNew = hScreen - hChild;
282        SetWindowPos (hwndChild, NULL, xNew, yNew, 0, 0, flags);
283    }

Legend:
Removed from v.15  
changed lines
  Added in v.16

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26