HICON image_make_icon_handle( Handle img, Point size, Point * hotSpot) { PIcon i = ( PIcon) img; HICON r; ICONINFO ii; int bpp = i-> type & imBPP; Bool noSZ = i-> w != size. x || i-> h != size. y; Bool noBPP = bpp != 1 && bpp != 4 && bpp != 8 && bpp != 24; HDC dc; XBITMAPINFO bi; Bool notAnIcon = !kind_of( img, CIcon); ii. fIcon = hotSpot ? false : true; ii. xHotspot = hotSpot ? hotSpot-> x : 0; ii. yHotspot = hotSpot ? hotSpot-> y : 0; if ( noSZ || noBPP) { i = ( PIcon)( i-> self-> dup( img)); if ( noSZ) i-> self-> set_size(( Handle) i, size); if ( noBPP) i-> self-> set_type(( Handle) i, ( bpp < 4) ? 1 : (( bpp < 8) ? 4 : (( bpp < 24) ? 8 : 24)) ); } if (!( dc = dc_alloc())) { if (( Handle) i != img) Object_destroy(( Handle) i); return NULL; } image_get_binfo(( Handle)i, &bi); if ( bi. bmiHeader. biClrUsed > 0) bi. bmiHeader. biClrUsed = bi. bmiHeader. biClrImportant = i-> palSize; if ( !( ii. hbmColor = CreateDIBitmap( dc, &bi. bmiHeader, CBM_INIT, i-> data, ( BITMAPINFO*) &bi, DIB_RGB_COLORS))) apiErr; bi. bmiHeader. biBitCount = bi. bmiHeader. biPlanes = 1; bi. bmiColors[ 0]. rgbRed = bi. bmiColors[ 0]. rgbGreen = bi. bmiColors[ 0]. rgbBlue = 0; bi. bmiColors[ 1]. rgbRed = bi. bmiColors[ 1]. rgbGreen = bi. bmiColors[ 1]. rgbBlue = 255; if ( !( ii. hbmMask = CreateDIBitmap( dc, &bi. bmiHeader, CBM_INIT, notAnIcon ? NULL : i-> mask, ( BITMAPINFO*) &bi, DIB_RGB_COLORS))) apiErr; dc_free(); if ( !( r = CreateIconIndirect( &ii))) apiErr; DeleteObject( ii. hbmColor); DeleteObject( ii. hbmMask); if (( Handle) i != img) Object_destroy(( Handle) i); return r; }
Bool apc_dbm_create( Handle self, Bool monochrome) { Bool palc = 0; objCheck false; apcErrClear; apt_set( aptBitmap); apt_set( aptDeviceBitmap); apt_set( aptCompatiblePS); if ( !( sys ps = CreateCompatibleDC( 0))) apiErrRet; sys lastSize. x = var w; sys lastSize. y = var h; if ( monochrome) sys bm = CreateBitmap( var w, var h, 1, 1, nil); else { HDC dc; if (!( dc = dc_alloc())) { DeleteDC( sys ps); return false; } if (( sys pal = palette_create( self))) { sys stockPalette = SelectPalette( sys ps, sys pal, 1); RealizePalette( sys ps); palc = 1; } sys bm = CreateCompatibleBitmap( dc, var w, var h); if ( guts. displayBMInfo. bmiHeader. biBitCount == 8) apt_clear( aptCompatiblePS); } if ( !sys bm) { apiErr; if ( !monochrome) dc_free(); if ( palc) { SelectPalette( sys ps, sys stockPalette, 1); DeleteObject( sys stockPalette); sys stockPalette = nil; } DeleteDC( sys ps); return false; } if ( !monochrome) dc_free(); sys stockBM = SelectObject( sys ps, sys bm); hwnd_enter_paint( self); if ( monochrome) sys bpp = 1; hash_store( imageMan, &self, sizeof( self), (void*)self); return true; }
void * dc_realloc(void * ptr, size_t size) { if(!ptr){ ptr = dc_alloc(size); return ptr; } if(size == 0){ dc_free(ptr); return NULL; } void * word_before_ptr = (void *)((uint64 *)ptr - 1); void * new_ptr; uint64 cap = *(uint64 *)word_before_ptr; if(size <= POW2(cap)){ printf("dc_mm : %s","reallocate but return the original pointer."); return ptr; } new_ptr = dc_alloc(size); memcpy(new_ptr, ptr, POW2(cap)); dc_free(ptr); printf("dc_mm : %s","reallocation finished"); return new_ptr; }
void dbm_recreate( Handle self) { HBITMAP bm, stock; HDC dc, dca; HPALETTE p = nil; if ((( PDeviceBitmap) self)-> monochrome) return; if ( !( dc = CreateCompatibleDC( 0))) { apiErr; return; } if (!( dca = dc_alloc())) { DeleteDC( dc); return; } if ( sys pal) { p = SelectPalette( dc, sys pal, 1); RealizePalette( dc); } if ( !( bm = CreateCompatibleBitmap( dca, var w, var h))) { DeleteDC( dc); dc_free(); apiErr; return; } stock = SelectObject( dc, bm); BitBlt( dc, 0, 0, var w, var h, sys ps, 0, 0, SRCCOPY); if ( sys pal) { SelectPalette( sys ps, sys stockPalette, 1); sys stockPalette = p; } else sys stockPalette = GetCurrentObject( dc, OBJ_PAL); if ( sys stockBM) SelectObject( sys ps, sys stockBM); DeleteObject( sys bm); DeleteDC( sys ps); sys ps = dc; sys bm = bm; sys stockBM = stock; dc_free(); }
/* select a node frome the extra idle list */ void * select_extra(uint64 cap) { void * ptr , * chunk_ptr; if(0 == elm_table[cap]->idle_num) return dc_alloc(POW2(cap)); pthread_mutex_lock(extra_mutex[cap]); ptr = pop(elm_table[cap]->chunks_list); append(ptr,elm_table[cap]->chunks_list); --(elm_table[cap]->idle_num); extra_apply[cap]++; pthread_mutex_unlock(extra_mutex[cap]); chunk_ptr = (void *)((uint64 *)ptr + 1); printf("dc_mm : %s%8ld%s\n","select a specific capacity ", POW2(cap), " Bytes form extra chunks list."); return chunk_ptr; }
/* select a node from the pre-allocated idle list */ void * select_pre_alloced(uint64 cap) { int pos = cap - SMALL; /* position of the pointer in the array. */ void * ptr , * chunk_ptr; if(0 == chunks_manager_table[pos]->idle_num) return dc_alloc(POW2(cap)); pthread_mutex_lock(pre_alloc_mutex[pos]); ptr = pop(chunks_manager_table[pos]->idle_chunks); push(ptr,chunks_manager_table[pos]->alloced_chunks); --(chunks_manager_table[pos]->idle_num); pre_alloc_apply[pos]++; pthread_mutex_unlock(pre_alloc_mutex[pos]); chunk_ptr = (void *)((uint64 *)ptr + 1); printf("dc_mm : %s%8ld%s\n","select a specific capacity ", POW2(cap), " Bytes form pre-allocated chunks list."); return chunk_ptr; }
void image_query_bits( Handle self, Bool forceNewImage) { PImage i = ( PImage) self; XBITMAPINFO xbi; BITMAPINFO * bi; int newBits; HDC ops = nil; BITMAP bitmap; if ( forceNewImage) { ops = sys ps; if ( !ops) { if ( !( sys ps = dc_alloc())) return; } } if ( !GetObject( sys bm, sizeof( BITMAP), ( LPSTR) &bitmap)) { apiErr; return; // if GetObject fails to get even BITMAP, there will be no good in farther run for sure. } if (( bitmap. bmPlanes == 1) && ( ( bitmap. bmBitsPixel == 1) || ( bitmap. bmBitsPixel == 4) || ( bitmap. bmBitsPixel == 8) || ( bitmap. bmBitsPixel == 24) )) newBits = bitmap. bmBitsPixel; else { newBits = ( bitmap. bmBitsPixel <= 4) ? 4 : (( bitmap. bmBitsPixel <= 8) ? 8 : 24); } if ( forceNewImage) { i-> self-> create_empty( self, bitmap. bmWidth, bitmap. bmHeight, newBits); } else { if (( newBits != ( i-> type & imBPP)) || (( i-> type & ~imBPP) != 0)) i-> self-> create_empty( self, i-> w, i-> h, newBits); } bi = image_get_binfo( self, &xbi); if ( !GetDIBits( sys ps, sys bm, 0, i-> h, i-> data, bi, DIB_RGB_COLORS)) apiErr; if (( i-> type & imBPP) < 24) { int j, nColors = 1 << ( i-> type & imBPP); for ( j = 0; j < nColors; j++) { i-> palette[ j]. r = xbi. bmiColors[ j]. rgbRed; i-> palette[ j]. g = xbi. bmiColors[ j]. rgbGreen; i-> palette[ j]. b = xbi. bmiColors[ j]. rgbBlue; } } if ( forceNewImage) { if ( !ops) { dc_free(); } sys ps = ops; } }
Bool window_subsystem_init( char * error_buf) { WNDCLASSW wc; HDC dc; HBITMAP hbm; OSVERSIONINFO os = { sizeof( OSVERSIONINFO)}; guts. version = GetVersion(); GetVersionEx( &os); guts. alloc_utf8_to_wchar_visual = (( os.dwMajorVersion > 5) || (os.dwMajorVersion == 5 && os.dwMinorVersion > 1)) ? alloc_utf8_to_wchar_visual : alloc_utf8_to_wchar; guts. mainThreadId = GetCurrentThreadId(); guts. errorMode = SetErrorMode( SEM_FAILCRITICALERRORS); guts. desktopWindow = GetDesktopWindow(); memset( &wc, 0, sizeof( wc)); wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; wc.lpfnWndProc = ( WNDPROC) generic_app_handler; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = guts. instance; wc.hIcon = LoadIcon( guts. instance, IDI_APPLICATION); wc.hCursor = LoadCursor( NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)NULL; wc.lpszClassName = L"GenericApp"; RegisterClassW( &wc); memset( &wc, 0, sizeof( wc)); wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; wc.lpfnWndProc = ( WNDPROC) generic_frame_handler; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = guts. instance; wc.hIcon = LoadIcon( guts. instance, IDI_APPLICATION); wc.hCursor = LoadCursor( NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)NULL; wc.lpszClassName = L"GenericFrame"; RegisterClassW( &wc); memset( &wc, 0, sizeof( wc)); wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; wc.lpfnWndProc = ( WNDPROC) generic_view_handler; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = guts. instance; wc.hIcon = LoadIcon( guts. instance, IDI_APPLICATION); wc.hCursor = NULL; // LoadCursor( NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)NULL; wc.lpszClassName = L"Generic"; RegisterClassW( &wc); stylusMan = hash_create(); fontMan = hash_create(); patMan = hash_create(); menuMan = hash_create(); imageMan = hash_create(); regnodeMan = hash_create(); create_font_hash(); { LOGBRUSH b = { BS_HOLLOW, 0, 0}; Font f; hPenHollow = CreatePen( PS_NULL, 0, 0); hBrushHollow = CreateBrushIndirect( &b); hPatHollow. dotsCount = 0; hPatHollow. dotsPtr = nil; FONTSTRUCSIZE = (char *)(&(f. name)) - (char *)(&f); } if (!( dc = dc_alloc())) return false; guts. displayResolution. x = GetDeviceCaps( dc, LOGPIXELSX); guts. displayResolution. y = GetDeviceCaps( dc, LOGPIXELSY); { LOGFONT lf; HFONT sfont; // getting most common font name memset( &lf, 0, sizeof( lf)); lf. lfCharSet = OEM_CHARSET; lf. lfOutPrecision = OUT_DEFAULT_PRECIS; lf. lfClipPrecision = CLIP_DEFAULT_PRECIS; lf. lfQuality = PROOF_QUALITY; lf. lfPitchAndFamily = DEFAULT_PITCH; sfont = SelectObject( dc, CreateFontIndirect( &lf)); GetTextFace( dc, 256, guts. defaultSystemFont); // getting common fixed font name lf. lfHeight = 320; lf. lfPitchAndFamily = FIXED_PITCH; DeleteObject( SelectObject( dc, CreateFontIndirect( &lf))); GetTextFace( dc, 256, guts. defaultFixedFont); // getting common variable font name lf. lfPitchAndFamily = VARIABLE_PITCH; DeleteObject( SelectObject( dc, CreateFontIndirect( &lf))); GetTextFace( dc, 256, guts. defaultVariableFont); DeleteObject( SelectObject( dc, sfont)); // getting system font presets memset( &guts. windowFont, 0, sizeof( Font)); strcpy( guts. windowFont. name, DEFAULT_WIDGET_FONT); guts. windowFont. size = DEFAULT_WIDGET_FONT_SIZE; guts. windowFont. width = guts. windowFont. height = C_NUMERIC_UNDEF; #ifdef FONT_CHECK guts. windowFont. size = 12; #endif apc_font_pick( nilHandle, &guts. windowFont, &guts. windowFont); guts. ncmData. cbSize = sizeof( NONCLIENTMETRICS); SystemParametersInfo( SPI_GETNONCLIENTMETRICS, sizeof( NONCLIENTMETRICS), ( PVOID) &guts. ncmData, 0); font_logfont2font( &guts. ncmData. lfMenuFont, &guts. menuFont, &guts. displayResolution); font_logfont2font( &guts. ncmData. lfMessageFont, &guts. msgFont, &guts. displayResolution); font_logfont2font( &guts. ncmData. lfCaptionFont, &guts. capFont, &guts. displayResolution); } memset( &guts. displayBMInfo, 0, sizeof( guts. displayBMInfo)); guts. displayBMInfo. bmiHeader. biSize = sizeof( BITMAPINFO); if ( !( hbm = GetCurrentObject( dc, OBJ_BITMAP))) { apiErr; dc_free(); return false; } if ( !GetDIBits( dc, hbm, 0, 0, NULL, &guts. displayBMInfo, DIB_PAL_COLORS)) { guts. displayBMInfo. bmiHeader. biBitCount = GetDeviceCaps( dc, BITSPIXEL); guts. displayBMInfo. bmiHeader. biPlanes = GetDeviceCaps( dc, PLANES); } dc_free(); guts. insertMode = true; guts. iconSizeSmall. x = GetSystemMetrics( SM_CXSMICON); guts. iconSizeSmall. y = GetSystemMetrics( SM_CYSMICON); guts. iconSizeLarge. x = GetSystemMetrics( SM_CXICON); guts. iconSizeLarge. y = GetSystemMetrics( SM_CYICON); guts. pointerSize. x = GetSystemMetrics( SM_CXCURSOR); guts. pointerSize. y = GetSystemMetrics( SM_CYCURSOR); list_create( &guts. transp, 8, 8); list_create( &guts. files, 8, 8); list_create( &guts. sockets, 8, 8); // selecting locale layout, more or less latin-like { char buf[ KL_NAMELENGTH * 2] = ""; HKL current = GetKeyboardLayout( 0); int i, j, size = GetKeyboardLayoutList( 0, nil); HKL * kl = ( HKL *) malloc( sizeof( HKL) * size); guts. keyLayout = nil; if ( !GetKeyboardLayoutName( buf)) apiErr; for ( j = 0; j < ( sizeof( keyLayouts) / sizeof( char*)); j++) { if ( strncmp( buf + 4, keyLayouts[ j], 4) == 0) { guts. keyLayout = current; goto found_1; } } if ( kl) { GetKeyboardLayoutList( size, kl); for ( i = 0; i < size; i++) { ActivateKeyboardLayout( kl[ i], 0); if ( !GetKeyboardLayoutName( buf)) apiErr; for ( j = 0; j < ( sizeof( keyLayouts) / sizeof( char*)); j++) { if ( strncmp( buf + 4, keyLayouts[ j], 4) == 0) { guts. keyLayout = kl[ i]; goto found_2; } } } found_2:; ActivateKeyboardLayout( current, 0); } found_1:; free( kl); } guts. currentKeyState = guts. keyState; memset( guts. emptyKeyState, 0, sizeof( guts. emptyKeyState)); guts. smDblClk. x = GetSystemMetrics( SM_CXDOUBLECLK); guts. smDblClk. y = GetSystemMetrics( SM_CYDOUBLECLK); return true; }