diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /utils/mxtk | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'utils/mxtk')
33 files changed, 5198 insertions, 0 deletions
diff --git a/utils/mxtk/mx.cpp b/utils/mxtk/mx.cpp new file mode 100644 index 0000000..8d5e35a --- /dev/null +++ b/utils/mxtk/mx.cpp @@ -0,0 +1,1152 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mx.cpp +// implementation: Win32 API +// last modified: Apr 18 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mx.h" +#include "mxtk/mxWindow.h" +#include "mxtk/mxEvent.h" +#include "mxtk/mxLinkedList.h" +#include <windows.h> +#include <commctrl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "tier1/utlvector.h" + + +#define WM_MOUSEWHEEL 0x020A + +//#include <ostream.h" + + + +void mxTab_resizeChild (HWND hwnd); + + + +mxWindow *g_mainWindow = 0; +static mxLinkedList *g_widgetList = 0; +static mxWindow *g_idleWindow = 0; + +static MSG msg; +static HWND g_hwndToolTipControl = 0; +static bool isClosing = false; +static HACCEL g_hAcceleratorTable = NULL; + +void mx::createAccleratorTable( int numentries, Accel_t *entries ) +{ + CUtlVector< ACCEL > accelentries; + + for ( int i = 0; i < numentries; ++i ) + { + const Accel_t& entry = entries[ i ]; + + ACCEL add; + add.key = entry.key; + add.cmd = entry.command; + add.fVirt = 0; + if ( entry.flags & ACCEL_ALT ) + { + add.fVirt |= FALT; + } + if ( entry.flags & ACCEL_CONTROL ) + { + add.fVirt |= FCONTROL; + } + if ( entry.flags & ACCEL_SHIFT ) + { + add.fVirt |= FSHIFT; + } + if ( entry.flags & ACCEL_VIRTKEY ) + { + add.fVirt |= FVIRTKEY; + } + + accelentries.AddToTail( add ); + } + + g_hAcceleratorTable = ::CreateAcceleratorTable( accelentries.Base(), accelentries.Count() ); +} + + + +void +mx_addWidget (mxWidget *widget) +{ + if (g_widgetList) + g_widgetList->add ((void *) widget); +} + + + +void +mx_removeWidget (mxWidget *widget) +{ + if (g_widgetList) + g_widgetList->remove ((void *) widget); +} + + + +HWND +mx_CreateToolTipControl () +{ + if (!g_hwndToolTipControl) + { + if (g_mainWindow) + { + g_hwndToolTipControl = CreateWindowEx (0, TOOLTIPS_CLASS, "", WS_POPUP | WS_EX_TOPMOST, + 0, 0, 0, 0, (HWND) g_mainWindow->getHandle (), + (HMENU) NULL, (HINSTANCE) GetModuleHandle (NULL), NULL); + } + } + + return g_hwndToolTipControl; +} + +//----------------------------------------------------------------------------- +// Purpose: +// Input : *window - +// *event - +// Output : static void +//----------------------------------------------------------------------------- +static void RecursiveHandleEvent( mxWindow *window, mxEvent *event ) +{ + while ( window ) + { + if ( window->handleEvent ( event ) ) + break; + + window = window->getParent(); + } +} + +char const *translatecode( int code ) +{ + switch ( code ) + { + case NM_CLICK: + return "NM_CLICK"; + case NM_CUSTOMDRAW: + return "NM_CUSTOMDRAW"; + case NM_DBLCLK: + return "NM_DBLCLK"; + case NM_KILLFOCUS: + return "NM_KILLFOCUS"; + case NM_RCLICK: + return "NM_RCLICK"; + case NM_RETURN: + return "NM_RETURN"; + case NM_SETCURSOR: + return "NM_SETCURSOR"; + case NM_SETFOCUS: + return "NM_SETFOCUS"; + case TVN_BEGINDRAG: + return "TVN_BEGINDRAG"; + case TVN_BEGINLABELEDIT: + return "TVN_BEGINLABELEDIT"; + case TVN_BEGINRDRAG: + return "TVN_BEGINRDRAG"; + case TVN_DELETEITEM: + return "TVN_DELETEITEM"; + case TVN_ENDLABELEDIT: + return "TVN_ENDLABELEDIT"; + case TVN_GETDISPINFO: + return "TVN_GETDISPINFO"; + case TVN_GETINFOTIP: + return "TVN_GETINFOTIP"; + case TVN_ITEMEXPANDED: + return "TVN_ITEMEXPANDED"; + case TVN_ITEMEXPANDING: + return "TVN_ITEMEXPANDING"; + case TVN_KEYDOWN : + return "TVN_KEYDOWN"; + case TVN_SELCHANGED : + return "TVN_SELCHANGED"; + case TVN_SELCHANGING : + return "TVN_SELCHANGING"; + case TVN_SETDISPINFO : + return "TVN_SETDISPINFO"; + case TVN_SINGLEEXPAND: + return "TVN_SINGLEEXPAND"; + } + + return "Unknown!!!"; +} +static LRESULT CALLBACK WndProc (HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam) +{ + static bool bDragging = FALSE; + + switch (uMessage) + { + case WM_SETFOCUS: + case WM_KILLFOCUS: + { + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + if ( window ) + { + mxEvent event; + event.event = mxEvent::Focus; + event.widget = NULL; + event.action = (uMessage == WM_SETFOCUS); + RecursiveHandleEvent( window, &event ); + return 0; + } + } + break; + + case WM_ACTIVATE: + { + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + if ( window ) + { + mxEvent event; + event.event = mxEvent::Activate; + event.widget = NULL; + event.action = (LOWORD( wParam ) != WA_INACTIVE); + RecursiveHandleEvent( window, &event ); + return 0; + } + } + break; + + case WM_COMMAND: + { + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + if (LOWORD (wParam) > 0 && window) + { + WORD wNotifyCode = (WORD) HIWORD (wParam); + HWND hwndCtrl = (HWND) lParam; + mxEvent event; + + CHAR className[128]; + GetClassName (hwndCtrl, className, 128); + if (!strcmpi (className, "edit")) + { + if (wNotifyCode != EN_CHANGE) + break; + } + else if (!strcmpi (className, "combobox")) + { + if (wNotifyCode != CBN_SELCHANGE) + break; + } + else if (!strcmpi (className, "listbox")) + { + if (wNotifyCode != LBN_SELCHANGE) + break; + } + + event.event = mxEvent::Action; + event.widget = (mxWidget *) GetWindowLong ((HWND) lParam, GWL_USERDATA); + event.action = (int) LOWORD (wParam); + RecursiveHandleEvent( window, &event ); + } + } + break; + + case WM_NOTIFY: + { + if (isClosing) + break; + + NMHDR *nmhdr = (NMHDR *) lParam; + mxEvent event; + +#if 0 + //if ( nmhdr->idFrom > 0 ) + { + mxWidget *temp = (mxWidget *) GetWindowLong (nmhdr->hwndFrom, GWL_USERDATA); + if ( temp && temp->getType() == MX_TREEVIEW ) + { + NMTREEVIEW *nmt = ( NMTREEVIEW * )nmhdr; + + HTREEITEM hItem = TreeView_GetSelection (nmhdr->hwndFrom); + + char sz[ 256 ]; + sprintf( sz, "tree view receiving notify %i : %s action %i old %p new %p selection %p\n", nmhdr->code, translatecode( nmhdr->code ), + nmt->action, nmt->itemOld, nmt->itemNew, hItem ); + + OutputDebugString( sz ); + } + } +#endif + + if (nmhdr->code == TVN_SELCHANGED) + { + if (nmhdr->idFrom > 0) + { + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + event.event = mxEvent::Action; + event.widget = (mxWidget *) GetWindowLong (nmhdr->hwndFrom, GWL_USERDATA); + event.action = (int) nmhdr->idFrom; + + RECT rc; + HTREEITEM hItem = TreeView_GetSelection (nmhdr->hwndFrom); + TreeView_GetItemRect (nmhdr->hwndFrom, hItem, &rc, TRUE); + event.x = (int) rc.left; + event.y = (int) rc.bottom; + RecursiveHandleEvent( window, &event ); + + } + } + else if (nmhdr->code == LVN_ITEMCHANGED) + { + if (nmhdr->idFrom > 0) + { + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + event.event = mxEvent::Action; + event.widget = (mxWidget *) GetWindowLong (nmhdr->hwndFrom, GWL_USERDATA); + event.action = (int) nmhdr->idFrom; + + RecursiveHandleEvent( window, &event ); + } + } + else if (nmhdr->code == NM_RCLICK) + { + if (nmhdr->idFrom > 0) + { + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + event.event = mxEvent::Action; + event.widget = (mxWidget *) GetWindowLong (nmhdr->hwndFrom, GWL_USERDATA); + event.action = (int) nmhdr->idFrom; + event.flags = mxEvent::RightClicked; + + if ( event.widget ) + { + if ( event.widget->getType () == MX_TREEVIEW ) + { + RECT rc; + HTREEITEM hItem = TreeView_GetSelection (nmhdr->hwndFrom); + TreeView_GetItemRect (nmhdr->hwndFrom, hItem, &rc, TRUE); + event.x = (int) rc.left; + event.y = (int) rc.bottom; + } + } + RecursiveHandleEvent( window, &event ); + } + } + else if (nmhdr->code == NM_DBLCLK) + { + if (nmhdr->idFrom > 0) + { + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + event.event = mxEvent::Action; + event.widget = (mxWidget *) GetWindowLong (nmhdr->hwndFrom, GWL_USERDATA); + event.action = (int) nmhdr->idFrom; + event.flags = mxEvent::DoubleClicked; + + if (event.widget ) + { + if ( event.widget->getType () == MX_TREEVIEW ) + { + RECT rc; + HTREEITEM hItem = TreeView_GetSelection (nmhdr->hwndFrom); + TreeView_GetItemRect (nmhdr->hwndFrom, hItem, &rc, TRUE); + event.x = (int) rc.left; + event.y = (int) rc.bottom; + } + } + + RecursiveHandleEvent( window, &event ); + return TRUE; + } + } + else if (nmhdr->code == TCN_SELCHANGING) + { + TC_ITEM ti; + + int index = TabCtrl_GetCurSel (nmhdr->hwndFrom); + if (index >= 0) + { + ti.mask = TCIF_PARAM; + TabCtrl_GetItem (nmhdr->hwndFrom, index, &ti); + mxWindow *window = (mxWindow *) ti.lParam; + if (window) + window->setVisible (false); + } + } + else if (nmhdr->code == TCN_SELCHANGE) + { + mxTab_resizeChild (nmhdr->hwndFrom); + if (nmhdr->idFrom > 0) + { + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + event.event = mxEvent::Action; + event.widget = (mxWidget *) GetWindowLong (nmhdr->hwndFrom, GWL_USERDATA); + event.action = (int) nmhdr->idFrom; + RecursiveHandleEvent( window, &event ); + } + } + } + break; + + case WM_SIZE: + { + mxEvent event; + + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + if (window) + { + event.event = mxEvent::Size; + event.width = (int) LOWORD (lParam); + event.height = (int) HIWORD (lParam); + window->handleEvent (&event); + } + } + break; + case WM_WINDOWPOSCHANGED: + { + mxEvent event; + + + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + if (window) + { + event.event = mxEvent::PosChanged; + + WINDOWPOS *wp = ( WINDOWPOS * )lParam; + + event.x = wp->x; + event.y = wp->y; + event.width = wp->cx; + event.height = wp->cy; + + window->handleEvent (&event); + } + } + break; + + case WM_ERASEBKGND: + { + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + if (window) + { + if (window->getType () == MX_GLWINDOW) + return 0; + if (window->getType () == MX_MATSYSWINDOW) + return 0; + + if ( !isClosing && !window->PaintBackground() ) + { + return 0; + } + } + } + break; + + case WM_HSCROLL: + case WM_VSCROLL: + { + mxWidget *widget = (mxWidget *) GetWindowLong ((HWND) lParam, GWL_USERDATA); + if (!widget) + { + break; + } + + if (widget->getType() != MX_SCROLLBAR && widget->getType() != MX_SLIDER) + { + break; + } + + + switch (LOWORD (wParam)) + { + case TB_LINEUP: // SB_LINEUP SB_LINELEFT + break; + case TB_LINEDOWN: // SB_LINEDOWN SB_LINERIGHT + break; + case TB_PAGEUP: // SB_PAGEUP SB_PAGELEFT + break; + case TB_PAGEDOWN: // SB_PAGEDOWN SB_PAGERIGHT + break; + case TB_THUMBPOSITION: // SB_THUMBPOSITION + break; + case TB_THUMBTRACK: // SB_THUMBTRACK + break; + case TB_TOP: // SB_TOP SB_LEFT + break; + case TB_BOTTOM: // SB_BOTTOM SB_RIGHT + break; + case TB_ENDTRACK: // SB_ENDSCROLL + break; + default: + break; + } + + switch (LOWORD (wParam)) + { + case TB_LINEUP: // SB_LINEUP SB_LINELEFT + case TB_LINEDOWN: // SB_LINEDOWN SB_LINERIGHT + case TB_PAGEUP: // SB_PAGEUP SB_PAGELEFT + case TB_PAGEDOWN: // SB_PAGEDOWN SB_PAGERIGHT + case TB_THUMBPOSITION: // SB_THUMBPOSITION + case TB_THUMBTRACK: // SB_THUMBTRACK + case TB_TOP: // SB_TOP SB_LEFT + case TB_BOTTOM: // SB_BOTTOM SB_RIGHT + case TB_ENDTRACK: // SB_ENDSCROLL + { + mxEvent event; + + event.event = mxEvent::Action; + event.widget = widget; + event.action = widget->getId (); + event.modifiers = LOWORD (wParam); + event.height = HIWORD( wParam ); + mxWindow *window = widget->getParent (); + + if ( event.action > 0 ) + { + RecursiveHandleEvent( window, &event ); + } + } + break; + } + } + break; + + case WM_PAINT: + { + if ( !isClosing ) + { + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + if (window) + { + window->redraw (); + } + } + } + break; + + case WM_PARENTNOTIFY: + { + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + if (window) + { + if ( wParam == WM_LBUTTONDOWN || + wParam == WM_MBUTTONDOWN || + wParam == WM_RBUTTONDOWN /*|| + wParam & WM_XBUTTONDOWN*/ ) + { + mxEvent event; + event.event = mxEvent::ParentNotify; + event.x = (short)LOWORD (lParam); + event.y = (short)HIWORD (lParam); + event.buttons = 0; + event.modifiers = 0; + + if ( wParam == WM_LBUTTONDOWN ) + event.buttons |= mxEvent::MouseLeftButton; + + if ( wParam == WM_RBUTTONDOWN ) + event.buttons |= mxEvent::MouseRightButton; + + if ( wParam == WM_MBUTTONDOWN ) + event.buttons |= mxEvent::MouseMiddleButton; + + window->handleEvent (&event); + RecursiveHandleEvent( window, &event ); + return 0; + } + } + } + break; + + case WM_LBUTTONDOWN: + case WM_MBUTTONDOWN: + case WM_RBUTTONDOWN: + { + bDragging = TRUE; + SetCapture (hwnd); + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + + if (window) + { + mxEvent event; + event.event = mxEvent::MouseDown; + event.x = (short)LOWORD (lParam); + event.y = (short)HIWORD (lParam); + event.buttons = 0; + event.modifiers = 0; + + if (uMessage == WM_MBUTTONDOWN) + event.buttons |= mxEvent::MouseMiddleButton; + else if (uMessage == WM_RBUTTONDOWN) + event.buttons |= mxEvent::MouseRightButton; + else + event.buttons |= mxEvent::MouseLeftButton; + + if (wParam & MK_LBUTTON) + event.buttons |= mxEvent::MouseLeftButton; + + if (wParam & MK_RBUTTON) + event.buttons |= mxEvent::MouseRightButton; + + if (wParam & MK_MBUTTON) + event.buttons |= mxEvent::MouseMiddleButton; + + if (wParam & MK_CONTROL) + event.modifiers |= mxEvent::KeyCtrl; + + if (wParam & MK_SHIFT) + event.modifiers |= mxEvent::KeyShift; + + window->handleEvent (&event); + } + } + break; + + case WM_LBUTTONUP: + case WM_MBUTTONUP: + case WM_RBUTTONUP: + { + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + if (window) + { + mxEvent event; + event.event = mxEvent::MouseUp; + event.x = (short) LOWORD (lParam); + event.y = (short) HIWORD (lParam); + event.buttons = 0; + event.modifiers = 0; + + if (uMessage == WM_MBUTTONUP) + event.buttons |= mxEvent::MouseMiddleButton; + else if (uMessage == WM_RBUTTONUP) + event.buttons |= mxEvent::MouseRightButton; + else + event.buttons |= mxEvent::MouseLeftButton; + + if (wParam & MK_LBUTTON) + event.buttons |= mxEvent::MouseLeftButton; + + if (wParam & MK_RBUTTON) + event.buttons |= mxEvent::MouseRightButton; + + if (wParam & MK_MBUTTON) + event.buttons |= mxEvent::MouseMiddleButton; + + if (wParam & MK_CONTROL) + event.modifiers |= mxEvent::KeyCtrl; + + if (wParam & MK_SHIFT) + event.modifiers |= mxEvent::KeyShift; + + window->handleEvent (&event); + } + bDragging = FALSE; + ReleaseCapture (); + } + break; + + case WM_MOUSEMOVE: + { + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + if (window) + { + mxEvent event; + + if (bDragging) + event.event = mxEvent::MouseDrag; + else + event.event = mxEvent::MouseMove; + + event.x = (short) LOWORD (lParam); + event.y = (short) HIWORD (lParam); + event.buttons = 0; + event.modifiers = 0; + + if (wParam & MK_LBUTTON) + event.buttons |= mxEvent::MouseLeftButton; + + if (wParam & MK_RBUTTON) + event.buttons |= mxEvent::MouseRightButton; + + if (wParam & MK_MBUTTON) + event.buttons |= mxEvent::MouseMiddleButton; + + if (wParam & MK_CONTROL) + event.modifiers |= mxEvent::KeyCtrl; + + if (wParam & MK_SHIFT) + event.modifiers |= mxEvent::KeyShift; + + window->handleEvent (&event); + } + } + break; + case WM_NCLBUTTONDOWN: + case WM_NCMBUTTONDOWN: + case WM_NCRBUTTONDOWN: + { + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + + if (window) + { + mxEvent event; + event.event = mxEvent::NCMouseDown; + event.x = (short) LOWORD (lParam); + event.y = (short) HIWORD (lParam); + event.buttons = 0; + event.modifiers = 0; + + if (uMessage == WM_NCMBUTTONDOWN) + event.buttons |= mxEvent::MouseMiddleButton; + else if (uMessage == WM_NCRBUTTONDOWN) + event.buttons |= mxEvent::MouseRightButton; + else + event.buttons |= mxEvent::MouseLeftButton; + + window->handleEvent (&event); + } + } + break; + + case WM_NCLBUTTONUP: + case WM_NCMBUTTONUP: + case WM_NCRBUTTONUP: + { + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + if (window) + { + mxEvent event; + event.event = mxEvent::NCMouseUp; + event.x = (short) LOWORD (lParam); + event.y = (short) HIWORD (lParam); + event.buttons = 0; + event.modifiers = 0; + + if (uMessage == WM_NCMBUTTONUP) + event.buttons |= mxEvent::MouseMiddleButton; + else if (uMessage == WM_NCRBUTTONUP) + event.buttons |= mxEvent::MouseRightButton; + else + event.buttons |= mxEvent::MouseLeftButton; + + window->handleEvent (&event); + } + } + break; + + case WM_NCMOUSEMOVE: + { + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + if (window) + { + mxEvent event; + + event.event = mxEvent::NCMouseMove; + + event.x = (short) LOWORD (lParam); + event.y = (short) HIWORD (lParam); + event.buttons = 0; + event.modifiers = 0; + + window->handleEvent (&event); + } + } + break; + + case WM_KEYDOWN: + case WM_SYSKEYDOWN: + { + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + if (window) + { + mxEvent event; + event.event = mxEvent::KeyDown; + event.key = (int) wParam; + if ( window->handleEvent (&event) ) + return 0; + } + } + break; + + case WM_CHAR: + { + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + if (window) + { + mxEvent event; + event.event = mxEvent::Char; + event.key = (int) wParam; + if ( window->handleEvent (&event) ) + return 0; + } + } + break; + + case WM_SYSCHAR: + return 0; + break; + + case WM_KEYUP: + case WM_SYSKEYUP: + { + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + if (window) + { + mxEvent event; + event.event = mxEvent::KeyUp; + event.key = (int) wParam; + if ( window->handleEvent (&event) ) + return 0; + } + } + break; + + case WM_MOUSEWHEEL: + { + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + if (window) + { + mxEvent event; + memset( &event, 0, sizeof( event ) ); + event.event = mxEvent::MouseWheeled; + event.x = (short) LOWORD (lParam); + event.y = (short) HIWORD (lParam); + + if (wParam & MK_LBUTTON) + event.buttons |= mxEvent::MouseLeftButton; + + if (wParam & MK_RBUTTON) + event.buttons |= mxEvent::MouseRightButton; + + if (wParam & MK_MBUTTON) + event.buttons |= mxEvent::MouseMiddleButton; + + if (wParam & MK_CONTROL) + event.modifiers |= mxEvent::KeyCtrl; + + if (wParam & MK_SHIFT) + event.modifiers |= mxEvent::KeyShift; + + event.height = (short)HIWORD( wParam );; + RecursiveHandleEvent( window, &event ); + } + } + break; + case WM_TIMER: + { + if (isClosing) + break; + + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + if (window) + { + mxEvent event; + event.event = mxEvent::Timer; + window->handleEvent (&event); + } + } + break; + + case WM_CLOSE: + if (g_mainWindow) + { + if ((void *) hwnd == g_mainWindow->getHandle ()) + { + mx::quit (); + } + else + { + ShowWindow (hwnd, SW_HIDE); + + mxWindow *window = (mxWindow *) GetWindowLong (hwnd, GWL_USERDATA); + if (window) + { + mxEvent event; + event.event = mxEvent::Close; + window->handleEvent( &event ); + } + } + } + //else // shouldn't happen + //DestroyWindow (hwnd); + return 0; +/* + case WM_DESTROY: + if (g_mainWindow) + { + if ((void *) hwnd == g_mainWindow->getHandle ()) + mx::quit (); + } + break; +*/ + } + + return DefWindowProc (hwnd, uMessage, wParam, lParam); +} + + + +int +mx::init(int argc, char **argv) +{ + WNDCLASS wc; + wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; + wc.lpfnWndProc = WndProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = (HINSTANCE) GetModuleHandle (NULL); + wc.hIcon = LoadIcon (wc.hInstance, "MX_ICON"); + wc.hCursor = LoadCursor (NULL, IDC_ARROW); + wc.hbrBackground = (HBRUSH) COLOR_WINDOW; + wc.lpszMenuName = NULL; + wc.lpszClassName = "mx_class"; + + if (!wc.hIcon) + wc.hIcon = LoadIcon (NULL, IDI_WINLOGO); + + if (!RegisterClass (&wc)) + return 0; + + InitCommonControls (); + + g_widgetList = new mxLinkedList (); + + isClosing = false; + + return 1; +} + + + +int +mx::run() +{ + int messagecount = 0; + + while (1) + { + bool doframe = false; + if ( PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE) || !g_idleWindow ) + { + if (!GetMessage (&msg, NULL, 0, 0)) + { + doframe = false; + break; + } + + if ( !g_hAcceleratorTable || + !TranslateAccelerator( (HWND)g_mainWindow->getHandle (), g_hAcceleratorTable, &msg )) + { + TranslateMessage( &msg ); + DispatchMessage( &msg ); + } + messagecount++; + + if ( messagecount > 10 ) + { + messagecount = 0; + doframe = true; + } + } + else if (g_idleWindow) + { + doframe = true; + messagecount = 0; + } + + if ( doframe && g_idleWindow ) + { + mxEvent event; + event.event = mxEvent::Idle; + g_idleWindow->handleEvent (&event); + } + } + + return msg.wParam; +} + + + +int +mx::check () +{ + if (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE)) + { + if (GetMessage (&msg, NULL, 0, 0)) + { + TranslateMessage (&msg); + DispatchMessage (&msg); + } + + return 1; + } + + return 0; +} + + + +void +mx::quit () +{ + isClosing = true; + + mxWindow *mainwnd = getMainWindow(); + if ( mainwnd ) + { + if ( !mainwnd->Closing() ) + { + isClosing = false; + return; + } + } + + if (g_widgetList) + { + // remove from back to front + mxListNode *node = g_widgetList->getLast (); + + // Pass 1, see if anyone objects to closing + while (node) + { + mxWidget *widget = (mxWidget *) g_widgetList->getData (node); + node = g_widgetList->getPrev (node); + + bool canclose = true; + if ( widget ) + { + if ( !widget->CanClose() ) + { + canclose = false; + } + } + + if ( !canclose ) + { + isClosing = false; + return; + } + } + + node = g_widgetList->getLast (); + + // Pass 2, call OnDelete to allow final cleanup + while (node) + { + mxWidget *widget = (mxWidget *) g_widgetList->getData (node); + node = g_widgetList->getPrev (node); + + if ( widget ) + { + widget->OnDelete(); + } + } + + node = g_widgetList->getLast (); + + // Pass 3, delete stuff + while (node) + { + mxWidget *widget = (mxWidget *) g_widgetList->getData (node); + node = g_widgetList->getPrev (node); + + // remove it! + if ( widget ) + { + delete widget; + } + } + + delete g_widgetList; + } + + if (g_hwndToolTipControl) + DestroyWindow (g_hwndToolTipControl); + + if ( g_hAcceleratorTable ) + { + DestroyAcceleratorTable( g_hAcceleratorTable ); + g_hAcceleratorTable = 0; + } + + PostQuitMessage (0); + UnregisterClass ("mx_class", (HINSTANCE) GetModuleHandle (NULL)); +} + + + +int +mx::setDisplayMode (int w, int h, int bpp) +{ + DEVMODE dm; + + dm.dmSize = sizeof (DEVMODE); + dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; + dm.dmBitsPerPel = bpp; + dm.dmPelsWidth = w; + dm.dmPelsHeight = h; + + if (w == 0 || h == 0 || bpp == 0) + ChangeDisplaySettings (0, 0); + else + ChangeDisplaySettings (&dm, CDS_FULLSCREEN); + + return 0; +} + + + +void +mx::setIdleWindow (mxWindow *window) +{ + g_idleWindow = window; +} + + + +int +mx::getDisplayWidth () +{ + return (int) GetSystemMetrics (SM_CXSCREEN); +} + + + +int +mx::getDisplayHeight () +{ + return (int) GetSystemMetrics (SM_CYSCREEN); +} + + + +mxWindow* +mx::getMainWindow () +{ + return g_mainWindow; +} + + + +const char * +mx::getApplicationPath () +{ + static char path[256]; + GetModuleFileName (0, path, 256); + char *ptr = strrchr (path, '\\'); + if (ptr) + *ptr = '\0'; + + return path; +} + + + +int +mx::getTickCount () +{ + return (int) GetTickCount (); +} diff --git a/utils/mxtk/mxbmp.cpp b/utils/mxtk/mxbmp.cpp new file mode 100644 index 0000000..1f6616c --- /dev/null +++ b/utils/mxtk/mxbmp.cpp @@ -0,0 +1,276 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxBmp.cpp +// implementation: all +// last modified: Apr 15 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. + +// lbmlib.c + +#include "mxtk/mxBmp.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + + + +mxImage * +mxBmpRead (const char *filename) +{ + int i; + FILE *pfile = 0; + mxBitmapFileHeader bmfh; + mxBitmapInfoHeader bmih; + mxBitmapRGBQuad rgrgbPalette[256]; + int cbBmpBits; + byte *pbBmpBits; + byte *pb, *pbPal = 0; + int cbPalBytes; + int biTrueWidth; + mxImage *image = 0; + + // File exists? + if ((pfile = fopen (filename, "rb")) == 0) + return 0; + + // Read file header + if (fread (&bmfh, sizeof bmfh, 1/*count*/, pfile) != 1) + goto GetOut; + + // Bogus file header check + if (!(bmfh.bfReserved1 == 0 && bmfh.bfReserved2 == 0)) + goto GetOut; + + // Read info header + if (fread (&bmih, sizeof bmih, 1/*count*/, pfile) != 1) + goto GetOut; + + // Bogus info header check + if (!(bmih.biSize == sizeof bmih && bmih.biPlanes == 1)) + goto GetOut; + + // Bogus bit depth? Only 8-bit supported. + if (bmih.biBitCount != 8) + goto GetOut; + + // Bogus compression? Only non-compressed supported. + if (bmih.biCompression != 0) //BI_RGB) + goto GetOut; + + // Figure out how many entires are actually in the table + if (bmih.biClrUsed == 0) + { + bmih.biClrUsed = 256; + cbPalBytes = (1 << bmih.biBitCount) * sizeof (mxBitmapRGBQuad); + } + else + { + cbPalBytes = bmih.biClrUsed * sizeof (mxBitmapRGBQuad); + } + + // Read palette (bmih.biClrUsed entries) + if (fread (rgrgbPalette, cbPalBytes, 1/*count*/, pfile) != 1) + goto GetOut; + + image = new mxImage (); + if (!image) + goto GetOut; + + if (!image->create (bmih.biWidth, bmih.biHeight, 8)) + { + delete image; + goto GetOut; + } + + pb = (byte *) image->palette; + + // Copy over used entries + for (i = 0; i < (int) bmih.biClrUsed; i++) + { + *pb++ = rgrgbPalette[i].rgbRed; + *pb++ = rgrgbPalette[i].rgbGreen; + *pb++ = rgrgbPalette[i].rgbBlue; + } + + // Fill in unused entires will 0,0,0 + for (i = bmih.biClrUsed; i < 256; i++) + { + *pb++ = 0; + *pb++ = 0; + *pb++ = 0; + } + + // Read bitmap bits (remainder of file) + cbBmpBits = bmfh.bfSize - ftell (pfile); + pb = (byte *) malloc (cbBmpBits * sizeof (byte)); + if (pb == 0) + { + free (pbPal); + goto GetOut; + } + + if (fread (pb, cbBmpBits, 1/*count*/, pfile) != 1) + { + free (pb); + free (pbPal); + goto GetOut; + } +/* + pbBmpBits = malloc(cbBmpBits); + if (pbBmpBits == 0) + { + free (pb); + free (pbPal); + goto GetOut; + } +*/ + pbBmpBits = (byte *) image->data; + + // data is actually stored with the width being rounded up to a multiple of 4 + biTrueWidth = (bmih.biWidth + 3) & ~3; + + // reverse the order of the data. + pb += (bmih.biHeight - 1) * biTrueWidth; + for(i = 0; i < bmih.biHeight; i++) + { + memmove (&pbBmpBits[biTrueWidth * i], pb, biTrueWidth); + pb -= biTrueWidth; + } + + pb += biTrueWidth; + free (pb); + +GetOut: + if (pfile) + fclose (pfile); + + return image; +} + + + +bool +mxBmpWrite (const char *filename, mxImage *image) +{ + int i; + FILE *pfile = 0; + mxBitmapFileHeader bmfh; + mxBitmapInfoHeader bmih; + mxBitmapRGBQuad rgrgbPalette[256]; + int cbBmpBits; + byte *pbBmpBits; + byte *pb = 0; + int cbPalBytes; + int biTrueWidth; + + if (!image || !image->data || !image->palette) + return false; + + // File exists? + if ((pfile = fopen(filename, "wb")) == 0) + return false; + + biTrueWidth = ((image->width + 3) & ~3); + cbBmpBits = biTrueWidth * image->height; + cbPalBytes = 256 * sizeof (mxBitmapRGBQuad); + + // Bogus file header check + //bmfh.bfType = MAKEWORD( 'B', 'M' ); + bmfh.bfType = (word) (('M' << 8) | 'B'); + bmfh.bfSize = sizeof bmfh + sizeof bmih + cbBmpBits + cbPalBytes; + bmfh.bfReserved1 = 0; + bmfh.bfReserved2 = 0; + bmfh.bfOffBits = sizeof bmfh + sizeof bmih + cbPalBytes; + + // Write file header + if (fwrite (&bmfh, sizeof bmfh, 1/*count*/, pfile) != 1) + { + fclose (pfile); + return false; + } + + // Size of structure + bmih.biSize = sizeof bmih; + // Width + bmih.biWidth = biTrueWidth; + // Height + bmih.biHeight = image->height; + // Only 1 plane + bmih.biPlanes = 1; + // Only 8-bit supported. + bmih.biBitCount = 8; + // Only non-compressed supported. + bmih.biCompression = 0; //BI_RGB; + bmih.biSizeImage = 0; + + // huh? + bmih.biXPelsPerMeter = 0; + bmih.biYPelsPerMeter = 0; + + // Always full palette + bmih.biClrUsed = 256; + bmih.biClrImportant = 0; + + // Write info header + if (fwrite (&bmih, sizeof bmih, 1/*count*/, pfile) != 1) + { + fclose (pfile); + return false; + } + + + // convert to expanded palette + pb = (byte *) image->palette; + + // Copy over used entries + for (i = 0; i < (int) bmih.biClrUsed; i++) + { + rgrgbPalette[i].rgbRed = *pb++; + rgrgbPalette[i].rgbGreen = *pb++; + rgrgbPalette[i].rgbBlue = *pb++; + rgrgbPalette[i].rgbReserved = 0; + } + + // Write palette (bmih.biClrUsed entries) + cbPalBytes = bmih.biClrUsed * sizeof (mxBitmapRGBQuad); + if (fwrite (rgrgbPalette, cbPalBytes, 1/*count*/, pfile) != 1) + { + fclose (pfile); + return false; + } + + pbBmpBits = (byte *) malloc (cbBmpBits * sizeof (byte)); + if (!pbBmpBits) + { + fclose (pfile); + return false; + } + + pb = (byte *) image->data; + // reverse the order of the data. + pb += (image->height - 1) * image->width; + for(i = 0; i < bmih.biHeight; i++) + { + memmove (&pbBmpBits[biTrueWidth * i], pb, image->width); + pb -= image->width; + } + + // Write bitmap bits (remainder of file) + if (fwrite (pbBmpBits, cbBmpBits, 1/*count*/, pfile) != 1) + { + free (pbBmpBits); + fclose (pfile); + return false; + } + + free (pbBmpBits); + fclose (pfile); + + return true; +}
\ No newline at end of file diff --git a/utils/mxtk/mxbutton.cpp b/utils/mxtk/mxbutton.cpp new file mode 100644 index 0000000..b6bc5fc --- /dev/null +++ b/utils/mxtk/mxbutton.cpp @@ -0,0 +1,53 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxButton.cpp +// implementation: Win32 API +// last modified: Apr 12 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxButton.h" +#include <windows.h> + + + +class mxButton_i +{ +public: + int dummy; +}; + + + +mxButton::mxButton (mxWindow *parent, int x, int y, int w, int h, const char *label, int id) +: mxWidget (parent, x, y, w, h, label) +{ + if (!parent) + return; + + DWORD dwStyle = WS_VISIBLE | WS_CHILD; + HWND hwndParent = (HWND) ((mxWidget *) parent)->getHandle (); + + void *handle = (void *) CreateWindowEx (0, "BUTTON", label, dwStyle, + x, y, w, h, hwndParent, + (HMENU) id, (HINSTANCE) GetModuleHandle (NULL), NULL); + + SendMessage ((HWND) handle, WM_SETFONT, (WPARAM) (HFONT) GetStockObject (ANSI_VAR_FONT), MAKELPARAM (TRUE, 0)); + SetWindowLong ((HWND) handle, GWL_USERDATA, (LONG) this); + + setType (MX_BUTTON); + setHandle (handle); + setParent (parent); + setId (id); +} + + + +mxButton::~mxButton () +{ +} diff --git a/utils/mxtk/mxcheckbox.cpp b/utils/mxtk/mxcheckbox.cpp new file mode 100644 index 0000000..d704980 --- /dev/null +++ b/utils/mxtk/mxcheckbox.cpp @@ -0,0 +1,69 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxCheckBox.cpp +// implementation: Win32 API +// last modified: Mar 18 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxCheckBox.h" +#include <windows.h> + + + +class mxCheckBox_i +{ +public: + int dummy; +}; + + + +mxCheckBox::mxCheckBox (mxWindow *parent, int x, int y, int w, int h, const char *label, int id) +: mxWidget (parent, x, y, w, h, label) +{ + if (!parent) + return; + + HWND hwndParent = (HWND) ((mxWidget *) parent)->getHandle (); + + void *handle = (void *) CreateWindowEx (0, "BUTTON", label, WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX, + x, y, w, h, hwndParent, + (HMENU) id, (HINSTANCE) GetModuleHandle (NULL), NULL); + + SendMessage ((HWND) handle, WM_SETFONT, (WPARAM) (HFONT) GetStockObject (ANSI_VAR_FONT), MAKELPARAM (TRUE, 0)); + SetWindowLong ((HWND) handle, GWL_USERDATA, (LONG) this); + + setHandle (handle); + setType (MX_CHECKBOX); + setParent (parent); + setId (id); + setChecked (false); +} + + + +mxCheckBox::~mxCheckBox () +{ +} + + + +void +mxCheckBox::setChecked (bool b) +{ + SendMessage ((HWND) getHandle (), BM_SETCHECK, (WPARAM) b ? BST_CHECKED:BST_UNCHECKED, 0L); +} + + + +bool +mxCheckBox::isChecked () const +{ + return (SendMessage ((HWND) getHandle (), BM_GETCHECK, 0, 0L) == BST_CHECKED); +} diff --git a/utils/mxtk/mxchoice.cpp b/utils/mxtk/mxchoice.cpp new file mode 100644 index 0000000..f6f5c14 --- /dev/null +++ b/utils/mxtk/mxchoice.cpp @@ -0,0 +1,101 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxChoice.cpp +// implementation: Win32 API +// last modified: Apr 28 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxChoice.h" +#include <windows.h> + + + +class mxChoice_i +{ +public: + int dummy; +}; + + + +mxChoice::mxChoice (mxWindow *parent, int x, int y, int w, int h, int id) +: mxWidget (parent, x, y, w, h) +{ + if (!parent) + return; + + HWND hwndParent = (HWND) ((mxWidget *) parent)->getHandle (); + + void *handle = (void *) CreateWindowEx (0, "COMBOBOX", "", WS_VISIBLE | WS_CHILD | WS_VSCROLL | CBS_DROPDOWNLIST, + x, y, w, h + 500, hwndParent, + (HMENU) id, (HINSTANCE) GetModuleHandle (NULL), NULL); + + SendMessage ((HWND) handle, WM_SETFONT, (WPARAM) (HFONT) GetStockObject (ANSI_VAR_FONT), MAKELPARAM (TRUE, 0)); + SetWindowLong ((HWND) handle, GWL_USERDATA, (LONG) this); + + setHandle (handle); + setType (MX_CHOICE); + setParent (parent); + setId (id); +} + + + +mxChoice::~mxChoice () +{ + removeAll (); +} + + + +void +mxChoice::add (const char *item) +{ + SendMessage ((HWND) getHandle (), CB_ADDSTRING, 0, (LPARAM) (LPCTSTR) item); +} + + + +void +mxChoice::select (int index) +{ + SendMessage ((HWND) getHandle (), CB_SETCURSEL, (WPARAM) index, 0L); +} + + + +void +mxChoice::remove (int index) +{ + SendMessage ((HWND) getHandle (), CB_DELETESTRING, (WPARAM) index, 0L); +} + + + +void +mxChoice::removeAll () +{ + SendMessage ((HWND) getHandle (), CB_RESETCONTENT, 0, 0L); +} + + + +int +mxChoice::getItemCount () const +{ + return (int) SendMessage ((HWND) getHandle (), CB_GETCOUNT, 0, 0L); +} + + + +int +mxChoice::getSelectedIndex () const +{ + return (int) SendMessage ((HWND) getHandle (), CB_GETCURSEL, 0, 0L); +} diff --git a/utils/mxtk/mxchoosecolor.cpp b/utils/mxtk/mxchoosecolor.cpp new file mode 100644 index 0000000..6b6e328 --- /dev/null +++ b/utils/mxtk/mxchoosecolor.cpp @@ -0,0 +1,48 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxChooseColor.cpp +// implementation: Win32 API +// last modified: Mar 14 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxChooseColor.h" +#include "mxtk/mxWindow.h" +#include <windows.h> +#include <commdlg.h> + + + +bool +mxChooseColor (mxWindow *parent, int *r, int *g, int *b) +{ + CHOOSECOLOR cc; + static COLORREF custColors[16]; + + BYTE rr = *r; + BYTE gg = *g; + BYTE bb = *b; + + memset (&cc, 0, sizeof (CHOOSECOLOR)); + cc.lStructSize = sizeof (CHOOSECOLOR); + cc.hwndOwner = parent ? (HWND) parent->getHandle ():NULL; + cc.rgbResult = RGB (rr, gg, bb); + cc.lpCustColors = custColors; + cc.Flags = CC_ANYCOLOR | CC_FULLOPEN | CC_RGBINIT; + + if (ChooseColor (&cc)) + { + *r = (int) GetRValue (cc.rgbResult); + *g = (int) GetGValue (cc.rgbResult); + *b = (int) GetBValue (cc.rgbResult); + + return true; + } + + return false; +} diff --git a/utils/mxtk/mxfiledialog.cpp b/utils/mxtk/mxfiledialog.cpp new file mode 100644 index 0000000..574a206 --- /dev/null +++ b/utils/mxtk/mxfiledialog.cpp @@ -0,0 +1,108 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxFileDialog.cpp +// implementation: Win32 API +// last modified: Mar 14 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxFileDialog.h" +#include "mxtk/mxWindow.h" +#include <windows.h> +#include <commdlg.h> +#include <string.h> + + + +static char sd_path[_MAX_PATH] = ""; + + + +const char* +mxGetOpenFileName (mxWindow *parent, const char *path, const char *filter) +{ + CHAR szPath[_MAX_PATH], szFilter[_MAX_PATH]; + + strcpy (sd_path, ""); + + if (path) + strcpy (szPath, path); + else + strcpy (szPath, ""); + + if (filter) + { + memset (szFilter, 0, _MAX_PATH); + strcpy (szFilter, filter); + strcpy (szFilter + strlen (szFilter) + 1, filter); + } + else + strcpy (szFilter, ""); + + + OPENFILENAME ofn; + memset (&ofn, 0, sizeof (ofn)); + ofn.lStructSize = sizeof (ofn); + if (parent) + ofn.hwndOwner = (HWND) parent->getHandle (); + ofn.hInstance = (HINSTANCE) GetModuleHandle (NULL); + ofn.lpstrFilter = szFilter; + ofn.nFilterIndex = 1; + ofn.lpstrFile = sd_path; + ofn.nMaxFile = _MAX_PATH; + if (path && strlen (path)) + ofn.lpstrInitialDir = szPath; + ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY; + + if (GetOpenFileName (&ofn)) + return sd_path; + else + return 0; +} + + + +const char* +mxGetSaveFileName (mxWindow *parent, const char *path, const char *filter) +{ + CHAR szPath[_MAX_PATH], szFilter[_MAX_PATH]; + + strcpy (sd_path, ""); + + if (path) + strcpy (szPath, path); + else + strcpy (szPath, ""); + + if (filter) + { + memset (szFilter, 0, _MAX_PATH); + strcpy (szFilter, filter); + strcpy (szFilter + strlen (szFilter) + 1, filter); + } + else + strcpy (szFilter, ""); + + OPENFILENAME ofn; + memset (&ofn, 0, sizeof (ofn)); + ofn.lStructSize = sizeof (ofn); + if (parent) + ofn.hwndOwner = (HWND) parent->getHandle (); + ofn.hInstance = (HINSTANCE) GetModuleHandle (NULL); + ofn.lpstrFilter = szFilter; + ofn.lpstrFile = sd_path; + ofn.nMaxFile = _MAX_PATH; + if (path && strlen (path)) + ofn.lpstrInitialDir = szPath; + ofn.Flags = OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY; + + if (GetSaveFileName (&ofn)) + return sd_path; + else + return 0; +} diff --git a/utils/mxtk/mxglwindow.cpp b/utils/mxtk/mxglwindow.cpp new file mode 100644 index 0000000..03121a8 --- /dev/null +++ b/utils/mxtk/mxglwindow.cpp @@ -0,0 +1,190 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxGlWindow.cpp +// implementation: Win32 API +// last modified: Apr 21 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxGlWindow.h" +#include <windows.h> +//#include <ostream.h" + + + +static int g_formatMode = mxGlWindow::FormatDouble; +static int g_formatColorBits = 24; +static int g_formatDepthBits = 16; + + + +class mxGlWindow_i +{ +public: + HDC hdc; + HGLRC hglrc; +}; + + + +mxGlWindow::mxGlWindow (mxWindow *parent, int x, int y, int w, int h, const char *label, int style) +: mxWindow (parent, x, y, w, h, label, style) +{ + PIXELFORMATDESCRIPTOR pfd = + { + sizeof (PIXELFORMATDESCRIPTOR), // size of this pfd + 1, // version number + PFD_DRAW_TO_WINDOW | // support window + PFD_SUPPORT_OPENGL | // support OpenGL + PFD_DOUBLEBUFFER, // double buffered + PFD_TYPE_RGBA, // RGBA type + 24, // 24-bit color depth + 0, 0, 0, 0, 0, 0, // color bits ignored + 0, // no alpha buffer + 0, // shift bit ignored + 0, // no accumulation buffer + 0, 0, 0, 0, // accum bits ignored + 16, // 32-bit z-buffer + 0, // no stencil buffer + 0, // no auxiliary buffer + PFD_MAIN_PLANE, // main layer + 0, // reserved + 0, 0, 0 // layer masks ignored + }; + + d_this = new mxGlWindow_i; + + pfd.cColorBits = g_formatColorBits; + pfd.cDepthBits = g_formatDepthBits; + + bool error = false; + + if ((d_this->hdc = GetDC ((HWND) getHandle ())) == NULL) + { + error = true; + goto done; + } + + int pfm; + if ((pfm = ChoosePixelFormat (d_this->hdc, &pfd)) == 0) + { + error = true; + goto done; + } + + if (SetPixelFormat (d_this->hdc, pfm, &pfd) == FALSE) + { + error = true; + goto done; + } + + DescribePixelFormat (d_this->hdc, pfm, sizeof (pfd), &pfd); + + if ((d_this->hglrc = wglCreateContext (d_this->hdc)) == 0) + { + error = true; + goto done; + } + + if (!wglMakeCurrent (d_this->hdc, d_this->hglrc)) + { + error = true; + goto done; + } + + setType (MX_GLWINDOW); + setDrawFunc (0); + +done: + if (error) + delete this; +} + + + +mxGlWindow::~mxGlWindow () +{ + if (d_this->hglrc) + { + wglMakeCurrent (NULL, NULL); + //wglDeleteContext (d_this->hglrc); + } + + if (d_this->hdc) + ReleaseDC ((HWND) getHandle (), d_this->hdc); + + delete d_this; +} + + + +int +mxGlWindow::handleEvent (mxEvent *event) +{ + return 0; +} + + + +void +mxGlWindow::redraw () +{ + makeCurrent (); + if (d_drawFunc) + d_drawFunc (); + else + draw (); + swapBuffers (); +} + + + +void +mxGlWindow::draw () +{ +} + + + +int +mxGlWindow::makeCurrent () +{ + if (wglMakeCurrent (d_this->hdc, d_this->hglrc)) + return 1; + + return 0; +} + + + +int +mxGlWindow::swapBuffers () +{ + if (SwapBuffers (d_this->hdc)) + return 1; + + return 0; +} + + + +void +mxGlWindow::setDrawFunc (void (*func) (void)) +{ + d_drawFunc = func; +} + + + +void +mxGlWindow::setFormat (int mode, int colorBits, int depthBits) +{ + g_formatMode = mode; + g_formatColorBits = colorBits; + g_formatDepthBits = depthBits; +} diff --git a/utils/mxtk/mxgroupbox.cpp b/utils/mxtk/mxgroupbox.cpp new file mode 100644 index 0000000..ab17c00 --- /dev/null +++ b/utils/mxtk/mxgroupbox.cpp @@ -0,0 +1,50 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxGroupBox.cpp +// implementation: Win32 API +// last modified: Mar 18 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxGroupBox.h" +#include <windows.h> + + + +class mxGroupBox_i +{ +public: + int dummy; +}; + + + +mxGroupBox::mxGroupBox (mxWindow *parent, int x, int y, int w, int h, const char *label) +: mxWidget (parent, x, y, w, h, label) +{ + if (!parent) + return; + + HWND hwndParent = (HWND) ((mxWidget *) parent)->getHandle (); + + void *handle = (void *) CreateWindowEx (0, "BUTTON", label, WS_VISIBLE | WS_CHILD | BS_GROUPBOX, + x, y, w, h, hwndParent, + (HMENU) NULL, (HINSTANCE) GetModuleHandle (NULL), NULL); + + SendMessage ((HWND) handle, WM_SETFONT, (WPARAM) (HFONT) GetStockObject (ANSI_VAR_FONT), MAKELPARAM (TRUE, 0)); + + setHandle (handle); + setType (MX_GROUPBOX); + setParent (parent); +} + + + +mxGroupBox::~mxGroupBox () +{ +} diff --git a/utils/mxtk/mxlabel.cpp b/utils/mxtk/mxlabel.cpp new file mode 100644 index 0000000..9b27b19 --- /dev/null +++ b/utils/mxtk/mxlabel.cpp @@ -0,0 +1,51 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxLabel.cpp +// implementation: Win32 API +// last modified: Mar 18 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxLabel.h" +#include <windows.h> + + + +class mxLabel_i +{ +public: + int dummy; +}; + + + +mxLabel::mxLabel (mxWindow *parent, int x, int y, int w, int h, const char *label) +: mxWidget (parent, x, y, w, h, label) +{ + + if (!parent) + return; + + HWND hwndParent = (HWND) ((mxWidget *) parent)->getHandle (); + + void *handle = (void *) CreateWindowEx (0, "STATIC", label, WS_VISIBLE | WS_CHILD, + x, y, w, h, hwndParent, + (HMENU) NULL, (HINSTANCE) GetModuleHandle (NULL), NULL); + + SendMessage ((HWND) handle, WM_SETFONT, (WPARAM) (HFONT) GetStockObject (ANSI_VAR_FONT), MAKELPARAM (TRUE, 0)); + + setHandle (handle); + setType (MX_LABEL); + setParent (parent); +} + + + +mxLabel::~mxLabel () +{ +} diff --git a/utils/mxtk/mxlineedit.cpp b/utils/mxtk/mxlineedit.cpp new file mode 100644 index 0000000..035852f --- /dev/null +++ b/utils/mxtk/mxlineedit.cpp @@ -0,0 +1,140 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxLineEdit.cpp +// implementation: Win32 API +// last modified: Mar 18 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxLineEdit.h" +#include <windows.h> +#include "mxtk/mxEvent.h" +#include "mxtk/mxWindow.h" + + +class mxLineEdit_i +{ +public: + int dummy; +}; + +#include "tier0/dbg.h" + + +typedef LRESULT (CALLBACK * WndProc_t)(HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam); + +static WndProc_t s_OldWndProc = 0; + +static LRESULT CALLBACK EditWndProc (HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam) +{ + int iret = 0; + + // This lovely bit of hackery ensures we get return key events + if ( uMessage == WM_CHAR) + { + iret = s_OldWndProc( hwnd, uMessage, wParam, lParam ); + + // Post the message directly to all windows in the hierarchy until + // someone responds + mxLineEdit *lineEdit = (mxLineEdit *) GetWindowLong (hwnd, GWL_USERDATA); + mxEvent event; + event.event = mxEvent::KeyDown; + event.action = lineEdit->getId(); + event.key = (int) wParam; + + mxWindow* window = lineEdit->getParent(); + while (window) + { + if (window->handleEvent (&event)) + break; + + window = window->getParent (); + } + } + else + { + if ( uMessage == WM_LBUTTONDOWN ) + { + SetFocus( hwnd ); + } + iret = s_OldWndProc( hwnd, uMessage, wParam, lParam ); + } + return iret; +} + +mxLineEdit::mxLineEdit (mxWindow *parent, int x, int y, int w, int h, const char *label, int id, int style) +: mxWidget (parent, x, y, w, h, label) +{ + if (!parent) + return; + + DWORD dwStyle = WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL | WS_TABSTOP; // | ES_WANTRETURN | ES_MULTILINE; + HWND hwndParent = (HWND) ((mxWidget *) parent)->getHandle (); + + if (style == ReadOnly) + dwStyle |= ES_READONLY; + else if (style == Password) + dwStyle |= ES_PASSWORD; + + if (!s_OldWndProc) + { + WNDCLASSEX editClass; + GetClassInfoEx( (HINSTANCE) GetModuleHandle (NULL), "EDIT", &editClass ); + s_OldWndProc = editClass.lpfnWndProc; + + editClass.cbSize = sizeof(WNDCLASSEX); + editClass.cbClsExtra = 0; + editClass.lpfnWndProc = EditWndProc; + editClass.lpszClassName = "mx_edit"; + RegisterClassEx( &editClass ); + } + + void *handle = (void *) CreateWindowEx (WS_EX_CLIENTEDGE, "mx_edit", label, dwStyle, //WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL, + x, y, w, h, hwndParent, + (HMENU) id, (HINSTANCE) GetModuleHandle (NULL), NULL); + + SendMessage ((HWND) handle, WM_SETFONT, (WPARAM) (HFONT) GetStockObject (ANSI_VAR_FONT), MAKELPARAM (TRUE, 0)); + SendMessage ((HWND) getHandle (), EM_LIMITTEXT, (WPARAM) 256, 0L); + SetWindowLong ((HWND) handle, GWL_USERDATA, (LONG) this); + + setHandle (handle); + setType (MX_LINEEDIT); + setParent (parent); + setId (id); +} + + + +mxLineEdit::~mxLineEdit () +{ +} + +void mxLineEdit::clear() +{ + SendMessage( (HWND)getHandle(), WM_SETTEXT, (WPARAM)0, (LPARAM)"" ); +} + +void mxLineEdit::getText( char *buf, size_t bufsize ) +{ + buf[ 0 ] = 0; + SendMessage( (HWND) getHandle (), WM_GETTEXT, (WPARAM)bufsize, (LPARAM)buf ); +} + +void +mxLineEdit::setMaxLength (int max) +{ + SendMessage ((HWND) getHandle (), EM_LIMITTEXT, (WPARAM) max, 0L); +} + + + +int +mxLineEdit::getMaxLength () const +{ + return (int) SendMessage ((HWND) getHandle (), EM_GETLIMITTEXT, 0, 0L); +} diff --git a/utils/mxtk/mxlistbox.cpp b/utils/mxtk/mxlistbox.cpp new file mode 100644 index 0000000..8cb27dc --- /dev/null +++ b/utils/mxtk/mxlistbox.cpp @@ -0,0 +1,155 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxListBox.cpp +// implementation: Win32 API +// last modified: Mar 18 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxListBox.h" +#include <windows.h> + + + +class mxListBox_i +{ +public: + int dummy; +}; + + + +mxListBox::mxListBox (mxWindow *parent, int x, int y, int w, int h, int id, int style) +: mxWidget (parent, x, y, w, h) +{ + if (!parent) + return; + + DWORD dwStyle = WS_VISIBLE | WS_CHILD | LBS_NOTIFY | WS_VSCROLL | WS_HSCROLL; + HWND hwndParent = (HWND) ((mxWidget *) parent)->getHandle (); + + if (style == MultiSelection) + dwStyle |= LBS_MULTIPLESEL | LBS_EXTENDEDSEL; + + void *handle = (void *) CreateWindowEx (WS_EX_CLIENTEDGE, "LISTBOX", "", WS_VISIBLE | WS_CHILD | LBS_NOTIFY | WS_VSCROLL, + x, y, w, h, hwndParent, + (HMENU) id, (HINSTANCE) GetModuleHandle (NULL), NULL); + + SendMessage ((HWND) handle, WM_SETFONT, (WPARAM) (HFONT) GetStockObject (ANSI_VAR_FONT), MAKELPARAM (TRUE, 0)); + SetWindowLong ((HWND) handle, GWL_USERDATA, (LONG) this); + + setHandle (handle); + setType (MX_LISTBOX); + setParent (parent); + setId (id); +} + + + +mxListBox::~mxListBox () +{ + removeAll (); +} + + + +void +mxListBox::add (const char *item) +{ + SendMessage ((HWND) getHandle (), LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) item); +} + + + +void +mxListBox::select (int index) +{ + SendMessage ((HWND) getHandle (), LB_SETCURSEL, (WPARAM) index, 0L); +} + + + +void +mxListBox::deselect (int index) +{ + SendMessage ((HWND) getHandle (), LB_SETSEL, (WPARAM) FALSE, (LPARAM) (UINT) index); +} + + + +void +mxListBox::remove (int index) +{ + SendMessage ((HWND) getHandle (), LB_DELETESTRING, (WPARAM) index, 0L); +} + + + +void +mxListBox::removeAll () +{ + SendMessage ((HWND) getHandle (), LB_RESETCONTENT, 0, 0L); +} + + + +void +mxListBox::setItemText (int index, const char *item) +{ + //SendMessage ((HWND) getHandle (), LB_SETTEXT, (WPARAM) index, (LPARAM) (LPCTSTR) item); +} + + + +void +mxListBox::setItemData (int index, void *data) +{ + SendMessage ((HWND) getHandle (), LB_SETITEMDATA, (WPARAM) index, (LPARAM) data); +} + + + +int +mxListBox::getItemCount () const +{ + return (int) SendMessage ((HWND) getHandle (), LB_GETCOUNT, 0, 0L); +} + + + +int +mxListBox::getSelectedIndex () const +{ + return (int) SendMessage ((HWND) getHandle (), LB_GETCURSEL, 0, 0L); +} + + + +bool +mxListBox::isSelected (int index) const +{ + return (bool) (SendMessage ((HWND) getHandle (), LB_GETSEL, (WPARAM) index, 0L) > 0); +} + + + +const char* +mxListBox::getItemText (int index) const +{ + static char text[256]; + SendMessage ((HWND) getHandle (), LB_GETTEXT, (WPARAM) index, (LPARAM) (LPCTSTR) text); + return text; +} + + + +void* +mxListBox::getItemData (int index) const +{ + return (void *) SendMessage ((HWND) getHandle (), LB_GETITEMDATA, (WPARAM) index, 0L); +} diff --git a/utils/mxtk/mxlistview.cpp b/utils/mxtk/mxlistview.cpp new file mode 100644 index 0000000..6206d4f --- /dev/null +++ b/utils/mxtk/mxlistview.cpp @@ -0,0 +1,334 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxListView.cpp +// implementation: Win32 API +// last modified: May 03 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxListView.h" +#include <windows.h> +#include <commctrl.h> + + + +class mxListView_i +{ +public: + HWND d_hwnd; +}; + + + +mxListView::mxListView (mxWindow *parent, int x, int y, int w, int h, int id) +: mxWidget (parent, x, y, w, h) +{ + if (!parent) + return; + + d_this = new mxListView_i; + + DWORD dwStyle = LVS_NOSORTHEADER | LVS_REPORT | LVS_SHOWSELALWAYS | WS_VISIBLE | WS_CHILD; + HWND hwndParent = (HWND) ((mxWidget *) parent)->getHandle (); + + d_this->d_hwnd = CreateWindowEx (WS_EX_CLIENTEDGE, WC_LISTVIEW, "", dwStyle, + x, y, w, h, hwndParent, + (HMENU) id, (HINSTANCE) GetModuleHandle (NULL), NULL); + + SendMessage (d_this->d_hwnd, WM_SETFONT, (WPARAM) (HFONT) GetStockObject (ANSI_VAR_FONT), MAKELPARAM (TRUE, 0)); + SetWindowLong (d_this->d_hwnd, GWL_USERDATA, (LONG) this); + + setHandle ((void *) d_this->d_hwnd); + setType (MX_LISTVIEW); + setParent (parent); + setId (id); +} + + + +mxListView::~mxListView () +{ + remove (0); + delete d_this; +} +int mxListView::add ( const char *item ) +{ + if (!d_this) + return 0; + + LVITEM lvItem; + memset( &lvItem, 0, sizeof( lvItem ) ); + + lvItem.iItem = getItemCount(); + + lvItem.mask = LVIF_TEXT; + lvItem.pszText = (LPSTR) item; + lvItem.cchTextMax = 256; + + return ListView_InsertItem( d_this->d_hwnd, &lvItem ); +} + +void +mxListView::remove ( int index ) +{ + if (!d_this) + return; + + ListView_DeleteItem (d_this->d_hwnd, index ); +} + +void +mxListView::removeAll () +{ + ListView_DeleteAllItems(d_this->d_hwnd); +} + +void +mxListView::setLabel ( int item , int column, const char *label) +{ + if (!d_this) + return; + + LVITEM lvItem; + memset( &lvItem, 0, sizeof( lvItem ) ); + lvItem.mask = LVIF_TEXT; + lvItem.iItem = item; + lvItem.iSubItem = column; + + lvItem.pszText = (LPSTR) label; + lvItem.cchTextMax = 256; + + ListView_SetItem (d_this->d_hwnd, &lvItem); +} + +void mxListView::setLabel( int item, int column, const wchar_t *label ) +{ + if (!d_this) + return; + + LV_ITEMW lvItem; + memset( &lvItem, 0, sizeof( lvItem ) ); + lvItem.mask = LVIF_TEXT; + lvItem.iItem = item; + lvItem.iSubItem = column; + + lvItem.pszText = (wchar_t *)label; + lvItem.cchTextMax = 256; + + SendMessage(d_this->d_hwnd, LVM_SETITEMW, 0, (LPARAM)(const LV_ITEMW FAR*)(&lvItem)); +} + +void +mxListView::setUserData ( int item, int column, void *userData) +{ + if (!d_this) + return; + + LVITEM lvItem; + memset( &lvItem, 0, sizeof( lvItem ) ); + lvItem.mask = LVIF_PARAM; + lvItem.iItem = item; + lvItem.iSubItem = column; + lvItem.lParam = (LPARAM) userData; + + ListView_SetItem (d_this->d_hwnd, &lvItem); +} + + +void +mxListView::setSelected ( int item, bool b) +{ + if (!d_this) + return; + + ListView_SetItemState (d_this->d_hwnd, item, b ? ( LVIS_SELECTED | LVIS_FOCUSED ): 0 , LVIS_SELECTED | LVIS_FOCUSED ); +} + +int mxListView::getItemCount() const +{ + if (!d_this) + return 0; + + return ListView_GetItemCount( d_this->d_hwnd ); +} + +int mxListView::getNextSelectedItem( int startitem /*= 0*/ ) const +{ + if (!d_this) + return -1; + + if ( ListView_GetSelectedCount( d_this->d_hwnd ) == 0 ) + return -1; + + int c = getItemCount(); + int start = startitem + 1; + + while ( start < c ) + { + if ( isSelected( start ) ) + return start; + start++; + } + + return -1; +} + +int mxListView::getNumSelected() const +{ + if (!d_this) + return 0; + + return ListView_GetSelectedCount( d_this->d_hwnd ); +} + +const char* +mxListView::getLabel ( int item, int column ) const +{ + static char label[256]; + strcpy (label, ""); + + if (!d_this) + return label; + + LVITEM lvItem; + memset( &lvItem, 0, sizeof( lvItem ) ); + lvItem.mask = LVIF_TEXT; + lvItem.iItem = item; + lvItem.iSubItem = column; + lvItem.pszText = (LPSTR) label; + lvItem.cchTextMax = 256; + ListView_GetItem (d_this->d_hwnd, &lvItem); + + return lvItem.pszText; +} + + + +void* +mxListView::getUserData ( int item, int column ) const +{ + if (!d_this) + return 0; + + LVITEM lvItem; + memset( &lvItem, 0, sizeof( lvItem ) ); + lvItem.mask = LVIF_PARAM; + lvItem.iItem = item; + lvItem.iSubItem = column; + + ListView_GetItem (d_this->d_hwnd, &lvItem); + + return (void *) lvItem.lParam; +} + + + +bool +mxListView::isSelected ( int index ) const +{ + if (!d_this) + return false; + + int state = ListView_GetItemState( d_this->d_hwnd, index, LVIS_SELECTED ); + if ( state & LVIS_SELECTED ) + return true; + + return false; +} + +void mxListView::setImageList( void *himagelist ) +{ + ListView_SetImageList(d_this->d_hwnd, (HIMAGELIST)himagelist, LVSIL_SMALL ); +} + +void mxListView::setImage( int item, int column, int imagenormal ) +{ + if (!d_this) + return; + + LVITEM lvItem; + memset( &lvItem, 0, sizeof( lvItem ) ); + lvItem.mask = LVIF_IMAGE; + lvItem.iItem = item; + lvItem.iSubItem = column; + lvItem.iImage = imagenormal; + //lvItem.state = INDEXTOSTATEIMAGEMASK( imagenormal ); + //lvItem.stateMask = -1; + + ListView_SetItem (d_this->d_hwnd, &lvItem); +} + +void mxListView::insertTextColumn( int column, int width, char const *label ) +{ + if (!d_this) + return; + + LVCOLUMN col; + memset( &col, 0, sizeof( col ) ); + + col.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH | LVCF_ORDER; + col.iOrder = column; + col.pszText = (char *)label; + col.cchTextMax = 256; + col.iSubItem = column; + col.cx = width; + + ListView_InsertColumn( d_this->d_hwnd, column, &col ); +} + +void mxListView::insertImageColumn( int column, int width, int imageindex ) +{ + if (!d_this) + return; + + LVCOLUMN col; + memset( &col, 0, sizeof( col ) ); + + col.mask = LVCF_IMAGE | LVCF_SUBITEM | LVCF_WIDTH | LVCF_ORDER | LVCF_FMT; + col.fmt = LVCFMT_IMAGE; + col.iOrder = column; + col.iSubItem = column; + col.cx = width; + col.iImage = imageindex; + + ListView_InsertColumn( d_this->d_hwnd, column, &col ); +} + +void mxListView::setDrawingEnabled( bool draw ) +{ + if (!d_this) + return; + + SendMessage( d_this->d_hwnd, WM_SETREDRAW, (WPARAM)draw ? TRUE : FALSE, (LPARAM)0 ); +} + +void mxListView::deselectAll() +{ + if ( !d_this ) + return; + + setDrawingEnabled( false ); + int c = getItemCount(); + for ( int i = 0; i < c; i++ ) + { + if ( isSelected( i ) ) + { + setSelected( i, false ); + } + } + + setDrawingEnabled( true ); +} + +void mxListView::scrollToItem( int item ) +{ + if ( !d_this ) + return; + + ListView_EnsureVisible( d_this->d_hwnd, item, FALSE ); +} diff --git a/utils/mxtk/mxmatsyswindow.cpp b/utils/mxtk/mxmatsyswindow.cpp new file mode 100644 index 0000000..3ed0896 --- /dev/null +++ b/utils/mxtk/mxmatsyswindow.cpp @@ -0,0 +1,108 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxMatSysWindow.cpp +// implementation: Win32 API +// last modified: Apr 21 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxMatSysWindow.h" +#include <windows.h> + +class mxMatSysWindow_i +{ +public: + HDC hdc; + HGLRC hglrc; +}; + + + +mxMatSysWindow::mxMatSysWindow (mxWindow *parent, int x, int y, int w, int h, const char *label, int style) +: mxWindow (parent, x, y, w, h, label, style) +{ + d_this = new mxMatSysWindow_i; + + bool error = false; + + if ((d_this->hdc = GetDC ((HWND) getHandle ())) == NULL) + { + error = true; + goto done; + } + + setDrawFunc (0); + +done: + if (error) + delete this; +} + + + +mxMatSysWindow::~mxMatSysWindow () +{ + if (d_this->hdc) + ReleaseDC ((HWND) getHandle (), d_this->hdc); + + delete d_this; +} + + + +int +mxMatSysWindow::handleEvent (mxEvent *event) +{ + return 0; +} + + + +void +mxMatSysWindow::redraw () +{ + // makeCurrent (); + if (d_drawFunc) + d_drawFunc (); + else + draw (); + // swapBuffers (); +} + + + +void +mxMatSysWindow::draw () +{ +} + + + +int +mxMatSysWindow::makeCurrent () +{ + return 1; +} + + + +int +mxMatSysWindow::swapBuffers () +{ + return 0; +} + + + +void +mxMatSysWindow::setDrawFunc (void (*func) (void)) +{ + d_drawFunc = func; +} + + diff --git a/utils/mxtk/mxmenu.cpp b/utils/mxtk/mxmenu.cpp new file mode 100644 index 0000000..5d0740b --- /dev/null +++ b/utils/mxtk/mxmenu.cpp @@ -0,0 +1,116 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxMenu.cpp +// implementation: Win32 API +// last modified: Mar 18 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxMenu.h" +#include <windows.h> +#include <string.h> +//#include <ostream.h" + + + +class mxMenu_i +{ +public: + int dummy; +}; + + + +mxMenu::mxMenu () +: mxWidget (0, 0, 0, 0, 0) +{ + void *handle = (void *) CreateMenu (); + + setHandle (handle); + setType (MX_MENU); +} + + + +mxMenu::~mxMenu () +{ +} + + + +void +mxMenu::add (const char *item, int id) +{ + AppendMenu ((HMENU) getHandle (), MF_STRING, (UINT) id, item); +} + + + +void +mxMenu::addMenu (const char *item, mxMenu *menu) +{ + AppendMenu ((HMENU) getHandle (), MF_POPUP, (UINT) menu->getHandle (), item); +} + + + +void +mxMenu::addSeparator () +{ + AppendMenu ((HMENU) getHandle (), MF_SEPARATOR, 0, 0); +} + + + +void +mxMenu::setEnabled (int id, bool b) +{ + EnableMenuItem ((HMENU) getHandle (), (UINT) id, MF_BYCOMMAND | (b ? MF_ENABLED:MF_GRAYED)); +} + + + +void +mxMenu::setChecked (int id, bool b) +{ + CheckMenuItem ((HMENU) getHandle (), (UINT) id, MF_BYCOMMAND | (b ? MF_CHECKED:MF_UNCHECKED)); +} + + + +bool +mxMenu::isEnabled (int id) const +{ + MENUITEMINFO mii; + + memset (&mii, 0, sizeof (mii)); + mii.cbSize = sizeof (mii); + mii.fMask = MIIM_STATE; + GetMenuItemInfo ((HMENU) getHandle (), (UINT) id, false, &mii); + if (mii.fState & MFS_GRAYED) + return true; + + return false; +} + + + +bool +mxMenu::isChecked (int id) const +{ + MENUITEMINFO mii; + + memset (&mii, 0, sizeof (mii)); + mii.cbSize = sizeof (mii); + mii.fMask = MIIM_STATE; + GetMenuItemInfo ((HMENU) getHandle (), (UINT) id, false, &mii); + if (mii.fState & MFS_CHECKED) + return true; + + return false; +} diff --git a/utils/mxtk/mxmenubar.cpp b/utils/mxtk/mxmenubar.cpp new file mode 100644 index 0000000..2cc4fae --- /dev/null +++ b/utils/mxtk/mxmenubar.cpp @@ -0,0 +1,121 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxMenuBar.cpp +// implementation: Win32 API +// last modified: Apr 28 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxMenuBar.h" +#include <windows.h> +#include <string.h> + + + +class mxMenuBar_i +{ +public: + int dummy; +}; + + + +mxMenuBar::mxMenuBar (mxWindow *parent) +: mxWidget (0, 0, 0, 0, 0) +{ + void *handle = (void *) CreateMenu (); + setHandle (handle); + setType (MX_MENUBAR); + setParent (parent); + + if (parent) + { + mxWidget *w = (mxWidget *) parent; + SetMenu ((HWND) w->getHandle (), (HMENU) handle); + } +} + + + +mxMenuBar::~mxMenuBar () +{ +} + + + +void +mxMenuBar::addMenu (const char *item, mxMenu *menu) +{ + AppendMenu ((HMENU) getHandle (), MF_POPUP, (UINT) ((mxWidget *) menu)->getHandle (), item); +} + + + +void +mxMenuBar::setEnabled (int id, bool b) +{ + EnableMenuItem ((HMENU) getHandle (), (UINT) id, MF_BYCOMMAND | (b ? MF_ENABLED:MF_GRAYED)); +} + + + +void +mxMenuBar::setChecked (int id, bool b) +{ + CheckMenuItem ((HMENU) getHandle (), (UINT) id, MF_BYCOMMAND | (b ? MF_CHECKED:MF_UNCHECKED)); +} + + + +void +mxMenuBar::modify (int id, int newId, const char *newItem) +{ + ModifyMenu ((HMENU) getHandle (), (UINT) id, MF_BYCOMMAND | MF_STRING, (UINT) newId, (LPCTSTR) newItem); +} + + + +bool +mxMenuBar::isEnabled (int id) const +{ + MENUITEMINFO mii; + + memset (&mii, 0, sizeof (mii)); + mii.cbSize = sizeof (mii); + mii.fMask = MIIM_STATE; + GetMenuItemInfo ((HMENU) getHandle (), (UINT) id, false, &mii); + if (mii.fState & MFS_GRAYED) + return true; + + return false; +} + + + +bool +mxMenuBar::isChecked (int id) const +{ + MENUITEMINFO mii; + + memset (&mii, 0, sizeof (mii)); + mii.cbSize = sizeof (mii); + mii.fMask = MIIM_STATE; + GetMenuItemInfo ((HMENU) getHandle (), (UINT) id, false, &mii); + if (mii.fState & MFS_CHECKED) + return true; + + return false; +} + + + +int +mxMenuBar::getHeight () const +{ + return 0; +} diff --git a/utils/mxtk/mxmessagebox.cpp b/utils/mxtk/mxmessagebox.cpp new file mode 100644 index 0000000..621fb09 --- /dev/null +++ b/utils/mxtk/mxmessagebox.cpp @@ -0,0 +1,63 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxMessageBox.cpp +// implementation: Win32 API +// last modified: Mar 14 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxMessageBox.h" +#include "mxtk/mxWindow.h" +#include <windows.h> +#include <commdlg.h> +#include <string.h> + + + +int +mxMessageBox (mxWindow *parent, const char *msg, const char *title, int style) +{ + HWND hwndParent = 0; + if (parent) + hwndParent = (HWND) parent->getHandle (); + + UINT uType = 0; + + if (style & MX_MB_OK) + uType |= MB_OK; + else if (style & MX_MB_YESNO) + uType |= MB_YESNO; + else if (style & MX_MB_YESNOCANCEL) + uType |= MB_YESNOCANCEL; + + if (style & MX_MB_INFORMATION) + uType |= MB_ICONINFORMATION; + else if (style & MX_MB_ERROR) + uType |= MB_ICONHAND; + else if (style & MX_MB_WARNING) + uType |= MB_ICONEXCLAMATION; + else if (style & MX_MB_QUESTION) + uType |= MB_ICONQUESTION; + + int ret = MessageBox (hwndParent, msg, title, uType); + + switch (ret) + { + case IDOK: + case IDYES: + return 0; + + case IDNO: + return 1; + + case IDCANCEL: + return 2; + } + + return 0; +} diff --git a/utils/mxtk/mxpath.cpp b/utils/mxtk/mxpath.cpp new file mode 100644 index 0000000..cad3b95 --- /dev/null +++ b/utils/mxtk/mxpath.cpp @@ -0,0 +1,98 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxpath.cpp +// implementation: all +// last modified: May 04 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxpath.h" +#ifdef WIN32 +#include <windows.h> +#else +#include <unistd.h" +#endif +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + + + +bool +mx_setcwd (const char *path) +{ +#ifdef WIN32 + return (SetCurrentDirectory (path) == TRUE); +#else + return (chdir (path) != -1); +#endif +} + + + +const char * +mx_getcwd () +{ + static char path[256]; +#ifdef WIN32 + GetCurrentDirectory (256, path); +#else + getcwd (path, 256); +#endif + return path; +} + + + +const char * +mx_getpath (const char *filename) +{ + static char path[256]; +#ifdef WIN32 + _splitpath (filename, 0, path, 0, 0); +#else + strcpy (path, filename); + char *ptr = strrchr (path, '/'); + if (ptr) + *ptr = '\0'; +#endif + return path; +} + + + +const char * +mx_getextension (const char *filename) +{ + static char ext[256]; +#ifdef WIN32 + _splitpath (filename, 0, 0, 0, ext); +#else + char *ptr = strrchr (filename, '.'); + if (ptr) + strcpy (ext, ptr); + else + strcpy (ext, ""); +#endif + return ext; +} + + + +const char * +mx_gettemppath () +{ + static char path[256]; +#ifdef WIN32 + GetTempPath (256, path); +#else + strcpy (path, "/tmp"); +#endif + + return path; +} diff --git a/utils/mxtk/mxpcx.cpp b/utils/mxtk/mxpcx.cpp new file mode 100644 index 0000000..f4eb6d6 --- /dev/null +++ b/utils/mxtk/mxpcx.cpp @@ -0,0 +1,98 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxPcx.cpp +// implementation: all +// last modified: Apr 15 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxPcx.h" +#include <stdio.h> +#include <stdlib.h> + + + +mxImage * +mxPcxRead (const char *filename) +{ + FILE *file = fopen (filename, "rb"); + if (!file) + return 0; + + mxPcxHeader header; + if (fread (&header, sizeof (mxPcxHeader), 1, file) == -1) + { + fclose (file); + return 0; + } +/* + if (header.bitsPerPixel != 8 || + header.version != 5) + { + fclose (file); + return 0; + } + + (void) fseek (file, -769, SEEK_END); + if (fgetc (file) != 12) { + fclose (file); + return NULL; + } +*/ + (void) fseek (file, -768, SEEK_END); + + int w = header.xmax - header.xmin + 1; + int h = header.ymax - header.ymin + 1; + + mxImage *image = new mxImage (); + if (!image->create (w, h, 8)) + { + delete image; + fclose (file); + return 0; + } + + if (fread ((byte *) image->palette, sizeof (byte), 768, file) == -1) + { + fclose (file); + return 0; + } + + (void) fseek(file, sizeof (mxPcxHeader), SEEK_SET); + int ptr = 0; + int ch, rep; + byte *data = (byte *) image->data; + int size = w * h; + while (ptr < size) + { + ch = fgetc(file); + if (ch >= 192) + { + rep = ch - 192; + ch = fgetc(file); + } + else { + rep = 1; + } + + while (rep--) + data[ptr++] = (byte)ch; + } + + fclose(file); + + return image; +} + + + +bool +mxPcxWrite (const char * /*filename*/, mxImage * /*image*/) +{ + return false; +}
\ No newline at end of file diff --git a/utils/mxtk/mxpopupmenu.cpp b/utils/mxtk/mxpopupmenu.cpp new file mode 100644 index 0000000..6732d5e --- /dev/null +++ b/utils/mxtk/mxpopupmenu.cpp @@ -0,0 +1,126 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxPopupMenu.cpp +// implementation: Win32 API +// last modified: Mar 18 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxPopupMenu.h" +#include <windows.h> + + + +class mxPopupMenu_i +{ +public: + int dummy; +}; + + + +mxPopupMenu::mxPopupMenu () +: mxWidget (0, 0, 0, 0, 0) +{ + void *handle = (void *) CreatePopupMenu (); + setHandle (handle); + setType (MX_POPUPMENU); +} + + + +mxPopupMenu::~mxPopupMenu () +{ +} + + + +int +mxPopupMenu::popup (mxWidget *widget, int x, int y) +{ + POINT pt; + pt.x = x; + pt.y = y; + + ClientToScreen ((HWND) widget->getHandle (), &pt); + return (int) TrackPopupMenu ((HMENU) getHandle (), /*TPM_NONOTIFY | TPM_RETURNCMD | */ TPM_LEFTALIGN | TPM_TOPALIGN, pt.x, pt.y, 0, (HWND) widget->getHandle (), NULL); +} + + + +void +mxPopupMenu::add (const char *item, int id) +{ + AppendMenu ((HMENU) getHandle (), MF_STRING, (UINT) id, item); +} + + + +void +mxPopupMenu::addMenu (const char *item, mxPopupMenu *menu) +{ + AppendMenu ((HMENU) getHandle (), MF_POPUP, (UINT) menu->getHandle (), item); +} + + + +void +mxPopupMenu::addSeparator () +{ + AppendMenu ((HMENU) getHandle (), MF_SEPARATOR, 0, 0); +} + + + +void +mxPopupMenu::setEnabled (int id, bool b) +{ + EnableMenuItem ((HMENU) getHandle (), (UINT) id, MF_BYCOMMAND | (b ? MF_ENABLED:MF_GRAYED)); +} + + + +void +mxPopupMenu::setChecked (int id, bool b) +{ + CheckMenuItem ((HMENU) getHandle (), (UINT) id, MF_BYCOMMAND | (b ? MF_CHECKED:MF_UNCHECKED)); +} + + + +bool +mxPopupMenu::isEnabled (int id) const +{ + MENUITEMINFO mii; + + memset (&mii, 0, sizeof (mii)); + mii.cbSize = sizeof (mii); + mii.fMask = MIIM_STATE; + GetMenuItemInfo ((HMENU) getHandle (), (UINT) id, false, &mii); + if (mii.fState & MFS_GRAYED) + return true; + + return false; +} + + + +bool +mxPopupMenu::isChecked (int id) const +{ + MENUITEMINFO mii; + + memset (&mii, 0, sizeof (mii)); + mii.cbSize = sizeof (mii); + mii.fMask = MIIM_STATE; + GetMenuItemInfo ((HMENU) getHandle (), (UINT) id, false, &mii); + if (mii.fState & MFS_CHECKED) + return true; + + return false; +} diff --git a/utils/mxtk/mxprogressbar.cpp b/utils/mxtk/mxprogressbar.cpp new file mode 100644 index 0000000..8d20eca --- /dev/null +++ b/utils/mxtk/mxprogressbar.cpp @@ -0,0 +1,89 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxProgressBar.cpp +// implementation: Win32 API +// last modified: Mar 18 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxProgressBar.h" +#include <windows.h> +#include <commctrl.h> + + + +class mxProgressBar_i +{ +public: + int d_value; + int d_steps; +}; + + + +mxProgressBar::mxProgressBar (mxWindow *parent, int x, int y, int w, int h, int style) +: mxWidget (parent, x, y, w, h) +{ + d_this = new mxProgressBar_i; + + DWORD dwStyle = WS_VISIBLE | WS_CHILD; + HWND hwndParent = parent ? (HWND) ((mxWidget *) parent)->getHandle () : NULL; + + if (style == Smooth) + dwStyle |= PBS_SMOOTH; + + void *handle = (void *) CreateWindowEx (0, PROGRESS_CLASS, "", dwStyle, + x, y, w, h, hwndParent, + (HMENU) NULL, (HINSTANCE) GetModuleHandle (NULL), NULL); + + SendMessage ((HWND) handle, WM_SETFONT, (WPARAM) (HFONT) GetStockObject (ANSI_VAR_FONT), MAKELPARAM (TRUE, 0)); + + setHandle (handle); + setType (MX_PROGRESSBAR); + setParent (parent); +} + + + +mxProgressBar::~mxProgressBar () +{ + delete d_this; +} + + + +void +mxProgressBar::setValue (int value) +{ + d_this->d_value = value; + SendMessage ((HWND) getHandle (), PBM_SETPOS, (WPARAM) value, 0L); +} + + +void +mxProgressBar::setTotalSteps (int steps) +{ + d_this->d_steps = steps; + SendMessage ((HWND) getHandle (), PBM_SETRANGE, 0, MAKELPARAM (0, steps)); +} + + + +int +mxProgressBar::getValue () const +{ + return d_this->d_value; +} + + + +int +mxProgressBar::getTotalSteps () const +{ + return d_this->d_steps; +} diff --git a/utils/mxtk/mxradiobutton.cpp b/utils/mxtk/mxradiobutton.cpp new file mode 100644 index 0000000..51d4f3f --- /dev/null +++ b/utils/mxtk/mxradiobutton.cpp @@ -0,0 +1,74 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxRadioButton.cpp +// implementation: Win32 API +// last modified: Mar 18 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxRadioButton.h" +#include <windows.h> + + + +class mxRadioButton_i +{ +public: + int dummy; +}; + + + +mxRadioButton::mxRadioButton (mxWindow *parent, int x, int y, int w, int h, const char *label, int id, bool newGroup) +: mxWidget (parent, x, y, w, h, label) +{ + if (!parent) + return; + + DWORD dwStyle = WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON; + HWND hwndParent = (HWND) ((mxWidget *) parent)->getHandle (); + + if (newGroup) + dwStyle |= WS_GROUP; + + void *handle = (void *) CreateWindowEx (0, "BUTTON", label, dwStyle, + x, y, w, h, hwndParent, + (HMENU) id, (HINSTANCE) GetModuleHandle (NULL), NULL); + + SendMessage ((HWND) handle, WM_SETFONT, (WPARAM) (HFONT) GetStockObject (ANSI_VAR_FONT), MAKELPARAM (TRUE, 0)); + SetWindowLong ((HWND) handle, GWL_USERDATA, (LONG) this); + + setHandle (handle); + setType (MX_RADIOBUTTON); + setParent (parent); + setId (id); + + setChecked (newGroup); +} + + + +mxRadioButton::~mxRadioButton () +{ +} + + + +void +mxRadioButton::setChecked (bool b) +{ + SendMessage ((HWND) getHandle (), BM_SETCHECK, (WPARAM) b ? BST_CHECKED:BST_UNCHECKED, 0L); +} + + + +bool +mxRadioButton::isChecked () const +{ + return (SendMessage ((HWND) getHandle (), BM_GETCHECK, 0, 0L) == BST_CHECKED); +} diff --git a/utils/mxtk/mxscrollbar.cpp b/utils/mxtk/mxscrollbar.cpp new file mode 100644 index 0000000..ae10bc2 --- /dev/null +++ b/utils/mxtk/mxscrollbar.cpp @@ -0,0 +1,134 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxScrollbar.cpp +// implementation: Win32 API +// last modified: Mar 18 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxScrollbar.h" +#include <windows.h> +#include <commctrl.h> + + + +class mxScrollbar_i +{ +public: + int dummy; +}; + + + +mxScrollbar::mxScrollbar (mxWindow *parent, int x, int y, int w, int h, int id, int style) +: mxWidget (parent, x, y, w, h) +{ + if (!parent) + return; + + DWORD dwStyle = WS_CHILD | WS_VISIBLE; + HWND hwndParent = (HWND) ((mxWidget *) parent)->getHandle (); + + if (style == Horizontal) + dwStyle = WS_CHILD | WS_VISIBLE | SBS_HORZ | SBS_RIGHTALIGN; + else if (style == Vertical) + dwStyle = WS_CHILD | WS_VISIBLE | SBS_VERT | SBS_RIGHTALIGN; // WS_VSCROLL; + + void *handle = (void *) CreateWindowEx (0, "SCROLLBAR", "", dwStyle, + x, y, w, h, hwndParent, + (HMENU) id, (HINSTANCE) GetModuleHandle (NULL), NULL); + + SendMessage ((HWND) handle, WM_SETFONT, (WPARAM) (HFONT) GetStockObject (ANSI_VAR_FONT), MAKELPARAM (TRUE, 0)); + SetWindowLong ((HWND) handle, GWL_USERDATA, (LONG) this); + + setHandle (handle); + setType (MX_SCROLLBAR); + setParent (parent); + setId (id); +} + + + +mxScrollbar::~mxScrollbar () +{ +} + + + +void +mxScrollbar::setValue (int ivalue) +{ + SetScrollPos( (HWND) getHandle (), SB_CTL, ivalue, FALSE ); +} + + + +void +mxScrollbar::setRange (int min, int max ) +{ + SCROLLINFO si = { sizeof( SCROLLINFO ), SIF_RANGE, min, max, 0, 0, 0 }; + + SetScrollInfo( (HWND) getHandle (), SB_CTL, &si, TRUE ); +} + + + +void +mxScrollbar::setPagesize (int size) +{ + SCROLLINFO si = { sizeof( SCROLLINFO ), SIF_PAGE, 0, 0, (UINT)size, 0, 0 }; + + SetScrollInfo( (HWND) getHandle (), SB_CTL, &si, TRUE ); +} + + + +int +mxScrollbar::getValue () const +{ + // SCROLLINFO si = { sizeof( SCROLLINFO ), SIF_POS | SIF_TRACKPOS, 0, 0, 0, 0, 0 }; + // GetScrollInfo( (HWND) getHandle (), SB_CTL, &si ); + // return si.nPos; + return GetScrollPos( (HWND) getHandle (), SB_CTL ); +} + + + +int +mxScrollbar::getMinValue () const +{ + SCROLLINFO si = { sizeof( SCROLLINFO ), SIF_RANGE, 0, 0, 0, 0, 0 }; + + GetScrollInfo( (HWND) getHandle (), SB_CTL, &si ); + + return si.nMin; +} + + + +int +mxScrollbar::getMaxValue () const +{ + SCROLLINFO si = { sizeof( SCROLLINFO ), SIF_RANGE, 0, 0, 0, 0, 0 }; + + GetScrollInfo( (HWND) getHandle (), SB_CTL, &si ); + + return si.nMax; +} + + + +int +mxScrollbar::getPagesize () const +{ + SCROLLINFO si = { sizeof( SCROLLINFO ), SIF_PAGE, 0, 0, 0, 0, 0 }; + + GetScrollInfo( (HWND) getHandle (), SB_CTL, &si ); + + return si.nPage; +} diff --git a/utils/mxtk/mxslider.cpp b/utils/mxtk/mxslider.cpp new file mode 100644 index 0000000..899d253 --- /dev/null +++ b/utils/mxtk/mxslider.cpp @@ -0,0 +1,137 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxSlider.cpp +// implementation: Win32 API +// last modified: Mar 18 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxSlider.h" +#include <windows.h> +#include <commctrl.h> + + + +class mxSlider_i +{ +public: + int dummy; +}; + + + +mxSlider::mxSlider (mxWindow *parent, int x, int y, int w, int h, int id, int style) +: mxWidget (parent, x, y, w, h) +{ + if (!parent) + return; + + DWORD dwStyle = WS_CHILD | WS_VISIBLE; + HWND hwndParent = (HWND) ((mxWidget *) parent)->getHandle (); + + if (style == Horizontal) + dwStyle = WS_CHILD | WS_VISIBLE | TBS_HORZ; + else if (style == Vertical) + dwStyle = WS_CHILD | WS_VISIBLE | TBS_VERT; + + void *handle = (void *) CreateWindowEx (0, TRACKBAR_CLASS, "", dwStyle, + x, y, w, h, hwndParent, + (HMENU) id, (HINSTANCE) GetModuleHandle (NULL), NULL); + + SendMessage ((HWND) handle, WM_SETFONT, (WPARAM) (HFONT) GetStockObject (ANSI_VAR_FONT), MAKELPARAM (TRUE, 0)); + SetWindowLong ((HWND) handle, GWL_USERDATA, (LONG) this); + + setHandle (handle); + setType (MX_SLIDER); + setParent (parent); + setId (id); +} + + + +mxSlider::~mxSlider () +{ +} + + + +void +mxSlider::setValue (float value) +{ + int ivalue = (int)((((value - m_min) / (m_max - m_min)) * m_ticks) + 0.5); + SendMessage ((HWND) getHandle (), TBM_SETPOS, (WPARAM) true, (LPARAM) ivalue); +} + + + +void +mxSlider::setRange (float min, float max, int ticks) +{ + m_min = min; + m_max = max; + m_ticks = ticks; + SendMessage ((HWND) getHandle (), TBM_SETRANGE, (WPARAM) true, (LPARAM) MAKELONG(0, ticks)); +} + + + +void +mxSlider::setSteps (int line, int page) +{ + SendMessage ((HWND) getHandle (), TBM_SETLINESIZE, 0, (LPARAM) line); + SendMessage ((HWND) getHandle (), TBM_SETPAGESIZE, 0, (LPARAM) page); +} + + + +float +mxSlider::getValue () const +{ + int ivalue = SendMessage ((HWND) getHandle (), TBM_GETPOS, 0, 0L); + return (ivalue / (float)m_ticks) * (m_max - m_min) + m_min; +} + + +float +mxSlider::getTrackValue ( int ivalue ) const +{ + return (ivalue / (float)m_ticks) * (m_max - m_min) + m_min; +} + + +float +mxSlider::getMinValue () const +{ + return m_min; + // return (int) SendMessage ((HWND) getHandle (), TBM_GETRANGEMIN, 0, 0L); +} + + + +float +mxSlider::getMaxValue () const +{ + return m_max; + // return (int) SendMessage ((HWND) getHandle (), TBM_GETRANGEMAX, 0, 0L); +} + + + +int +mxSlider::getLineStep () const +{ + return (int) SendMessage ((HWND) getHandle (), TBM_GETLINESIZE, 0, 0L); +} + + + +int +mxSlider::getPageStep () const +{ + return (int) SendMessage ((HWND) getHandle (), TBM_GETPAGESIZE, 0, 0L); +} diff --git a/utils/mxtk/mxstring.cpp b/utils/mxtk/mxstring.cpp new file mode 100644 index 0000000..797b71f --- /dev/null +++ b/utils/mxtk/mxstring.cpp @@ -0,0 +1,54 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxstring.cpp +// implementation: all +// last modified: May 04 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxstring.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <ctype.h> + + + +int +mx_strncasecmp (const char *s1, const char *s2, int count) +{ +#ifdef WIN32 + return _strnicmp (s1, s2, count); +#else + return strncasecmp (s1, s2, count); +#endif +} + + + +int +mx_strcasecmp (const char *s1, const char *s2) +{ +#ifdef WIN32 + return _stricmp (s1, s2); +#else + return strcasecmp (s1, s2); +#endif +} + + + + +char * +mx_strlower (char *str) +{ + int i; + for (i = (int)strlen (str) - 1; i >= 0; i--) + str[i] = (char)tolower (str[i]); + return str; +} diff --git a/utils/mxtk/mxtab.cpp b/utils/mxtk/mxtab.cpp new file mode 100644 index 0000000..adea8f3 --- /dev/null +++ b/utils/mxtk/mxtab.cpp @@ -0,0 +1,130 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxTab.cpp +// implementation: Win32 API +// last modified: Apr 18 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxTab.h" +#include <windows.h> +#include <commctrl.h> + +#include <stdio.h> + +class mxTab_i +{ +public: + int dummy; +}; + + + +void mxTab_resizeChild (HWND hwnd) +{ + TC_ITEM ti; + + int index = TabCtrl_GetCurSel (hwnd); + if (index >= 0) + { + ti.mask = TCIF_PARAM; + TabCtrl_GetItem (hwnd, index, &ti); + mxWidget *widget = (mxWidget *) ti.lParam; + if (widget) + { + RECT rc, rc2; + + GetWindowRect (hwnd, &rc); + ScreenToClient (GetParent (hwnd), (LPPOINT) &rc.left); + ScreenToClient (GetParent (hwnd), (LPPOINT) &rc.right); + + TabCtrl_GetItemRect (hwnd, index, &rc2); + + int ex = GetSystemMetrics (SM_CXEDGE); + int ey = GetSystemMetrics (SM_CYEDGE); + rc.top += (rc2.bottom - rc2.top) + 3 * ey; + rc.left += 2 * ex; + rc.right -= 2 * ex; + rc.bottom -= 2 * ey; + HDWP hdwp = BeginDeferWindowPos (2); + DeferWindowPos (hdwp, hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER); + DeferWindowPos (hdwp, (HWND) widget->getHandle (), HWND_TOP, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_SHOWWINDOW); + EndDeferWindowPos (hdwp); + } + } +} + + + +mxTab::mxTab (mxWindow *parent, int x, int y, int w, int h, int id) +: mxWidget (parent, x, y, w, h) +{ + if (!parent) + return; + + DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS; + HWND hwndParent = (HWND) ((mxWidget *) parent)->getHandle (); + + void *handle = (void *) CreateWindowEx (0, WC_TABCONTROL, "", dwStyle, + x, y, w, h, hwndParent, + (HMENU) id, (HINSTANCE) GetModuleHandle (NULL), NULL); + + SendMessage ((HWND) handle, WM_SETFONT, (WPARAM) (HFONT) GetStockObject (ANSI_VAR_FONT), MAKELPARAM (TRUE, 0)); + SetWindowLong ((HWND) handle, GWL_USERDATA, (LONG) this); + + setHandle (handle); + setType (MX_TAB); + setParent (parent); + setId (id); +} + + + +mxTab::~mxTab () +{ + //TabCtrl_DeleteAllItems ((HWND) getHandle ()); +} + + + +void +mxTab::add (mxWidget *widget, const char *text) +{ + TC_ITEM ti; + + ti.mask = TCIF_TEXT | TCIF_PARAM; + ti.pszText = (LPSTR) text; + ti.lParam = (LPARAM) widget; + + TabCtrl_InsertItem ((HWND) getHandle (), TabCtrl_GetItemCount ((HWND) getHandle ()), &ti); + mxTab_resizeChild ((HWND) getHandle ()); +} + + + +void +mxTab::remove (int index) +{ + TabCtrl_DeleteItem ((HWND) getHandle (), index); +} + + + +void +mxTab::select (int index) +{ + TabCtrl_SetCurSel ((HWND) getHandle (), index); +} + + + +int +mxTab::getSelectedIndex () const +{ + return (int) TabCtrl_GetCurSel ((HWND) getHandle ()); +} diff --git a/utils/mxtk/mxtga.cpp b/utils/mxtk/mxtga.cpp new file mode 100644 index 0000000..addedf3 --- /dev/null +++ b/utils/mxtk/mxtga.cpp @@ -0,0 +1,140 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxTga.cpp +// implementation: all +// last modified: Apr 15 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxTga.h" +#include <stdio.h> +#include <stdlib.h> + + + +mxImage * +mxTgaRead (const char *filename) +{ + FILE *file; + file = fopen (filename, "rb"); + if (!file) + return 0; + + byte identFieldLength; + byte colorMapType; + byte imageTypeCode; + fread (&identFieldLength, sizeof (byte), 1, file); + fread (&colorMapType, sizeof (byte), 1, file); + fread (&imageTypeCode, sizeof (byte), 1, file); + + fseek (file, 12, SEEK_SET); + + word width, height; + byte pixelSize; + fread (&width, sizeof (word), 1, file); + fread (&height, sizeof (word), 1, file); + fread (&pixelSize, sizeof (byte), 1, file); + + // only 24-bit RGB uncompressed + if (colorMapType != 0 || + imageTypeCode != 2 || + pixelSize != 24) + { + fclose (file); + return 0; + } + + fseek (file, 18 + identFieldLength, SEEK_SET); + + mxImage *image = new mxImage (); + if (!image->create (width, height, 24)) + { + delete image; + fclose (file); + return 0; + } + + byte *data = (byte *) image->data; + for (int y = 0; y < height; y++) + { + byte *scanline = (byte *) &data[(height - y - 1) * width * 3]; + for (int x = 0; x < width; x++) + { + scanline[x * 3 + 2] = (byte) fgetc (file); + scanline[x * 3 + 1] = (byte) fgetc (file); + scanline[x * 3 + 0] = (byte) fgetc (file); + //scanline[x * 4 + 3] = 0xff; + } + } + + fclose (file); + + return image; +} + + + +bool +mxTgaWrite (const char *filename, mxImage *image) +{ + if (!image) + return false; + + if (image->bpp != 24) + return false; + + FILE *file = fopen (filename, "wb"); + if (!file) + return false; + + // + // write header + // + fputc (0, file); // identFieldLength + fputc (0, file); // colorMapType == 0, no color map + fputc (2, file); // imageTypeCode == 2, uncompressed RGB + + word w = 0; + fwrite (&w, sizeof (word), 1, file); // colorMapOrigin + fwrite (&w, sizeof (word), 1, file); // colorMapLength + fputc (0, file); // colorMapEntrySize + + fwrite (&w, sizeof (word), 1, file); // imageOriginX + fwrite (&w, sizeof (word), 1, file); // imageOriginY + + w = (word) image->width; + fwrite (&w, sizeof (word), 1, file); // imageWidth + + w = (word) image->height; + fwrite (&w, sizeof (word), 1, file); // imageHeight + + fputc (24, file); // imagePixelSize + fputc (0, file); // imageDescriptorByte + + // write no ident field + + // write no color map + + // write imagedata + + byte *data = (byte *) image->data; + for (int y = 0; y < image->height; y++) + { + byte *scanline = (byte *) &data[(image->height - y - 1) * image->width * 3]; + for (int x = 0; x < image->width; x++) + { + fputc ((byte) scanline[x * 3 + 2], file); + fputc ((byte) scanline[x * 3 + 1], file); + fputc ((byte) scanline[x * 3 + 0], file); + } + } + + fclose (file); + + return true; +}
\ No newline at end of file diff --git a/utils/mxtk/mxtogglebutton.cpp b/utils/mxtk/mxtogglebutton.cpp new file mode 100644 index 0000000..f855fc1 --- /dev/null +++ b/utils/mxtk/mxtogglebutton.cpp @@ -0,0 +1,69 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxToggleButton.cpp +// implementation: Win32 API +// last modified: Apr 28 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include <mx/mxToggleButton.h> +#include <windows.h> + + + +class mxToggleButton_i +{ +public: + int dummy; +}; + + + +mxToggleButton::mxToggleButton (mxWindow *parent, int x, int y, int w, int h, const char *label, int id) +: mxWidget (parent, x, y, w, h, label) +{ + if (!parent) + return; + + HWND hwndParent = (HWND) ((mxWidget *) parent)->getHandle (); + + void *handle = (void *) CreateWindowEx (0, "BUTTON", label, WS_VISIBLE | WS_CHILD | BS_PUSHLIKE | BS_AUTOCHECKBOX | WS_TABSTOP, + x, y, w, h, hwndParent, + (HMENU) id, (HINSTANCE) GetModuleHandle (NULL), NULL); + + SendMessage ((HWND) handle, WM_SETFONT, (WPARAM) (HFONT) GetStockObject (ANSI_VAR_FONT), MAKELPARAM (TRUE, 0)); + SetWindowLong ((HWND) handle, GWL_USERDATA, (LONG) this); + + setHandle (handle); + setType (MX_TOGGLEBUTTON); + setParent (parent); + setId (id); + setChecked (false); +} + + + +mxToggleButton::~mxToggleButton () +{ +} + + + +void +mxToggleButton::setChecked (bool b) +{ + SendMessage ((HWND) getHandle (), BM_SETCHECK, (WPARAM) b ? BST_CHECKED:BST_UNCHECKED, 0L); +} + + + +bool +mxToggleButton::isChecked () const +{ + return (SendMessage ((HWND) getHandle (), BM_GETCHECK, 0, 0L) == BST_CHECKED); +} diff --git a/utils/mxtk/mxtoolkitwin32.vpc b/utils/mxtk/mxtoolkitwin32.vpc new file mode 100644 index 0000000..efeccc9 --- /dev/null +++ b/utils/mxtk/mxtoolkitwin32.vpc @@ -0,0 +1,98 @@ +//----------------------------------------------------------------------------- +// MXTOOLKITWIN32.VPC +// +// Project Script +//----------------------------------------------------------------------------- + +$Macro SRCDIR "..\.." +$Macro OUTLIBDIR "$LIBCOMMON" + +$Include "$SRCDIR\vpc_scripts\source_lib_base.vpc" + +$Configuration +{ + $Compiler + { + $AdditionalIncludeDirectories "$BASE,..\..\public" + $PreprocessorDefinitions "$BASE;_CRT_SECURE_NO_DEPRECATE" + } +} + +$Project "Mxtoolkitwin32" +{ + $Folder "Source Files" + { + $File "mx.cpp" + $File "mxBmp.cpp" + $File "mxButton.cpp" + $File "mxCheckBox.cpp" + $File "mxChoice.cpp" + $File "mxChooseColor.cpp" + $File "mxFileDialog.cpp" + $File "mxGlWindow.cpp" + $File "mxGroupBox.cpp" + $File "mxLabel.cpp" + $File "mxLineEdit.cpp" + $File "mxListBox.cpp" + $File "mxlistview.cpp" + $File "mxMatSysWindow.cpp" + $File "mxMenu.cpp" + $File "mxMenuBar.cpp" + $File "mxMessageBox.cpp" + $File "mxpath.cpp" + $File "mxPcx.cpp" + $File "mxPopupMenu.cpp" + $File "mxProgressBar.cpp" + $File "mxRadioButton.cpp" + $File "mxScrollbar.cpp" + $File "mxSlider.cpp" + $File "mxstring.cpp" + $File "mxTab.cpp" + $File "mxTga.cpp" + $File "mxToolTip.cpp" + $File "mxTreeView.cpp" + $File "mxWidget.cpp" + $File "mxWindow.cpp" + } + + $Folder "Header Files" + { + $File "..\..\public\mxtk\gl.h" + $File "..\..\public\mxtk\mx.h" + $File "..\..\public\mxtk\mxBmp.h" + $File "..\..\public\mxtk\mxButton.h" + $File "..\..\public\mxtk\mxCheckBox.h" + $File "..\..\public\mxtk\mxChoice.h" + $File "..\..\public\mxtk\mxChooseColor.h" + $File "..\..\public\mxtk\mxEvent.h" + $File "..\..\public\mxtk\mxFileDialog.h" + $File "..\..\public\mxtk\mxGlWindow.h" + $File "..\..\public\mxtk\mxGroupBox.h" + $File "..\..\public\mxtk\mxImage.h" + $File "..\..\public\mxtk\mxInit.h" + $File "..\..\public\mxtk\mxLabel.h" + $File "..\..\public\mxtk\mxLineEdit.h" + $File "..\..\public\mxtk\mxLinkedList.h" + $File "..\..\public\mxtk\mxListBox.h" + $File "..\..\public\mxtk\mxlistview.h" + $File "..\..\public\mxtk\mxMatSysWindow.h" + $File "..\..\public\mxtk\mxMenu.h" + $File "..\..\public\mxtk\mxMenuBar.h" + $File "..\..\public\mxtk\mxMessageBox.h" + $File "..\..\public\mxtk\mxpath.h" + $File "..\..\public\mxtk\mxPcx.h" + $File "..\..\public\mxtk\mxPopupMenu.h" + $File "..\..\public\mxtk\mxProgressBar.h" + $File "..\..\public\mxtk\mxRadioButton.h" + $File "..\..\public\mxtk\mxScrollbar.h" + $File "..\..\public\mxtk\mxSlider.h" + $File "..\..\public\mxtk\mxstring.h" + $File "..\..\public\mxtk\mxTab.h" + $File "..\..\public\mxtk\mxTga.h" + $File "..\..\public\mxtk\mxToggleButton.h" + $File "..\..\public\mxtk\mxToolTip.h" + $File "..\..\public\mxtk\mxTreeView.h" + $File "..\..\public\mxtk\mxWidget.h" + $File "..\..\public\mxtk\mxWindow.h" + } +} diff --git a/utils/mxtk/mxtooltip.cpp b/utils/mxtk/mxtooltip.cpp new file mode 100644 index 0000000..473d356 --- /dev/null +++ b/utils/mxtk/mxtooltip.cpp @@ -0,0 +1,41 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxToolTip.cpp +// implementation: Win32 API +// last modified: Mar 14 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxToolTip.h" +#include "mxtk/mxWidget.h" +#include <windows.h> +#include <commctrl.h> + + + +HWND mx_CreateToolTipControl (void); + + + +void +mxToolTip::add (mxWidget *widget, const char *text) +{ + if (!widget) + return; + + TOOLINFO ti; + + memset (&ti, 0, sizeof (TOOLINFO)); + ti.cbSize = sizeof (TOOLINFO); + ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS; + ti.uId = (UINT) (HWND) widget->getHandle (); + ti.lpszText = (LPTSTR) text; + + HWND ctrl = mx_CreateToolTipControl (); + SendMessage (ctrl, TTM_ADDTOOL, 0, (LPARAM) &ti); +} diff --git a/utils/mxtk/mxtreeview.cpp b/utils/mxtk/mxtreeview.cpp new file mode 100644 index 0000000..107a8b0 --- /dev/null +++ b/utils/mxtk/mxtreeview.cpp @@ -0,0 +1,356 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxTreeView.cpp +// implementation: Win32 API +// last modified: May 03 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxTreeView.h" +#include <windows.h> +#include <commctrl.h> + + + +class mxTreeView_i +{ +public: + HWND d_hwnd; +}; + + + +mxTreeView::mxTreeView (mxWindow *parent, int x, int y, int w, int h, int id) +: mxWidget (parent, x, y, w, h) +{ + if (!parent) + return; + + d_this = new mxTreeView_i; + + DWORD dwStyle = TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_SHOWSELALWAYS | WS_VISIBLE | WS_CHILD; + HWND hwndParent = (HWND) ((mxWidget *) parent)->getHandle (); + + d_this->d_hwnd = CreateWindowEx (WS_EX_CLIENTEDGE, WC_TREEVIEW, "", dwStyle, + x, y, w, h, hwndParent, + (HMENU) id, (HINSTANCE) GetModuleHandle (NULL), NULL); + + SendMessage (d_this->d_hwnd, WM_SETFONT, (WPARAM) (HFONT) GetStockObject (ANSI_VAR_FONT), MAKELPARAM (TRUE, 0)); + SetWindowLong (d_this->d_hwnd, GWL_USERDATA, (LONG) this); + + setHandle ((void *) d_this->d_hwnd); + setType (MX_TREEVIEW); + setParent (parent); + setId (id); +} + + + +mxTreeView::~mxTreeView () +{ + remove (0); + delete d_this; +} + + + +mxTreeViewItem* +mxTreeView::add (mxTreeViewItem *parent, const char *item) +{ + if (!d_this) + return 0; + + TV_ITEM tvItem; + tvItem.mask = TVIF_TEXT; + tvItem.pszText = (LPSTR) item; + tvItem.cchTextMax = 256; + + HTREEITEM hParent; + if (!parent) + hParent = TVI_ROOT; + else + hParent = (HTREEITEM) parent; + + TV_INSERTSTRUCT tvInsert; + tvInsert.hParent = hParent; + tvInsert.hInsertAfter = TVI_LAST; + tvInsert.item = tvItem; + + return (mxTreeViewItem *) TreeView_InsertItem (d_this->d_hwnd, &tvInsert); +} + + +void +mxTreeView::remove (mxTreeViewItem *item) +{ + if (!d_this) + return; + + if (!item) + TreeView_DeleteAllItems (d_this->d_hwnd); + else + TreeView_DeleteItem (d_this->d_hwnd, (HTREEITEM) item); +} + +void +mxTreeView::removeAll () +{ + remove( 0 ); +} + +void +mxTreeView::setLabel (mxTreeViewItem *item, const char *label) +{ + if (!d_this) + return; + + if (item) + { + TV_ITEM tvItem; + tvItem.mask = TVIF_HANDLE | TVIF_TEXT; + tvItem.hItem = (HTREEITEM) item; + tvItem.pszText = (LPSTR) label; + tvItem.cchTextMax = 256; + + TreeView_SetItem (d_this->d_hwnd, &tvItem); + } +} + + + +void +mxTreeView::setUserData (mxTreeViewItem *item, void *userData) +{ + if (!d_this) + return; + + if (item) + { + TV_ITEM tvItem; + tvItem.mask = TVIF_HANDLE | TVIF_PARAM; + tvItem.hItem = (HTREEITEM) item; + tvItem.lParam = (LPARAM) userData; + + TreeView_SetItem (d_this->d_hwnd, &tvItem); + } +} + + + +void +mxTreeView::setOpen (mxTreeViewItem *item, bool b) +{ + if (!d_this) + return; + + if (item) + TreeView_Expand (d_this->d_hwnd, (HTREEITEM) item, b ? TVE_EXPAND:TVE_COLLAPSE); +} + + + +void +mxTreeView::setSelected (mxTreeViewItem *item, bool b) +{ + if (!d_this) + return; + + if (item) + TreeView_SelectItem (d_this->d_hwnd, (HTREEITEM) item); +} + + + +mxTreeViewItem* +mxTreeView::getFirstChild (mxTreeViewItem *item) const +{ + if (!d_this) + return 0; + + return (mxTreeViewItem *) TreeView_GetChild (d_this->d_hwnd, item ? (HTREEITEM) item:TVI_ROOT); +} + + + +mxTreeViewItem* +mxTreeView::getNextChild (mxTreeViewItem *item) const +{ + if (!d_this) + return 0; + + if (item) + return (mxTreeViewItem *) TreeView_GetNextSibling (d_this->d_hwnd, (HTREEITEM) item); + else + return 0; +} + + + +mxTreeViewItem* +mxTreeView::getSelectedItem () const +{ + if (!d_this) + return 0; + + return (mxTreeViewItem *) TreeView_GetSelection (d_this->d_hwnd); +} + + + +const char* +mxTreeView::getLabel (mxTreeViewItem *item) const +{ + static char label[256]; + strcpy (label, ""); + + if (!d_this) + return label; + + if (item) + { + TV_ITEM tvItem; + tvItem.mask = TVIF_HANDLE | TVIF_TEXT; + tvItem.hItem = (HTREEITEM) item; + tvItem.pszText = (LPSTR) label; + tvItem.cchTextMax = 256; + + TreeView_GetItem (d_this->d_hwnd, &tvItem); + + return tvItem.pszText; + } + + return label; +} + + + +void* +mxTreeView::getUserData (mxTreeViewItem *item) const +{ + if (!d_this) + return 0; + + if (item) + { + TV_ITEM tvItem; + tvItem.mask = TVIF_HANDLE | TVIF_PARAM; + tvItem.hItem = (HTREEITEM) item; + + TreeView_GetItem (d_this->d_hwnd, &tvItem); + + return (void *) tvItem.lParam; + } + + return 0; +} + + + +bool +mxTreeView::isOpen (mxTreeViewItem *item) const +{ + if (!d_this) + return false; + + if (item) + { + TV_ITEM tvItem; + tvItem.mask = TVIF_HANDLE | TVIF_STATE; + tvItem.hItem = (HTREEITEM) item; + tvItem.stateMask = TVIS_STATEIMAGEMASK; + + TreeView_GetItem (d_this->d_hwnd, &tvItem); + + return ((tvItem.state & TVIS_EXPANDED) == TVIS_EXPANDED); + } + + return false; +} + + + +bool +mxTreeView::isSelected (mxTreeViewItem *item) const +{ + if (!d_this) + return false; + + if (item) + { + TV_ITEM tvItem; + tvItem.mask = TVIF_HANDLE | TVIF_STATE; + tvItem.hItem = (HTREEITEM) item; + tvItem.stateMask = TVIS_STATEIMAGEMASK; + + TreeView_GetItem (d_this->d_hwnd, &tvItem); + + return ((tvItem.state & TVIS_SELECTED) == TVIS_SELECTED); + } + + return false; +} + + + +mxTreeViewItem * +mxTreeView::getParent (mxTreeViewItem *item) const +{ + if (!d_this) + return 0; + + if (item) + return (mxTreeViewItem *) TreeView_GetParent (d_this->d_hwnd, (HTREEITEM) item); + + return 0; +} + +void mxTreeView::setImageList( void *himagelist ) +{ + TreeView_SetImageList(d_this->d_hwnd, (HIMAGELIST)himagelist, TVSIL_NORMAL); +} + +void mxTreeView::setImages(mxTreeViewItem *item, int imagenormal, int imageselected ) +{ + if (!d_this) + return; + + if (item) + { + TV_ITEM tvItem; + tvItem.mask = TVIF_HANDLE | TVIF_SELECTEDIMAGE | TVIF_IMAGE ; + tvItem.hItem = (HTREEITEM) item; + tvItem.iImage = imagenormal; + tvItem.iSelectedImage = imageselected; + tvItem.stateMask = TVIS_STATEIMAGEMASK; + + TreeView_SetItem (d_this->d_hwnd, &tvItem); + } +} +void mxTreeView::sortTree( mxTreeViewItem *parent, bool recurse, + void *func, int parameter ) +{ + if (!d_this) + return; + + TVSORTCB cb; + memset( &cb, 0, sizeof( cb ) ); + + cb.hParent = (HTREEITEM)parent; + cb.lParam = parameter; + cb.lpfnCompare = (int (__stdcall *)(long,long,long)) func; + + TreeView_SortChildrenCB( d_this->d_hwnd, &cb, recurse ); +} + +void mxTreeView::scrollTo( mxTreeViewItem *item ) +{ + if (!d_this) + return; + + TreeView_EnsureVisible( d_this->d_hwnd, item ); +} diff --git a/utils/mxtk/mxwidget.cpp b/utils/mxtk/mxwidget.cpp new file mode 100644 index 0000000..a7e6b26 --- /dev/null +++ b/utils/mxtk/mxwidget.cpp @@ -0,0 +1,306 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxWidget.cpp +// implementation: Win32 API +// last modified: Mar 19 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxWidget.h" +#include <windows.h> +#include <commctrl.h> +#include <string.h> +#include <stdlib.h> +#include <stdio.h> + +void mxTab_resizeChild (HWND hwnd); +void mx_addWidget (mxWidget *widget); +void mx_removeWidget (mxWidget *widget); + + + +class mxWidget_i +{ +public: + mxWindow *d_parent_p; + HWND d_hwnd; + void *d_userData; + int d_type; +}; + + + +mxWidget::mxWidget (mxWindow *parent, int x, int y, int w, int h, const char *label) +{ + d_this = new mxWidget_i; + + setHandle (0); + setType (-1); + setParent (parent); + setBounds (x, y, w, h); + setVisible (true); + setEnabled (true); + setId (0); + setUserData (0); + setLabel (label); + + mx_addWidget (this); +} + + + +mxWidget::~mxWidget () +{ + mx_removeWidget (this); + + if (d_this->d_type == MX_MENU || + d_this->d_type == MX_MENUBAR || + d_this->d_type == MX_POPUPMENU) + DestroyMenu ((HMENU) d_this->d_hwnd); + else + DestroyWindow (d_this->d_hwnd); + + delete d_this; +} + +bool mxWidget::CanClose() +{ + // Assume yes + return true; +} + +void mxWidget::OnDelete() +{ + // Nothing +} + +void +mxWidget::setHandle (void *handle) +{ + d_this->d_hwnd = (HWND) handle; +} + + + +void +mxWidget::setType (int type) +{ + d_this->d_type = type; +} + + + +void +mxWidget::setParent (mxWindow *parentWindow) +{ + d_this->d_parent_p = parentWindow; +} + + + +void +mxWidget::setBounds (int x, int y, int w, int h) +{ + char str[128]; + GetClassName (d_this->d_hwnd, str, 128); + + if (!strcmp (str, "COMBOBOX")) + MoveWindow (d_this->d_hwnd, x, y, w, h + 100, TRUE); + else + MoveWindow (d_this->d_hwnd, x, y, w, h, TRUE); + + if (!strcmp (str, WC_TABCONTROL)) + mxTab_resizeChild (d_this->d_hwnd); +} + + + +void +mxWidget::setLabel (const char *format, ... ) +{ + if (format == NULL) + { + if (d_this->d_hwnd) + { + SetWindowText (d_this->d_hwnd, NULL); + } + return; + } + + va_list argptr; + static char string[1024]; + + va_start (argptr, format); + vsprintf (string, format,argptr); + va_end (argptr); + + if (d_this->d_hwnd) + { + SetWindowText (d_this->d_hwnd, string); + } +} + + +void +mxWidget::setVisible (bool b) +{ + if (b) + SetWindowPos (d_this->d_hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); + else + ShowWindow (d_this->d_hwnd, SW_HIDE); +} + + + +void +mxWidget::setEnabled (bool b) +{ + EnableWindow (d_this->d_hwnd, b); +} + + + +void +mxWidget::setId (int id) +{ + SetWindowLong (d_this->d_hwnd, GWL_ID, (LONG) id); +} + + + +void +mxWidget::setUserData (void *userData) +{ + d_this->d_userData = userData; +} + + + +void* +mxWidget:: getHandle () const +{ + return (void *) d_this->d_hwnd; +} + + + +int +mxWidget::getType () const +{ + return d_this->d_type; +} + + + +mxWindow* +mxWidget::getParent () const +{ + return d_this->d_parent_p; +} + + + +int +mxWidget::x () const +{ + RECT rc; + GetWindowRect (d_this->d_hwnd, &rc); + return (int) rc.left; +} + + + +int +mxWidget::y () const +{ + RECT rc; + GetWindowRect (d_this->d_hwnd, &rc); + return (int) rc.top; +} + + + +int +mxWidget::w () const +{ + RECT rc; + GetWindowRect (d_this->d_hwnd, &rc); + return (int) (rc.right - rc.left); +} + + + +int +mxWidget::h () const +{ + RECT rc; + GetWindowRect (d_this->d_hwnd, &rc); + return (int) (rc.bottom - rc.top); +} + + + +int +mxWidget::w2 () const +{ + RECT rc; + GetClientRect (d_this->d_hwnd, &rc); + return (int) (rc.right - rc.left); +} + + + +int +mxWidget::h2 () const +{ + RECT rc; + GetClientRect (d_this->d_hwnd, &rc); + return (int) (rc.bottom - rc.top); +} + + + +const char* +mxWidget::getLabel () const +{ + static char label[256]; + GetWindowText (d_this->d_hwnd, label, 256); + return label; +} + + + +bool +mxWidget::isVisible () const +{ + return ( IsWindowVisible (d_this->d_hwnd) ? true : false ); +} + + + +bool +mxWidget::isEnabled () const +{ + return ( IsWindowEnabled (d_this->d_hwnd) ? true : false ); +} + + + +int +mxWidget::getId () const +{ + return (int) GetWindowLong (d_this->d_hwnd, GWL_ID); +} + + + +void* +mxWidget::getUserData () const +{ + return d_this->d_userData; +} diff --git a/utils/mxtk/mxwindow.cpp b/utils/mxtk/mxwindow.cpp new file mode 100644 index 0000000..83c6b1c --- /dev/null +++ b/utils/mxtk/mxwindow.cpp @@ -0,0 +1,113 @@ +// +// mxToolKit (c) 1999 by Mete Ciragan +// +// file: mxWindow.cpp +// implementation: Win32 API +// last modified: Apr 12 1999, Mete Ciragan +// copyright: The programs and associated files contained in this +// distribution were developed by Mete Ciragan. The programs +// are not in the public domain, but they are freely +// distributable without licensing fees. These programs are +// provided without guarantee or warrantee expressed or +// implied. +// +#include "mxtk/mxWindow.h" +#include <windows.h> + + + +extern mxWindow *g_mainWindow; + + + +class mxWindow_i +{ +public: + UINT d_uTimer; +}; + + + +mxWindow::mxWindow (mxWindow *parent, int x, int y, int w, int h, const char *label, int style) +: mxWidget (parent, x, y, w, h, label) +{ + d_this = new mxWindow_i; + d_this->d_uTimer = 0; + + DWORD dwStyle = 0; + if (style == Normal) + dwStyle = WS_OVERLAPPEDWINDOW; + else if (style == Popup) + dwStyle = WS_POPUP; + else if (style == Dialog || style == ModalDialog) + dwStyle = WS_CAPTION | WS_SYSMENU; + + void *parentHandle = 0; + if (parent) + { + parentHandle = parent->getHandle (); + dwStyle = WS_CHILD | WS_VISIBLE; + } + + void *handle = (void *) CreateWindowEx (0, "mx_class", label, dwStyle, + x, y, w, h, (HWND) parentHandle, + (HMENU) NULL, (HINSTANCE) GetModuleHandle (NULL), NULL); + + SetWindowLong ((HWND) handle, GWL_USERDATA, reinterpret_cast< LONG >( this ) ); + + setHandle (handle); + setType (MX_WINDOW); + setParent (parent); + //setLabel (label); + //setBounds (x, y, w, h); + + if (!parent && !g_mainWindow) + g_mainWindow = this; +} + + + +mxWindow::~mxWindow () +{ + SetWindowLong ((HWND) (HWND) getHandle(), GWL_USERDATA, (LONG) 0 ); + delete d_this; +} + + + +int +mxWindow::handleEvent (mxEvent * /*event*/ ) +{ + return 0; +} + + + +void +mxWindow::redraw () +{ +} + +void +mxWindow::setTimer (int milliSeconds) +{ + if (d_this->d_uTimer) + { + KillTimer ((HWND) getHandle (), d_this->d_uTimer); + d_this->d_uTimer = 0; + } + + if (milliSeconds > 0) + { + d_this->d_uTimer = 21001; + d_this->d_uTimer = (UINT)SetTimer ((HWND) getHandle (), d_this->d_uTimer, milliSeconds, NULL); + } +} + + + +void +mxWindow::setMenuBar (mxMenuBar *menuBar) +{ + SetMenu ((HWND) getHandle (), (HMENU) ((mxWidget *) menuBar)->getHandle ()); +} |