~ubuntu-branches/ubuntu/raring/lmms/raring-proposed

« back to all changes in this revision

Viewing changes to plugins/zynaddsubfx/fltk/src/Fl_win32.cxx

  • Committer: Charlie Smotherman
  • Date: 2012-12-05 22:08:38 UTC
  • mfrom: (33.1.7 lmms_0.4.13)
  • Revision ID: cjsmo@cableone.net-20121205220838-09pjfzew9m5023hr
* New  Upstream release.
  - Minor tweaking to ZynAddSubFX, CALF, SWH plugins  and Stefan Fendt's RC
    filters.
  - Added UI fixes: Magnentic effect of knobs and Piano-roll fixes
  - Updated German localization and copyright year
* debian/lmms-common.install:
  - added /usr/share/applications so the lmms.desktop file will correctly
    install (LP: #863366)
  - This should also fix the Software Center not displaying lmms in sound
    and video (LP: #824231)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//
2
 
// "$Id: Fl_win32.cxx 7659 2010-07-01 13:21:32Z manolo $"
 
2
// "$Id: Fl_win32.cxx 8759 2011-05-30 12:33:51Z manolo $"
3
3
//
4
4
// WIN32-specific code for the Fast Light Tool Kit (FLTK).
5
5
//
6
 
// Copyright 1998-2009 by Bill Spitzak and others.
 
6
// Copyright 1998-2010 by Bill Spitzak and others.
7
7
//
8
8
// This library is free software; you can redistribute it and/or
9
9
// modify it under the terms of the GNU Library General Public
29
29
// in.  Search other files for "WIN32" or filenames ending in _win32.cxx
30
30
// for other system-specific code.
31
31
 
 
32
// This file must be #include'd in Fl.cxx and not compiled separately.
 
33
 
32
34
#ifndef FL_DOXYGEN
33
35
#include <FL/Fl.H>
34
 
#include <FL/x.H>
35
36
#include <FL/fl_utf8.h>
36
37
#include <FL/Fl_Window.H>
37
38
#include <FL/fl_draw.H>
38
39
#include <FL/Enumerations.H>
39
40
#include <FL/Fl_Tooltip.H>
 
41
#include <FL/Fl_Paged_Device.H>
40
42
#include "flstring.h"
41
43
#include "Fl_Font.H"
42
44
#include <stdio.h>
46
48
#ifdef __CYGWIN__
47
49
#  include <sys/time.h>
48
50
#  include <unistd.h>
49
 
#else
50
 
# if !defined(USE_WSOCK1)
51
 
#  include <winsock2.h>
52
 
#else
53
 
#  include <winsock.h>
54
 
# endif
55
 
#endif
56
 
#if !defined(USE_WSOCK1)
57
 
#  define WSCK_DLL_NAME "WS2_32.DLL"
58
 
#else
59
 
#  define WSCK_DLL_NAME "WSOCK32.DLL"
60
 
#endif
61
 
#include <winuser.h>
62
 
#include <commctrl.h>
63
 
 
64
 
#if defined(__GNUC__) && __GNUC__ >= 3
 
51
#endif
 
52
 
 
53
#if !defined(NO_TRACK_MOUSE)
 
54
#  include <commctrl.h> // TrackMouseEvent
 
55
// fabien: Ms Visual Studio >= 2003 permit embedded lib reference
 
56
// that makes fltk use easier as only fltk libs are now requested
 
57
// This idea could be extended to fltk libs themselves, 
 
58
// implementer should then care about DLL linkage flags ...
 
59
#  if (_MSC_VER>=1310)
 
60
#    pragma comment (lib, "comctl32.lib")
 
61
#  endif
 
62
#endif
 
63
 
 
64
#if defined(__GNUC__)
65
65
# include <wchar.h>
66
66
#endif
67
67
 
68
 
// The following include files require GCC 3.x or a non-GNU compiler...
69
 
#if !defined(__GNUC__) || __GNUC__ >= 3
70
 
#  include <ole2.h>
71
 
#  include <shellapi.h>
72
 
#endif // !__GNUC__ || __GNUC__ >= 3
 
68
#include <ole2.h>
 
69
#include <shellapi.h>
73
70
 
74
71
#include "aimm.h"
75
72
 
97
94
 
98
95
static Fl_GDI_Graphics_Driver fl_gdi_driver;
99
96
static Fl_Display_Device fl_gdi_display(&fl_gdi_driver);
100
 
FL_EXPORT Fl_Display_Device *fl_display_device = (Fl_Display_Device*)&fl_gdi_display; // does not change
101
97
FL_EXPORT Fl_Graphics_Driver *fl_graphics_driver = (Fl_Graphics_Driver*)&fl_gdi_driver; // the current target driver of graphics operations
102
 
FL_EXPORT Fl_Surface_Device *fl_surface = (Fl_Surface_Device*)fl_display_device; // the current target surface of graphics operations
 
98
Fl_Surface_Device* Fl_Surface_Device::_surface = (Fl_Surface_Device*)&fl_gdi_display; // the current target surface of graphics operations
 
99
Fl_Display_Device *Fl_Display_Device::_display = &fl_gdi_display; // the platform display
103
100
 
104
101
// dynamic wsock dll handling api:
105
102
#if defined(__CYGWIN__) && !defined(SOCKET)
106
103
# define SOCKET int
107
104
#endif
 
105
 
 
106
// note: winsock2.h has been #include'd in Fl.cxx
 
107
#define WSCK_DLL_NAME "WS2_32.DLL"
 
108
 
108
109
typedef int (WINAPI* fl_wsk_select_f)(int, fd_set*, fd_set*, fd_set*, const struct timeval*);
109
110
typedef int (WINAPI* fl_wsk_fd_is_set_f)(SOCKET, fd_set *);
110
111
 
111
112
static HMODULE s_wsock_mod = 0;
112
 
static fl_wsk_select_f s_wsock_select=0;
113
 
static fl_wsk_fd_is_set_f fl_wsk_fd_is_set=0;
 
113
static fl_wsk_select_f s_wsock_select = 0;
 
114
static fl_wsk_fd_is_set_f fl_wsk_fd_is_set = 0;
114
115
 
115
116
static HMODULE get_wsock_mod() {
116
117
  if (!s_wsock_mod) {
245
246
static int maxfd = 0;
246
247
static fd_set fdsets[3];
247
248
 
248
 
#if !defined(__GNUC__) || __GNUC__ >= 3
249
249
extern IDropTarget *flIDropTarget;
250
 
#endif // !__GNUC__ || __GNUC__ >= 3
251
250
 
252
251
static int nfds = 0;
253
252
static int fd_array_size = 0;
568
567
      EmptyClipboard();
569
568
      HGLOBAL hMem = GlobalAlloc(GHND, utf16_len * 2 + 2); // moveable and zero'ed mem alloc.
570
569
      LPVOID memLock = GlobalLock(hMem);
571
 
      fl_utf8toUtf16(fl_selection_buffer[clipboard], fl_selection_length[clipboard], (unsigned short*) memLock, utf16_len * 2);
 
570
      fl_utf8toUtf16(fl_selection_buffer[clipboard], fl_selection_length[clipboard], (unsigned short*) memLock, utf16_len + 1);
572
571
      GlobalUnlock(hMem);
573
572
      SetClipboardData(CF_UNICODETEXT, hMem);
574
573
      CloseClipboard();
743
742
  {VK_LWIN,     FL_Meta_L},
744
743
  {VK_RWIN,     FL_Meta_R},
745
744
  {VK_APPS,     FL_Menu},
 
745
  {VK_SLEEP, FL_Sleep},
746
746
  {VK_MULTIPLY, FL_KP+'*'},
747
747
  {VK_ADD,      FL_KP+'+'},
748
748
  {VK_SUBTRACT, FL_KP+'-'},
750
750
  {VK_DIVIDE,   FL_KP+'/'},
751
751
  {VK_NUMLOCK,  FL_Num_Lock},
752
752
  {VK_SCROLL,   FL_Scroll_Lock},
 
753
# if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0500)
 
754
  {VK_BROWSER_BACK, FL_Back},
 
755
  {VK_BROWSER_FORWARD, FL_Forward},
 
756
  {VK_BROWSER_REFRESH, FL_Refresh},
 
757
  {VK_BROWSER_STOP, FL_Stop},
 
758
  {VK_BROWSER_SEARCH, FL_Search},
 
759
  {VK_BROWSER_FAVORITES, FL_Favorites},
 
760
  {VK_BROWSER_HOME, FL_Home_Page},
 
761
  {VK_VOLUME_MUTE, FL_Volume_Mute},
 
762
  {VK_VOLUME_DOWN, FL_Volume_Down},
 
763
  {VK_VOLUME_UP, FL_Volume_Up},
 
764
  {VK_MEDIA_NEXT_TRACK, FL_Media_Next},
 
765
  {VK_MEDIA_PREV_TRACK, FL_Media_Prev},
 
766
  {VK_MEDIA_STOP, FL_Media_Stop},
 
767
  {VK_MEDIA_PLAY_PAUSE, FL_Media_Play},
 
768
  {VK_LAUNCH_MAIL, FL_Mail},
 
769
#endif
753
770
  {0xba,        ';'},
754
771
  {0xbb,        '='},
755
772
  {0xbc,        ','},
1076
1093
            break;
1077
1094
        }
1078
1095
      }
1079
 
    } else if ((lParam & (1<<31))==0){
 
1096
    } else if ((lParam & (1<<31))==0) {
 
1097
#ifdef FLTK_PREVIEW_DEAD_KEYS
 
1098
      if ((lParam & (1<<24))==0) { // clear if dead key (always?)
 
1099
        xchar u = (xchar) wParam;
 
1100
        Fl::e_length = fl_utf8fromwc(buffer, 1024, &u, 1);
 
1101
        buffer[Fl::e_length] = 0;
 
1102
      } else { // set if "extended key" (never printable?)
 
1103
        buffer[0] = 0;
 
1104
        Fl::e_length = 0;
 
1105
      }
 
1106
#else
1080
1107
      buffer[0] = 0;
1081
1108
      Fl::e_length = 0;
 
1109
#endif
1082
1110
    }
1083
1111
    Fl::e_text = buffer;
1084
1112
    if (lParam & (1<<31)) { // key up events.
1087
1115
    }
1088
1116
    // for (int i = lParam&0xff; i--;)
1089
1117
    while (window->parent()) window = window->window();
1090
 
    if (Fl::handle(FL_KEYBOARD,window)) return 0;
 
1118
    if (Fl::handle(FL_KEYBOARD,window)) {
 
1119
          if (uMsg==WM_DEADCHAR || uMsg==WM_SYSDEADCHAR)
 
1120
                Fl::compose_state = 1;
 
1121
          return 0;
 
1122
        }
1091
1123
    break;}
1092
1124
 
1093
1125
  case WM_MOUSEWHEEL: {
1400
1432
    first_class_name = class_name;
1401
1433
  }
1402
1434
 
1403
 
  const wchar_t* class_namew = L"FLTK";
1404
 
  const wchar_t* message_namew = L"FLTK::ThreadWakeup";
 
1435
  wchar_t class_namew[100]; // (limited) buffer for Windows class name
 
1436
 
 
1437
  // convert UTF-8 class_name to wchar_t for RegisterClassExW and CreateWindowExW
 
1438
 
 
1439
  fl_utf8toUtf16(class_name,strlen(class_name),         // in
 
1440
                 (unsigned short*)class_namew,          // out
 
1441
                 sizeof(class_namew)/sizeof(wchar_t));  // max. size
 
1442
 
1405
1443
  if (!class_name_list.has_name(class_name)) {
1406
 
    WNDCLASSEX wc;
1407
1444
    WNDCLASSEXW wcw;
1408
 
 
1409
 
    memset(&wc, 0, sizeof(wc));
1410
 
    wc.cbSize = sizeof(WNDCLASSEX);
1411
1445
    memset(&wcw, 0, sizeof(wcw));
1412
1446
    wcw.cbSize = sizeof(WNDCLASSEXW);
1413
1447
 
1428
1462
    wcw.hbrBackground = NULL;
1429
1463
    wcw.lpszMenuName = NULL;
1430
1464
    wcw.lpszClassName = class_namew;
1431
 
    wcw.cbSize = sizeof(WNDCLASSEXW);
1432
1465
    RegisterClassExW(&wcw);
1433
 
    class_name_list.add_name((const char *)class_namew);
 
1466
    class_name_list.add_name(class_name);
1434
1467
  }
1435
1468
 
1436
 
  // const char* message_name = "FLTK::ThreadWakeup";
1437
 
  // if (!fl_wake_msg) fl_wake_msg = RegisterWindowMessage(message_name);
 
1469
  const wchar_t* message_namew = L"FLTK::ThreadWakeup";
1438
1470
  if (!fl_wake_msg) fl_wake_msg = RegisterWindowMessageW(message_namew);
1439
1471
 
1440
1472
  HWND parent;
1547
1579
    w->redraw(); // force draw to happen
1548
1580
  }
1549
1581
  // If we've captured the mouse, we dont want to activate any
1550
 
  // other windows from the code, or we loose the capture.
 
1582
  // other windows from the code, or we lose the capture.
1551
1583
  ShowWindow(x->xid, !showit ? SW_SHOWMINNOACTIVE :
1552
1584
             (Fl::grab() || (style & WS_POPUP)) ? SW_SHOWNOACTIVATE : SW_SHOWNORMAL);
1553
1585
 
1554
 
  // Drag-n-drop requires GCC 3.x or a non-GNU compiler...
1555
 
#if !defined(__GNUC__) || __GNUC__ >= 3
1556
1586
  // Register all windows for potential drag'n'drop operations
1557
 
  static char oleInitialized = 0;
1558
 
  if (!oleInitialized) { OleInitialize(0L); oleInitialized=1; }
1559
 
 
 
1587
  fl_OleInitialize();
1560
1588
  RegisterDragDrop(x->xid, flIDropTarget);
 
1589
 
1561
1590
  if (!fl_aimm) {
1562
 
    static char been_here = 0;
1563
 
    if (!been_here && !oleInitialized) CoInitialize(NULL);
1564
 
    been_here = 1;
1565
1591
    CoCreateInstance(CLSID_CActiveIMM, NULL, CLSCTX_INPROC_SERVER,
1566
1592
                     IID_IActiveIMMApp, (void**) &fl_aimm);
1567
1593
    if (fl_aimm) {
1568
1594
      fl_aimm->Activate(TRUE);
1569
1595
    }
1570
1596
  }
1571
 
#endif // !__GNUC__ || __GNUC__ >= 3
1572
1597
 
1573
1598
  if (w->modal()) {Fl::modal_ = w; fl_fix_focus();}
1574
1599
  return x;
1927
1952
}
1928
1953
 
1929
1954
Fl_Region XRectangleRegion(int x, int y, int w, int h) {
1930
 
  if (Fl_Surface_Device::surface()->type() == Fl_Display_Device::device_type) return CreateRectRgn(x,y,x+w,y+h);
 
1955
  if (Fl_Surface_Device::surface()->class_name() == Fl_Display_Device::class_id) return CreateRectRgn(x,y,x+w,y+h);
1931
1956
  // because rotation may apply, the rectangle becomes a polygon in device coords
1932
1957
  POINT pt[4] = { {x, y}, {x + w, y}, {x + w, y + h}, {x, y + h} };
1933
1958
  LPtoDP(fl_gc, pt, 4);
1934
1959
  return CreatePolygonRgn(pt, 4, ALTERNATE);
1935
1960
}
1936
1961
 
 
1962
Window fl_xid_(const Fl_Window *w) {
 
1963
  Fl_X *temp = Fl_X::i(w); 
 
1964
  return temp ? temp->xid : 0;
 
1965
}
 
1966
 
 
1967
int Fl_Window::decorated_w()
 
1968
{
 
1969
  if (!shown() || parent() || !border() || !visible()) return w();
 
1970
  int X, Y, bt, bx, by;
 
1971
  Fl_X::fake_X_wm(this, X, Y, bt, bx, by);
 
1972
  return w() + 2 * bx;
 
1973
}
 
1974
 
 
1975
int Fl_Window::decorated_h()
 
1976
{
 
1977
  if (!shown() || parent() || !border() || !visible()) return h();
 
1978
  int X, Y, bt, bx, by;
 
1979
  Fl_X::fake_X_wm(this, X, Y, bt, bx, by);
 
1980
  return h() + bt + 2 * by;
 
1981
}
 
1982
 
 
1983
void Fl_Paged_Device::print_window(Fl_Window *win, int x_offset, int y_offset)
 
1984
{
 
1985
  if (!win->shown() || win->parent() || !win->border() || !win->visible()) {
 
1986
    this->print_widget(win, x_offset, y_offset);
 
1987
    return;
 
1988
  }
 
1989
  int X, Y, bt, bx, by, ww, wh; // compute the window border sizes
 
1990
  Fl_X::fake_X_wm(win, X, Y, bt, bx, by);
 
1991
  ww = win->w() + 2 * bx;
 
1992
  wh = win->h() + bt + 2 * by;
 
1993
  Fl_Display_Device::display_device()->set_current(); // make window current
 
1994
  win->show();
 
1995
  Fl::check();
 
1996
  win->make_current();
 
1997
  HDC save_gc = fl_gc;
 
1998
  fl_gc = GetDC(NULL); // get the screen device context
 
1999
  // capture the 4 window sides from screen
 
2000
  RECT r; GetWindowRect(fl_window, &r);
 
2001
  uchar *top_image = fl_read_image(NULL, r.left, r.top, ww, bt + by);
 
2002
  uchar *left_image = fl_read_image(NULL, r.left, r.top, bx, wh);
 
2003
  uchar *right_image = fl_read_image(NULL, r.right - bx, r.top, bx, wh);
 
2004
  uchar *bottom_image = fl_read_image(NULL, r.left, r.bottom-by, ww, by);
 
2005
  ReleaseDC(NULL, fl_gc); fl_gc = save_gc;
 
2006
  this->set_current();
 
2007
  // print the 4 window sides
 
2008
  fl_draw_image(top_image, x_offset, y_offset, ww, bt + by, 3);
 
2009
  fl_draw_image(left_image, x_offset, y_offset, bx, wh, 3);
 
2010
  fl_draw_image(right_image, x_offset + win->w() + bx, y_offset, bx, wh, 3);
 
2011
  fl_draw_image(bottom_image, x_offset, y_offset + win->h() + bt + by, ww, by, 3);
 
2012
  delete[] top_image;
 
2013
  delete[] left_image;
 
2014
  delete[] right_image;
 
2015
  delete[] bottom_image;
 
2016
  // print the window inner part
 
2017
  this->print_widget(win, x_offset + bx, y_offset + bt + by);
 
2018
  fl_gc = GetDC(fl_xid(win));
 
2019
  ReleaseDC(fl_xid(win), fl_gc);
 
2020
}  
 
2021
 
1937
2022
#ifdef USE_PRINT_BUTTON
1938
2023
// to test the Fl_Printer class creating a "Print front window" button in a separate window
1939
2024
// contains also preparePrintFront call above
1949
2034
  if( printer.start_job(1) ) { o->window()->show(); return; }
1950
2035
  if( printer.start_page() ) { o->window()->show(); return; }
1951
2036
  printer.printable_rect(&w,&h);
 
2037
  int  wh, ww;
 
2038
  wh = win->decorated_h();
 
2039
  ww = win->decorated_w();
1952
2040
  // scale the printer device so that the window fits on the page
1953
2041
  float scale = 1;
1954
 
  if (win->w() > w || win->h() > h) {
1955
 
    scale = (float)w/win->w();
1956
 
    if ((float)h/win->h() < scale) scale = (float)h/win->h();
 
2042
  if (ww > w || wh > h) {
 
2043
    scale = (float)w/ww;
 
2044
    if ((float)h/wh < scale) scale = (float)h/wh;
1957
2045
    printer.scale(scale, scale);
1958
2046
  }
1959
2047
// #define ROTATE 20.0
1964
2052
  printer.rotate(ROTATE);
1965
2053
  printer.print_widget( win, - win->w()/2, - win->h()/2 );
1966
2054
  //printer.print_window_part( win, 0,0, win->w(), win->h(), - win->w()/2, - win->h()/2 );
1967
 
#else
1968
 
  printer.print_widget( win );
1969
 
  //printer.print_window_part( win, 0,0, win->w(), win->h() );
 
2055
#else  
 
2056
  printer.print_window(win);
1970
2057
#endif
1971
2058
  printer.end_page();
1972
2059
  printer.end_job();
1989
2076
#endif // FL_DOXYGEN
1990
2077
 
1991
2078
//
1992
 
// End of "$Id: Fl_win32.cxx 7659 2010-07-01 13:21:32Z manolo $".
 
2079
// End of "$Id: Fl_win32.cxx 8759 2011-05-30 12:33:51Z manolo $".
1993
2080
//